Skip to content

Commit

Permalink
Remove ejabberd_rdbms and mongoose_rdbms_type
Browse files Browse the repository at this point in the history
  • Loading branch information
gustawlippa committed Nov 9, 2021
1 parent d856ba0 commit 714bbe7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 64 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
mod_mam_cassandra_arch_params,
mod_mam_cassandra_prefs_params, mod_mam_muc_cassandra_arch_params,
mod_pubsub_db_backend, mod_revproxy_dynamic,
mod_shared_roster, mongoose_rdbms_type,
mod_shared_roster,
%% Deprecated functions
{crypto, rand_uniform, 2},
{ranch, start_listener, 6},
Expand Down
1 change: 0 additions & 1 deletion src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ start(normal, _Args) ->
%% ejabberd_sm is started separately because it may use one of the outgoing_pools
%% but some outgoing_pools should be started only with ejabberd_sup already running
ejabberd_sm:start(),
ejabberd_rdbms:start(),
ejabberd_auth:start(),
mongoose_cluster_id:start(),
start_services(),
Expand Down
55 changes: 0 additions & 55 deletions src/ejabberd_rdbms.erl

This file was deleted.

2 changes: 1 addition & 1 deletion src/pubsub/mod_pubsub_db_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ stop() ->

%% ------------------------ Queries execution --------------------
prepare_select_nodes_by_owner() ->
case {mongoose_rdbms:db_engine(global), mongoose_rdbms_type:get()} of
case {mongoose_rdbms:db_engine(global), mongoose_rdbms:db_type()} of
{mysql, _} ->
mongoose_rdbms:prepare(pubsub_select_nodes_by_owner, pubsub_nodes, [owners],
<<"SELECT name, type FROM pubsub_nodes WHERE owners = convert(?, JSON);">>);
Expand Down
11 changes: 11 additions & 0 deletions src/rdbms/mongoose_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
sql_dirty/2,
to_bool/1,
db_engine/1,
db_type/0,
print_state/1,
use_escaped/1]).

Expand Down Expand Up @@ -734,6 +735,16 @@ db_engine(_HostType) ->
try mongoose_backend:get_backend_name(global, ?MODULE)
catch error:badarg -> undefined end.

%% @doc Used to optimise queries for different databases.
%% @todo Should be refactored to use host types with this module.
%% Also, this parameter should not be global, but pool-name parameterized
-spec db_type() -> mssql | generic.
db_type() ->
case ejabberd_config:get_local_option(rdbms_server_type) of
"mssql" -> mssql;
_ -> generic
end.

-spec connect(Settings :: term(), Retry :: non_neg_integer(), RetryAfter :: non_neg_integer(),
MaxRetryDelay :: non_neg_integer()) -> {ok, term()} | {error, any()}.
connect(Settings, Retry, RetryAfter, MaxRetryDelay) ->
Expand Down
9 changes: 4 additions & 5 deletions src/rdbms/rdbms_queries.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
execute_upsert/5]).

-ignore_xref([
{mongoose_rdbms_type, get, 0},
count_records_where/3, get_db_specific_limits/1, get_db_specific_offset/2, get_db_type/0
]).

Expand All @@ -57,7 +56,7 @@
-define(generic, true).
-endif.

-define(RDBMS_TYPE, (mongoose_rdbms_type:get())).
-define(RDBMS_TYPE, (mongoose_rdbms:db_type())).

-include("mongoose.hrl").

Expand All @@ -82,7 +81,7 @@ get_db_type() ->
UpdateParams :: [any()],
UniqueKeyValues :: [any()]) -> mongoose_rdbms:query_result().
execute_upsert(Host, Name, InsertParams, UpdateParams, UniqueKeyValues) ->
case {mongoose_rdbms:db_engine(Host), mongoose_rdbms_type:get()} of
case {mongoose_rdbms:db_engine(Host), mongoose_rdbms:db_type()} of
{mysql, _} ->
mongoose_rdbms:execute(Host, Name, InsertParams ++ UpdateParams);
{pgsql, _} ->
Expand Down Expand Up @@ -111,14 +110,14 @@ prepare_upsert(Host, Name, Table, InsertFields, Updates, UniqueKeyFields) ->

prepared_upsert_fields(InsertFields, Updates, UniqueKeyFields) ->
UpdateFields = lists:filter(fun is_field/1, Updates),
case mongoose_rdbms_type:get() of
case mongoose_rdbms:db_type() of
mssql ->
UniqueKeyFields ++ InsertFields ++ UpdateFields;
_ -> InsertFields ++ UpdateFields
end.

upsert_query(Host, Table, InsertFields, Updates, UniqueKeyFields) ->
case {mongoose_rdbms:db_engine(Host), mongoose_rdbms_type:get()} of
case {mongoose_rdbms:db_engine(Host), mongoose_rdbms:db_type()} of
{mysql, _} ->
upsert_mysql_query(Table, InsertFields, Updates, UniqueKeyFields);
{pgsql, _} ->
Expand Down
2 changes: 1 addition & 1 deletion src/vcard/mod_vcard_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ search(HostType, LServer, Data) ->
limit_type(infinity) ->
infinity;
limit_type(_Limit) ->
case mongoose_rdbms_type:get() of
case mongoose_rdbms:db_type() of
mssql -> top;
_ -> limit
end.
Expand Down

0 comments on commit 714bbe7

Please sign in to comment.