summaryrefslogtreecommitdiff
path: root/storage/connect/jdbconn.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2016-07-11 15:22:30 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2016-07-11 15:22:30 +0200
commit8388ae6c006fc9d890aa146912ff00ce63e01208 (patch)
tree2e83150592335d4f3fc5556c636e851317eeaded /storage/connect/jdbconn.cpp
parentfca92ced7375618d90c05fd9591d122097c9d38c (diff)
downloadmariadb-git-8388ae6c006fc9d890aa146912ff00ce63e01208.tar.gz
- Try distributing the JdbcInterface.jar
${INSTALL_PLUGIN_DIR} --> ${INSTALL_PLUGINDIR} modified: storage/connect/CMakeLists.txt - Try several paths when looking for JVM lib modified: storage/connect/jdbconn.cpp - Make Jdbc tests running on Windows and Linux modified: storage/connect/mysql-test/connect/r/jdbc.result modified: storage/connect/mysql-test/connect/r/jdbc_new.result modified: storage/connect/mysql-test/connect/t/jdbc.test modified: storage/connect/mysql-test/connect/t/jdbc_new.test - Fix compiler's warnings modified: storage/connect/ha_connect.cc modified: storage/connect/jdbconn.cpp modified: storage/connect/jsonudf.cpp
Diffstat (limited to 'storage/connect/jdbconn.cpp')
-rw-r--r--storage/connect/jdbconn.cpp84
1 files changed, 54 insertions, 30 deletions
diff --git a/storage/connect/jdbconn.cpp b/storage/connect/jdbconn.cpp
index 2bfec4981b3..d3e573e692c 100644
--- a/storage/connect/jdbconn.cpp
+++ b/storage/connect/jdbconn.cpp
@@ -835,39 +835,52 @@ void JDBConn::ResetJVM(void)
/***********************************************************************/
bool JDBConn::GetJVM(PGLOBAL g)
{
+ int ntry;
+
if (!LibJvm) {
char soname[512];
#if defined(__WIN__)
- if (JvmPath) {
- strcat(strcpy(soname, JvmPath), "\\jvm.dll");
- } else if (getenv("JAVA_HOME")) {
+ for (ntry = 0; !LibJvm && ntry < 3; ntry++) {
+ if (!ntry && JvmPath) {
+ strcat(strcpy(soname, JvmPath), "\\jvm.dll");
+ ntry = 3; // No other try
+ } else if (ntry < 2 && getenv("JAVA_HOME")) {
strcpy(soname, getenv("JAVA_HOME"));
+
+ if (ntry == 1)
+ strcat(soname, "\\jre");
+
strcat(soname, "\\bin\\client\\jvm.dll");
- } else {
- // Try to find it through the registry
- char version[16];
- char javaKey[64] = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
- LONG rc;
- DWORD BufferSize = 16;
+ } else {
+ // Try to find it through the registry
+ char version[16];
+ char javaKey[64] = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
+ LONG rc;
+ DWORD BufferSize = 16;
- strcpy(soname, "jvm.dll"); // In case it fails
+ strcpy(soname, "jvm.dll"); // In case it fails
- if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "CurrentVersion",
- RRF_RT_ANY, NULL, (PVOID)&version, &BufferSize)) == ERROR_SUCCESS) {
- strcat(strcat(javaKey, "\\"), version);
- BufferSize = 512;
+ if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "CurrentVersion",
+ RRF_RT_ANY, NULL, (PVOID)&version, &BufferSize)) == ERROR_SUCCESS) {
+ strcat(strcat(javaKey, "\\"), version);
+ BufferSize = sizeof(soname);
- if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "RuntimeLib",
- RRF_RT_ANY, NULL, (PVOID)&soname, &BufferSize)) != ERROR_SUCCESS)
- printf("rc=%ld\n", rc);
+ if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "RuntimeLib",
+ RRF_RT_ANY, NULL, (PVOID)&soname, &BufferSize)) != ERROR_SUCCESS)
+ printf("RegGetValue: rc=%ld\n", rc);
- } // endif rc
+ } // endif rc
- } // endelse
+ ntry = 3; // Try this only once
+ } // endelse
- // Load the desired shared library
- if (!(LibJvm = LoadLibrary(soname))) {
+ // Load the desired shared library
+ LibJvm = LoadLibrary(soname);
+ } // endfor ntry
+
+ // Get the needed entries
+ if (!LibJvm) {
char buf[256];
DWORD rc = GetLastError();
@@ -898,15 +911,23 @@ bool JDBConn::GetJVM(PGLOBAL g)
#else // !__WIN__
const char *error = NULL;
- if (JvmPath)
- strcat(strcpy(soname, JvmPath), "/libjvm.so");
- else if (getenv("JAVA_HOME"))
- strcat(strcpy(soname, getenv("JAVA_HOME")), "/bin/client/libjvm.so");
- else
- strcpy(soname, "libjvm.so");
+ for (ntry = 0; !LibJvm && ntry < 2; ntry++) {
+ if (!ntry && JvmPath) {
+ strcat(strcpy(soname, JvmPath), "/libjvm.so");
+ ntry = 2;
+ } else if (!ntry && getenv("JAVA_HOME")) {
+ // TODO: Replace i386 by a better guess
+ strcat(strcpy(soname, getenv("JAVA_HOME")), "/jre/lib/i386/client/libjvm.so");
+ } else { // Will need LD_LIBRARY_PATH to be set
+ strcpy(soname, "libjvm.so");
+ ntry = 2;
+ } // endelse
+
+ LibJvm = dlopen(soname, RTLD_LAZY);
+ } // endfor ntry
// Load the desired shared library
- if (!(LibJvm = dlopen(soname, RTLD_LAZY))) {
+ if (!LibJvm) {
error = dlerror();
sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error));
} else if (!(CreateJavaVM = (CRTJVM)dlsym(LibJvm, "JNI_CreateJavaVM"))) {
@@ -982,6 +1003,11 @@ int JDBConn::Open(PJPARM sop)
#define N 1
#endif
+ // Java source will be compiled as ajar file installed in the plugin dir
+ jpop->Append(sep);
+ jpop->Append(GetPluginDir());
+ jpop->Append("JdbcInterface.jar");
+
//================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[N]; // JVM invocation options
@@ -1317,9 +1343,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
{
PGLOBAL& g = m_G;
jint ctyp;
- jlong dtv;
jstring cn, jn = nullptr;
- jobject dob;
if (rank == 0)
if (!name || (jn = env->NewStringUTF(name)) == nullptr) {