Skip to content

Commit

Permalink
Unify behaviour and return value in private backends
Browse files Browse the repository at this point in the history
Previous commit introduced badmatch, which I believe wasn't properly handled by the
layer above.
  • Loading branch information
Pawel Pikula committed Aug 19, 2015
1 parent 2da3a15 commit 40088fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions apps/ejabberd/src/mod_private_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ init(_Host, _Opts) ->

multi_set_data(LUser, LServer, NS2XML) ->
F = fun() -> multi_set_data_t(LUser, LServer, NS2XML) end,
{atomic, ok} = mnesia:transaction(F),
ok.
case mnesia:transaction(F) of
{atomic, ok} -> ok;
{aborted, Reason} -> {aborted, Reason}
end.

multi_set_data_t(LUser, LServer, NS2XML) ->
[set_data_t(LUser, LServer, NS, XML) || {NS, XML} <- NS2XML],
Expand Down
7 changes: 5 additions & 2 deletions apps/ejabberd/src/mod_private_odbc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ init(_Host, _Opts) ->

multi_set_data(LUser, LServer, NS2XML) ->
F = fun() -> multi_set_data_t(LUser, LServer, NS2XML) end,
{atomic, ok} = odbc_queries:sql_transaction(LServer, F),
ok.
case odbc_queries:sql_transaction(LServer, F) of
{atomic, ok} -> ok;
{aborted, Reason} -> {aborted, Reason};
{error, Reason} -> {error, Reason}
end.

multi_set_data_t(LUser, LServer, NS2XML) ->
SLUser = ejabberd_odbc:escape(LUser),
Expand Down
10 changes: 7 additions & 3 deletions apps/ejabberd/src/mod_private_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ init(_Host, _Opts) ->
-spec multi_set_data(ejabberd:luser(), ejabberd:lserver(),
{binary(), ejabberd:xmlterm()}) -> ok.
multi_set_data(LUser, LServer, NS2XML) ->
[set_private_data(LUser, LServer, NS, XML) || {NS, XML} <- NS2XML],
ok.
R = [set_private_data(LUser, LServer, NS, XML) || {NS, XML} <- NS2XML],
%% check if something returned with error msg
case lists:keyfind(error, 1, R) of
{error, Reason} -> {error, Reason};
false -> ok
end.

-spec multi_get_data(ejabberd:luser(), ejabberd:lserver(),
{binary(), term()}) -> ok.
Expand All @@ -57,7 +61,7 @@ remove_user(LUser, LServer) ->

set_private_data(LUser, LServer, NS, XML) ->
Obj = riakc_obj:new(bucket_type(LServer), key(LUser, NS), xml:element_to_binary(XML)),
ok = mongoose_riak:put(Obj).
mongoose_riak:put(Obj).

get_private_data(LUser, LServer, NS, Default) ->
case mongoose_riak:get(bucket_type(LServer), key(LUser, NS)) of
Expand Down
4 changes: 4 additions & 0 deletions doc/modules/mod_private.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This module implements [XEP-0049 (Private XML Storage)](http://xmpp.org/extensio
* **iqdisc**
* **backend** (atom, default: `mnesia`) - Storage backend. Currently `mnesia`, `odbc`, `riak` and `mysql` are supported . `mysql` uses MySQL-specific queries so in some cases it is more efficient than generic `odbc`.

**CAUTION:** Riak backend doesn't support transactions(rollbacks), so please avoid inserting more
than one value in one set request, otherwise you may end up with partially save data, backend returns
first error.

### Example Configuration
```
{mod_private, []}
Expand Down

0 comments on commit 40088fb

Please sign in to comment.