From 2fcd4c6df35d8b3c5f84d291c3ba9fbd8556a031 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 30 Oct 2012 17:03:48 +0700 Subject: [PATCH] #1 minor refactoring --- node/ejdb.js | 28 ++++++++++++- node/ejdb_native.cc | 67 ++++++++++++++++++++++++++--- node/nbproject/configurations.xml | 11 +++-- node/tests/t1.js | 6 +++ tcejdb/ejdb.c | 86 +++++++++++++++++++------------------- tcejdb/ejdb.h | 88 +++++++++++++++++++-------------------- tcejdb/samples/sample1/sample1.c | 2 +- tcejdb/testejdb/t1.c | 2 +- tcejdb/testejdb/t2.c | 54 ++++++++++++------------ tcejdb/testejdb/t3.c | 8 ++-- 10 files changed, 223 insertions(+), 129 deletions(-) create mode 100644 node/tests/t1.js diff --git a/node/ejdb.js b/node/ejdb.js index 143a7e7..b319762 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -1,2 +1,28 @@ -var ejdblib = require("build/Release/ejdb_native"); \ No newline at end of file +var ejdblib = require("./build/Release/ejdb_native"); +var EJDBImpl = ejdblib.NodeEJDB + +const DEFAULT_OPEN_MODE = (ejdblib.JBOWRITER | ejdblib.JBOCREAT); +var EJDB = function(dbFile, openMode) { + this._impl = new EJDBImpl(dbFile, (openMode > 0) ? openMode : DEFAULT_OPEN_MODE); + return this; +}; + +for (var k in ejdblib) { //Export constants + if (k.indexOf("JB") === 0) { + EJDB[k] = ejdblib[k]; + } +} +EJDB.DEFAULT_OPEN_MODE = DEFAULT_OPEN_MODE; + +EJDB.open = function(dbFile, openMode) { + return new EJDB(dbFile, openMode); +}; + +EJDB.prototype.close = function() { + return this._impl.close(); +} + + +module.exports = EJDB; + diff --git a/node/ejdb_native.cc b/node/ejdb_native.cc index 7da86af..e425399 100644 --- a/node/ejdb_native.cc +++ b/node/ejdb_native.cc @@ -2,14 +2,16 @@ #include #include #include -#include -#include #include "ejdb_args.h" #include "ejdb_cmd.h" #include "ejdb_logging.h" #include "ejdb_thread.h" +#include +#include +#include + using namespace node; using namespace v8; @@ -27,27 +29,82 @@ namespace ejdb { static Persistent constructor_template; + EJDB *m_jb; + static Handle s_new_object(const Arguments& args) { HandleScope scope; REQ_STR_ARG(0, dbPath); - + REQ_INT32_ARG(1, mode); + NodeEJDB *nejdb = new NodeEJDB(); + if (!nejdb->open(*dbPath, mode)) { + std::ostringstream os; + os << "Unable to open database: " << (*dbPath) << " error: " << nejdb->jb_error_msg(); + EJ_LOG_ERROR(os.str().c_str()); + delete nejdb; + return scope.Close(ThrowException(Exception::Error(String::New(os.str().c_str())))); + } + nejdb->Wrap(args.This()); return scope.Close(args.This()); } - NodeEJDB() { + NodeEJDB() : m_jb(NULL) { } virtual ~NodeEJDB() { + if (m_jb) { + ejdbdel(m_jb); + } + } + + bool open(const char* dbpath, int mode) { + m_jb = ejdbnew(); + if (!m_jb) { + return false; + } + return ejdbopen(m_jb, dbpath, mode); + } + + bool close() { + if (m_jb) { + return ejdbclose(m_jb); + } + } + + const char* jb_error_msg() { + return m_jb ? ejdberrmsg(ejdbecode(m_jb)) : "unknown"; } + public: static void Init(Handle target) { HandleScope scope; - Local t = FunctionTemplate::New(s_new_object); constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("NodeEJDB")); + + //Open mode + NODE_DEFINE_CONSTANT(target, JBOREADER); + NODE_DEFINE_CONSTANT(target, JBOWRITER); + NODE_DEFINE_CONSTANT(target, JBOCREAT); + NODE_DEFINE_CONSTANT(target, JBOTRUNC); + NODE_DEFINE_CONSTANT(target, JBONOLCK); + NODE_DEFINE_CONSTANT(target, JBOLCKNB); + NODE_DEFINE_CONSTANT(target, JBOTSYNC); + + //Indexes + NODE_DEFINE_CONSTANT(target, JBIDXDROP); + NODE_DEFINE_CONSTANT(target, JBIDXDROPALL); + NODE_DEFINE_CONSTANT(target, JBIDXOP); + NODE_DEFINE_CONSTANT(target, JBIDXREBLD); + NODE_DEFINE_CONSTANT(target, JBIDXNUM); + NODE_DEFINE_CONSTANT(target, JBIDXSTR); + NODE_DEFINE_CONSTANT(target, JBIDXARR); + + //Misc + NODE_DEFINE_CONSTANT(target, JBQRYCOUNT); + + target->Set(v8::String::NewSymbol("NodeEJDB"), constructor_template->GetFunction()); } void Ref() { diff --git a/node/nbproject/configurations.xml b/node/nbproject/configurations.xml index 3fe02ba..58f454e 100644 --- a/node/nbproject/configurations.xml +++ b/node/nbproject/configurations.xml @@ -7,10 +7,7 @@ - ejdb_native.node - ejdb_native.node - linker.lock Makefile binding.Makefile @@ -3249,7 +3246,15 @@ + + pthread_mutex.h + + ejdb_args.h + ejdb_cmd.h + ejdb_logging.cc + ejdb_logging.h ejdb_native.cc + ejdb_thread.h BSON_MAX_FPATH_LEN) { - _ejdbsetecode(jcoll->jb, JDBEFPATHINVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__); rv = false; goto finish; } @@ -511,15 +511,15 @@ EJDB_EXPORT bool ejdbsetindex(EJCOLL *jcoll, const char *fpath, int flags) { goto finish; } if (tcitype) { - if (flags & JDIDXSTR) { + if (flags & JBIDXSTR) { ipath[0] = 's'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL); } - if (rv && (flags & JDIDXNUM)) { + if (rv && (flags & JBIDXNUM)) { ipath[0] = 'n'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL); } - if (rv && (flags & JDIDXARR)) { + if (rv && (flags & JBIDXARR)) { ipath[0] = 'a'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, NULL); } @@ -537,15 +537,15 @@ EJDB_EXPORT bool ejdbsetindex(EJCOLL *jcoll, const char *fpath, int flags) { } } } else { - if ((flags & JDIDXSTR) && (ibld || !(oldiflags & JDIDXSTR))) { + if ((flags & JBIDXSTR) && (ibld || !(oldiflags & JBIDXSTR))) { ipath[0] = 's'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, NULL); } - if (rv && (flags & JDIDXNUM) && (ibld || !(oldiflags & JDIDXNUM))) { + if (rv && (flags & JBIDXNUM) && (ibld || !(oldiflags & JBIDXNUM))) { ipath[0] = 'n'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITDECIMAL, _bsonipathrowldr, NULL); } - if (rv && (flags & JDIDXARR) && (ibld || !(oldiflags & JDIDXARR))) { + if (rv && (flags & JBIDXARR) && (ibld || !(oldiflags & JBIDXARR))) { ipath[0] = 'a'; rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITTOKEN, _bsonipathrowldr, NULL); } @@ -1221,7 +1221,7 @@ static TCLIST* _qrysearch(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int q _qrydup(q, ejq, EJQINTERNAL); *outcount = 0; - bool onlycount = (qflags & EJQRYCOUNT); //quering only for result set count + bool onlycount = (qflags & JBQRYCOUNT); //quering only for result set count bool all = false; //need all records EJQF *mqf = NULL; //main indexed query condition if exists @@ -1683,7 +1683,7 @@ sorting: /* Sorting resultset */ sctx.ofs = ofs; sctx.ofsz = ofsz; if (ejdbtimsortlist(res, _ejdbsoncmp, &sctx)) { - _ejdbsetecode(jcoll->jb, JDBEQRSSORTING, __FILE__, __LINE__, __func__); + _ejdbsetecode(jcoll->jb, JBEQRSSORTING, __FILE__, __LINE__, __func__); } finish: //revert max @@ -1783,7 +1783,7 @@ static TDBIDX* _qryfindidx(EJCOLL *jcoll, EJQF *qf, bson *idxmeta) { return NULL; } int iflags = bson_iterator_int(&it); - if (iflags & JDIDXARR) { //array token index exists so convert qf into TDBQCSTROR + if (iflags & JBIDXARR) { //array token index exists so convert qf into TDBQCSTROR for (int i = 0; i < tdb->inum; ++i) { TDBIDX *idx = tdb->idxs + i; if (!strcmp(qf->fpath, idx->name + 1)) { @@ -2014,7 +2014,7 @@ static bool _metasetbson(EJDB *jb, const char *colname, int colnamesz, TCMAP *cmeta = tctdbget(jb->metadb, colname, colnamesz); if (!cmeta) { - _ejdbsetecode(jb, JDBEMETANVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jb, JBEMETANVALID, __FILE__, __LINE__, __func__); rv = false; goto finish; } @@ -2067,7 +2067,7 @@ static bson* _metagetbson(EJDB *jb, const char *colname, int colnamesz, const ch bson *rv = NULL; TCMAP *cmeta = tctdbget(jb->metadb, colname, colnamesz); if (!cmeta) { - _ejdbsetecode(jb, JDBEMETANVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jb, JBEMETANVALID, __FILE__, __LINE__, __func__); return NULL; } int bsz; @@ -2100,12 +2100,12 @@ static bson* _imetaidx(EJCOLL *jcoll, const char *ipath) { char fpathkey[BSON_MAX_FPATH_LEN + 1]; TCMAP *cmeta = tctdbget(jcoll->jb->metadb, jcoll->cname, jcoll->cnamesz); if (!cmeta) { - _ejdbsetecode(jcoll->jb, JDBEMETANVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jcoll->jb, JBEMETANVALID, __FILE__, __LINE__, __func__); goto finish; } int klen = snprintf(fpathkey, BSON_MAX_FPATH_LEN + 1, "i%s", ipath); //'i' prefix for all columns with index meta if (klen > BSON_MAX_FPATH_LEN) { - _ejdbsetecode(jcoll->jb, JDBEFPATHINVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__); goto finish; } int bsz; @@ -2213,7 +2213,7 @@ static int _parse_qobj_impl(EJDB* jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa qf.ftype = ftype; } else { if (!pqf) { //Require parent query object - ret = JDBQINVALID; + ret = JBEQERROR; break; } qf = *pqf; @@ -2241,7 +2241,7 @@ static int _parse_qobj_impl(EJDB* jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa strcmp("$bt", fkey) && strcmp("$strand", fkey) && strcmp("$stror", fkey)) { - ret = JDBEQINVALIDQCONTROL; + ret = JBEQINVALIDQCONTROL; break; } bson_iterator sit; @@ -2249,7 +2249,7 @@ static int _parse_qobj_impl(EJDB* jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa bson_type atype = 0; TCLIST *tokens = _fetch_bson_str_array(&sit, &atype); if (atype == 0) { - ret = JDBEQINOPNOTARRAY; + ret = JBEQINOPNOTARRAY; tclistdel(tokens); break; } @@ -2270,7 +2270,7 @@ static int _parse_qobj_impl(EJDB* jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa } else if (!strcmp("$bt", fkey)) { //between qf.tcop = TDBQCNUMBT; if (TCLISTNUM(tokens) != 2) { - ret = JDBEQINOPNOTARRAY; + ret = JBEQINOPNOTARRAY; TCFREE(qf.expr); tclistdel(qf.exprlist); break; @@ -2372,7 +2372,7 @@ static int _parse_qobj_impl(EJDB* jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa TCMALLOC(qf.regex, sizeof (rxbuf)); memcpy(qf.regex, &rxbuf, sizeof (rxbuf)); } else { - ret = JDBEQINVALIDQRX; + ret = JBEQINVALIDQRX; TCFREE(qf.fpath); TCFREE(qf.expr); break; @@ -2593,7 +2593,7 @@ static bool _updatebsonidx(EJCOLL *jcoll, const bson_oid_t *oid, const bson *bs, bool rv = true; TCMAP *cmeta = tctdbget(jcoll->jb->metadb, jcoll->cname, jcoll->cnamesz); if (!cmeta) { - _ejdbsetecode(jcoll->jb, JDBEMETANVALID, __FILE__, __LINE__, __func__); + _ejdbsetecode(jcoll->jb, JBEMETANVALID, __FILE__, __LINE__, __func__); return false; } TCMAP *imap = NULL; //New index map @@ -2653,13 +2653,13 @@ static bool _updatebsonidx(EJCOLL *jcoll, const bson_oid_t *oid, const bson *bs, imap = tcmapnew2(16); rimap = tcmapnew2(16); } - for (int i = 4; i <= 6; ++i) { /* JDIDXNUM, JDIDXSTR, JDIDXARR */ + for (int i = 4; i <= 6; ++i) { /* JBIDXNUM, JBIDXSTR, JBIDXARR */ bool rm = false; - if ((1 << i) == JDIDXNUM && (JDIDXNUM & iflags)) { + if ((1 << i) == JBIDXNUM && (JBIDXNUM & iflags)) { ikey[0] = 'n'; - } else if ((1 << i) == JDIDXSTR && (JDIDXSTR & iflags)) { + } else if ((1 << i) == JBIDXSTR && (JBIDXSTR & iflags)) { ikey[0] = 's'; - } else if ((1 << i) == JDIDXARR && (JDIDXARR & iflags)) { + } else if ((1 << i) == JBIDXARR && (JBIDXARR & iflags)) { ikey[0] = 'a'; if (ofvalue && oft == BSON_ARRAY && (!fvalue || ft != oft || fvaluesz != ofvaluesz || memcmp(fvalue, ofvalue, fvaluesz))) { @@ -2733,7 +2733,7 @@ static bool _addcoldb0(const char* cname, EJDB *jb, EJCOLLOPTS *opts, EJCOLL **r static bool _createcoldb(const char* colname, EJDB *jb, EJCOLLOPTS *opts, TCTDB **res) { assert(jb && jb->metadb); if (!JBISVALCOLNAME(colname)) { - _ejdbsetecode(jb, JDBEINVALIDCOLNAME, __FILE__, __LINE__, __func__); + _ejdbsetecode(jb, JBEINVALIDCOLNAME, __FILE__, __LINE__, __func__); *res = NULL; return false; } diff --git a/tcejdb/ejdb.h b/tcejdb/ejdb.h index 43c8f70..4669805 100644 --- a/tcejdb/ejdb.h +++ b/tcejdb/ejdb.h @@ -34,39 +34,39 @@ typedef struct { /**< EJDB collection tuning options. */ #define JBMAXCOLNAMELEN 128 enum { /** Error codes */ - JDBEINVALIDCOLNAME = 9000, /**< Invalid collection name. */ - JDBEINVALIDBSON = 9001, /**< Invalid bson object. */ - JDBEQINVALIDQCONTROL = 9002, /**< Invalid query control field starting with '$'. */ - JDBEQINOPNOTARRAY = 9003, /**< $strand, $stror, $in, $nin, $bt keys requires not empty array value. */ - JDBEMETANVALID = 9004, /**< Inconsistent database metadata. */ - JDBEFPATHINVALID = 9005, /**< Invalid field path value. */ - JDBEQINVALIDQRX = 9006, /**< Invalid query regexp value. */ - JDBEQRSSORTING = 9007, /**< Result set sorting error. */ - JDBQINVALID = 9008 /**< Query generic error. */ + JBEINVALIDCOLNAME = 9000, /**< Invalid collection name. */ + JBEINVALIDBSON = 9001, /**< Invalid bson object. */ + JBEQINVALIDQCONTROL = 9002, /**< Invalid query control field starting with '$'. */ + JBEQINOPNOTARRAY = 9003, /**< $strand, $stror, $in, $nin, $bt keys requires not empty array value. */ + JBEMETANVALID = 9004, /**< Inconsistent database metadata. */ + JBEFPATHINVALID = 9005, /**< Invalid field path value. */ + JBEQINVALIDQRX = 9006, /**< Invalid query regexp value. */ + JBEQRSSORTING = 9007, /**< Result set sorting error. */ + JBEQERROR = 9008 /**< Query generic error. */ }; enum { /** Database open modes */ - JDBOREADER = 1 << 0, /**< Open as a reader. */ - JDBOWRITER = 1 << 1, /**< Open as a writer. */ - JDBOCREAT = 1 << 2, /**< Create if db file not exists. */ - JDBOTRUNC = 1 << 3, /**< Truncate db. */ - JDBONOLCK = 1 << 4, /**< Open without locking. */ - JDBOLCKNB = 1 << 5, /**< Lock without blocking. */ - JDBOTSYNC = 1 << 6 /**< Synchronize every transaction. */ + JBOREADER = 1 << 0, /**< Open as a reader. */ + JBOWRITER = 1 << 1, /**< Open as a writer. */ + JBOCREAT = 1 << 2, /**< Create if db file not exists. */ + JBOTRUNC = 1 << 3, /**< Truncate db. */ + JBONOLCK = 1 << 4, /**< Open without locking. */ + JBOLCKNB = 1 << 5, /**< Lock without blocking. */ + JBOTSYNC = 1 << 6 /**< Synchronize every transaction. */ }; enum { /** Index modes, index types. */ - JDIDXDROP = 1 << 0, /**< Drop index. */ - JDIDXDROPALL = 1 << 1, /**< Drop index for all types. */ - JDIDXOP = 1 << 2, /**< Optimize index. */ - JDIDXREBLD = 1 << 3, /**< Rebuild index. */ - JDIDXNUM = 1 << 4, /**< Number index. */ - JDIDXSTR = 1 << 5, /**< String index.*/ - JDIDXARR = 1 << 6, /**< Array token index. */ + JBIDXDROP = 1 << 0, /**< Drop index. */ + JBIDXDROPALL = 1 << 1, /**< Drop index for all types. */ + JBIDXOP = 1 << 2, /**< Optimize index. */ + JBIDXREBLD = 1 << 3, /**< Rebuild index. */ + JBIDXNUM = 1 << 4, /**< Number index. */ + JBIDXSTR = 1 << 5, /**< String index.*/ + JBIDXARR = 1 << 6, /**< Array token index. */ }; enum { /*< Query search mode flags in ejdbqrysearch() */ - EJQRYCOUNT = 1 /*< Query only count(*) */ + JBQRYCOUNT = 1 /*< Query only count(*) */ }; /** @@ -110,13 +110,13 @@ EJDB_EXPORT bool ejdbclose(EJDB *jb); * @param jb Database object created with `ejdbnew' * @param path Path to the database file. * @param mode Open mode bitmask flags: - * `JDBOREADER` Open as a reader. - * `JDBOWRITER` Open as a writer. - * `JDBOCREAT` Create db if it not exists - * `JDBOTRUNC` Truncate db. - * `JDBONOLCK` Open without locking. - * `JDBOLCKNB` Lock without blocking. - * `JDBOTSYNC` Synchronize every transaction. + * `JBOREADER` Open as a reader. + * `JBOWRITER` Open as a writer. + * `JBOCREAT` Create db if it not exists + * `JBOTRUNC` Truncate db. + * `JBONOLCK` Open without locking. + * `JBOLCKNB` Lock without blocking. + * `JBOTSYNC` Synchronize every transaction. * @return */ EJDB_EXPORT bool ejdbopen(EJDB *jb, const char *path, int mode); @@ -244,26 +244,26 @@ EJDB_EXPORT void ejdbquerydel(EJQ* q); * Set index for JSON field in EJDB collection. * * - Available index types: - * - `JDIDXSTR` String index for JSON string values. - * - `JDIDXNUM` Index for JSON number values. - * - `JDIDXARR` Token index for JSON arrays and string values. + * - `JBIDXSTR` String index for JSON string values. + * - `JBIDXNUM` Index for JSON number values. + * - `JBIDXARR` Token index for JSON arrays and string values. * * - One JSON field can have several indexes for different types. * * - Available index operations: - * - `JDIDXDROP` Drop index of specified type. - * - Eg: flag = JDIDXDROP | JDIDXNUM (Drop number index) - * - `JDIDXDROPALL` Drop index for all types. - * - `JDIDXREBLD` Rebuild index of specified type. - * - `JDIDXOP` Optimize index of specified type. + * - `JBIDXDROP` Drop index of specified type. + * - Eg: flag = JBIDXDROP | JBIDXNUM (Drop number index) + * - `JBIDXDROPALL` Drop index for all types. + * - `JBIDXREBLD` Rebuild index of specified type. + * - `JBIDXOP` Optimize index of specified type. * * Examples: * - Set index for JSON path `addressbook.number` for strings and numbers: - * `ejdbsetindex(ccoll, "album.number", JDIDXSTR | JDIDXNUM)` + * `ejdbsetindex(ccoll, "album.number", JBIDXSTR | JBIDXNUM)` * - Set index for array: - * `ejdbsetindex(ccoll, "album.tags", JDIDXARR)` + * `ejdbsetindex(ccoll, "album.tags", JBIDXARR)` * - Rebuild previous index: - * `ejdbsetindex(ccoll, "album.tags", JDIDXARR | JDIDXREBLD)` + * `ejdbsetindex(ccoll, "album.tags", JBIDXARR | JBIDXREBLD)` * * Many index examples can be found in `testejdb/t2.c` test case. * @@ -280,11 +280,11 @@ EJDB_EXPORT bool ejdbsetindex(EJCOLL *coll, const char *ipath, int flags); * @param jcoll EJDB database * @param q Query handle created with ejdbcreatequery() * @param count Output count pointer. Result set size will be stored into it. - * @param qflags Execution flag. If EJQRYCOUNT is set the only count of matching records will be computed + * @param qflags Execution flag. If JBQRYCOUNT is set the only count of matching records will be computed * without resultset, this operation is analog of count(*) in SQL and can be faster than operations with resultsets. * @param log Optional extended string to collect debug information during query execution, can be NULL. * @return TCLIST with matched bson records data. - * If (qflags & EJQRYCOUNT) then NULL will be returned + * If (qflags & JBQRYCOUNT) then NULL will be returned * and only count reported. */ EJDB_EXPORT TCLIST* ejdbqrysearch(EJCOLL *jcoll, const EJQ *q, uint32_t *count, int qflags, TCXSTR *log); diff --git a/tcejdb/samples/sample1/sample1.c b/tcejdb/samples/sample1/sample1.c index df2ab0e..266bf24 100644 --- a/tcejdb/samples/sample1/sample1.c +++ b/tcejdb/samples/sample1/sample1.c @@ -6,7 +6,7 @@ static EJDB *jb; int main() { setlocale(LC_ALL, "en_US.UTF-8"); jb = ejdbnew(); - if (!ejdbopen(jb, "addressbook", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) { + if (!ejdbopen(jb, "addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)) { return 1; } diff --git a/tcejdb/testejdb/t1.c b/tcejdb/testejdb/t1.c index d9a5a85..17c24e9 100644 --- a/tcejdb/testejdb/t1.c +++ b/tcejdb/testejdb/t1.c @@ -19,7 +19,7 @@ static EJDB *jb; int init_suite(void) { jb = ejdbnew(); - if (!ejdbopen(jb, "dbt1", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) { + if (!ejdbopen(jb, "dbt1", JBOWRITER | JBOCREAT | JBOTRUNC)) { return 1; } return 0; diff --git a/tcejdb/testejdb/t2.c b/tcejdb/testejdb/t2.c index f9e86eb..d1aea95 100644 --- a/tcejdb/testejdb/t2.c +++ b/tcejdb/testejdb/t2.c @@ -23,7 +23,7 @@ static EJDB *jb; int init_suite(void) { jb = ejdbnew(); - if (!ejdbopen(jb, "dbt2", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) { + if (!ejdbopen(jb, "dbt2", JBOWRITER | JBOCREAT | JBOTRUNC)) { return 1; } return 0; @@ -118,11 +118,11 @@ void testAddData() { void testSetIndex1() { EJCOLL *ccoll = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(ccoll); - CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXSTR)); - CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXSTR | JDIDXNUM)); - CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JDIDXDROPALL)); - CU_ASSERT_TRUE(ejdbsetindex(ccoll, "address.zip", JDIDXSTR)); - CU_ASSERT_TRUE(ejdbsetindex(ccoll, "name", JDIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXSTR | JBIDXNUM)); + CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(ccoll, "address.zip", JBIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(ccoll, "name", JBIDXSTR)); //Insert new record with active index //Record 4 @@ -297,7 +297,7 @@ void testQuery2() { void testQuery3() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.zip", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.zip", JBIDXDROPALL)); bson bsq1; bson_init_as_query(&bsq1); @@ -354,7 +354,7 @@ void testQuery3() { void testQuery4() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL)); bson bsq1; bson_init_as_query(&bsq1); @@ -442,7 +442,7 @@ void testQuery5() { void testQuery6() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JDIDXARR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXARR)); bson bsq1; bson_init_as_query(&bsq1); @@ -617,7 +617,7 @@ void testQuery8() { void testQuery9() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXDROPALL)); bson bsq1; bson_init_as_query(&bsq1); @@ -675,7 +675,7 @@ void testQuery9() { void testQuery10() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JDIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXSTR)); //"address.street" : {"$in" : ["Pirogova", "Beverly Hills"]} bson bsq1; @@ -740,7 +740,7 @@ void testQuery10() { void testQuery11() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXDROPALL)); //"address.street" : {"$in" : ["Pirogova", "Beverly Hills"]} bson bsq1; @@ -937,7 +937,7 @@ void testQuery13() { void testQuery14() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "drinks", JDIDXARR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "drinks", JBIDXARR)); //"drinks" : {"$in" : [4, 77676.22]} bson bsq1; @@ -991,7 +991,7 @@ void testQuery14() { void testQuery15() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM)); bson bsq1; bson_init_as_query(&bsq1); @@ -1037,7 +1037,7 @@ void testQuery15() { void testQuery16() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL)); bson bsq1; bson_init_as_query(&bsq1); @@ -1082,7 +1082,7 @@ void testQuery16() { void testQuery17() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM)); //"dblscore" : {"$bt" : [0.95, 0.3]} bson bsq1; @@ -1144,7 +1144,7 @@ void testQuery17() { tclistdel(q1res); ejdbquerydel(q1); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL)); bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "dblscore"); @@ -1203,7 +1203,7 @@ void testQuery17() { void testQuery18() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXARR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR)); //{"name" : {$strand : ["Travolta", "John"]}} bson bsq1; @@ -1258,7 +1258,7 @@ void testQuery18() { //Second query tcxstrclear(log); tclistdel(q1res); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL)); count = 0; q1res = ejdbqrysearch(contacts, q1, &count, 0, log); @@ -1292,7 +1292,7 @@ void testQuery18() { void testQuery19() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXARR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR)); //{"name" : {$stror : ["Travolta", "Антонов", "John"]}} bson bsq1; @@ -1351,7 +1351,7 @@ void testQuery19() { //No-index query tcxstrclear(log); tclistdel(q1res); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL)); count = 0; q1res = ejdbqrysearch(contacts, q1, &count, 0, log); @@ -1390,7 +1390,7 @@ void testQuery20() { //{'dblscore' : {'$gte' : 0.93}} EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM)); bson bsq1; bson_init_as_query(&bsq1); @@ -1489,7 +1489,7 @@ void testQuery20() { ejdbquerydel(q1); //NOINDEX - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL)); //NOINDEX GTE bson_init_as_query(&bsq1); @@ -1548,7 +1548,7 @@ void testQuery21() { //{'dblscore' : {'lte' : 0.93}} EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXNUM)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM)); //LTE bson bsq1; @@ -1656,7 +1656,7 @@ void testQuery21() { tcxstrdel(log); ejdbquerydel(q1); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL)); //NOINDEX GTE bson_init_as_query(&bsq1); @@ -1714,7 +1714,7 @@ void testQuery21() { void testQuery22() { EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(contacts); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JDIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JBIDXSTR)); //{"address.country" : {$begin : "Ru"}} bson bsq1; @@ -1777,7 +1777,7 @@ void testQuery22() { tcxstrdel(log); ejdbquerydel(q1); - CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JDIDXDROPALL)); + CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JBIDXDROPALL)); bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "address.country"); diff --git a/tcejdb/testejdb/t3.c b/tcejdb/testejdb/t3.c index 1c2ac2b..f39e235 100644 --- a/tcejdb/testejdb/t3.c +++ b/tcejdb/testejdb/t3.c @@ -26,7 +26,7 @@ static bson* recs; int init_suite(void) { assert(QRS < RS); jb = ejdbnew(); - if (!ejdbopen(jb, "dbt3", JDBOWRITER | JDBOCREAT | JDBOTRUNC)) { + if (!ejdbopen(jb, "dbt3", JBOWRITER | JBOCREAT | JBOTRUNC)) { return 1; } srandom(tcmstime()); @@ -89,7 +89,7 @@ void testPerf1() { EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL); assert(q); uint32_t count; - ejdbqrysearch(coll, q, &count, EJQRYCOUNT, NULL); + ejdbqrysearch(coll, q, &count, JBQRYCOUNT, NULL); assert(count); if (count != 1) { fprintf(stderr, "CNT=%u\n", count); @@ -102,7 +102,7 @@ void testPerf1() { i, tcmstime() - st, (unsigned long) ((tcmstime() - st) / QRS)); st = tcmstime(); - CU_ASSERT_TRUE(ejdbsetindex(coll, "rstring", JDIDXSTR)); + CU_ASSERT_TRUE(ejdbsetindex(coll, "rstring", JBIDXSTR)); fprintf(stderr, "testPerf1(): SET INDEX 'rstring' TIME: %lu ms\n", tcmstime() - st); st = tcmstime(); @@ -114,7 +114,7 @@ void testPerf1() { EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL); assert(q); uint32_t count; - ejdbqrysearch(coll, q, &count, EJQRYCOUNT, NULL); + ejdbqrysearch(coll, q, &count, JBQRYCOUNT, NULL); assert(count); acount += count; ejdbquerydel(q); -- 2.7.4