Commit 94e5d7de authored by Olivier Bertrand's avatar Olivier Bertrand

- Add Support of the MongoDB Java Driver.

  modified:   storage/connect/CMakeLists.txt
  modified:   storage/connect/JavaWrappers.jar
  modified:   storage/connect/colblk.h
  modified:   storage/connect/filter.cpp
  modified:   storage/connect/filter.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/ha_connect.h
  modified:   storage/connect/jdbccat.h
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/mongofam.cpp
  modified:   storage/connect/mongofam.h
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/mycat.h
  modified:   storage/connect/tabext.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabjdbc.h
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  modified:   storage/connect/tabmgo.cpp
  modified:   storage/connect/tabmgo.h
  created:    storage/connect/Mongo2Interface.java
  created:    storage/connect/Mongo3Interface.java
  created:    storage/connect/cmgoconn.cpp
  created:    storage/connect/cmgoconn.h
  created:    storage/connect/javaconn.cpp
  created:    storage/connect/javaconn.h
  created:    storage/connect/jmgfam.cpp
  created:    storage/connect/jmgfam.h
  created:    storage/connect/jmgoconn.cpp
  created:    storage/connect/jmgoconn.h
  created:    storage/connect/mongo.cpp
  created:    storage/connect/mongo.h
  created:    storage/connect/tabjmg.cpp
  created:    storage/connect/tabjmg.h

- tdbp not initialized when catched exception
in CntGetTDB (connect.cc line 188)
  modified:   storage/connect/connect.h

- CheckCleanup should sometimes doing cleanup on pure info
Sometimes MariaDB loops on info to get the size of all tables in a database.
This can sometimes fail by exhausted memory.
CheckCleanup now have a force boolean parameter (defaulting to false)
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/user_connect.cc
  modified:   storage/connect/user_connect.h

Change the copyright of some source files
  modified:   storage/connect/connect.cc
  modified:   storage/connect/connect.h
  modified:   storage/connect/engmsg.h
  modified:   storage/connect/global.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/ha_connect.h
  modified:   storage/connect/msgid.h
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/mycat.h
  modified:   storage/connect/os.h
  modified:   storage/connect/osutil.c
  modified:   storage/connect/osutil.h
  modified:   storage/connect/user_connect.cc
  modified:   storage/connect/user_connect.h
parent c51548d6
......@@ -245,7 +245,7 @@ int main() {
ENDIF(CONNECT_WITH_ODBC)
#
# JDBC
# JDBC and MongoDB Java Driver
#
IF(APPLE)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine without JDBC support" OFF)
......@@ -262,9 +262,13 @@ IF(CONNECT_WITH_JDBC)
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY}) will be dynamically linked
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h
javaconn.cpp jdbconn.cpp tabjdbc.cpp
jmgoconn.cpp jmgfam.cpp mongo.cpp tabjmg.cpp
jdbccat.h javaconn.h jdbconn.h tabjdbc.h
jmgoconn.h jmgfam.h mongo.h tabjmg.h
JdbcInterface.java ApacheInterface.java MariadbInterface.java
MysqlInterface.java OracleInterface.java PostgresqlInterface.java
Mongo2Interface.java Mongo3Interface.java
JavaWrappers.jar)
# TODO: Find how to compile and install the java wrapper classes
# Find required libraries and include directories
......@@ -292,7 +296,7 @@ IF(CONNECT_WITH_ZIP)
ENDIF(CONNECT_WITH_ZIP)
#
# MONGO (CMAKE NOT YET WORKING)
# MONGO C Driver (CMAKE NOT YET WORKING)
#
#OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
......@@ -302,16 +306,21 @@ ENDIF(CONNECT_WITH_ZIP)
# # Adding some typical places to search in
# SET(PC_MONGO_INCLUDE_DIRS
# C:/mongo-c-driver/include
# D:/mongo-c-driver/include)
# D:/mongo-c-driver/include)
# SET(PC_MONGO_LIBRARY_DIRS
# C:/mongo-c-driver/lib
# D:/mongo-c-driver/lib)
# D:/mongo-c-driver/lib)
# ENDIF(WIN32)
# FIND_PACKAGE(libmongoc)
# IF (MONGO_FOUND)
# INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
# SET(MONGO_LIBRARY ${MONGO_LIBRARIES})
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongofam.cpp mongofam.h)
# SET(CONNECT_SOURCES ${CONNECT_SOURCES}
# cmgoconn.cpp mongofam.cpp tabmgo.cpp
# cmgoconn.h mongofam.h tabmgo.h)
# IF (NOT JAVA_FOUND AND JNI_FOUND)
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
# add_definitions(-DMONGO_SUPPORT)
# ENDIF(MONGO_FOUND)
#ENDIF(CONNECT_WITH_MONGO)
......@@ -339,3 +348,4 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${IPHLPAPI_LIBRARY})
This diff was suppressed by a .gitattributes entry.
package wrappers;
import java.util.Date;
import java.util.List;
import java.util.Set;
import com.mongodb.AggregationOptions;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.Cursor;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoException;
import com.mongodb.WriteConcernException;
import com.mongodb.WriteResult;
import com.mongodb.util.JSON;
public class Mongo2Interface {
boolean DEBUG = false;
String Errmsg = "No error";
Set<String> Colnames = null;
Cursor cursor = null;
MongoClient client = null;
DB db = null;
DBCollection coll = null;
BasicDBObject doc = null;
BasicDBObject dbq = null;
BasicDBObject dbf = null;
List<DBObject> pip = null;
AggregationOptions aop = null;
// === Constructors/finalize =========================================
public Mongo2Interface() {
this(false);
} // end of default constructor
public Mongo2Interface(boolean b) {
DEBUG = b;
} // end of constructor
protected void SetErrmsg(String str) {
if (DEBUG)
System.out.println(str);
Errmsg = str;
} // end of SetErrmsg
protected void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int MongoConnect(String[] parms) {
int rc = 0;
if (DEBUG)
System.out.println("Mongo2: URI=" + parms[0] + " DB=" + parms[1]);
try {
MongoClientURI uri = new MongoClientURI(parms[0]);
client = new MongoClient(uri);
if (DEBUG)
System.out.println("Connection " + client.toString() + " established");
// Now connect to your databases
db = client.getDB(parms[1]);
if (parms[2] != null && !parms[2].isEmpty()) {
if (DEBUG)
System.out.println("user=" + parms[2] + " pwd=" + parms[3]);
@SuppressWarnings("deprecation")
boolean auth = db.authenticate(parms[2], parms[3].toCharArray());
if (DEBUG)
System.out.println("Authentication: " + auth);
} // endif user
} catch (MongoException me) {
SetErrmsg(me);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of MongoConnect
public int MongoDisconnect() {
int rc = 0;
try {
if (cursor != null) {
if (DEBUG)
System.out.println("Closing cursor");
cursor.close();
cursor = null;
} // endif client
if (client != null) {
if (DEBUG)
System.out.println("Closing connection");
client.close();
client = null;
} // endif client
} catch (MongoException se) {
SetErrmsg(se);
rc += 8;
} // end try/catch
return rc;
} // end of MongoDisconnect
public boolean GetCollection(String name) {
if (DEBUG)
System.out.println("GetCollection: name=" + name);
try {
coll = db.getCollection(name);
} catch (Exception e) {
SetErrmsg(e);
return true;
} // end try/catch
return false;
} // end of GetCollection
public long GetCollSize() {
return (coll != null) ? coll.count() : 0;
} // end of GetCollSize
public boolean FindColl(String query, String fields) {
if (DEBUG)
System.out.println("FindColl: query=" + query + " fields=" + fields);
try {
if (query != null || fields != null) {
dbq = (BasicDBObject) JSON.parse((query != null) ? query : "{}");
if (fields != null) {
dbf = (BasicDBObject) JSON.parse(fields);
cursor = coll.find(dbq, dbf);
} else
cursor = coll.find(dbq);
} else
cursor = coll.find();
} catch (Exception e) {
SetErrmsg(e);
return true;
} // end try/catch
return false;
} // end of FindColl
@SuppressWarnings("unchecked")
public boolean AggregateColl(String pipeline) {
if (DEBUG)
System.out.println("AggregateColl: pipeline=" + pipeline);
try {
DBObject pipe = (DBObject) JSON.parse(pipeline);
pip = (List<DBObject>) pipe.get("pipeline");
aop = AggregationOptions.builder().batchSize(0).allowDiskUse(true)
.outputMode(AggregationOptions.OutputMode.CURSOR).build();
cursor = coll.aggregate(pip, aop);
} catch (MongoException me) {
SetErrmsg(me);
return true;
} // end try/catch
return false;
} // end of AggregateColl
public boolean Rewind() {
if (cursor != null)
cursor.close();
if (pip == null) {
if (dbf != null)
cursor = coll.find(dbq, dbf);
else if (dbq != null)
cursor = coll.find(dbq);
else
cursor = coll.find();
} else
cursor = coll.aggregate(pip, aop);
return (cursor == null);
} // end of Rewind
public int ReadNext() {
try {
if (cursor.hasNext()) {
doc = (BasicDBObject) cursor.next();
if (DEBUG)
System.out.println("Class doc = " + doc.getClass());
Colnames = doc.keySet();
return 1;
} else
return 0;
} catch (MongoException me) {
SetErrmsg(me);
return -1;
} // end try/catch
} // end of ReadNext
public boolean Fetch(int row) {
if (cursor.hasNext()) {
doc = (BasicDBObject) cursor.next();
Colnames = doc.keySet();
return true;
} else
return false;
} // end of Fetch
public String GetDoc() {
return (doc != null) ? doc.toString() : null;
} // end of GetDoc
public Set<String> GetColumns() {
if (doc != null)
return doc.keySet();
else
return null;
} // end of GetColumns
public String ColumnDesc(int n, int[] val) {
// if (rsmd == null) {
// System.out.println("No result metadata");
// return null;
// } else try {
// val[0] = rsmd.getColumnType(n);
// val[1] = rsmd.getPrecision(n);
// val[2] = rsmd.getScale(n);
// val[3] = rsmd.isNullable(n);
// return rsmd.getColumnLabel(n);
// } catch (SQLException se) {
// SetErrmsg(se);
// } //end try/catch
return null;
} // end of ColumnDesc
protected Object GetFieldObject(String path) {
Object o = null;
BasicDBObject dob = null;
BasicDBList lst = null;
String[] names = null;
if (path == null || path.equals("*"))
return doc;
else if (doc instanceof BasicDBObject)
dob = doc;
// else if (o instanceof BasicDBList)
// lst = (BasicDBList) doc;
else
return doc;
try {
names = path.split("\\.");
for (String name : names) {
if (lst != null) {
o = lst.get(Integer.parseInt(name));
} else
o = dob.get(name);
if (o == null)
break;
if (DEBUG)
System.out.println("Class o = " + o.getClass());
if (o instanceof BasicDBObject) {
dob = (BasicDBObject) o;
lst = null;
} else if (o instanceof BasicDBList) {
lst = (BasicDBList) o;
} else
break;
} // endfor name
} catch (IndexOutOfBoundsException x) {
o = null;
} catch (MongoException se) {
SetErrmsg(se);
o = null;
} // end try/catch
return o;
} // end of GetFieldObject
public String GetField(String path) {
Object o = GetFieldObject(path);
if (o != null) {
if (o instanceof Date) {
Integer TS = (int) (((Date) o).getTime() / 1000);
return TS.toString();
} // endif Date
return o.toString();
} else
return null;
} // end of GetField
public Object MakeDocument() {
return new BasicDBObject();
} // end of MakeDocument
public boolean DocAdd(Object bdc, String key, Object val) {
try {
((BasicDBObject) bdc).append(key, val);
} catch (MongoException me) {
SetErrmsg(me);
return true;
} // end try/catch
return false;
} // end of DocAdd
public Object MakeArray() {
return new BasicDBList();
} // end of MakeArray
public boolean ArrayAdd(Object bar, int n, Object val) {
try {
((BasicDBList) bar).put(n, val);
} catch (MongoException me) {
SetErrmsg(me);
return true;
} catch (Exception ex) {
SetErrmsg(ex);
return true;
} // end try/catch
return false;
} // end of ArrayAdd
public boolean CollInsert(Object dob) {
try {
coll.insert((BasicDBObject) dob);
} catch (MongoException me) {
SetErrmsg(me);
return true;
} catch (Exception ex) {
SetErrmsg(ex);
return true;
} // end try/catch
return false;
} // end of CollInsert
public long CollUpdate(Object upd) {
long n = -1;
if (DEBUG)
System.out.println("upd: " + upd.toString());
try {
DBObject qry = new BasicDBObject("_id", doc.get("_id"));
WriteResult res = coll.update(qry, (DBObject) upd);
if (DEBUG)
System.out.println("CollUpdate: " + res.toString());
n = res.getN();
} catch (MongoException me) {
SetErrmsg(me);
} catch (Exception ex) {
SetErrmsg(ex);
} // end try/catch
return n;
} // end of CollUpdate
public long CollDelete(boolean all) {
long n = -1;
try {
WriteResult res;
BasicDBObject qry = new BasicDBObject();
if (!all)
qry.append("_id", doc.get("_id"));
res = coll.remove(qry);
if (DEBUG)
System.out.println("CollDelete: " + res.toString());
n = res.getN();
} catch (WriteConcernException wx) {
SetErrmsg(wx);
} catch (MongoException me) {
SetErrmsg(me);
} catch (UnsupportedOperationException ux) {
SetErrmsg(ux);
n = 0;
} // end try/catch
return n;
} // end of CollDelete
} // end of class MongoInterface
This diff is collapsed.
This diff is collapsed.
/***********************************************************************/
/* CMgoConn.h : header file for the MongoDB connection classes. */
/***********************************************************************/
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
#include <bson.h>
#include <bcon.h>
#include <mongoc.h>
// C connection to a MongoDB data source
class TDBMGO;
class MGOCOL;
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
typedef class INCOL *PINCOL;
typedef class MGODEF *PMGODEF;
typedef class TDBMGO *PTDBMGO;
typedef class MGOCOL *PMGOCOL;
typedef struct mongo_parms {
PTDB Tdbp;
PCSZ Uristr; // Driver URI
PCSZ Db_name;
PCSZ Coll_name;
PCSZ Options;
PCSZ Filter;
bool Pipe;
//PCSZ User; // User connect info
//PCSZ Pwd; // Password connect info
//int Fsize; // Fetch size
//bool Scrollable; // Scrollable cursor
} CMGOPARM, *PCPARM;
typedef struct KEYCOL {
KEYCOL *Next;
PINCOL Incolp;
PCOL Colp;
char *Key;
} *PKC;
/***********************************************************************/
/* Used when inserting values in a MongoDB collection. */
/***********************************************************************/
class INCOL : public BLOCK {
public:
// Constructor
INCOL(bool ar) { Klist = NULL; Array = ar; }
// Methods
void AddCol(PGLOBAL g, PCOL colp, char *jp);
//Members
bson_t Child;
PKC Klist;
bool Array;
}; // end of INCOL;
/***********************************************************************/
/* CMgoConn class. */
/***********************************************************************/
class CMgoConn : public BLOCK {
friend class TDBMGO;
friend class MGODISC;
public:
// Constructor
CMgoConn(PGLOBAL g, PCPARM pcg);
//static void *mgo_alloc(size_t n);
//static void *mgo_calloc(size_t n, size_t sz);
//static void *mgo_realloc(void *m, size_t n);
//static void mgo_free(void *) {}
// Implementation
bool IsConnected(void) { return m_Connected; }
bool Connect(PGLOBAL g);
int CollSize(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
int ReadNext(PGLOBAL g);
PSZ GetDocument(PGLOBAL g);
void ShowDocument(bson_iter_t *iter, const bson_t *doc, const char *k);
void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp);
int Write(PGLOBAL g);
bool DocDelete(PGLOBAL g);
void Rewind(void);
void Close(void);
PSZ Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b);
void GetColumnValue(PGLOBAL g, PCOL colp);
bool AddValue(PGLOBAL g, PCOL colp, bson_t *doc, char *key, bool upd);
protected:
// Members
PCPARM Pcg;
mongoc_uri_t *Uri;
mongoc_client_pool_t *Pool; // Thread safe client pool
mongoc_client_t *Client; // The MongoDB client
mongoc_database_t *Database; // The MongoDB database
mongoc_collection_t *Collection; // The MongoDB collection
mongoc_cursor_t *Cursor;
const bson_t *Document;
bson_t *Query; // MongoDB cursor filter
bson_t *Opts; // MongoDB cursor options
bson_error_t Error;
bson_iter_t Iter; // Used to retrieve column value
bson_iter_t Desc; // Descendant iter
PINCOL Fpc; // To insert INCOL classes
bool m_Connected;
}; // end of class CMgoConn
......@@ -38,7 +38,8 @@ class DllExport COLBLK : public XOBJECT {
virtual PTDB GetTo_Tdb(void) {return To_Tdb;}
virtual int GetClustered(void) {return 0;}
virtual int IsClustered(void) {return FALSE;}
PCOL GetNext(void) {return Next;}
virtual PSZ GetJpath(PGLOBAL g, bool proj) {return NULL;}
PCOL GetNext(void) {return Next;}
PSZ GetName(void) {return Name;}
int GetIndex(void) {return Index;}
ushort GetColUse(void) {return ColUse;}
......
/* Copyright (C) Olivier Bertrand 2004 - 2017
/* Copyright (C) MariaDB Corporation Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -185,7 +185,7 @@ bool CntInfo(PGLOBAL g, PTDB tp, PXF info)
/***********************************************************************/
PTDB CntGetTDB(PGLOBAL g, LPCSTR name, MODE mode, PHC h)
{
PTDB tdbp;
PTDB tdbp = NULL;
PTABLE tabp;
PDBUSER dup = PlgGetUser(g);
volatile PCATLG cat = (dup) ? dup->Catalog : NULL; // Safe over throw
......
/* Copyright (C) Olivier Bertrand 2004 - 2011
/* Copyright (C) MariaDB Corporation Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,6 +15,7 @@
/**************** Cnt H Declares Source Code File (.H) *****************/
/* Name: CONNECT.H Version 2.4 */
/* Author Olivier BERTRAND bertrandop@gmail.com */
/* This file contains the some based classes declares. */
/***********************************************************************/
#include "filamtxt.h"
......
/* Copyright (C) MariaDB Corporation Ab */
#define MSG_ACCESS_VIOLATN "Access violation"
#define MSG_ADD_BAD_TYPE "Array add value type mismatch (%s -> %s)"
#define MSG_ALLOC_ERROR "Error allocating %s"
......
......@@ -33,18 +33,11 @@
#include "tabcol.h"
#include "xtable.h"
#include "array.h"
//#include "subquery.h"
#include "filter.h"
//#include "token.h"
//#include "select.h"
#include "xindex.h"
#if defined(MONGO_SUPPORT)
#include "filamtxt.h"
#include "tabdos.h"
#include "tabjson.h"
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#include "tabext.h"
#include "tabmgo.h"
#endif // MONGO_SUPPORT
#endif // MONGO_SUPPORT || JDBC_SUPPORT
/***********************************************************************/
/* Utility routines. */
......@@ -1412,11 +1405,11 @@ PFIL FILTER::Copy(PTABS t)
} // end of Copy
#endif // 0
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
/***********************************************************************/
/* Make selector json representation for Mongo tables. */
/***********************************************************************/
#if defined(MONGO_SUPPORT)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s, bool m)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
{
s->Append('{');
......@@ -1428,29 +1421,21 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s, bool m)
s->Append(Opc == OP_AND ? "and" : "or");
s->Append("\":[");
if (((PFIL)Arg(0))->MakeSelector(g, s, m))
if (((PFIL)Arg(0))->MakeSelector(g, s))
return true;
s->Append(',');
if (((PFIL)Arg(1))->MakeSelector(g, s, m))
if (((PFIL)Arg(1))->MakeSelector(g, s))
return true;
s->Append(']');
} else {
char *pth, buf[501];
if (GetArgType(0) != TYPE_COLBLK)
return true;
s->Append('"');
if (m)
pth = ((PMGOCOL)Arg(0))->Jpath;
else if (!(pth = ((PJCOL)Arg(0))->GetJpath(g, false)))
return true;
s->Append(pth);
s->Append(((PCOL)Arg(0))->GetJpath(g, false));
s->Append("\":{\"$");
switch (Opc) {
......@@ -1472,33 +1457,33 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s, bool m)
case OP_LE:
s->Append("lte");
break;
//case OP_NULL:
// s->Append("ne");
// break;
//case OP_LIKE:
// s->Append("ne");
// break;
//case OP_EXIST:
// s->Append("ne");
// break;
case OP_NULL:
case OP_LIKE:
case OP_EXIST:
default:
return true;
} // endswitch Opc
s->Append("\":");
if (GetArgType(1) == TYPE_COLBLK)
return true;
if (GetArgType(1) == TYPE_COLBLK) {
s->Append("\"$");
s->Append(((PEXTCOL)Arg(1))->GetJpath(g, false));
s->Append('"');
} else {
char buf[501];
Arg(1)->Prints(g, buf, 500);
s->Append(buf);
} // endif Type
Arg(1)->Prints(g, buf, 500);
s->Append(buf);
s->Append('}');
} // endif Opc
s->Append('}');
return false;
} // end of MakeSelector
#endif // MONGO_SUPPORT
#endif // MONGO_SUPPORT || JDBC_SUPPORT
/*********************************************************************/
/* Make file output of FILTER contents. */
......
/*************** Filter H Declares Source Code File (.H) ***************/
/* Name: FILTER.H Version 1.2 */
/* Name: FILTER.H Version 1.3 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2010-2015 */
/* (C) Copyright to the author Olivier BERTRAND 2010-2017 */
/* */
/* This file contains the FILTER and derived classes declares. */
/***********************************************************************/
......@@ -61,9 +61,9 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */
//virtual PXOB CheckSubQuery(PGLOBAL, PSQL);
//virtual bool CheckLocal(PTDB);
//virtual int CheckSpcCol(PTDB tdbp, int n);
#if defined(MONGO_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s, bool m);
#endif // MONGO_SUPPORT
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s);
#endif // MONGO_SUPPORT || JDBC_SUPPORT
virtual void Printf(PGLOBAL g, FILE *f, uint n);
virtual void Prints(PGLOBAL g, char *ps, uint z);
// PFIL Linearize(bool nosep);
......
/***********************************************************************/
/* GLOBAL.H: Declaration file used by all CONNECT implementations. */
/* (C) Copyright Olivier Bertrand 1993-2017 */
/* (C) Copyright MariaDB Corporation Ab */
/* Author Olivier Bertrand 1993-2017 */
/***********************************************************************/
/***********************************************************************/
......
/* Copyright (C) Olivier Bertrand 2004 - 2017
/* Copyright (C) MariaDB Corporation Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -98,8 +98,7 @@
rnd_next signals that it has reached the end of its data. Calls to
ha_connect::extra() are hints as to what will be occuring to the request.
Happy use!<br>
-Olivier
Author Olivier Bertrand
*/
#ifdef USE_PRAGMA_IMPLEMENTATION
......@@ -209,10 +208,10 @@ pthread_mutex_t parmut = PTHREAD_MUTEX_INITIALIZER;
/***********************************************************************/
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info);
PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
#if defined(MONGO_SUPPORT)
PQRYRES MGOColumns(PGLOBAL g, char *db, PTOS topt, bool info);
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ url, PTOS topt, bool info);
#endif // MONGO_SUPPORT
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
void PushWarning(PGLOBAL g, THD *thd, int level);
......@@ -701,7 +700,7 @@ static int connect_init_func(void *p)
DTVAL::SetTimeShift(); // Initialize time zone shift once for all
BINCOL::SetEndian(); // Initialize host endian setting
#if defined(JDBC_SUPPORT)
JDBConn::SetJVM();
JAVAConn::SetJVM();
#endif // JDBC_SUPPORT
DBUG_RETURN(0);
} // end of connect_init_func
......@@ -726,7 +725,7 @@ static int connect_done_func(void *)
#endif // MONGO_SUPPORT
#ifdef JDBC_SUPPORT
JDBConn::ResetJVM();
JAVAConn::ResetJVM();
#endif // JDBC_SUPPORT
#if defined(__WIN__)
......@@ -4081,7 +4080,7 @@ int ha_connect::info(uint flag)
if (xmod == MODE_ANY || xmod == MODE_ALTER) {
// Pure info, not a query
pure= true;
xp->CheckCleanup();
xp->CheckCleanup(xmod == MODE_ANY && valid_query_id == 0);
} // endif xmod
// This is necessary for getting file length
......@@ -4094,8 +4093,10 @@ int ha_connect::info(uint flag)
} else
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
if (!(tdbp= GetTDB(g)))
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
if (!(tdbp = GetTDB(g))) {
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
} // endif tdbp
valid_info = false;
} // endif tdbp
......@@ -5299,16 +5300,18 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(ODBC_SUPPORT)
POPARM sop= NULL;
PCSZ ucnc= NULL;
bool cnc= false;
PCSZ tabtyp = NULL;
bool cnc= false;
int cto= -1, qto= -1;
#endif // ODBC_SUPPORT
#if defined(JDBC_SUPPORT)
PJPARM sjp= NULL;
#endif // JDBC_SUPPORT
#if defined(JDBC_SUPPORT) || defined(MONGO_SUPPORT)
PCSZ driver= NULL;
char *url= NULL;
//char *prop= NULL;
PCSZ tabtyp= NULL;
#endif // JDBC_SUPPORT
#endif // JDBC_SUPPORT || MONGO_SUPPORT
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool bif, ok= false, dbf= false;
TABTYPE ttp= TAB_UNDEF;
......@@ -5361,19 +5364,17 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif // __WIN__
port= atoi(GetListOption(g, "port", topt->oplist, "0"));
#if defined(ODBC_SUPPORT)
mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0"));
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0"));
cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1"));
qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1"));
if ((ucnc= GetListOption(g, "UseDSN", topt->oplist)))
cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0);
#endif
#if defined(JDBC_SUPPORT)
#if defined(JDBC_SUPPORT) || defined(MONGO_SUPPORT)
driver= GetListOption(g, "Driver", topt->oplist, NULL);
// url= GetListOption(g, "URL", topt->oplist, NULL);
// prop = GetListOption(g, "Properties", topt->oplist, NULL);
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
#endif // JDBC_SUPPORT
#endif // JDBC_SUPPORT || MONGO_SUPPORT
#if defined(PROMPT_OK)
cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0"));
#endif // PROMPT_OK
......@@ -5585,14 +5586,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
ok = true;
break;
#if defined(MONGO_SUPPORT)
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
case TAB_MONGO:
if (!topt->tabname)
topt->tabname = tab;
ok = true;
break;
#endif // MONGO_SUPPORT
#endif // MONGO_SUPPORT || JDBC_SUPPORT
case TAB_VIR:
ok = true;
break;
......@@ -5733,13 +5734,36 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
qrp = VirColumns(g, fnc == FNC_COL);
break;
case TAB_JSON:
qrp = JSONColumns(g, (char*)db, dsn, topt, fnc == FNC_COL);
qrp = JSONColumns(g, db, dsn, topt, fnc == FNC_COL);
break;
#if defined(MONGO_SUPPORT)
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
case TAB_MONGO:
qrp = MGOColumns(g, (char*)db, topt, fnc == FNC_COL);
if (!(url = strz(g, create_info->connect_string)) || !*url)
url = "mongodb://localhost:27017";
#if !defined(MONGO_SUPPORT)
driver = "JAVA";
// strcpy(g->Message, "No column discovery for Java MONGO tables yet");
// Temporarily use the JSONColumns function
qrp = JSONColumns(g, db, url, topt, fnc == FNC_COL);
#elif !defined(JDBC_SUPPORT)
driver = "C";
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
#else // MONGO_SUPPORT && JDBC_SUPPORT
if (!driver)
driver = "C";
if (toupper(*driver) == 'C') {
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
} else {
// strcpy(g->Message, "No column discovery for Java MONGO tables yet");
// Temporarily use the JSONColumns function
qrp = JSONColumns(g, db, url, topt, fnc == FNC_COL);
} // endif driver
#endif // MONGO_SUPPORT && JDBC_SUPPORT
break;
#endif // MONGO_SUPPORT
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
case TAB_XML:
qrp = XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL);
......
/* Copyright (C) Olivier Bertrand 2004 - 2015
/* Copyright (C) MariaDB Corporation Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -14,6 +14,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
/** @file ha_connect.h
Author Olivier Bertrand
@brief
The ha_connect engine is a prototype storage engine to access external data.
......
This diff is collapsed.
/***********************************************************************/
/* JavaConn.h : header file for the Java connection classes. */
/***********************************************************************/
/***********************************************************************/
/* Included C-definition files required by the interface. */
/***********************************************************************/
#include "block.h"
#include "jdbccat.h"
/***********************************************************************/
/* Java native interface. */
/***********************************************************************/
#include <jni.h>
/***********************************************************************/
/* Constants and defines. */
/***********************************************************************/
// Miscellaneous sizing info
#define MAX_NUM_OF_MSG 10 // Max number of error messages
//efine MAX_CURRENCY 30 // Max size of Currency($) string
#define MAX_TNAME_LEN 32 // Max size of table names
//efine MAX_FNAME_LEN 256 // Max size of field names
//efine MAX_STRING_INFO 256 // Max size of string from SQLGetInfo
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
//efine MAX_CONNECT_LEN 512 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE 0 // TYPE_NULL
#if !defined(__WIN__)
typedef unsigned char *PUCHAR;
#endif // !__WIN__
enum JCATINFO {
CAT_TAB = 1, // JDBC Tables
CAT_COL = 2, // JDBC Columns
CAT_KEY = 3, // JDBC PrimaryKeys
//CAT_STAT = 4, // SQLStatistics
//CAT_SPC = 5 // SQLSpecialColumns
};
/***********************************************************************/
/* This structure is used to control the catalog functions. */
/***********************************************************************/
typedef struct tagJCATPARM {
JCATINFO Id; // Id to indicate function
PQRYRES Qrp; // Result set pointer
PCSZ DB; // Database (Schema)
PCSZ Tab; // Table name or pattern
PCSZ Pat; // Table type or column pattern
} JCATPARM;
typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
typedef jint(JNICALL *GETJVM) (JavaVM **, jsize, jsize *);
#if defined(_DEBUG)
typedef jint(JNICALL *GETDEF) (void *);
#endif // _DEBUG
class JAVAConn;
/***********************************************************************/
/* JAVAConn class. */
/***********************************************************************/
class JAVAConn : public BLOCK {
friend class TDBJMG;
private:
JAVAConn(); // Standard (unused) constructor
public:
// Constructor
JAVAConn(PGLOBAL g, PCSZ wrapper);
// Set static variables
static void SetJVM(void) {
LibJvm = NULL;
CreateJavaVM = NULL;
GetCreatedJavaVMs = NULL;
#if defined(_DEBUG)
GetDefaultJavaVMInitArgs = NULL;
#endif // _DEBUG
} // end of SetJVM
static void ResetJVM(void);
static bool GetJVM(PGLOBAL g);
// Implementation
public:
//virtual ~JAVAConn();
bool IsOpen(void) { return m_Opened; }
bool IsConnected(void) { return m_Connected; }
// Java operations
protected:
bool gmID(PGLOBAL g, jmethodID& mid, const char *name, const char *sig);
bool Check(jint rc = 0);
public:
virtual void AddJars(PSTRG jpop, char sep) = 0;
virtual bool Connect(PJPARM sop) = 0;
virtual bool Open(PGLOBAL g);
virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options,
PCSZ filter, bool pipe) = 0;
virtual void Close(void);
protected:
// Members
#if defined(__WIN__)
static HANDLE LibJvm; // Handle to the jvm DLL
#else // !__WIN__
static void *LibJvm; // Handle for the jvm shared library
#endif // !__WIN__
static CRTJVM CreateJavaVM;
static GETJVM GetCreatedJavaVMs;
#if defined(_DEBUG)
static GETDEF GetDefaultJavaVMInitArgs;
#endif // _DEBUG
PGLOBAL m_G;
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
jclass jdi; // Pointer to the java wrapper class
jobject job; // The java wrapper class object
jmethodID errid; // The GetErrmsg method ID
bool m_Opened;
bool m_Connected;
PCSZ DiscFunc;
PCSZ Msg;
PCSZ m_Wrap;
int m_Rows;
}; // end of JAVAConn class definition
#ifndef __JDBCCAT_H
#define __JDBCCAT_H
// Timeout and net wait defaults
#define DEFAULT_LOGIN_TIMEOUT -1 // means do not set
#define DEFAULT_QUERY_TIMEOUT -1 // means do not set
......@@ -8,9 +11,9 @@ typedef struct jdbc_parms {
PCSZ Url; // Driver URL
PCSZ User; // User connect info
PCSZ Pwd; // Password connect info
//char *Properties; // Connection property list
//int Cto; // Connect timeout
//int Qto; // Query timeout
int Version; // Driver version
int Fsize; // Fetch size
bool Scrollable; // Scrollable cursor
} JDBCPARM, *PJPARM;
......@@ -28,3 +31,5 @@ PQRYRES JDBCSrcCols(PGLOBAL g, PCSZ src, PJPARM sop);
PQRYRES JDBCTables(PGLOBAL g, PCSZ db, PCSZ tabpat,
PCSZ tabtyp, int maxres, bool info, PJPARM sop);
PQRYRES JDBCDrivers(PGLOBAL g, int maxres, bool info);
#endif // __JDBCCAT_H
This diff is collapsed.
/***********************************************************************/
/* JDBConn.h : header file for the JDBC connection classes. */
/***********************************************************************/
//nclude <windows.h> /* Windows include file */
//nclude <windowsx.h> /* Message crackers */
/***********************************************************************/
/* Included C-definition files required by the interface. */
/***********************************************************************/
#include "block.h"
/***********************************************************************/
/* JDBC interface. */
/***********************************************************************/
#include <jni.h>
/***********************************************************************/
/* Constants and defines. */
/***********************************************************************/
// Miscellaneous sizing info
#define MAX_NUM_OF_MSG 10 // Max number of error messages
//efine MAX_CURRENCY 30 // Max size of Currency($) string
#define MAX_TNAME_LEN 32 // Max size of table names
//efine MAX_FNAME_LEN 256 // Max size of field names
//efine MAX_STRING_INFO 256 // Max size of string from SQLGetInfo
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
//efine MAX_CONNECT_LEN 512 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE 0 // TYPE_NULL
#if !defined(__WIN__)
typedef unsigned char *PUCHAR;
#endif // !__WIN__
enum JCATINFO {
CAT_TAB = 1, // JDBC Tables
CAT_COL = 2, // JDBC Columns
CAT_KEY = 3, // JDBC PrimaryKeys
//CAT_STAT = 4, // SQLStatistics
//CAT_SPC = 5 // SQLSpecialColumns
};
/***********************************************************************/
/* This structure is used to control the catalog functions. */
/***********************************************************************/
typedef struct tagJCATPARM {
JCATINFO Id; // Id to indicate function
PQRYRES Qrp; // Result set pointer
PCSZ DB; // Database (Schema)
PCSZ Tab; // Table name or pattern
PCSZ Pat; // Table type or column pattern
} JCATPARM;
typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
typedef jint(JNICALL *GETJVM) (JavaVM **, jsize, jsize *);
#if defined(_DEBUG)
typedef jint(JNICALL *GETDEF) (void *);
#endif // _DEBUG
#include "javaconn.h"
// JDBC connection to a data source
class TDBJDBC;
......@@ -66,7 +12,7 @@ class TDBXJDC;
/***********************************************************************/
/* JDBConn class. */
/***********************************************************************/
class JDBConn : public BLOCK {
class JDBConn : public JAVAConn {
friend class TDBJDBC;
friend class TDBXJDC;
//friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&);
......@@ -74,118 +20,80 @@ class JDBConn : public BLOCK {
JDBConn(); // Standard (unused) constructor
public:
JDBConn(PGLOBAL g, TDBJDBC *tdbp);
// Constructor
JDBConn(PGLOBAL g, PCSZ wrapper);
int Open(PJPARM sop);
int Rewind(PCSZ sql);
void Close(void);
PQRYRES AllocateResult(PGLOBAL g);
virtual void AddJars(PSTRG jpop, char sep);
PQRYRES AllocateResult(PGLOBAL g, PTDB tdbp);
// Attributes
public:
char *GetQuoteChar(void) { return m_IDQuoteChar; }
// Database successfully opened?
bool IsOpen(void) { return m_Opened; }
//PSZ GetStringInfo(ushort infotype);
int GetMaxValue(int infotype);
//PSZ GetConnect(void) { return m_Connect; }
char *GetQuoteChar(void) { return m_IDQuoteChar; }
virtual int GetMaxValue(int infotype);
public:
// Operations
//void SetLoginTimeout(DWORD sec) {m_LoginTimeout = sec;}
//void SetQueryTimeout(DWORD sec) {m_QueryTimeout = sec;}
//void SetUserName(PSZ user) {m_User = user;}
//void SetUserPwd(PSZ pwd) {m_Pwd = pwd;}
int GetResultSize(PCSZ sql, JDBCCOL *colp);
int ExecuteQuery(PCSZ sql);
int ExecuteUpdate(PCSZ sql);
int Fetch(int pos = 0);
virtual bool Connect(PJPARM sop);
virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options,
PCSZ filter, bool pipe) {return true;}
virtual int GetResultSize(PCSZ sql, PCOL colp);
virtual int ExecuteCommand(PCSZ sql);
virtual int ExecuteQuery(PCSZ sql);
virtual int ExecuteUpdate(PCSZ sql);
virtual int Fetch(int pos = 0);
virtual void SetColumnValue(int rank, PSZ name, PVAL val);
// Jdbc operations
bool PrepareSQL(PCSZ sql);
int ExecuteSQL(void);
int ExecuteSQL(void); // Prepared statement
bool SetParam(JDBCCOL *colp);
int ExecSQLcommand(PCSZ sql);
void SetColumnValue(int rank, PSZ name, PVAL val);
int GetCatInfo(JCATPARM *cap);
//bool GetDataSources(PQRYRES qrp);
bool GetDrivers(PQRYRES qrp);
PQRYRES GetMetaData(PGLOBAL g, PCSZ src);
public:
// Set static variables
static void SetJVM(void) {
LibJvm = NULL;
CreateJavaVM = NULL;
GetCreatedJavaVMs = NULL;
#if defined(_DEBUG)
GetDefaultJavaVMInitArgs = NULL;
#endif // _DEBUG
} // end of SetJVM
static void ResetJVM(void);
static bool GetJVM(PGLOBAL g);
int Rewind(PCSZ sql);
// Implementation
public:
//virtual ~JDBConn();
// JDBC operations
protected:
bool gmID(PGLOBAL g, jmethodID& mid, const char *name, const char *sig);
bool Check(jint rc = 0);
//void ThrowDJX(int rc, PSZ msg/*, HSTMT hstmt = SQL_NULL_HSTMT*/);
//void ThrowDJX(PSZ msg);
//void Free(void);
protected:
// Members
#if defined(__WIN__)
static HANDLE LibJvm; // Handle to the jvm DLL
#else // !__WIN__
static void *LibJvm; // Handle for the jvm shared library
#endif // !__WIN__
static CRTJVM CreateJavaVM;
static GETJVM GetCreatedJavaVMs;
#if defined(_DEBUG)
static GETDEF GetDefaultJavaVMInitArgs;
#endif // _DEBUG
PGLOBAL m_G;
TDBJDBC *m_Tdb;
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
jclass jdi; // Pointer to the java wrapper class
jobject job; // The java wrapper class object
jmethodID xqid; // The ExecuteQuery method ID
jmethodID xuid; // The ExecuteUpdate method ID
jmethodID xid; // The Execute method ID
jmethodID grs; // The GetResult method ID
jmethodID readid; // The ReadNext method ID
jmethodID fetchid; // The Fetch method ID
jmethodID typid; // The ColumnType method ID
jmethodID prepid; // The CreatePrepStmt method ID
jmethodID xpid; // The ExecutePrep method ID
jmethodID pcid; // The ClosePrepStmt method ID
jmethodID errid; // The GetErrmsg method ID
jmethodID objfldid; // The ObjectField method ID
jmethodID chrfldid; // The StringField method ID
jmethodID intfldid; // The IntField method ID
jmethodID dblfldid; // The DoubleField method ID
jmethodID fltfldid; // The FloatField method ID
jmethodID datfldid; // The DateField method ID
jmethodID timfldid; // The TimeField method ID
jmethodID tspfldid; // The TimestampField method ID
jmethodID bigfldid; // The BigintField method ID
PCSZ Msg;
char *m_Wrap;
#if 0
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
jclass jdi; // Pointer to the java wrapper class
jobject job; // The java wrapper class object
jmethodID errid; // The GetErrmsg method ID
#endif // 0
jmethodID xqid; // The ExecuteQuery method ID
jmethodID xuid; // The ExecuteUpdate method ID
jmethodID xid; // The Execute method ID
jmethodID grs; // The GetResult method ID
jmethodID readid; // The ReadNext method ID
jmethodID fetchid; // The Fetch method ID
jmethodID typid; // The ColumnType method ID
jmethodID prepid; // The CreatePrepStmt method ID
jmethodID xpid; // The ExecutePrep method ID
jmethodID pcid; // The ClosePrepStmt method ID
jmethodID objfldid; // The ObjectField method ID
jmethodID chrfldid; // The StringField method ID
jmethodID intfldid; // The IntField method ID
jmethodID dblfldid; // The DoubleField method ID
jmethodID fltfldid; // The FloatField method ID
jmethodID datfldid; // The DateField method ID
jmethodID timfldid; // The TimeField method ID
jmethodID tspfldid; // The TimestampField method ID
jmethodID bigfldid; // The BigintField method ID
// PCSZ Msg;
// PCSZ m_Wrap;
char m_IDQuoteChar[2];
PCSZ m_Pwd;
int m_Ncol;
int m_Aff;
int m_Rows;
int m_Fetch;
int m_RowsetSize;
jboolean m_Updatable;
jboolean m_Transact;
jboolean m_Scrollable;
bool m_Opened;
bool m_Full;
}; // end of JDBConn class definition
This diff is collapsed.
/************** MongoFam H Declares Source Code File (.H) **************/
/* Name: jmgfam.h Version 1.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */
/* This file contains the JAVA MongoDB access method classes declares */
/***********************************************************************/
#pragma once
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
#include "block.h"
//#include "mongo.h"
#include "jmgoconn.h"
typedef class JMGFAM *PJMGFAM;
typedef class MGODEF *PMGODEF;
/***********************************************************************/
/* This is the Java MongoDB Access Method class declaration. */
/***********************************************************************/
class DllExport JMGFAM : public DOSFAM {
friend void mongo_init(bool);
public:
// Constructor
JMGFAM(PJDEF tdp);
JMGFAM(PJMGFAM txfp);
// Implementation
virtual AMT GetAmType(void) { return TYPE_AM_MGO; }
virtual bool GetUseTemp(void) { return false; }
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) JMGFAM(this); }
void SetLrecl(int lrecl) { Lrecl = lrecl; }
// Methods
virtual void Reset(void);
virtual int GetFileLength(PGLOBAL g);
virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s);
virtual bool AllocateBuffer(PGLOBAL g) { return false; }
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos);
virtual int SkipRecord(PGLOBAL g, bool header);
virtual bool OpenTableFile(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
virtual bool OpenTempFile(PGLOBAL g) { return false; }
virtual bool MoveIntermediateLines(PGLOBAL g, bool *b) { return false; }
virtual int RenameTempFile(PGLOBAL g) { return RC_OK; }
virtual int InitDelete(PGLOBAL g, int fpos, int spos);
bool Init(PGLOBAL g);
//bool MakeCursor(PGLOBAL g);
// Members
JMgoConn *Jcp; // Points to a Mongo connection class
JDBCPARM Ops; // Additional parameters
PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode;
PCSZ Uristr;
PCSZ Db_name;
PCSZ Coll_name;
PCSZ Options;
PCSZ Filter;
PSZ Wrapname;
bool Done; // Init done
bool Pipe;
int Version;
int Curpos; // Cursor position of last fetch
}; // end of class JMGFAM
This diff is collapsed.
/***********************************************************************/
/* JMgoConn.h : header file for the MongoDB connection classes. */
/***********************************************************************/
/***********************************************************************/
/* Java interface. */
/***********************************************************************/
#include "javaconn.h"
// Java connection to a MongoDB data source
class TDBJMG;
class JMGCOL;
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
typedef class JNCOL *PJNCOL;
typedef class MGODEF *PMGODEF;
typedef class TDBJMG *PTDBJMG;
typedef class JMGCOL *PJMGCOL;
#if 0
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class MGODISC : public BLOCK {
public:
// Constructor
MGODISC(PGLOBAL g, int *lg);
// Functions
int GetColumns(PGLOBAL g, char *db, PTOS topt);
bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char *pcn, char *pfmt, int i, int k, bool b);
// Members
BCOL bcol;
PBCOL bcp, fbcp, pbcp;
PMGODEF tdp;
TDBJMG *tmgp;
int *length;
int n, k, lvl;
bool all;
}; // end of MGODISC
#endif // 0
typedef struct JKCOL {
JKCOL *Next;
PJNCOL Jncolp;
PCOL Colp;
char *Key;
int N;
} *PJKC;
/***********************************************************************/
/* Used when inserting values in a MongoDB collection. */
/***********************************************************************/
class JNCOL : public BLOCK {
public:
// Constructor
JNCOL(bool ar) { Klist = NULL; Array = ar; }
// Methods
void AddCol(PGLOBAL g, PCOL colp, PSZ jp);
//Members
PJKC Klist;
bool Array;
}; // end of JNCOL;
/***********************************************************************/
/* JMgoConn class. */
/***********************************************************************/
class JMgoConn : public JAVAConn {
friend class TDBJMG;
//friend class TDBXJDC;
//friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&);
private:
JMgoConn(); // Standard (unused) constructor
public:
// Constructor
JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper);
// Implementation
public:
virtual void AddJars(PSTRG jpop, char sep);
virtual bool Connect(PJPARM sop);
virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, PCSZ filter, bool pipe);
// PQRYRES AllocateResult(PGLOBAL g, TDBEXT *tdbp, int n);
// Attributes
public:
// virtual int GetMaxValue(int infotype);
public:
// Operations
virtual int Fetch(int pos = 0);
virtual PSZ GetColumnValue(PSZ name);
int CollSize(PGLOBAL g);
bool FindCollection(PCSZ query, PCSZ proj);
bool AggregateCollection(PCSZ pipeline);
void MakeColumnGroups(PGLOBAL g, PTDB tdbp);
bool GetMethodId(PGLOBAL g, MODE mode);
jobject MakeObject(PGLOBAL g, PCOL colp, bool& error);
jobject MakeDoc(PGLOBAL g, PJNCOL jcp);
int DocWrite(PGLOBAL g);
int DocUpdate(PGLOBAL g, PTDB tdbp);
int DocDelete(PGLOBAL g, bool all);
bool Rewind(void);
PSZ GetDocument(void);
protected:
// Members
PCSZ CollName; // The collation name
jmethodID gcollid; // The GetCollection method ID
jmethodID countid; // The GetCollSize method ID
jmethodID fcollid; // The FindColl method ID
jmethodID acollid; // The AggregateColl method ID
jmethodID readid; // The ReadNext method ID
jmethodID fetchid; // The Fetch method ID
jmethodID rewindid; // The Rewind method ID
jmethodID getdocid; // The GetDoc method ID
jmethodID objfldid; // The ObjectField method ID
jmethodID mkdocid; // The MakeDocument method ID
jmethodID docaddid; // The DocAdd method ID
jmethodID mkarid; // The MakeArray method ID
jmethodID araddid; // The ArrayAdd method ID
jmethodID insertid; // The CollInsert method ID
jmethodID updateid; // The CollUpdate method ID
jmethodID deleteid; // The CollDelete method ID
PJNCOL Fpc; // To JNCOL classes
int m_Fetch;
int m_Version; // Java driver version (2 or 3)
}; // end of JMgoConn class definition
/************** mongo C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: mongo Version 1.0 */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* These programs are the MGODEF class execution routines. */
/***********************************************************************/
/***********************************************************************/
/* Include relevant sections of the MariaDB header file. */
/***********************************************************************/
#include <my_global.h>
/***********************************************************************/
/* Include application header files: */
/* global.h is header containing all global declarations. */
/* plgdbsem.h is header containing the DB application declarations. */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "xtable.h"
#include "tabext.h"
#if defined(MONGO_SUPPORT)
#include "tabmgo.h"
#endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT)
#include "tabjmg.h"
#endif // JDBC_SUPPORT
/* -------------------------- Class MGODEF --------------------------- */
MGODEF::MGODEF(void)
{
Driver = NULL;
Uri = NULL;
Colist = NULL;
Filter = NULL;
Level = 0;
Base = 0;
Version = 0;
Pipe = false;
} // end of MGODEF constructor
/***********************************************************************/
/* DefineAM: define specific AM block values. */
/***********************************************************************/
bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
{
if (EXTDEF::DefineAM(g, "MGO", poff))
return true;
else if (!Tabschema)
Tabschema = GetStringCatInfo(g, "Dbname", "*");
# if !defined(JDBC_SUPPORT)
Driver = "C";
#elif !defined(MONGO_SUPPORT)
Driver = "JAVA";
#else
Driver = GetStringCatInfo(g, "Driver", "C");
#endif
Uri = GetStringCatInfo(g, "Connect", "mongodb://localhost:27017");
Colist = GetStringCatInfo(g, "Colist", NULL);
Filter = GetStringCatInfo(g, "Filter", NULL);
Base = GetIntCatInfo("Base", 0) ? 1 : 0;
Version = GetIntCatInfo("Version", 3);
if (Version == 2)
Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo2Interface");
else
Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo3Interface");
Pipe = GetBoolCatInfo("Pipeline", false);
return false;
} // end of DefineAM
/***********************************************************************/
/* GetTable: makes a new Table Description Block. */
/***********************************************************************/
PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
{
if (Catfunc == FNC_COL) {
#if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C')
return new(g)TDBGOL(this);
#endif // MONGO_SUPPORT
strcpy(g->Message, "No column find for Java Mongo yet");
return NULL;
} // endif Catfunc
#if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C')
return new(g) TDBMGO(this);
#endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT)
return new(g) TDBJMG(this);
#else // !JDBC_SUPPORT
strcpy(g->Message, "No MONGO nor Java support");
return NULL;
#endif // !JDBC_SUPPORT
} // end of GetTable
/**************** mongo H Declares Source Code File (.H) ***************/
/* Name: mongo.h Version 1.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */
/* This file contains the common MongoDB classes declares. */
/***********************************************************************/
#ifndef __MONGO_H
#define __MONGO_H
#include "osutil.h"
#include "block.h"
#include "colblk.h"
typedef class MGODEF *PMGODEF;
typedef struct _bncol {
struct _bncol *Next;
char *Name;
char *Fmt;
int Type;
int Len;
int Scale;
bool Cbn;
bool Found;
} BCOL, *PBCOL;
/***********************************************************************/
/* MongoDB table. */
/***********************************************************************/
class DllExport MGODEF : public EXTDEF { /* Table description */
friend class TDBMGO;
friend class TDBJMG;
friend class TDBGOL;
friend class MGOFAM;
friend class MGODISC;
friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public:
// Constructor
MGODEF(void);
// Implementation
virtual const char *GetType(void) { return "MONGO"; }
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
PCSZ Driver; /* MongoDB Driver (C or JAVA) */
PCSZ Uri; /* MongoDB connection URI */
PSZ Wrapname; /* Java wrapper name */
PCSZ Colist; /* Options list */
PCSZ Filter; /* Filtering query */
int Level; /* Used for catalog table */
int Base; /* The array index base */
int Version; /* The Java driver version */
bool Pipe; /* True is Colist is a pipeline */
}; // end of MGODEF
#endif // __MONGO_H
This diff is collapsed.
/************** MongoFam H Declares Source Code File (.H) **************/
/* Name: mongofam.h Version 1.3 */
/* Name: mongofam.h Version 1.4 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */
/* This file contains the MongoDB access method classes declares. */
/***********************************************************************/
#pragma once
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
#include <bson.h>
#include <bcon.h>
#include <mongoc.h>
#include "block.h"
//#include "array.h"
#include "cmgoconn.h"
typedef class TXTFAM *PTXF;
typedef class MGOFAM *PMGOFAM;
......@@ -37,6 +27,7 @@ class DllExport MGOFAM : public DOSFAM {
virtual bool GetUseTemp(void) { return false; }
virtual int GetPos(void);
virtual int GetNextPos(void);
void SetTdbp(PTDBDOS tdbp) { Tdbp = tdbp; }
virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) MGOFAM(this); }
void SetLrecl(int lrecl) { Lrecl = lrecl; }
......@@ -63,35 +54,12 @@ class DllExport MGOFAM : public DOSFAM {
virtual int RenameTempFile(PGLOBAL g) { return RC_OK; }
virtual int InitDelete(PGLOBAL g, int fpos, int spos);
bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
//static void *mgo_alloc(size_t n);
//static void *mgo_calloc(size_t n, size_t sz);
//static void *mgo_realloc(void *m, size_t n);
//static void mgo_free(void *) {}
// Members
//static PGLOBAL G;
mongoc_uri_t *Uri;
mongoc_client_pool_t *Pool; // Thread safe client pool
mongoc_client_t *Client; // The MongoDB client
mongoc_database_t *Database; // The MongoDB database
mongoc_collection_t *Collection; // The MongoDB collection
mongoc_cursor_t *Cursor;
const bson_t *Document;
//bson_mem_vtable_t Vtable;
bson_t *Query; // MongoDB cursor filter
bson_t *Opts; // MongoDB cursor options
bson_error_t Error;
PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode;
const char *Uristr;
const char *Db_name;
const char *Coll_name;
const char *Options;
const char *Filter;
bool Done; // Init done
bool Pipe;
CMgoConn *Cmgp; // Points to a C Mongo connection class
CMGOPARM Pcg; // Parms passed to Cmgp
PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode;
bool Done; // Init done
}; // end of class MGOFAM
/* Copyright (C) MariaDB Corporation Ab */
#define MSG_ACCESS_VIOLATN 200
#define MSG_ADD_BAD_TYPE 201
#define MSG_ALLOC_ERROR 202
......
This diff is collapsed.
/* Copyright (C) Olivier Bertrand 2004 - 2015
/* Copyright (C) MariaDB Corporation Ab
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,7 +15,7 @@
/**************** MYCAT H Declares Source Code File (.H) ***************/
/* Name: MYCAT.H Version 2.3 */
/* */
/* Author: Olivier Bertrand */
/* This file contains the CONNECT plugin MYCAT class definitions. */
/***********************************************************************/
#ifndef __MYCAT__H
......
/* Copyright (C) MariaDB Corporation Ab */
#ifndef _OS_H_INCLUDED
#define _OS_H_INCLUDED
......
/* Copyright (C) MariaDB Corporation Ab */
#include "my_global.h"
#include <stdlib.h>
#include <string.h>
......
/* Copyright (C) MariaDB Corporation Ab */
#ifndef __OSUTIL_H__
#define __OSUTIL_H__
......
......@@ -138,12 +138,12 @@ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_VIR = 171, /* Virtual tables am type no */
TYPE_AM_DMY = 172, /* DMY Dummy tables am type no */
TYPE_AM_SET = 180, /* SET Set tables am type no */
TYPE_AM_MYSQL = 192, /* MYSQL access method type no */
TYPE_AM_MYX = 193, /* MYSQL EXEC access method type */
TYPE_AM_CAT = 195, /* Catalog access method type no */
TYPE_AM_ZIP = 198, /* ZIP access method type no */
TYPE_AM_MGO = 199, /* MGO access method type no */
TYPE_AM_OUT = 200}; /* Output relations (storage) */
TYPE_AM_MYSQL = 190, /* MYSQL access method type no */
TYPE_AM_MYX = 191, /* MYSQL EXEC access method type */
TYPE_AM_CAT = 192, /* Catalog access method type no */
TYPE_AM_ZIP = 193, /* ZIP access method type no */
TYPE_AM_MGO = 194, /* MGO access method type no */
TYPE_AM_OUT = 200}; /* Output relations (storage) */
enum RECFM {RECFM_NAF = -2, /* Not a file */
RECFM_OEM = -1, /* OEM file access method */
......
......@@ -104,6 +104,8 @@ class DllExport EXTDEF : public TABDEF { /* EXT table */
/* This is the base class for all external tables. */
/***********************************************************************/
class DllExport TDBEXT : public TDB {
friend class JAVAConn;
friend class JMgoConn;
public:
// Constructors
TDBEXT(EXTDEF *tdp);
......@@ -164,7 +166,7 @@ class DllExport TDBEXT : public TDB {
}; // end of class TDBEXT
/***********************************************************************/
/* Virual class EXTCOL: external column. */
/* Virtual class EXTCOL: external column. */
/***********************************************************************/
class DllExport EXTCOL : public COLBLK {
friend class TDBEXT;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment