From: adam Date: Thu, 18 Jul 2013 11:44:31 +0000 (+0700) Subject: #59 #72 X-Git-Tag: v1.2.12~267 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e308822e4b66dc4080c4816e8d93ae084289744;p=platform%2Fupstream%2Fejdb.git #59 #72 --- diff --git a/nejdb/Ejdb.DB/EJDB.cs b/nejdb/Ejdb.DB/EJDB.cs index ed173e0..659a511 100644 --- a/nejdb/Ejdb.DB/EJDB.cs +++ b/nejdb/Ejdb.DB/EJDB.cs @@ -226,6 +226,9 @@ namespace Ejdb.DB { UnixMarshal.FreeHeap(cptr); } } + //EJDB_EXPORT bson* ejdbcommand(EJDB *jb, bson *cmd); + [DllImport(EJDB_LIB_NAME, EntryPoint="ejdbcommand2")] + internal static extern IntPtr _ejdbcommand([In] IntPtr db, [In] byte[] cmd); //EJDB_EXPORT bool ejdbsavebson3(EJCOLL *jcoll, void *bsdata, bson_oid_t *oid, bool merge); [DllImport(EJDB_LIB_NAME, EntryPoint="ejdbsavebson3")] internal static extern bool _ejdbsavebson([In] IntPtr coll, [In] byte[] bsdata, [Out] byte[] oid, [In] bool merge); @@ -799,6 +802,60 @@ namespace Ejdb.DB { } /// + /// Executes EJDB command. + /// + /// + /// Supported commands: + /// + /// 1) Exports database collections data. See ejdbexport() method. + /// + /// "export" : { + /// "path" : string, //Exports database collections data + /// "cnames" : [string array]|null, //List of collection names to export + /// "mode" : int|null //Values: null|`JBJSONEXPORT` See ejdbexport() method + /// } + /// + /// Command response: + /// { + /// "log" : string, //Diagnostic log about executing this command + /// "error" : string|null, //ejdb error message + /// "errorCode" : int|0, //ejdb error code + /// } + /// + /// 2) Imports previously exported collections data into ejdb. + /// + /// "import" : { + /// "path" : string //The directory path in which data resides + /// "cnames" : [string array]|null, //List of collection names to import + /// "mode" : int|null //Values: null|`JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdbimport() method + /// } + /// + /// Command response: + /// { + /// "log" : string, //Diagnostic log about executing this command + /// "error" : string|null, //ejdb error message + /// "errorCode" : int|0, //ejdb error code + /// } + /// + /// Command object + /// Command response. + public BSONDocument Command(BSONDocument cmd) { + CheckDisposed(); + byte[] cmdata = cmd.ToByteArray(); + //internal static extern IntPtr _ejdbcommand([In] IntPtr db, [In] byte[] cmd); + IntPtr cmdret = _ejdbcommand(_db, cmdata); + if (cmdret == IntPtr.Zero) { + return null; + } + byte[] bsdata = BsonPtrIntoByteArray(cmdret); + if (bsdata.Length == 0) { + return null; + } + BSONIterator it = new BSONIterator(bsdata); + return it.ToBSONDocument(); + } + + /// /// Save the BSON document doc into the collection. /// /// Name of collection. @@ -854,6 +911,7 @@ namespace Ejdb.DB { } return true; } + bool Save(IntPtr cptr, BSONDocument doc, bool merge) { bool rv; diff --git a/nejdb/Ejdb.Tests/TestEJDB.cs b/nejdb/Ejdb.Tests/TestEJDB.cs index c921fa3..b8b916b 100644 --- a/nejdb/Ejdb.Tests/TestEJDB.cs +++ b/nejdb/Ejdb.Tests/TestEJDB.cs @@ -182,6 +182,14 @@ namespace Ejdb.Tests { //[BSONValue: BSONType=ARRAY, Key=collections, Value=[BSONArray: [BSONValue: BSONType=OBJECT, Key=0, Value=[BSONDocument: [BSONValue: BSONType=STRING, Key=name, Value=parrots], [BSONValue: BSONType=STRING, Key=file, Value=testdb1_parrots], [BSONValue: BSONType=LONG, Key=records, Value=2], [BSONValue: BSONType=OBJECT, Key=options, Value=[BSONDocument: [BSONValue: BSONType=LONG, Key=buckets, Value=131071], [BSONValue: BSONType=LONG, Key=cachedrecords, Value=0], [BSONValue: BSONType=BOOL, Key=large, Value=False], [BSONValue: BSONType=BOOL, Key=compressed, Value=False]]], [BSONValue: BSONType=ARRAY, Key=indexes, Value=[BSONArray: ]]]]]]] q.Dispose(); + + //Test command execution + BSONDocument cmret = jb.Command(BSONDocument.ValueOf(new { + ping = "" + })); + Assert.IsNotNull(cmret); + Assert.AreEqual("pong", cmret["log"]); + jb.Dispose(); } } diff --git a/tcejdb/debian/libtcejdb9.symbols b/tcejdb/debian/libtcejdb9.symbols index 63a468f..b4587a0 100644 --- a/tcejdb/debian/libtcejdb9.symbols +++ b/tcejdb/debian/libtcejdb9.symbols @@ -162,6 +162,7 @@ libtcejdb.so.9 libtcejdb9 #MINVER# ejcollockmethod@Base 1.1.8 ejcollunlockmethod@Base 1.1.8 ejdbclose@Base 1.1.8 + ejdbcommand2@Base 1.1.14 ejdbcommand@Base 1.1.14 ejdbcreatecoll@Base 1.1.8 ejdbcreatequery2@Base 1.1.13 diff --git a/tcejdb/ejdb.c b/tcejdb/ejdb.c index d54d1c9..adafc36 100644 --- a/tcejdb/ejdb.c +++ b/tcejdb/ejdb.c @@ -843,6 +843,13 @@ finish: return !err; } +bson* ejdbcommand2(EJDB *jb, void *cmdbsondata) { + bson cmd; + bson_init_with_data(&cmd, cmdbsondata); + bson *bret = ejdbcommand(jb, &cmd); + return bret; +} + bson* ejdbcommand(EJDB *jb, bson *cmd) { bson *ret = bson_create(); int ecode = 0; diff --git a/tcejdb/ejdb.h b/tcejdb/ejdb.h index d527f14..a21c79d 100644 --- a/tcejdb/ejdb.h +++ b/tcejdb/ejdb.h @@ -596,7 +596,8 @@ EJDB_EXPORT bool ejdbimport(EJDB *jb, const char *path, TCLIST *cnames, int flag * @param cmd BSON command spec. * @return Allocated BSON command response object. Caller shoud call `bson_del()` on it. */ -EJDB_EXPORT bson* ejdbcommand(EJDB *jb, bson *cmd); +EJDB_EXPORT bson* ejdbcommand(EJDB *jb, bson *cmdbson); +EJDB_EXPORT bson* ejdbcommand2(EJDB *jb, void *cmdbsondata); EJDB_EXTERN_C_END