Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Error reporting from JDBCUtils.java to C code improved,comments added…

… in JDBCUtils.java,README formatting corrected
  • Loading branch information...
commit 7b985413e050f8bcd654cc2d065b169854cdbdcf 1 parent d174c44
@atris authored
Showing with 255 additions and 104 deletions.
  1. +49 −11 JDBCUtils.java
  2. +138 −44 README
  3. +68 −49 jdbc_fdw.c
View
60 JDBCUtils.java
@@ -30,6 +30,8 @@
private Statement sql;
private String[] Iterate;
private static JDBCDriverLoader JDBC_Driver_Loader;
+ private StringWriter exception_stack_trace_string_writer;
+ private PrintWriter exception_stack_trace_print_writer;
/*
* Initialize
@@ -50,19 +52,23 @@
String userName = options_array[3];
String password = options_array[4];
int querytimeoutvalue = Integer.parseInt(options_array[5]);
- File JarFile = new File(options_array[6]);
- String jarfile_path = JarFile.toURI().toURL().toString();
- StringWriter exception_stack_trace_string_writer = new StringWriter();
- PrintWriter exception_stack_trace_print_writer = new PrintWriter(exception_stack_trace_string_writer);
+
+ exception_stack_trace_string_writer = new StringWriter();
+ exception_stack_trace_print_writer = new PrintWriter(exception_stack_trace_string_writer);
NumberOfColumns = 0;
conn = null;
try
{
+ File JarFile = new File(options_array[6]);
+ String jarfile_path = JarFile.toURI().toURL().toString();
+
if (JDBC_Driver_Loader == null)
{
- JDBC_Driver_Loader = new JDBCDriverLoader(new URL[]{JarFile.toURI().toURL()});
+ /* If JDBC_Driver_Loader is being
+ * created. */
+ JDBC_Driver_Loader = new JDBCDriverLoader(new URL[]{JarFile.toURI().toURL()});
}
else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
{
@@ -80,8 +86,6 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
conn = JDBCDriver.connect(url, JDBCProperties);
db_metadata = conn.getMetaData();
- System.out.println("Connection to "+db_metadata.getDatabaseProductName()+" "+db_metadata.getDatabaseProductVersion()
- +" successful.\n");
sql = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
try
@@ -94,6 +98,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch(Exception setquerytimeout_exception)
{
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
setquerytimeout_exception.printStackTrace(exception_stack_trace_print_writer);
return (new String(exception_stack_trace_string_writer.toString()));
}
@@ -106,6 +115,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch (Exception initialize_exception)
{
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
initialize_exception.printStackTrace(exception_stack_trace_print_writer);
return (new String(exception_stack_trace_string_writer.toString()));
}
@@ -125,6 +139,8 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
try
{
+ /* Row-by-row processing is done in jdbc_fdw.One row
+ * at a time is returned to the C code. */
if (result_set.next())
{
for (i = 0; i < NumberOfColumns; i++)
@@ -133,6 +149,11 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
++NumberOfRows;
+
+ /* The current row in result_set is returned
+ * to the C code in a Java String array that
+ * has the value of the fields of the current
+ * row as it values. */
return (Iterate);
}
@@ -143,6 +164,7 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
returnresultset_exception.printStackTrace();
}
+ /* All of result_set's rows have been returned to the C code. */
return null;
}
@@ -150,7 +172,7 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
* Close
* Releases the resources used.
*/
- public void
+ public String
Close()
{
@@ -164,8 +186,16 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch (Exception close_exception)
{
- close_exception.printStackTrace();
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
+ close_exception.printStackTrace(exception_stack_trace_print_writer);
+ return (new String(exception_stack_trace_string_writer.toString()));
}
+
+ return null;
}
/*
@@ -173,7 +203,7 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
* Cancels the query and releases the resources in case query
* cancellation is requested by the user.
*/
- public void
+ public String
Cancel()
{
@@ -184,7 +214,15 @@ else if (JDBC_Driver_Loader.CheckIfClassIsLoaded(DriverClassName) == null)
}
catch(Exception cancel_exception)
{
- cancel_exception.printStackTrace();
+ /* If an exception occurs,it is returned back to the
+ * calling C code by returning a Java String object
+ * that has the exception's stack trace.
+ * If all goes well,a null String is returned. */
+
+ cancel_exception.printStackTrace(exception_stack_trace_print_writer);
+ return (new String(exception_stack_trace_string_writer.toString()));
}
+
+ return null;
}
}
View
182 README
@@ -11,11 +11,15 @@ url: The JDBC URL that shall be used to connect to the foreign database.
Note that URL has to be specified for jdbc_fdw
to work i.e. it is compulsory.
-querytimeout: The time after which a query shall automatically be terminated.The option can be used for terminating hung queries.
+querytimeout: The time after which a query shall automatically be terminated.
+ The option can be used for terminating hung queries.
-jarfile: The path and name(e.g. folder1/folder2/abc.jar) of the JAR file of the JDBC driver to be used of the foreign database.
+jarfile: The path and name(e.g. folder1/folder2/abc.jar) of the JAR file
+ of the JDBC driver to be used of the foreign database.
-maxheapsize: The value of the maximum heap size of the JVM being used in jdbc_fdw.Please read the notes about maxheapsize option in the installation instructions carefully before setting a value for the option.
+maxheapsize: The value of the maximum heap size of the JVM being used in jdbc_fdw.
+ Please read the notes about maxheapsize option in the installation
+ instructions carefully before setting a value for the option.
The following parameter can be set on a JDBC foreign table:
@@ -39,14 +43,18 @@ Installing
**Important**
-Please ensure that the URL you pass in the url option when creating the server is correct and is according to the JDBC URL that is accepted by the foreign database.Any fault in the passed JDBC URL can cause hard-to-understand errors.Please recheck and validate the JDBC URL before passing it in server options.
+Please ensure that the URL you pass in the url option when creating the server
+is correct and is according to the JDBC URL that is accepted by the foreign database.
+Any fault in the passed JDBC URL can cause hard-to-understand errors.Please recheck
+and validate the JDBC URL before passing it in server options.
************************************************************************************************************************************************
** Installation instructions for source installation of PostgreSQL
-Documentation for installing PostgreSQL from source can be found [here](http://www.postgresql.org/docs/current/static/installation.html).
+Documentation for installing PostgreSQL from source
+can be found [here](http://www.postgresql.org/docs/current/static/installation.html).
The steps to follow to install JDBC_FDW on source installation of PostgreSQL are:
@@ -66,18 +74,23 @@ The steps to follow to install JDBC_FDW on source installation of PostgreSQL are
gitc@ubuntu:~$ Make Clean
-5) Execute Make Install (You may have to change to root/installation privileges before executing Make Install)
+5) Execute Make Install
+(You may have to change to root/installation privileges before executing
+Make Install)
**Important** : Before running Make Install,please execute the following command:
gitc@ubuntu:~$ sudo ln -s /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so /usr/lib/libjvm.so
-Please replace the path in the command with the path to libjvm.so(it should be in Java JRE folder).
+Please replace the path in the command with the path to libjvm.so(it should be
+in Java JRE folder).
+
For locating libjvm.so,you can use the following command:
gitc@ubuntu:~$ locate libjvm.so
-Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so files are being shown.
+Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so
+files are being shown.
If the above command does not work,please execute the following command
@@ -101,22 +114,42 @@ After running one of the above commands,please execute the following command:
**Command to set up server that uses jdbc_fdw as the foreign data wrapper:**
- gitc@ubuntu:~$ CREATE SERVER jdbc_serv3 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(drivername 'org.postgresql.Driver',url 'jdbc:postgresql:gitc',querytimeout '15', jarfile '/home/gitc/Downloads/postgresql-9.1-902.jdbc3.jar');
+ CREATE SERVER jdbc_serv4 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(
+drivername 'org.sqlite.JDBC',
+url 'jdbc:sqlite:/home/atri/atri1.sdb',
+querytimeout '15',
+jarfile '/home/atri/Downloads/sqlite-jdbc-3.7.2.jar',
+maxheapsize '600'
+);
** Explanation of setting up options for the server
-drivername : The drivername has to be given the value of the exact class name which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
-
-url : The url has to be given the value of the JDBC URL of the database from which the data has to fetched by jdbc_fdw into PostgreSQL.
+drivername : The drivername has to be given the value of the exact class name
+which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
-jarfile : The jarfile has to be given the value of the path and name of the JAR file of the JDBC driver of the database from which the data has to fetched.
+url : The url has to be given the value of the JDBC URL of the database from
+which the data has to fetched by jdbc_fdw into PostgreSQL.
+jarfile : The jarfile has to be given the value of the path and name of the JAR
+file of the JDBC driver of the database from which the data has to fetched.
-querytimeout : The time after which a query will be terminated automatically.This can be used for terminating hung queries.
+querytimeout : The time after which a query will be terminated automatically.
+This can be used for terminating hung queries.
-maxheapsize : The value of the option shall be set to the maximum heap size of the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.This option is used for setting the maximum heap size of the JVM manually.
+maxheapsize : The value of the option shall be set to the maximum heap size of
+the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.
+This option is used for setting the maximum heap size of the JVM manually.
-**Important** : Please note that setting the maximum heap size of the JVM manually can lead to decrease in performance of jdbc_fdw.It is recommended that you double check the value you are setting in maxheapsize.It is not a compulsory option i.e. If you do net set any value for maxheapsize,the default value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.Please use it only if you want to set the maximum heap size of the JVM manually.Setting it to a very low value can lead to drastic performance hit. Also,since the JVM being used in jdbc fdw is created only once for the entire psql session,therefore,the first query issued that uses jdbc fdw shall set the value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
+**Important** : Please note that setting the maximum heap size of the JVM
+manually can lead to decrease in performance of jdbc_fdw.It is recommended that
+you double check the value you are setting in maxheapsize.It is not a
+compulsory option i.e. If you do net set any value for maxheapsize,the default
+value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.
+Please use it only if you want to set the maximum heap size of the JVM manually.
+Setting it to a very low value can lead to drastic performance hit.
+Also,since the JVM being used in jdbc fdw is created only once for the entire
+psql session,therefore,the first query issued that uses jdbc fdw shall set the
+value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
8) Create a user mapping for the server.
@@ -162,7 +195,8 @@ The output should be :
** Installation instructions for packaged installation of PostgreSQL on Debian versions
-Documentation for installing PostgreSQL from packages can be found [here](http://wiki.debian.org/PostgreSql).
+Documentation for installing PostgreSQL from packages can be found
+[here](http://wiki.debian.org/PostgreSql).
1) Ensure you have the PostgreSQL dev package installed.If not,please install the latest version.
@@ -182,20 +216,26 @@ Please replace '9.1' with the appropriate version of your installation of Postgr
gitc@ubuntu:~$ sudo PATH=/usr/lib/postgresql/9.1/bin/:$PATH make USE_PGXS=1 clean
-Assuming you have PostgreSQL installed in /usr/lib/postgresql.If not,please make appropriate changes to the $PATH value set in the command.
+Assuming you have PostgreSQL installed in /usr/lib/postgresql.If not,please
+make appropriate changes to the $PATH value set in the command.
-5)Execute Make Install (You may have to change to root/installation privileges before executing Make Install)
+5)Execute Make Install
+(You may have to change to root/installation privileges before executing Make
+Install)
**Important** : Before running Make Install,please execute the following command:
gitc@ubuntu:~$ sudo ln -s /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so /usr/lib/libjvm.so
-Please replace the path in the command with the path to libjvm.so(it should be in Java JRE folder).
+Please replace the path in the command with the path to libjvm.so
+(it should be in Java JRE folder).
+
For locating libjvm.so,you can use the following command:
gitc@ubuntu:~$ locate libjvm.so
-Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so files are being shown.
+Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so
+files are being shown.
If the above command does not work,please execute the following command
@@ -205,7 +245,8 @@ After running one of the above commands,please execute the following command:
gitc@ubuntu:~$ sudo PATH=/usr/lib/postgresql/9.1/bin/:$PATH make USE_PGXS=1 install
-Assuming you have PostgreSQL installed in /usr/lib/postgresql.If not,please make appropriate changes to the $PATH value set in the command.
+Assuming you have PostgreSQL installed in /usr/lib/postgresql.If not,please
+make appropriate changes to the $PATH value set in the command.
6) Ensure Make Install executes successfully without any warning or errors.
@@ -221,21 +262,42 @@ Assuming you have PostgreSQL installed in /usr/lib/postgresql.If not,please make
**Command to set up server that uses jdbc_fdw as the foreign data wrapper:**
- CREATE SERVER jdbc_serv4 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(drivername 'org.sqlite.JDBC',url 'jdbc:sqlite:/home/atri/atri1.sdb',querytimeout '15',jarfile '/home/atri/Downloads/sqlite-jdbc-3.7.2.jar',maxheapsize '600');
+ CREATE SERVER jdbc_serv4 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(
+drivername 'org.sqlite.JDBC',
+url 'jdbc:sqlite:/home/atri/atri1.sdb',
+querytimeout '15',
+jarfile '/home/atri/Downloads/sqlite-jdbc-3.7.2.jar',
+maxheapsize '600'
+);
** Explanation of setting up options for the server
-drivername : The drivername has to be given the value of the exact class name which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
+drivername : The drivername has to be given the value of the exact class name
+which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
-url : The url has to be given the value of the JDBC URL of the database from which the data has to fetched by jdbc_fdw into PostgreSQL.
+url : The url has to be given the value of the JDBC URL of the database from
+which the data has to fetched by jdbc_fdw into PostgreSQL.
-jarfile : The jarfile has to be given the value of the path and name of the JAR file of the JDBC driver of the database from which the data has to fetched.
+jarfile : The jarfile has to be given the value of the path and name of the JAR
+file of the JDBC driver of the database from which the data has to fetched.
-querytimeout : The time after which a query will be terminated automatically.This can be used for terminating hung queries.
+querytimeout : The time after which a query will be terminated automatically.
+This can be used for terminating hung queries.
-maxheapsize : The value of the option shall be set to the maximum heap size of the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.This option is used for setting the maximum heap size of the JVM manually.
+maxheapsize : The value of the option shall be set to the maximum heap size of
+the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.
+This option is used for setting the maximum heap size of the JVM manually.
-**Important** : Please note that setting the maximum heap size of the JVM manually can lead to decrease in performance of jdbc_fdw.It is recommended that you double check the value you are setting in maxheapsize.It is not a compulsory option i.e. If you do net set any value for maxheapsize,the default value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.Please use it only if you want to set the maximum heap size of the JVM manually.Setting it to a very low value can lead to drastic performance hit.Also,since the JVM being used in jdbc fdw is created only once for the entire psql session,therefore,the first query issued that uses jdbc fdw shall set the value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
+**Important** : Please note that setting the maximum heap size of the JVM
+manually can lead to decrease in performance of jdbc_fdw.It is recommended that
+you double check the value you are setting in maxheapsize.It is not a
+compulsory option i.e. If you do net set any value for maxheapsize,the default
+value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.
+Please use it only if you want to set the maximum heap size of the JVM manually.
+Setting it to a very low value can lead to drastic performance hit.
+Also,since the JVM being used in jdbc fdw is created only once for the entire
+psql session,therefore,the first query issued that uses jdbc fdw shall set the
+value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
10) Create a user mapping for the server.
@@ -262,9 +324,11 @@ The output should be :
** Installation Instruction for packaged installation of PostgreSQL on Red Hat versions
-Documentation for installing PostgreSQL from packages can be found [here](http://wiki.postgresql.org/wiki/Detailed_installation_guides#RedHat.2FFedora.2FCentOS).
+Documentation for installing PostgreSQL from packages can be found
+[here](http://wiki.postgresql.org/wiki/Detailed_installation_guides#RedHat.2FFedora.2FCentOS).
-1) Ensure you have the PostgreSQL dev package installed.If not,please install the latest version.
+1) Ensure you have the PostgreSQL dev package installed.If not,please install
+the latest version.
[root@AtriServer atri]# yum install postgresql-devel
@@ -280,20 +344,26 @@ Documentation for installing PostgreSQL from packages can be found [here](http:/
[root@AtriServer atri]# sudo PATH=/usr/local/pgsql/bin/:$PATH make USE_PGXS=1 clean
-Assuming you have PostgreSQL installed in /usr/local/pgsql.If not,please make appropriate changes to the $PATH value set in the command.
+Assuming you have PostgreSQL installed in /usr/local/pgsql.If not,please make
+appropriate changes to the $PATH value set in the command.
-5)Execute Make Install (You may have to change to root/installation privileges before executing Make Install)
+5)Execute Make Install
+(You may have to change to root/installation privileges before executing
+Make Install)
**Important** : Before running Make Install,please execute the following command:
[root@AtriServer atri]# ln -s /usr/lib/jvm/jre/lib/amd64/server/libjvm.so /usr/lib/libjvm.so
-Please replace the path in the command with the path to libjvm.so(it should be in Java JRE folder).
+Please replace the path in the command with the path to libjvm.so
+(it should be in Java JRE folder).
+
For locating libjvm.so,you can use the following command:
[root@AtriServer atri]# locate libjvm.so
-Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so files are being shown.
+Please give the path to libjvm.so in the 'server' folder if multiple libjvm.so
+files are being shown.
If the above command does not work,please execute the following command
@@ -303,7 +373,8 @@ After running one of the above commands,please execute the following command:
[root@AtriServer atri]# sudo PATH=/usr/local/pgsql/bin/:$PATH make USE_PGXS=1 install
-Assuming you have PostgreSQL installed in /usr/local/pgsql.If not,please make appropriate changes to the $PATH value set in the command.
+Assuming you have PostgreSQL installed in /usr/local/pgsql.If not,please make
+appropriate changes to the $PATH value set in the command.
6) Ensure Make Install executes successfully without any warning or errors.
@@ -319,21 +390,42 @@ Assuming you have PostgreSQL installed in /usr/local/pgsql.If not,please make ap
**Command to set up server that uses jdbc_fdw as the foreign data wrapper:**
- CREATE SERVER jdbc_serv4 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(drivername 'org.sqlite.JDBC',url 'jdbc:sqlite:/home/atri/atri1.sdb',querytimeout '15',jarfile '/home/atri/Downloads/sqlite-jdbc-3.7.2.jar',maxheapsize '600');
+ CREATE SERVER jdbc_serv4 FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(
+drivername 'org.sqlite.JDBC',
+url 'jdbc:sqlite:/home/atri/atri1.sdb',
+querytimeout '15',
+jarfile '/home/atri/Downloads/sqlite-jdbc-3.7.2.jar',
+maxheapsize '600'
+);
** Explanation of setting up options for the server
-drivername : The drivername has to be given the value of the exact class name which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
+drivername : The drivername has to be given the value of the exact class name
+which has to be loaded for the JDBC driver e.g. org.postgresql.Driver
-url : The url has to be given the value of the JDBC URL of the database from which the data has to fetched by jdbc_fdw into PostgreSQL.
+url : The url has to be given the value of the JDBC URL of the database from
+which the data has to fetched by jdbc_fdw into PostgreSQL.
-jarfile : The jarfile has to be given the value of the path and name of the JAR file of the JDBC driver of the database from which the data has to fetched.
+jarfile : The jarfile has to be given the value of the path and name of the JAR
+file of the JDBC driver of the database from which the data has to fetched.
-querytimeout : The time after which a query will be terminated automatically.This can be used for terminating hung queries.
+querytimeout : The time after which a query will be terminated automatically.
+This can be used for terminating hung queries.
-maxheapsize : The value of the option shall be set to the maximum heap size of the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.This option is used for setting the maximum heap size of the JVM manually.
+maxheapsize : The value of the option shall be set to the maximum heap size of
+the JVM which is being used in jdbc fdw.It can be set from 1 Mb onwards.
+This option is used for setting the maximum heap size of the JVM manually.
-**Important** : Please note that setting the maximum heap size of the JVM manually can lead to decrease in performance of jdbc_fdw.It is recommended that you double check the value you are setting in maxheapsize.It is not a compulsory option i.e. If you do net set any value for maxheapsize,the default value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.Please use it only if you want to set the maximum heap size of the JVM manually.Setting it to a very low value can lead to drastic performance hit.Also,since the JVM being used in jdbc fdw is created only once for the entire psql session,therefore,the first query issued that uses jdbc fdw shall set the value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
+**Important** : Please note that setting the maximum heap size of the JVM
+manually can lead to decrease in performance of jdbc_fdw.It is recommended that
+you double check the value you are setting in maxheapsize.It is not a
+compulsory option i.e. If you do net set any value for maxheapsize,the default
+value for the maximum heap size of the JVM being used in jdbc_fdw shall be used.
+Please use it only if you want to set the maximum heap size of the JVM manually.
+Setting it to a very low value can lead to drastic performance hit.
+Also,since the JVM being used in jdbc fdw is created only once for the entire
+psql session,therefore,the first query issued that uses jdbc fdw shall set the
+value of maximum heap size of the JVM(if the first query specifies a maximum heap value).
10) Create a user mapping for the server.
@@ -384,7 +476,9 @@ CREATE USER MAPPING FOR gitc
Features
--------
-1)jdbc_fdw can connect and fetch data to PostgreSQL from any data source that supports JDBC.
+1)jdbc_fdw can connect and fetch data to PostgreSQL from any data source that
+supports JDBC.
+
2)Basic query cancellation is supported.
--
View
117 jdbc_fdw.c
@@ -185,8 +185,10 @@ SIGINTInterruptCheckProcess()
if (InterruptFlag == true)
{
- jclass JDBCUtilsClass;
- jmethodID id_cancel;
+ jclass JDBCUtilsClass;
+ jmethodID id_cancel;
+ jstring cancel_result = NULL;
+ char *cancel_result_cstring = NULL;
JDBCUtilsClass = (*env)->FindClass(env, "JDBCUtils");
if (JDBCUtilsClass == NULL)
@@ -194,16 +196,24 @@ SIGINTInterruptCheckProcess()
elog(ERROR, "JDBCUtilsClass is NULL");
}
- id_cancel = (*env)->GetMethodID(env, JDBCUtilsClass, "Cancel", "()V");
+ id_cancel = (*env)->GetMethodID(env, JDBCUtilsClass, "Cancel", "()Ljava/lang/String;");
if (id_cancel == NULL)
{
elog(ERROR, "id_cancel is NULL");
}
- (*env)->CallObjectMethod(env,java_call,id_cancel);
+ cancel_result = (*env)->CallObjectMethod(env,java_call,id_cancel);
+ if (cancel_result != NULL)
+ {
+ cancel_result_cstring = ConvertStringToCString((jobject)cancel_result);
+ elog(ERROR, "%s", cancel_result_cstring);
+ }
InterruptFlag = false;
elog(ERROR, "Query has been cancelled");
+
+ (*env)->ReleaseStringUTFChars(env, cancel_result, cancel_result_cstring);
+ (*env)->DeleteLocalRef(env, cancel_result);
}
}
@@ -221,7 +231,7 @@ ConvertStringToCString(jobject java_cstring)
SIGINTInterruptCheckProcess();
JavaString = (*env)->FindClass(env, "java/lang/String");
- if (!((*env) -> IsInstanceOf(env, java_cstring, JavaString)))
+ if (!((*env)->IsInstanceOf(env, java_cstring, JavaString)))
{
elog(ERROR, "Object not an instance of String class");
}
@@ -246,7 +256,7 @@ static void
DestroyJVM()
{
- (*jvm) -> DestroyJavaVM(jvm);
+ (*jvm)->DestroyJavaVM(jvm);
}
/*
@@ -426,7 +436,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
));
}
- if (strcmp(def -> defname, "drivername") == 0)
+ if (strcmp(def->defname, "drivername") == 0)
{
if (svr_drivername)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
@@ -436,7 +446,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_drivername = defGetString(def);
}
- if (strcmp(def -> defname, "url") == 0)
+ if (strcmp(def->defname, "url") == 0)
{
if (svr_url)
ereport(ERROR,
@@ -447,7 +457,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_url = defGetString(def);
}
- if (strcmp(def -> defname, "querytimeout") == 0)
+ if (strcmp(def->defname, "querytimeout") == 0)
{
if (svr_querytimeout)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
@@ -457,7 +467,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_querytimeout = atoi(defGetString(def));
}
- if (strcmp(def -> defname, "jarfile") == 0)
+ if (strcmp(def->defname, "jarfile") == 0)
{
if (svr_jarfile)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
@@ -477,7 +487,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_maxheapsize = atoi(defGetString(def));
}
- if (strcmp(def -> defname, "username") == 0)
+ if (strcmp(def->defname, "username") == 0)
{
if (svr_username)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
@@ -487,7 +497,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_username = defGetString(def);
}
- if (strcmp(def -> defname, "password") == 0)
+ if (strcmp(def->defname, "password") == 0)
{
if (svr_password)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
@@ -496,7 +506,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_password = defGetString(def);
}
- else if (strcmp(def -> defname, "query") == 0)
+ else if (strcmp(def->defname, "query") == 0)
{
if (svr_table)
ereport(ERROR,
@@ -512,7 +522,7 @@ jdbc_fdw_validator(PG_FUNCTION_ARGS)
svr_query = defGetString(def);
}
- else if (strcmp(def -> defname, "table") == 0)
+ else if (strcmp(def->defname, "table") == 0)
{
if (svr_query)
ereport(ERROR,
@@ -611,22 +621,22 @@ jdbcGetOptions(Oid foreigntableid, char **drivername, char **url, int *querytime
{
DefElem *def = (DefElem *) lfirst(lc);
- if (strcmp(def -> defname, "drivername") == 0)
+ if (strcmp(def->defname, "drivername") == 0)
{
*drivername = defGetString(def);
}
- if (strcmp(def -> defname, "username") == 0)
+ if (strcmp(def->defname, "username") == 0)
{
*username = defGetString(def);
}
- if (strcmp(def -> defname, "querytimeout") == 0)
+ if (strcmp(def->defname, "querytimeout") == 0)
{
*querytimeout = atoi(defGetString(def));
}
- if (strcmp(def -> defname, "jarfile") == 0)
+ if (strcmp(def->defname, "jarfile") == 0)
{
*jarfile = defGetString(def);
}
@@ -636,22 +646,22 @@ jdbcGetOptions(Oid foreigntableid, char **drivername, char **url, int *querytime
*maxheapsize = atoi(defGetString(def));
}
- if (strcmp(def -> defname, "password") == 0)
+ if (strcmp(def->defname, "password") == 0)
{
*password = defGetString(def);
}
- if (strcmp(def -> defname, "query") == 0)
+ if (strcmp(def->defname, "query") == 0)
{
*query = defGetString(def);
}
- if (strcmp(def -> defname, "table") == 0)
+ if (strcmp(def->defname, "table") == 0)
{
*table = defGetString(def);
}
- if (strcmp(def -> defname, "url") == 0)
+ if (strcmp(def->defname, "url") == 0)
{
*url = defGetString(def);
}
@@ -814,9 +824,9 @@ jdbcBeginForeignScan(ForeignScanState *node, int eflags)
/* Stash away the state info we have already */
festate = (jdbcFdwExecutionState *) palloc(sizeof(jdbcFdwExecutionState));
- festate -> query = query;
- festate -> NumberOfColumns = 0;
- festate -> NumberOfRows = 0;
+ festate->query = query;
+ festate->NumberOfColumns = 0;
+ festate->NumberOfRows = 0;
/* Connect to the server and execute the query */
JDBCUtilsClass = (*env)->FindClass(env, "JDBCUtils");
@@ -871,10 +881,10 @@ jdbcBeginForeignScan(ForeignScanState *node, int eflags)
for (counter = 1; counter < 7; counter++)
{
- (*env) -> SetObjectArrayElement(env, arg_array, counter, StringArray[counter]);
+ (*env)->SetObjectArrayElement(env, arg_array, counter, StringArray[counter]);
}
- java_call = (*env) -> AllocObject(env, JDBCUtilsClass);
+ java_call = (*env)->AllocObject(env, JDBCUtilsClass);
if (java_call == NULL)
{
elog(ERROR, "java_call is NULL");
@@ -895,9 +905,9 @@ jdbcBeginForeignScan(ForeignScanState *node, int eflags)
(*env)->DeleteLocalRef(env, StringArray[referencedeletecounter]);
}
- (*env) -> DeleteLocalRef(env, arg_array);
- (*env) -> ReleaseStringUTFChars(env, initialize_result, initialize_result_cstring);
- (*env) -> DeleteLocalRef(env, initialize_result);
+ (*env)->DeleteLocalRef(env, arg_array);
+ (*env)->ReleaseStringUTFChars(env, initialize_result, initialize_result_cstring);
+ (*env)->DeleteLocalRef(env, initialize_result);
}
/*
@@ -916,15 +926,15 @@ jdbcIterateForeignScan(ForeignScanState *node)
int i = 0;
int j = 0;
jstring tempString;
- jdbcFdwExecutionState *festate = (jdbcFdwExecutionState *) node -> fdw_state;
- TupleTableSlot *slot = node -> ss.ss_ScanTupleSlot;
+ jdbcFdwExecutionState *festate = (jdbcFdwExecutionState *) node->fdw_state;
+ TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
/* Cleanup */
ExecClearTuple(slot);
SIGINTInterruptCheckProcess();
- if ((*env) -> PushLocalFrame(env, (festate -> NumberOfColumns + 10)) < 0)
+ if ((*env)->PushLocalFrame(env, (festate->NumberOfColumns + 10)) < 0)
{
/* frame not pushed, no PopLocalFrame needed */
elog(ERROR, "Error");
@@ -943,33 +953,33 @@ jdbcIterateForeignScan(ForeignScanState *node)
elog(ERROR, "id_returnresultset is NULL");
}
- values=(char**)palloc(sizeof(char*)*(festate -> NumberOfColumns));
+ values=(char**)palloc(sizeof(char*)*(festate->NumberOfColumns));
- java_rowarray = (*env) -> CallObjectMethod(env, java_call, id_returnresultset);
+ java_rowarray = (*env)->CallObjectMethod(env, java_call, id_returnresultset);
if (java_rowarray != NULL)
{
for (i = 0; i < (festate->NumberOfColumns); i++)
{
- values[i] = ConvertStringToCString((jobject)(*env) -> GetObjectArrayElement(env, java_rowarray, i));
+ values[i] = ConvertStringToCString((jobject)(*env)->GetObjectArrayElement(env, java_rowarray, i));
}
- tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(node -> ss.ss_currentRelation -> rd_att), values);
+ tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(node->ss.ss_currentRelation->rd_att), values);
ExecStoreTuple(tuple, slot, InvalidBuffer, false);
- ++ (festate -> NumberOfRows);
+ ++ (festate->NumberOfRows);
for (j = 0; j < festate->NumberOfColumns; j++)
{
- tempString = (jstring)(*env) -> GetObjectArrayElement(env, java_rowarray,j);
- (*env) -> ReleaseStringUTFChars(env, tempString, values[j]);
- (*env) -> DeleteLocalRef(env, tempString);
+ tempString = (jstring)(*env)->GetObjectArrayElement(env, java_rowarray,j);
+ (*env)->ReleaseStringUTFChars(env, tempString, values[j]);
+ (*env)->DeleteLocalRef(env, tempString);
}
- (*env) -> DeleteLocalRef(env, java_rowarray);
+ (*env)->DeleteLocalRef(env, java_rowarray);
}
- (*env) -> PopLocalFrame(env, NULL);
+ (*env)->PopLocalFrame(env, NULL);
return (slot);
}
@@ -983,7 +993,9 @@ jdbcEndForeignScan(ForeignScanState *node)
{
jmethodID id_close;
jclass JDBCUtilsClass;
- jdbcFdwExecutionState *festate = (jdbcFdwExecutionState *) node -> fdw_state;
+ jstring close_result = NULL;
+ char *close_result_cstring = NULL;
+ jdbcFdwExecutionState *festate = (jdbcFdwExecutionState *) node->fdw_state;
SIGINTInterruptCheckProcess();
@@ -993,20 +1005,27 @@ jdbcEndForeignScan(ForeignScanState *node)
elog(ERROR, "JDBCUtilsClass is NULL");
}
- id_close = (*env)->GetMethodID(env, JDBCUtilsClass, "Close", "()V");
+ id_close = (*env)->GetMethodID(env, JDBCUtilsClass, "Close", "()Ljava/lang/String;");
if (id_close == NULL)
{
elog(ERROR, "id_close is NULL");
}
- (*env) -> CallObjectMethod(env, java_call, id_close);
- if (festate -> query)
+ close_result = (*env)->CallObjectMethod(env, java_call, id_close);
+ if (close_result != NULL)
+ {
+ close_result_cstring = ConvertStringToCString((jobject)close_result);
+ elog(ERROR, "%s", close_result_cstring);
+ }
+ if (festate->query)
{
- pfree(festate -> query);
+ pfree(festate->query);
festate->query = 0;
}
- (*env) -> DeleteGlobalRef(env, java_call);
+ (*env)->ReleaseStringUTFChars(env, close_result, close_result_cstring);
+ (*env)->DeleteLocalRef(env, close_result);
+ (*env)->DeleteGlobalRef(env, java_call);
}
/*

0 comments on commit 7b98541

Please sign in to comment.
Something went wrong with that request. Please try again.