summaryrefslogtreecommitdiff
path: root/storage/connect/tabjmg.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2017-07-18 13:16:55 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2017-07-18 13:16:55 +0200
commitf590296c28ec54007692181e010d7064c1071ff2 (patch)
tree8ca5932a93f59bb60abfb0928ef483e96ed999d6 /storage/connect/tabjmg.cpp
parenta9d32010d0ba36cc9b9d7fb58eeace687bb13f7a (diff)
downloadmariadb-git-f590296c28ec54007692181e010d7064c1071ff2.tar.gz
-- Finalize work on MongoDB access
Implement discovery for the MongoDB Java Driver Create classes to minimize code and avoid dupicates Rearrange and rename implied files modified: storage/connect/CMakeLists.txt renamed: storage/connect/mongofam.cpp -> storage/connect/cmgfam.cpp renamed: storage/connect/mongofam.h -> storage/connect/cmgfam.h modified: storage/connect/cmgoconn.h modified: storage/connect/javaconn.h modified: storage/connect/jdbconn.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/jmgoconn.h modified: storage/connect/mongo.cpp modified: storage/connect/mongo.h renamed: storage/connect/tabmgo.cpp -> storage/connect/tabcmg.cpp renamed: storage/connect/tabmgo.h -> storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabjmg.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h -- Trace Sarea allocation and freeing modified: storage/connect/connect.cc modified: storage/connect/plugutil.cpp modified: storage/connect/user_connect.cc -- Null Json values where not mark as null in JSNX::SetJsonValue This was added in TYPE_NULL (declared as TYPE_VOID) modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp -- Null JValues are ignored in JSNX::CalculateArray Also done in tabjson.cpp for JSONCOL::CalculateArray modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp -- Null JSON values now represented by connect_json_null session variable modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp -- JVALUE has size = 1 modified: storage/connect/json.h -- Fix by vuvova because Debian compilation failure. modified: storage/connect/value.cpp
Diffstat (limited to 'storage/connect/tabjmg.cpp')
-rw-r--r--storage/connect/tabjmg.cpp129
1 files changed, 105 insertions, 24 deletions
diff --git a/storage/connect/tabjmg.cpp b/storage/connect/tabjmg.cpp
index bf147e76cc0..76a6c3aff6c 100644
--- a/storage/connect/tabjmg.cpp
+++ b/storage/connect/tabjmg.cpp
@@ -27,13 +27,108 @@
#include "mycat.h" // for FNC_COL
#include "filter.h"
+PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info);
+
+/* -------------------------- Class JMGDISC -------------------------- */
+
/***********************************************************************/
-/* This should be an option. */
+/* Initialyze. */
/***********************************************************************/
-#define MAXCOL 200 /* Default max column nb in result */
-#define TYPE_UNKNOWN 12 /* Must be greater than other types */
+bool JMGDISC::Init(PGLOBAL g)
+{
+ if (!(Jcp = ((TDBJMG*)tmgp)->Jcp)) {
+ strcpy(g->Message, "Init: Jcp is NULL");
+ return true;
+ } else if (Jcp->gmID(g, columnid, "ColumnDesc",
+ "(Ljava/lang/Object;I[II)Ljava/lang/Object;"))
+ return true;
+ else if (Jcp->gmID(g, bvnameid, "ColDescName", "()Ljava/lang/String;"))
+ return true;
+
+ return false;
+} // end of Init
+
+/***********************************************************************/
+/* Analyse passed document. */
+/***********************************************************************/
+bool JMGDISC::Find(PGLOBAL g)
+{
+ return ColDesc(g, nullptr, NULL, NULL, Jcp->m_Ncol, 0);
+} // end of Find
+
+/***********************************************************************/
+/* Analyse passed document. */
+/***********************************************************************/
+bool JMGDISC::ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt,
+ int ncol, int k)
+{
+ const char *key;
+ char colname[65];
+ char fmt[129];
+ bool rc = true;
+ jint *n = nullptr;
+ jstring jkey;
+ jobject jres;
+
+ // Build the java int array
+ jintArray val = Jcp->env->NewIntArray(5);
+
+ if (val == nullptr) {
+ strcpy(g->Message, "Cannot allocate jint array");
+ return true;
+ } else if (!ncol)
+ n = Jcp->env->GetIntArrayElements(val, 0);
+
+ for (int i = 0; i < ncol; i++) {
+ jres = Jcp->env->CallObjectMethod(Jcp->job, columnid, obj, i, val, lvl - k);
+ n = Jcp->env->GetIntArrayElements(val, 0);
+
+ if (Jcp->Check(n[0])) {
+ sprintf(g->Message, "ColDesc: %s", Jcp->Msg);
+ goto err;
+ } else if (!n[0])
+ continue;
+
+ jkey = (jstring)Jcp->env->CallObjectMethod(Jcp->job, bvnameid);
+ key = Jcp->env->GetStringUTFChars(jkey, (jboolean)false);
+
+ if (pcn) {
+ strncpy(colname, pcn, 64);
+ colname[64] = 0;
+ strncat(strncat(colname, "_", 65), key, 65);
+ } else
+ strcpy(colname, key);
+
+ if (pfmt) {
+ strncpy(fmt, pfmt, 128);
+ fmt[128] = 0;
+ strncat(strncat(fmt, ".", 129), key, 129);
+ } else
+ strcpy(fmt, key);
-PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
+ if (!jres) {
+ bcol.Type = n[0];
+ bcol.Len = n[1];
+ bcol.Scale = n[2];
+ bcol.Cbn = n[3];
+ AddColumn(g, colname, fmt, k);
+ } else {
+ if (n[0] == 2 && !all)
+ n[4] = MY_MIN(n[4], 1);
+
+ if (ColDesc(g, jres, colname, fmt, n[4], k + 1))
+ goto err;
+
+ } // endif jres
+
+ } // endfor i
+
+ rc = false;
+
+ err:
+ Jcp->env->ReleaseIntArrayElements(val, n, 0);
+ return rc;
+} // end of ColDesc
/* --------------------------- Class TDBJMG -------------------------- */
@@ -82,16 +177,6 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
TDBJMG::TDBJMG(TDBJMG *tdbp) : TDBEXT(tdbp)
{
Uri = tdbp->Uri;
-//Pool = tdbp->Pool;
-//Client = tdbp->Client;
-//Database = NULL;
-//Collection = tdbp->Collection;
-//Cursor = tdbp->Cursor;
-//Query = tdbp->Query;
-//Opts = tdbp->Opts;
-//Fpc = tdbp->Fpc;
-//Cnd = tdbp->Cnd;
-//Uristr = tdbp->Uristr;
Db_name = tdbp->Db_name;;
Coll_name = tdbp->Coll_name;
Options = tdbp->Options;
@@ -126,11 +211,7 @@ PTDB TDBJMG::Clone(PTABS t)
/***********************************************************************/
PCOL TDBJMG::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
{
- PJMGCOL colp = new(g) JMGCOL(g, cdp, this, cprec, n);
-
-//colp->Mbuf = (char*)PlugSubAlloc(g, NULL, colp->Long + 1);
- return colp;
- //return (colp->ParseJpath(g)) ? NULL : colp;
+ return new(g) JMGCOL(g, cdp, this, cprec, n);
} // end of MakeCol
/***********************************************************************/
@@ -497,12 +578,12 @@ TDBJGL::TDBJGL(PMGODEF tdp) : TDBCAT(tdp)
Db = tdp->GetTabschema();
} // end of TDBJCL constructor
- /***********************************************************************/
- /* GetResult: Get the list the JSON file columns. */
- /***********************************************************************/
+/***********************************************************************/
+/* GetResult: Get the list the MongoDB collection columns. */
+/***********************************************************************/
PQRYRES TDBJGL::GetResult(PGLOBAL g)
{
- return JSONColumns(g, Db, Uri, Topt, false);
+ return MGOColumns(g, Db, Uri, Topt, false);
} // end of GetResult
- /* -------------------------- End of mongo --------------------------- */
+/* -------------------------- End of mongo --------------------------- */