Rename table_{create,drop} session_{create,drop}, they operate on things

other than tables, and we no longer hardcode the object type.
This commit is contained in:
Keith Bostic 2012-02-16 15:07:44 -05:00
parent 6f0357b4c5
commit 7a19859ede
2 changed files with 31 additions and 32 deletions

View file

@ -53,36 +53,29 @@ static ERL_NIF_TERM ATOM_ERROR;
static ERL_NIF_TERM ATOM_OK;
// Prototypes
static ERL_NIF_TERM wterl_conn_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_conn_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_get(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_put(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_delete(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_table_create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_table_drop(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_conn_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_next(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_np_worker(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[], int next);
static ERL_NIF_TERM wterl_cursor_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_prev(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_reset(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_search(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_search_near(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_cursor_search_worker(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[], int near);
static ERL_NIF_TERM wterl_cursor_reset(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_delete(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_drop(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_get(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ERL_NIF_TERM wterl_session_put(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ErlNifFunc nif_funcs[] =
{
{"conn_open", 2, wterl_conn_open},
{"conn_close", 1, wterl_conn_close},
{"session_open", 1, wterl_session_open},
{"session_get", 3, wterl_session_get},
{"session_put", 4, wterl_session_put},
{"session_delete", 3, wterl_session_delete},
{"session_close", 1, wterl_session_close},
{"table_create", 3, wterl_table_create},
{"table_drop", 3, wterl_table_drop},
{"conn_open", 2, wterl_conn_open},
{"cursor_close", 1, wterl_cursor_close},
{"cursor_next", 1, wterl_cursor_next},
{"cursor_open", 2, wterl_cursor_open},
@ -90,9 +83,15 @@ static ErlNifFunc nif_funcs[] =
{"cursor_reset", 1, wterl_cursor_reset},
{"cursor_search", 2, wterl_cursor_search},
{"cursor_search_near", 2, wterl_cursor_search_near},
{"session_close", 1, wterl_session_close},
{"session_create", 3, wterl_session_create},
{"session_delete", 3, wterl_session_delete},
{"session_drop", 3, wterl_session_drop},
{"session_get", 3, wterl_session_get},
{"session_open", 1, wterl_session_open},
{"session_put", 4, wterl_session_put},
};
static ERL_NIF_TERM wterl_conn_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
char homedir[4096];
@ -324,7 +323,7 @@ static ERL_NIF_TERM wterl_session_close(ErlNifEnv* env, int argc, const ERL_NIF_
return enif_make_badarg(env);
}
static ERL_NIF_TERM wterl_table_create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
static ERL_NIF_TERM wterl_session_create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
wterl_session_handle* session_handle;
if (enif_get_resource(env, argv[0], wterl_session_RESOURCE, (void**)&session_handle))
@ -348,7 +347,7 @@ static ERL_NIF_TERM wterl_table_create(ErlNifEnv* env, int argc, const ERL_NIF_T
return enif_make_badarg(env);
}
static ERL_NIF_TERM wterl_table_drop(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
static ERL_NIF_TERM wterl_session_drop(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
wterl_session_handle* session_handle;
if (enif_get_resource(env, argv[0], wterl_session_RESOURCE, (void**)&session_handle))

View file

@ -29,10 +29,10 @@
session_put/4,
session_delete/3,
session_close/1,
table_create/2,
table_create/3,
table_drop/2,
table_drop/3,
session_create/2,
session_create/3,
session_drop/2,
session_drop/3,
cursor_close/1,
cursor_next/1,
cursor_open/2,
@ -84,16 +84,16 @@ session_delete(_Ref, _Table, _Key) ->
session_close(_Ref) ->
?nif_stub.
table_create(Ref, Name) ->
table_create(Ref, Name, "").
session_create(Ref, Name) ->
session_create(Ref, Name, "").
table_create(_Ref, _Name, _Config) ->
session_create(_Ref, _Name, _Config) ->
?nif_stub.
table_drop(Ref, Name) ->
table_drop(Ref, Name, "").
session_drop(Ref, Name) ->
session_drop(Ref, Name, "").
table_drop(_Ref, _Name, _Config) ->
session_drop(_Ref, _Name, _Config) ->
?nif_stub.
cursor_open(_Ref, _Table) ->
@ -186,10 +186,10 @@ basic_test() ->
{ok, SRef} = session_open(ConnRef),
%% Remove the table from any earlier run.
ok = table_drop(SRef, "table:test", "force"),
ok = session_drop(SRef, "table:test", "force"),
%% Create the table
ok = table_create(SRef, "table:test"),
ok = session_create(SRef, "table:test"),
%% Insert/delete a key using the session handle
ok = session_put(SRef, "table:test", <<"a">>, <<"apple">>),