/ucengine/src/backends/db/mongodb/mongodb_db.erl
Erlang | 66 lines | 28 code | 6 blank | 32 comment | 1 complexity | 89c7731eec57911fabfe1107515598fc MD5 | raw file
- %%
- %% U.C.Engine - Unified Collaboration Engine
- %% Copyright (C) 2011 af83
- %%
- %% This program is free software: you can redistribute it and/or modify
- %% it under the terms of the GNU Affero General Public License as published by
- %% the Free Software Foundation, either version 3 of the License, or
- %% (at your option) any later version.
- %%
- %% This program is distributed in the hope that it will be useful,
- %% but WITHOUT ANY WARRANTY; without even the implied warranty of
- %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- %% GNU Affero General Public License for more details.
- %%
- %% You should have received a copy of the GNU Affero General Public License
- %% along with this program. If not, see <http://www.gnu.org/licenses/>.
- %%
- -module(mongodb_db).
- -export([init/2,
- drop/0,
- terminate/0]).
- -include("uce.hrl").
- -include("mongodb.hrl").
- create_indexes(0, _Domain) ->
- ok;
- create_indexes(1, Domain) ->
- Modules = [uce_event_mongodb, uce_user_mongodb, uce_role_mongodb],
- [Module:index(Domain) || Module <- Modules].
- %%--------------------------------------------------------------------
- %% @spec (Domain::list, MongoPoolInfos::list) -> any()
- %% @doc Initialize mongodb dedicated connections pool for the given domain (vhost).
- %% @end
- %%--------------------------------------------------------------------
- init(Domain, MongoPoolInfos) ->
- catch application:start(emongo),
- [Size, Host, Port, Name, Index] = utils:get_values(MongoPoolInfos,
- [{size, "1"},
- {host, "localhost"},
- {port, ?DEFAULT_MONGODB_PORT},
- {database, ?DEFAULT_MONGODB_NAME},
- {index, 1}]),
- emongo:add_pool(Domain, Host, Port, Name, Size),
- create_indexes(Index, Domain).
- %%--------------------------------------------------------------------
- %% @spec () -> any()
- %% @doc Disconnect from mongodb by dropping all connections pool.
- %% @end
- %%--------------------------------------------------------------------
- drop() ->
- lists:foreach(fun({Domain, _}) ->
- catch emongo:drop_database(Domain)
- end,
- config:get('hosts')).
- %%--------------------------------------------------------------------
- %% @spec () -> ok
- %% @doc Terminate.
- %% @end
- %%--------------------------------------------------------------------
- terminate() ->
- ok.