/***********************************************************************/ /* AddJars: add some jar file to the Class path. */ /***********************************************************************/ void JMgoConn::AddJars(PSTRG jpop, char sep)
{ #ifdefined(DEVELOPMENT) if (m_Version == 2) {
jpop->Append(sep); // jpop->Append("C:/Eclipse/workspace/MongoWrap2/bin"); // jpop->Append(sep);
jpop->Append("C:/mongo-java-driver/mongo-java-driver-2.13.3.jar");
} else {
jpop->Append(sep); // jpop->Append("C:/Eclipse/workspace/MongoWrap3/bin"); // jpop->Append(sep); // jpop->Append("C:/Program Files/MariaDB 10.1/lib/plugin/JavaWrappers.jar"); // jpop->Append(sep);
jpop->Append("C:/mongo-java-driver/mongo-java-driver-3.4.2.jar");
} // endif m_Version #endif// DEVELOPMENT
} // end of AddJars
/***********************************************************************/ /* Connect: connect to a data source. */ /***********************************************************************/ bool JMgoConn::Connect(PJPARM sop)
{ bool err = false;
jint rc;
jboolean brc;
jstring cln;
PGLOBAL& g = m_G;
m_Version = sop->Version;
/*******************************************************************/ /* Create or attach a JVM. */ /*******************************************************************/ if (Open(g)) returntrue;
/*********************************************************************/ /* Get the collection. */ /*********************************************************************/ if (gmID(g, gcollid, "GetCollection", "(Ljava/lang/String;)Z")) returntrue;
m_Connected = true; returnfalse;
} // end of Connect
/***********************************************************************/ /* CollSize: returns the number of documents in the collection. */ /***********************************************************************/ int JMgoConn::CollSize(PGLOBAL g)
{ if (!gmID(g, countid, "GetCollSize", "()J")) {
jlong card = env->CallLongMethod(job, countid);
return (int)card;
} else return2; // Make MariaDB happy
} // end of CollSize
/***********************************************************************/ /* OpenDB: Data Base open routine for MONGO access method. */ /***********************************************************************/ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options,
PCSZ filter, bool pipe)
{ constchar *p; bool id, b = false, all = false;
uint len;
PCOL cp;
PSZ jp;
PCSZ op = NULL, sf = NULL, Options = options;
PSTRG s = NULL;
PFIL filp = tdbp->GetFilter();
if (Options && !stricmp(Options, "all")) {
Options = NULL;
all = true;
} else
id = (tdbp->GetMode() == MODE_UPDATE || tdbp->GetMode() == MODE_DELETE);
for (cp = tdbp->GetColumns(); cp && !all; cp = cp->GetNext()) if (cp->GetFmt() && !strcmp(cp->GetFmt(), "*") && (!Options || pipe))
all = true; elseif (!id)
id = !strcmp(cp->GetJpath(g, false), "_id");
if (pipe && Options) { if (trace(1))
htrc("Pipeline: %s\n", Options);
p = strrchr(Options, ']');
if (!p) {
snprintf(g->Message, sizeof(g->Message), "Missing ] in pipeline"); returntrue;
} else
*(char*)p = 0;
s = new(g) STRING(g, 1023, (PSZ)Options);
if (filp) {
s->Append(",{\"$match\":");
if (MakeSelector(g, filp, s)) {
snprintf(g->Message, sizeof(g->Message), "Failed making selector"); returntrue;
} else
s->Append('}');
tdbp->SetFilter(NULL); // Not needed anymore
} // endif To_Filter
if (!all && tdbp->GetColumns()) { // Project list
len = s->GetLength();
s->Append(",{\"$project\":{\"");
if (!id)
s->Append("_id\":0,\"");
for (PCOL cp = tdbp->GetColumns(); cp; cp = cp->GetNext()) { if (b)
s->Append(",\""); else
b = true;
/***********************************************************************/ /* Find a collection and make cursor. */ /***********************************************************************/ bool JMgoConn::FindCollection(PCSZ query, PCSZ proj)
{ bool rc = true;
jboolean brc;
jstring qry = nullptr, prj = nullptr;
PGLOBAL& g = m_G;
// Get the methods used to execute a query and get the result if (!gmID(g, fcollid, "FindColl", "(Ljava/lang/String;Ljava/lang/String;)Z")) { if (query)
qry = env->NewStringUTF(query);
/***********************************************************************/ /* Find a collection and make cursor. */ /***********************************************************************/ bool JMgoConn::AggregateCollection(PCSZ pipeline)
{ bool rc = true;
jboolean brc;
jstring pip = nullptr;
PGLOBAL& g = m_G;
// Get the methods used to execute a query and get the result if (!gmID(g, acollid, "AggregateColl", "(Ljava/lang/String;)Z")) {
pip = env->NewStringUTF(pipeline);
/***********************************************************************/ /* Get the Json string of the current document. */ /***********************************************************************/
PSZ JMgoConn::GetDocument(void)
{
PGLOBAL& g = m_G;
PSZ doc = NULL;
jstring jdc;
if (!gmID(g, getdocid, "GetDoc", "()Ljava/lang/String;")) {
jdc = (jstring)env->CallObjectMethod(job, getdocid);
if (jdc)
doc = (PSZ)GetUTFString(jdc);
} // endif getdocid
return doc;
} // end of GetDocument
/***********************************************************************/ /* Group columns for inserting or updating. */ /***********************************************************************/ void JMgoConn::MakeColumnGroups(PGLOBAL g, PTDB tdbp)
{
Fpc = new(g) JNCOL();
for (PCOL colp = tdbp->GetColumns(); colp; colp = colp->GetNext()) if (!colp->IsSpecial())
Fpc->AddCol(g, colp, colp->GetJpath(g, false));
} // end of MakeColumnGroups
/***********************************************************************/ /* Get additional method ID. */ /***********************************************************************/ bool JMgoConn::GetMethodId(PGLOBAL g, MODE mode)
{ if (mode == MODE_UPDATE) { if (gmID(g, mkdocid, "MakeDocument", "()Ljava/lang/Object;")) returntrue;
if (gmID(g, docaddid, "DocAdd", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;I)Z")) returntrue;
if (gmID(g, updateid, "CollUpdate", "(Ljava/lang/Object;)J")) returntrue;
/***********************************************************************/ /* Insert a new document in the collation. */ /***********************************************************************/ int JMgoConn::DocWrite(PGLOBAL g, PCSZ line)
{ int rc = RC_OK;
jobject doc = nullptr;
if (line) { int j;
jobject val = env->NewStringUTF(line);
if (env->CallBooleanMethod(job, insertid, doc)) { if (Check(-1))
snprintf(g->Message, sizeof(g->Message), "CollInsert: %s", Msg); else
snprintf(g->Message, sizeof(g->Message), "CollInsert: unknown error");
rc = RC_FX;
} // endif Insert
env->DeleteLocalRef(doc); return rc;
} // end of DocWrite
/***********************************************************************/ /* Update the current document from the collection. */ /***********************************************************************/ int JMgoConn::DocUpdate(PGLOBAL g, PTDB tdbp)
{ int j = 0, rc = RC_OK; bool error;
PCOL colp;
jstring jkey;
jobject val, upd, updlist = env->CallObjectMethod(job, mkdocid);
// Make the list of changes to do for (colp = tdbp->GetSetCols(); colp; colp = colp->GetNext()) {
jkey = env->NewStringUTF(colp->GetJpath(g, false));
val = MakeObject(g, colp, error);
if (env->CallBooleanMethod(job, docaddid, updlist, jkey, val, j)) return RC_OK;
env->DeleteLocalRef(jkey);
} // endfor colp
// Make the update parameter
upd = env->CallObjectMethod(job, mkdocid);
jkey = env->NewStringUTF("$set");
if (env->CallBooleanMethod(job, docaddid, upd, jkey, updlist, 0)) return RC_OK;
env->DeleteLocalRef(jkey);
jlong ar = env->CallLongMethod(job, updateid, upd);
if (trace(1))
htrc("DocUpdate: ar = %ld\n", ar);
if (Check((int)ar)) {
snprintf(g->Message, sizeof(g->Message), "CollUpdate: %s", Msg);
rc = RC_FX;
} // endif ar
return rc;
} // end of DocUpdate
/***********************************************************************/ /* Remove all or only the current document from the collection. */ /***********************************************************************/ int JMgoConn::DocDelete(PGLOBAL g, bool all)
{ int rc = RC_OK;
jlong ar = env->CallLongMethod(job, deleteid, all);
if (trace(1))
htrc("DocDelete: ar = %ld\n", ar);
if (Check((int)ar)) {
snprintf(g->Message, sizeof(g->Message), "CollDelete: %s", Msg);
rc = RC_FX;
} // endif ar
return rc;
} // end of DocDelete
/***********************************************************************/ /* Rewind the collection. */ /***********************************************************************/ bool JMgoConn::Rewind(void)
{ return env->CallBooleanMethod(job, rewindid);
} // end of Rewind
/***********************************************************************/ /* Retrieve the column string value from the document. */ /***********************************************************************/
PSZ JMgoConn::GetColumnValue(PSZ path)
{
PGLOBAL& g = m_G;
PSZ fld = NULL;
jstring fn, jn = nullptr;
if (!path || (jn = env->NewStringUTF(path)) == nullptr) {
snprintf(g->Message, sizeof(g->Message), "Fail to allocate jstring %s", SVP(path)); throw (int)TYPE_AM_MGO;
} // endif name
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.