CONNECT - OEM Table Example
This is an example showing how an OEM table can be implemented.
The header File my_global.h
:
/***********************************************************************/ /* Definitions needed by the included files. */ /***********************************************************************/ #if !defined(MY_GLOBAL_H) #define MY_GLOBAL_H typedef unsigned int uint; typedef unsigned int uint32; typedef unsigned short ushort; typedef unsigned long ulong; typedef unsigned long DWORD; typedef char *LPSTR; typedef const char *LPCSTR; typedef int BOOL; #if defined(__WIN__) typedef void *HANDLE; #else typedef int HANDLE; #endif typedef char *PSZ; typedef const char *PCSZ; typedef unsigned char BYTE; typedef unsigned char uchar; typedef long long longlong; typedef unsigned long long ulonglong; typedef char my_bool; struct charset_info_st {}; typedef const charset_info_st CHARSET_INFO; #define FALSE 0 #define TRUE 1 #define Item char #define MY_MAX(a,b) ((a>b)?(a):(b)) #define MY_MIN(a,b) ((a<b)?(a):(b)) #endif // MY_GLOBAL_H
Note: This is a fake my_global.h
that just contains what is useful for the jmgoem.cpp
source file.
The source File jmgoem.cpp
:
/************* jmgoem C++ Program Source Code File (.CPP) **************/ /* PROGRAM NAME: jmgoem Version 1.0 */ /* (C) Copyright to the author Olivier BERTRAND 2017 */ /* This program is the Java MONGO OEM module definition. */ /***********************************************************************/ /***********************************************************************/ /* Definitions needed by the included files. */ /***********************************************************************/ #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. */ /* (x)table.h is header containing the TDBASE declarations. */ /* tabext.h is header containing the TDBEXT declarations. */ /* mongo.h is header containing the MONGO declarations. */ /***********************************************************************/ #include "global.h" #include "plgdbsem.h" #if defined(HAVE_JMGO) #include "csort.h" #include "javaconn.h" #endif // HAVE_JMGO #include "xtable.h" #include "tabext.h" #include "mongo.h" /***********************************************************************/ /* These functions are exported from the MONGO library. */ /***********************************************************************/ extern "C" { PTABDEF __stdcall GetMONGO(PGLOBAL, void*); PQRYRES __stdcall ColMONGO(PGLOBAL, PTOS, void*, char*, char*, bool); } // extern "C" /***********************************************************************/ /* DB static variables. */ /***********************************************************************/ int TDB::Tnum; int DTVAL::Shift; #if defined(HAVE_JMGO) int CSORT::Limit = 0; double CSORT::Lg2 = log(2.0); size_t CSORT::Cpn[1000] = {0}; /* Precalculated cmpnum values */ #if defined(HAVE_JAVACONN) char *JvmPath = NULL; char *ClassPath = NULL; char *GetPluginDir(void) {return "C:/mongo-java-driver/mongo-java-driver-3.4.2.jar;" "C:/MariaDB-10.1/MariaDB/storage/connect/";} char *GetJavaWrapper(void) {return (char*)"wrappers/Mongo3Interface";} #else // !HAVE_JAVACONN HANDLE JAVAConn::LibJvm; // Handle to the jvm DLL CRTJVM JAVAConn::CreateJavaVM; GETJVM JAVAConn::GetCreatedJavaVMs; #if defined(_DEBUG) GETDEF JAVAConn::GetDefaultJavaVMInitArgs; #endif // _DEBUG #endif // !HAVE_JAVACONN #endif // HAVE_JMGO /***********************************************************************/ /* This function returns a Mongo definition class. */ /***********************************************************************/ PTABDEF __stdcall GetMONGO(PGLOBAL g, void *memp) { return new(g, memp) MGODEF; } // end of GetMONGO #ifdef NOEXP /***********************************************************************/ /* Functions to be defined if not exported by the CONNECT version. */ /***********************************************************************/ bool IsNum(PSZ s) { for (char *p = s; *p; p++) if (*p == ']') break; else if (!isdigit(*p) || *p == '-') return false; return true; } // end of IsNum #endif /***********************************************************************/ /* Return the columns definition to MariaDB. */ /***********************************************************************/ PQRYRES __stdcall ColMONGO(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) { #ifdef NOMGOCOL // Cannot use discovery strcpy(g->Message, "No discovery, MGOColumns is not accessible"); return NULL; #else return MGOColumns(g, db, NULL, tp, info); #endif } // end of ColMONGO
The file mongo.def
: (required only on Windows)
LIBRARY MONGO EXPORTS GetMONGO @1 ColMONGO @2
Compiling this OEM
To compile this OEM module, first make the two or three required files by copy/pasting from the above listings.
Even if this module is to be used with a binary distribution, you need some source files in order to successfully compile it. At least the CONNECT header files that are included in jmgoem.cpp
and the ones they can include. This can be obtained by downloading the MariaDB source file tar.gz and extracting from it the CONNECT sources files in a directory that will be added to the additional source directories if it is not the directory containing the above files.
The module must be linked to the ha_connect.lib
of the binary version it will used with. Recent distributions add this lib in the plugin directory.
The resulting module, for instance mongo.so
or mongo.dll
, must be placed in the plugin directory of the MariaDB server. Then, you will be able to use MONGO like tables simply replacing in the CREATE TABLE statement the option TABLE_TYPE=MONGO
with TABLE_TYPE=OEM SUBTYPE=MONGO MODULE=’mongo.(so|dll)’
. Actually, the module name, here supposedly ‘mongo’, can be anything you like.
This will work with the last (not yet) distributed versions of MariaDB 10.0 and 10.1 because, even it is not enabled, the MONGO type is included in them. This is also the case for MariaDB 10.2.9 but then, on Windows, you will have to define NOEXP and NOMGOCOL because these functions are not exported by this version.
To implement for older versions that do not contain the MONGO type, you can add the corresponding source files, namely javaconn.cpp
, jmgfam.cpp
, jmgoconn.cpp
, mongo.cpp
and tabjmg.cpp
that you should find in the CONNECT extracted source files if you downloaded a recent version. As they include my_global.h
, this is the reason why the included file was named this way. In addition, your compiling should define HAVE_JMGO
and HAVE_JAVACONN
. Of course, this is possible only if ha_connect.lib
is available.