| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-12-13 18:37:07 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-12-13 18:37:07 +0100 | 
| commit | 6e983617288abafcdcfd7fcf26fc246302a388f7 (patch) | |
| tree | 72658bf42400e808579a019d7dcd86d868442c93 /src/ataxia_client.erl | |
| parent | 730ac64b4f5a680a6f32c8a0bedccf500444fdc6 (diff) | |
...
Diffstat (limited to 'src/ataxia_client.erl')
| -rw-r--r-- | src/ataxia_client.erl | 297 | 
1 files changed, 270 insertions, 27 deletions
| diff --git a/src/ataxia_client.erl b/src/ataxia_client.erl index 95b544f..a2e47a8 100644 --- a/src/ataxia_client.erl +++ b/src/ataxia_client.erl @@ -10,12 +10,24 @@  -export  (     [ -      insert_at/5, -      insert/4, -      remove/3, -      fetch/4, +      add/4, +      add_at/5,        reserve/3, -      commit/4 + +      fetch/4, +      update/4, +      lock/4, +      remove/3, + +      fetch_any/4, +      update_any/4, +      lock_any/4, +      remove_any/3, + +      fetch_all/4, +      update_all/4, +      lock_all/4, +      remove_all/3     ]  ). @@ -36,7 +48,7 @@ get_db_node_for (_ObjectID) ->  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec insert_at +-spec add_at     (        atom(),        binary(), @@ -45,7 +57,7 @@ get_db_node_for (_ObjectID) ->        any()     )     -> ({'aborted', any()} | 'ok'). -insert_at (DB, ID, ReadPerm, WritePerm, Value) -> +add_at (DB, ID, ReadPerm, WritePerm, Value) ->     DBNode = get_db_node_for(ID),     Reply = @@ -53,19 +65,19 @@ insert_at (DB, ID, ReadPerm, WritePerm, Value) ->        (           DBNode,           atexia_server, -         insert_at, +         add_at,           [DB, ID, ReadPerm, WritePerm, Value]        ),     io:format     ( -      "~nshr_database:insert_at(~p) ! ~p -> ~p.~n", +      "~nataxia_client:add_at(~p) ! ~p -> ~p.~n",        [{DB, ID, ReadPerm, WritePerm, Value}, DBNode, Reply]     ),     Reply. --spec insert +-spec add     (        atom(),        ataxia_security:permission(), @@ -73,20 +85,42 @@ insert_at (DB, ID, ReadPerm, WritePerm, Value) ->        any()     )     -> ({'ok', ataxia_id:type()} | {'aborted', any()}). -insert (DB, ReadPerm, WritePerm, Value) -> +add (DB, ReadPerm, WritePerm, Value) ->     DBNode = get_random_db_node(),     Reply = -      rpc:call(DBNode, atexia_server, insert, [DB, ReadPerm, WritePerm, Value]), +      rpc:call(DBNode, atexia_server, add, [DB, ReadPerm, WritePerm, Value]),     io:format     ( -      "~nshr_database:insert(~p) ! ~p -> ok.~n", +      "~nataxia_client:add(~p) ! ~p -> ok.~n",        [{DB, ReadPerm, WritePerm, Value}, DBNode]     ),     Reply. +-spec reserve +   ( +      atom(), +      ataxia_security:user(), +      ataxia_id:type() +   ) +   -> ('ok' | 'unavailable'). +reserve (DB, User, ID) -> +   DBNode = get_db_node_for(ID), + +   Reply = rpc:call(DBNode, atexia_server, reserve, [DB, User, ID]), + +   io:format +   ( +      "~nataxia_client:reserve(~p) ! ~p -> ~p.~n", +      [{DB, User, ID}, DBNode, Reply] +   ), + +   Reply. + + +%%%% BY ID %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -spec fetch     (        atom(), @@ -98,17 +132,17 @@ insert (DB, ReadPerm, WritePerm, Value) ->  fetch (DB, User, Selector, ID) ->     DBNode = get_db_node_for(ID), -   Reply = rpc:call(DBNode, atexia_server, read, [DB, User, Selector, ID]), +   Reply = rpc:call(DBNode, atexia_server, fetch, [DB, User, Selector, ID]),     io:format     ( -      "~nshr_database:fetch(~p) ! ~p -> ~p.~n", +      "~nataxia_client:fetch(~p) ! ~p -> ~p.~n",        [{DB, User, Selector, ID}, DBNode, Reply]     ),     Reply. --spec commit +-spec update     (        atom(),        ataxia_security:user(), @@ -116,19 +150,41 @@ fetch (DB, User, Selector, ID) ->        ataxia_id:type()     )     -> ('ok' | 'not_found'). -commit (DB, User, Op, ID) -> +update (DB, User, Op, ID) ->     DBNode = get_db_node_for(ID), -   Reply = rpc:call(DBNode, atexia_server, query, [DB, User, Op, ID]), +   Reply = rpc:call(DBNode, atexia_server, update, [DB, User, Op, ID]),     io:format     ( -      "~nataxia_client:commit(~p) ! ~p -> ~p.~n", +      "~nataxia_client:update(~p) ! ~p -> ~p.~n",        [{DB, User, Op, ID}, DBNode, Reply]     ),     Reply. +-spec lock +   ( +      atom(), +      ataxia_security:user(), +      ataxia_time:type(), +      ataxia_id:type() +   ) +   -> ('ok' | 'not_found'). +lock (DB, User, Duration, ID) -> +   DBNode = get_db_node_for(ID), + +   Reply = rpc:call(DBNode, atexia_server, lock, [DB, User, Duration, ID]), + +   io:format +   ( +      "~nataxia_client:lock(~p) ! ~p -> ~p.~n", +      [{DB, User, Duration, ID}, DBNode, Reply] +   ), + +   Reply. + +  -spec remove     (        atom(), @@ -149,22 +205,209 @@ remove (DB, User, ID) ->     Reply. --spec reserve +%%%% ONE, BY CONDITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec fetch_any     (        atom(),        ataxia_security:user(), -      ataxia_id:type() +      ataxic:type(), +      ataxic:meta()     ) -   -> ('ok' | 'unavailable'). -reserve (DB, User, ID) -> -   DBNode = get_db_node_for(ID), +   -> ({'ok', ataxia_id:type(), any()} | 'not_found'). +fetch_any (DB, User, Selector, Condition) -> +   % TODO: Try all nodes one by one until one is found. +   DBNode = get_db_node_for(<<"">>), -   Reply = rpc:call(DBNode, atexia_server, reserve, [DB, User, ID]), +   Reply = +      rpc:call +      ( +         DBNode, +         atexia_server, +         fetch_any, +         [DB, User, Selector, Condition] +      ),     io:format     ( -      "~nataxia_client:reserve(~p) ! ~p -> ~p.~n", -      [{DB, User, ID}, DBNode, Reply] +      "~nataxia_client:fetch_any(~p) ! ~p -> ~p.~n", +      [{DB, User, Selector, Condition}, DBNode, Reply] +   ), + +   Reply. + +-spec update_any +   ( +      atom(), +      ataxia_security:user(), +      ataxiac:meta(), +      ataxiac:meta() +   ) +   -> ({'ok', ataxia_id:type()} | 'not_found'). +update_any (DB, User, Op, Condition) -> +   % TODO: Try all nodes one by one until one is found. +   DBNode = get_db_node_for(<<"">>), + +   Reply = +      rpc:call(DBNode, atexia_server, update_any, [DB, User, Op, Condition]), + +   io:format +   ( +      "~nataxia_client:update(~p) ! ~p -> ~p.~n", +      [{DB, User, Op, Condition}, DBNode, Reply]     ),     Reply. + +-spec lock_any +   ( +      atom(), +      ataxia_security:user(), +      ataxia_time:type(), +      ataxic:meta() +   ) +   -> ({'ok', ataxia_id:type()} | 'not_found'). +lock_any (DB, User, Duration, Condition) -> +   % TODO: Try all nodes one by one until one is found. +   DBNode = get_db_node_for(<<"">>), + +   Reply = +      rpc:call +      ( +         DBNode, +         atexia_server, +         lock_any, +         [DB, User, Duration, Condition] +      ), + +   io:format +   ( +      "~nataxia_client:lock_any(~p) ! ~p -> ~p.~n", +      [{DB, User, Duration, Condition}, DBNode, Reply] +   ), + +   Reply. + +-spec remove_any +   ( +      atom(), +      ataxia_security:user(), +      ataxic:meta() +   ) +   -> ({'ok', ataxia_id:type()} | 'not_found'). +remove_any (DB, User, Condition) -> +   % TODO: Try all nodes one by one until one is found. +   DBNode = get_db_node_for(<<"">>), + +   Reply = rpc:call(DBNode, atexia_server, remove_any, [DB, User, Condition]), + +   io:format +   ( +      "~nataxia_client:remove(~p) ! ~p -> ~p.~n", +      [{DB, User, Condition}, DBNode, Reply] +   ), + +   Reply. + +%%%% ALL, BY CONDITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec fetch_all +   ( +      atom(), +      ataxia_security:user(), +      ataxic:type(), +      ataxic:meta() +   ) +   -> ({'ok', list({ataxia_id:type(), any()})}). +fetch_all (DB, User, Selector, Condition) -> +   % TODO: Try all nodes one by one, apply to all they matching items. +   DBNode = get_db_node_for(<<"">>), + +   Reply = +      rpc:call +      ( +         DBNode, +         atexia_server, +         fetch_all, +         [DB, User, Selector, Condition] +      ), + +   io:format +   ( +      "~nataxia_client:fetch_all(~p) ! ~p -> ~p.~n", +      [{DB, User, Selector, Condition}, DBNode, Reply] +   ), + +   Reply. + +-spec update_all +   ( +      atom(), +      ataxia_security:user(), +      ataxiac:meta(), +      ataxiac:meta() +   ) +   -> {'ok', list(ataxia_id:type())}. +update_all (DB, User, Op, Condition) -> +   % TODO: Try all nodes one by one, apply to all they matching items. +   DBNode = get_db_node_for(<<"">>), + +   Reply = +      rpc:call(DBNode, atexia_server, update_all, [DB, User, Op, Condition]), + +   io:format +   ( +      "~nataxia_client:update(~p) ! ~p -> ~p.~n", +      [{DB, User, Op, Condition}, DBNode, Reply] +   ), + +   Reply. + +-spec lock_all +   ( +      atom(), +      ataxia_security:user(), +      ataxia_time:type(), +      ataxic:meta() +   ) +   -> {'ok', list(ataxia_id:type())}. +lock_all (DB, User, Duration, Condition) -> +   % TODO: Try all nodes one by one, apply to all they matching items. +   DBNode = get_db_node_for(<<"">>), + +   Reply = +      rpc:call +      ( +         DBNode, +         atexia_server, +         lock_all, +         [DB, User, Duration, Condition] +      ), + +   io:format +   ( +      "~nataxia_client:lock_all(~p) ! ~p -> ~p.~n", +      [{DB, User, Duration, Condition}, DBNode, Reply] +   ), + +   Reply. + +-spec remove_all +   ( +      atom(), +      ataxia_security:user(), +      ataxic:meta() +   ) +   -> {'ok', list(ataxia_id:type())}. +remove_all (DB, User, Condition) -> +   % TODO: Try all nodes one by one, apply to all they matching items. +   DBNode = get_db_node_for(<<"">>), + +   Reply = rpc:call(DBNode, atexia_server, remove_all, [DB, User, Condition]), + +   io:format +   ( +      "~nataxia_client:remove(~p) ! ~p -> ~p.~n", +      [{DB, User, Condition}, DBNode, Reply] +   ), + +   Reply. + | 


