working implementation of mnesia and ets based ezic.
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
{application, ezic,
|
{application, ezic,
|
||||||
[
|
[
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{vsn, "0.1.0"},
|
{vsn, "0.2.0"},
|
||||||
{applications, [
|
{applications, [
|
||||||
kernel,
|
kernel,
|
||||||
stdlib
|
stdlib
|
||||||
]},
|
]},
|
||||||
{mod, {ezic_app, []}},
|
{mod, {ezic_app, ezic_db_ets}},
|
||||||
{env, [{db_dir, "db"}]}
|
{env, [{db_dir, "db"}]}
|
||||||
]}.
|
]}.
|
||||||
@@ -14,10 +14,11 @@
|
|||||||
, insert_all/1
|
, insert_all/1
|
||||||
, wipe/1
|
, wipe/1
|
||||||
, flatten/0
|
, flatten/0
|
||||||
|
, get_implementation/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
start_link/0
|
start_link/1
|
||||||
, init/1
|
, init/1
|
||||||
, code_change/3
|
, code_change/3
|
||||||
, handle_call/3
|
, handle_call/3
|
||||||
@@ -27,6 +28,8 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
-record(state, {zones, rules, get_all, flatzone, insert_all, wipe, implementation}).
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% PUBLIC API
|
% PUBLIC API
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
@@ -63,18 +66,38 @@ wipe(Tab) ->
|
|||||||
flatten() ->
|
flatten() ->
|
||||||
gen_server:call(?MODULE, {flatten}).
|
gen_server:call(?MODULE, {flatten}).
|
||||||
|
|
||||||
|
get_implementation() ->
|
||||||
|
gen_server:call(?MODULE, {implementation}).
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%% GEN_SERVER
|
%% GEN_SERVER
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
start_link() ->
|
start_link(StartArgs) ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, StartArgs, []).
|
||||||
|
|
||||||
|
init(ezic_db_mnesia) ->
|
||||||
|
ezic_db_mnesia:init(),
|
||||||
|
State = #state{zones = fun ezic_db_mnesia:zones/1,
|
||||||
|
rules = fun ezic_db_mnesia:rules/1,
|
||||||
|
get_all = fun ezic_db_mnesia:get_all/1,
|
||||||
|
flatzone = fun ezic_db_mnesia:flatzone/2,
|
||||||
|
insert_all = fun ezic_db_mnesia:insert_all/1,
|
||||||
|
wipe = fun ezic_db_mnesia:wipe/1,
|
||||||
|
implementation = "mnesia"},
|
||||||
|
{ok, State};
|
||||||
init(_) ->
|
init(_) ->
|
||||||
ezic_db_ets:init(),
|
ezic_db_ets:init(),
|
||||||
{ok, []}.
|
State = #state{zones = fun ezic_db_ets:zones/1,
|
||||||
|
rules = fun ezic_db_ets:rules/1,
|
||||||
|
get_all = fun ezic_db_ets:get_all/1,
|
||||||
|
flatzone = fun ezic_db_ets:flatzone/2,
|
||||||
|
insert_all = fun ezic_db_ets:insert_all/1,
|
||||||
|
wipe = fun ezic_db_ets:wipe/1,
|
||||||
|
implementation = "ets"},
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
%%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
%%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
%% DB Lookup
|
%% DB Lookup
|
||||||
@@ -82,29 +105,39 @@ init(_) ->
|
|||||||
|
|
||||||
|
|
||||||
handle_call({zones, Name}, _, State) ->
|
handle_call({zones, Name}, _, State) ->
|
||||||
Matches= ezic_db_ets:zones(Name),
|
ZoneFun= State#state.zones,
|
||||||
|
Matches= ZoneFun(Name),
|
||||||
{reply, Matches, State};
|
{reply, Matches, State};
|
||||||
handle_call({rules, Name}, _, State) ->
|
handle_call({rules, Name}, _, State) ->
|
||||||
Matches= ezic_db_ets:rules(Name),
|
RuleFun= State#state.rules,
|
||||||
|
Matches= RuleFun(Name),
|
||||||
{reply, Matches, State};
|
{reply, Matches, State};
|
||||||
handle_call({all, Tab}, _, State) ->
|
handle_call({all, Tab}, _, State) ->
|
||||||
Matches= ezic_db_ets:get_all(Tab),
|
GetAllFun= State#state.get_all,
|
||||||
|
Matches= GetAllFun(Tab),
|
||||||
{reply, Matches, State};
|
{reply, Matches, State};
|
||||||
handle_call({flatzone, Date, Name}, _, State) ->
|
handle_call({flatzone, Date, Name}, _, State) ->
|
||||||
Result= ezic_db_ets:flatzone(Date, Name),
|
FlatzoneFun= State#state.flatzone,
|
||||||
|
Result= FlatzoneFun(Date, Name),
|
||||||
{reply, Result, State};
|
{reply, Result, State};
|
||||||
handle_call({insert_all, Records}, _, State) ->
|
handle_call({insert_all, Records}, _, State) ->
|
||||||
ezic_db_ets:insert_all(Records),
|
InsertAllFun= State#state.insert_all,
|
||||||
|
InsertAllFun(Records),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_call({wipe, Tab}, _, State) ->
|
handle_call({wipe, Tab}, _, State) ->
|
||||||
Result= ezic_db_ets:wipe(Tab),
|
WipeFun= State#state.wipe,
|
||||||
|
Result= WipeFun(Tab),
|
||||||
{reply, Result, State};
|
{reply, Result, State};
|
||||||
handle_call({flatten}, _, State) ->
|
handle_call({flatten}, _, State) ->
|
||||||
Zones= ezic_db_ets:get_all(zone),
|
GetAllFun= State#state.get_all,
|
||||||
Rules= ezic_db_ets:get_all(rule),
|
Zones= GetAllFun(zone),
|
||||||
|
Rules= GetAllFun(rule),
|
||||||
FlatZone= ezic_flatten:flatten(Zones, Rules),
|
FlatZone= ezic_flatten:flatten(Zones, Rules),
|
||||||
Result= ezic_db_ets:insert_all(FlatZone),
|
InsertAllFun= State#state.insert_all,
|
||||||
|
Result= InsertAllFun(FlatZone),
|
||||||
{reply, Result, State};
|
{reply, Result, State};
|
||||||
|
handle_call({implementation}, _, State) ->
|
||||||
|
{reply, State#state.implementation, State};
|
||||||
handle_call(_, _, State) ->
|
handle_call(_, _, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ create_tabs(ok) ->
|
|||||||
insert_all(Zones),
|
insert_all(Zones),
|
||||||
insert_all(Rules),
|
insert_all(Rules),
|
||||||
FlatZones = ezic_flatten:flatten(Zones, Rules),
|
FlatZones = ezic_flatten:flatten(Zones, Rules),
|
||||||
|
io:format("~p~n", [FlatZones]),
|
||||||
insert_all(FlatZones),
|
insert_all(FlatZones),
|
||||||
|
|
||||||
ok;
|
ok;
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ flatten_zone_set(FromTimeStub=#flatzone{utc_from=UTCFrom, dstoffset=DSTOffset}
|
|||||||
|
|
||||||
%% we gather all rules that _may_ apply
|
%% we gather all rules that _may_ apply
|
||||||
%Rules= ezic_db:rules(RuleName),
|
%Rules= ezic_db:rules(RuleName),
|
||||||
Rules= [R || R <- AllRules, R = #rule{name = RuleName}],
|
Rules= [R || R <- AllRules, R#rule.name =:= RuleName ],
|
||||||
|
|
||||||
?debugVal(FromTime),
|
?debugVal(FromTime),
|
||||||
?debugVal(Rules),
|
?debugVal(Rules),
|
||||||
|
|||||||
@@ -24,8 +24,8 @@
|
|||||||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||||
%% Description: Starts the supervisor
|
%% Description: Starts the supervisor
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
start_link(_) ->
|
start_link(StartArgs) ->
|
||||||
supervisor:start_link(?MODULE, []).
|
supervisor:start_link(?MODULE, StartArgs).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% Supervisor callbacks
|
%% Supervisor callbacks
|
||||||
@@ -39,9 +39,9 @@ start_link(_) ->
|
|||||||
%% to find out about restart strategy, maximum restart frequency and child
|
%% to find out about restart strategy, maximum restart frequency and child
|
||||||
%% specifications.
|
%% specifications.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
init(_) ->
|
init(StartArgs) ->
|
||||||
EzicDb = {ezic_db,{ezic_db, start_link, []},
|
EzicDb = {ezic_db,{ezic_db, start_link, [StartArgs]},
|
||||||
permanent,2000,worker,[ezic_db_ets]},
|
permanent,2000,worker,[ezic_db]},
|
||||||
{ok,{{one_for_all,3,30}, [EzicDb]}}.
|
{ok,{{one_for_all,3,30}, [EzicDb]}}.
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user