Commit b0c90e81 authored by Olivier Bertrand's avatar Olivier Bertrand

- New version of java wrappers as the "wrappers" package

  deleted:    storage/connect/JdbcApacheInterface.class
  deleted:    storage/connect/JdbcApacheInterface.java
  deleted:    storage/connect/JdbcDSInterface.class
  deleted:    storage/connect/JdbcDSInterface.java
  modified:   storage/connect/JdbcInterface.java
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabjdbc.h
  added:      storage/connect/ApacheInterface.java
  added:      storage/connect/Client.java
  added:      storage/connect/JdbcInterface.jar
  added:      storage/connect/MariadbInterface.java
  added:      storage/connect/MysqlInterface.java
  added:      storage/connect/OracleInterface.java
  added:      storage/connect/PostgresqlInterface.java
  added:      storage/connect/wrappers/ApacheInterface.class
  added:      storage/connect/wrappers/Client.class
  added:      storage/connect/wrappers/JdbcInterface.class
  added:      storage/connect/wrappers/MariadbInterface.class
  added:      storage/connect/wrappers/MysqlInterface.class
  added:      storage/connect/wrappers/OracleInterface.class
  added:      storage/connect/wrappers/PostgresqlInterface.class
parent 92dbe32d
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import org.apache.commons.dbcp2.BasicDataSource;
public class ApacheInterface extends JdbcInterface {
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
public ApacheInterface() {
this(true);
} // end of default constructor
public ApacheInterface(boolean b) {
super(b);
} // end of constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
BasicDataSource ds = null;
if (DEBUG)
System.out.println("Connecting to Apache data source");
try {
if (url == null)
throw new Exception("URL cannot be null");
if ((ds = pool.get(url)) == null) {
ds = new BasicDataSource();
ds.setDriverClassName(parms[0]);
ds.setUrl(url);
ds.setUsername(parms[2]);
ds.setPassword(parms[3]);
pool.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch (Exception e) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class ApacheInterface
package wrappers;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
public class Client {
static boolean DEBUG = true;
static final Console c = System.console();
static JdbcInterface jdi = null;
public static void main(String[] args) {
int rc, n, ncol, i = 0, fsize = 0;
boolean scrollable = false;
String s;
String[] parms = new String[4];
if (args.length > 0)
try {
i = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
i = 0;
} // end try/catch
switch (i) {
case 1:
jdi = new ApacheInterface(DEBUG);
break;
case 2:
jdi = new MysqlInterface(DEBUG);
break;
case 3:
jdi = new MariadbInterface(DEBUG);
break;
case 4:
jdi = new OracleInterface(DEBUG);
break;
case 5:
jdi = new PostgresqlInterface(DEBUG);
break;
default:
jdi = new JdbcInterface(DEBUG);
} // endswitch i
parms[0] = getLine("Driver: ", false);
parms[1] = getLine("URL: ", false);
parms[2] = getLine("User: ", false);
parms[3] = getLine("Password: ", true);
s = getLine("Fsize: ", false);
fsize = (s != null) ? Integer.parseInt(s) : 0;
s = getLine("Scrollable: ", false);
scrollable = (s != null) ? s.toLowerCase().charAt(0) != 'n' : false;
rc = jdi.JdbcConnect(parms, fsize, scrollable);
if (rc == 0) {
String query;
System.out.println("Successfully connected to " + parms[1]);
while ((query = getLine("Query: ", false)) != null) {
n = jdi.Execute(query);
System.out.println("Returned n = " + n);
if ((ncol = jdi.GetResult()) > 0)
PrintResult(ncol);
else
System.out.println("Affected rows = " + n);
} // endwhile
rc = jdi.JdbcDisconnect();
System.out.println("Disconnect returned " + rc);
} else
System.out.println(jdi.GetErrmsg() + " rc=" + rc);
} // end of main
private static void PrintResult(int ncol) {
// Get result set meta data
int i;
String columnName;
// Get the column names; column indices start from 1
for (i = 1; i <= ncol; i++) {
columnName = jdi.ColumnName(i);
if (columnName == null)
return;
// Get the name of the column's table name
//String tableName = rsmd.getTableName(i);
if (i > 1)
System.out.print("\t");
System.out.print(columnName);
} // endfor i
System.out.println();
// Loop through the result set
while (jdi.ReadNext() > 0) {
for (i = 1; i <= ncol; i++) {
if (i > 1)
System.out.print("\t");
if (DEBUG)
System.out.print("(" + jdi.ColumnType(i, null) + ")");
switch (jdi.ColumnType(i, null)) {
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
case java.sql.Types.CHAR:
System.out.print(jdi.StringField(i, null));
break;
case java.sql.Types.INTEGER:
System.out.print(jdi.IntField(i, null));
break;
case java.sql.Types.BIGINT:
System.out.print(jdi.BigintField(i, null));
break;
case java.sql.Types.TIMESTAMP:
System.out.print(jdi.TimestampField(i, null));
break;
case java.sql.Types.TIME:
System.out.print(jdi.TimeField(i, null));
break;
case java.sql.Types.DATE:
System.out.print(jdi.DateField(i, null));
break;
case java.sql.Types.SMALLINT:
System.out.print(jdi.IntField(i, null));
break;
case java.sql.Types.DOUBLE:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
case java.sql.Types.DECIMAL:
System.out.print(jdi.DoubleField(i, null));
break;
case java.sql.Types.BOOLEAN:
System.out.print(jdi.BooleanField(i, null));
default:
break;
} // endswitch Type
} // endfor i
System.out.println();
} // end while rs
} // end of PrintResult
// ==================================================================
private static String getLine(String p, boolean b) {
String response;
if (c != null) {
// Standard console mode
if (b) {
response = new String(c.readPassword(p));
} else
response = c.readLine(p);
} else {
// For instance when testing from Eclipse
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print(p);
try {
// Cannot suppress echo for password entry
response = in.readLine();
} catch (IOException e) {
response = "";
} // end of try/catch
} // endif c
return (response.isEmpty()) ? null : response;
} // end of getLine
} // end of class Client
This diff was suppressed by a .gitattributes entry.
import java.math.*;
import java.sql.*;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import org.apache.commons.dbcp2.BasicDataSource;
public class JdbcApacheInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
// === Constructors/finalize =========================================
public JdbcApacheInterface() {
this(true);
} // end of default constructor
public JdbcApacheInterface(boolean b) {
DEBUG = b;
} // end of constructor
private void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
private void SetErrmsg(String s) {
if (DEBUG)
System.out.println(s);
Errmsg = s;
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
BasicDataSource ds = null;
if (url == null) {
SetErrmsg("URL cannot be null");
return -1;
} // endif url
try {
if ((ds = pool.get(url)) == null) {
ds = new BasicDataSource();
ds.setDriverClassName(parms[0]);
ds.setUrl(url);
ds.setUsername(parms[2]);
ds.setPassword(parms[3]);
pool.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
public int CreatePrepStmt(String sql) {
int rc = 0;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException se) {
SetErrmsg(se);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -2;
} // end try/catch
return rc;
} // end of CreatePrepStmt
public void SetStringParm(int i, String s) {
try {
pstmt.setString(i, s);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetStringParm
public void SetIntParm(int i, int n) {
try {
pstmt.setInt(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetIntParm
public void SetShortParm(int i, short n) {
try {
pstmt.setShort(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetShortParm
public void SetBigintParm(int i, long n) {
try {
pstmt.setLong(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetBigintParm
public void SetFloatParm(int i, float f) {
try {
pstmt.setFloat(i, f);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetFloatParm
public void SetDoubleParm(int i, double d) {
try {
pstmt.setDouble(i, d);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetDoubleParm
public void SetTimestampParm(int i, Timestamp t) {
try {
pstmt.setTimestamp(i, t);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetTimestampParm
public int ExecutePrep() {
int n = -3;
if (pstmt != null) try {
n = pstmt.executeUpdate();
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecutePrep
public boolean ClosePrepStmt() {
boolean b = false;
if (pstmt != null) try {
pstmt.close();
pstmt = null;
} catch (SQLException se) {
SetErrmsg(se);
b = true;
} catch (Exception e) {
SetErrmsg(e);
b = true;
} // end try/catch
return b;
} // end of ClosePrepStmt
public int JdbcDisconnect() {
int rc = 0;
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
rc += 1;
} // nothing more we can do
// Close the statement and the connection
if (rs != null)
try {
if (DEBUG)
System.out.println("Closing result set");
rs.close();
} catch(SQLException se) {
SetErrmsg(se);
rc = 2;
} // nothing more we can do
if (stmt != null)
try {
if (DEBUG)
System.out.println("Closing statement");
stmt.close();
} catch(SQLException se) {
SetErrmsg(se);
rc += 4;
} // nothing more we can do
ClosePrepStmt();
if (conn != null)
try {
if (DEBUG)
System.out.println("Closing connection");
conn.close();
} catch (SQLException se) {
SetErrmsg(se);
rc += 8;
} //end try/catch
if (DEBUG)
System.out.println("All closed");
return rc;
} // end of JdbcDisconnect
public int GetMaxValue(int n) {
int m = 0;
try {
switch (n) {
case 1: // Max columns in table
m = dbmd.getMaxColumnsInTable();
break;
case 2: // Max catalog name length
m = dbmd.getMaxCatalogNameLength();
break;
case 3: // Max schema name length
m = dbmd.getMaxSchemaNameLength();
break;
case 4: // Max table name length
m = dbmd.getMaxTableNameLength();
break;
case 5: // Max column name length
m = dbmd.getMaxColumnNameLength();
break;
} // endswitch n
} catch(Exception e) {
SetErrmsg(e);
m = -1;
} // end try/catch
return m;
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
String[] typ = null;
if (parms[3] != null) {
typ = new String[1];
typ[0] = parms[3];
} // endif parms
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int Execute(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing '" + query + "'");
try {
boolean b = stmt.execute(query);
if (b == false) {
n = stmt.getUpdateCount();
if (rs != null) rs.close();
} // endif b
if (DEBUG)
System.out.println("Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of Execute
public int GetResult() {
int ncol = 0;
try {
rs = stmt.getResultSet();
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG)
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif rs
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of GetResult
public int ExecuteQuery(String query) {
int ncol = 0;
if (DEBUG)
System.out.println("Executing query '" + query + "'");
try {
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG) {
System.out.println("Query '" + query + "' executed successfully");
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif DEBUG
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of ExecuteQuery
public int ExecuteUpdate(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing update query '" + query + "'");
try {
n = stmt.executeUpdate(query);
if (DEBUG)
System.out.println("Update Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecuteUpdate
public int ReadNext() {
if (rs != null) {
try {
return rs.next() ? 1 : 0;
} catch (SQLException se) {
SetErrmsg(se);
return -1;
} //end try/catch
} else
return 0;
} // end of ReadNext
public boolean Fetch(int row) {
if (rs != null) {
try {
return rs.absolute(row);
} catch (SQLException se) {
SetErrmsg(se);
return false;
} //end try/catch
} else
return false;
} // end of Fetch
public String ColumnName(int n) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnName
public int ColumnType(int n, String name) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
if (n == 0)
n = rs.findColumn(name);
return rsmd.getColumnType(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 666; // Not a type
} // end of ColumnType
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
public String StringField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getString(n) : rs.getString(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of StringField
public int IntField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getInt(n) : rs.getInt(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of IntField
public long BigintField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of BiginttField
public double DoubleField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDouble(n) : rs.getDouble(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0.;
} // end of DoubleField
public float FloatField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getFloat(n) : rs.getFloat(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of FloatField
public boolean BooleanField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getBoolean(n) : rs.getBoolean(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of DateField
public Time TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimestampField
public String ObjectField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getObject(n).toString() : rs.getObject(name).toString();
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ObjectField
public int GetDrivers(String[] s, int mxs) {
int n = 0;
List<Driver> drivers = Collections.list(DriverManager.getDrivers());
int size = Math.min(mxs, drivers.size());
for (int i = 0; i < size; i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
s[n++] = driver.getClass().getName();
// Get version info
s[n++] = driver.getMajorVersion() + "." + driver.getMinorVersion();
s[n++] = driver.jdbcCompliant() ? "Yes" : "No";
s[n++] = driver.toString();
} // endfor i
return size;
} // end of GetDrivers
/**
* Adds the specified path to the java library path
* from Fahd Shariff blog
*
* @param pathToAdd the path to add
static public int addLibraryPath(String pathToAdd) {
System.out.println("jpath = " + pathToAdd);
try {
Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
String[] paths = (String[])usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
System.out.println("path = " + path);
if (path.equals(pathToAdd))
return -5;
} // endfor path
//add the new path
String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[paths.length] = pathToAdd;
usrPathsField.set(null, newPaths);
System.setProperty("java.library.path",
System.getProperty("java.library.path") + File.pathSeparator + pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
SetErrmsg(e);
return -1;
} // end try/catch
return 0;
} // end of addLibraryPath
*/
} // end of class JdbcApacheInterface
This diff was suppressed by a .gitattributes entry.
import java.math.*;
import java.sql.*;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import javax.sql.DataSource;
import org.mariadb.jdbc.MariaDbDataSource;
import org.postgresql.jdbc2.optional.PoolingDataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
import oracle.jdbc.pool.OracleDataSource;
public class JdbcDSInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
Hashtable<String,DataSource> dst = null;
// === Constructors/finalize =========================================
public JdbcDSInterface() {
this(true);
} // end of default constructor
public JdbcDSInterface(boolean b) {
DEBUG = b;
dst = new Hashtable<String, DataSource>();
} // end of constructor
private void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
private void SetErrmsg(String s) {
if (DEBUG)
System.out.println(s);
Errmsg = s;
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MysqlDataSource mds = null;
MariaDbDataSource ads = null;
OracleDataSource ods = null;
PoolingDataSource pds = null;
if (url == null) {
SetErrmsg("URL cannot be null");
return -1;
} // endif driver
try {
if ((ds = dst.get(url)) == null) {
if (url.toLowerCase().contains("mysql")) {
mds = new MysqlDataSource();
mds.setURL(url);
mds.setUser(parms[2]);
mds.setPassword(parms[3]);
ds = mds;
} else if (url.toLowerCase().contains("mariadb")) {
ads = new MariaDbDataSource();
ads.setUrl(url);
ads.setUser(parms[2]);
ads.setPassword(parms[3]);
ds = ads;
} else if (url.toLowerCase().contains("oracle")) {
ods = new OracleDataSource();
ods.setURL(url);
ods.setUser(parms[2]);
ods.setPassword(parms[3]);
ds = ods;
} else if (url.toLowerCase().contains("postgresql")) {
pds = new PoolingDataSource();
pds.setUrl(url);
pds.setUser(parms[2]);
pds.setPassword(parms[3]);
ds = pds;
} else {
SetErrmsg("Unsupported driver");
return -4;
} // endif driver
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
public int CreatePrepStmt(String sql) {
int rc = 0;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException se) {
SetErrmsg(se);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -2;
} // end try/catch
return rc;
} // end of CreatePrepStmt
public void SetStringParm(int i, String s) {
try {
pstmt.setString(i, s);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetStringParm
public void SetIntParm(int i, int n) {
try {
pstmt.setInt(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetIntParm
public void SetShortParm(int i, short n) {
try {
pstmt.setShort(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetShortParm
public void SetBigintParm(int i, long n) {
try {
pstmt.setLong(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetBigintParm
public void SetFloatParm(int i, float f) {
try {
pstmt.setFloat(i, f);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetFloatParm
public void SetDoubleParm(int i, double d) {
try {
pstmt.setDouble(i, d);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetDoubleParm
public void SetTimestampParm(int i, Timestamp t) {
try {
pstmt.setTimestamp(i, t);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetTimestampParm
public int ExecutePrep() {
int n = -3;
if (pstmt != null) try {
n = pstmt.executeUpdate();
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecutePrep
public boolean ClosePrepStmt() {
boolean b = false;
if (pstmt != null) try {
pstmt.close();
pstmt = null;
} catch (SQLException se) {
SetErrmsg(se);
b = true;
} catch (Exception e) {
SetErrmsg(e);
b = true;
} // end try/catch
return b;
} // end of ClosePrepStmt
public int JdbcDisconnect() {
int rc = 0;
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
rc += 1;
} // nothing more we can do
// Close the statement and the connection
if (rs != null)
try {
if (DEBUG)
System.out.println("Closing result set");
rs.close();
} catch(SQLException se) {
SetErrmsg(se);
rc = 2;
} // nothing more we can do
if (stmt != null)
try {
if (DEBUG)
System.out.println("Closing statement");
stmt.close();
} catch(SQLException se) {
SetErrmsg(se);
rc += 4;
} // nothing more we can do
ClosePrepStmt();
if (conn != null)
try {
if (DEBUG)
System.out.println("Closing connection");
conn.close();
} catch (SQLException se) {
SetErrmsg(se);
rc += 8;
} //end try/catch
if (DEBUG)
System.out.println("All closed");
return rc;
} // end of JdbcDisconnect
public int GetMaxValue(int n) {
int m = 0;
try {
switch (n) {
case 1: // Max columns in table
m = dbmd.getMaxColumnsInTable();
break;
case 2: // Max catalog name length
m = dbmd.getMaxCatalogNameLength();
break;
case 3: // Max schema name length
m = dbmd.getMaxSchemaNameLength();
break;
case 4: // Max table name length
m = dbmd.getMaxTableNameLength();
break;
case 5: // Max column name length
m = dbmd.getMaxColumnNameLength();
break;
} // endswitch n
} catch(Exception e) {
SetErrmsg(e);
m = -1;
} // end try/catch
return m;
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
String[] typ = null;
if (parms[3] != null) {
typ = new String[1];
typ[0] = parms[3];
} // endif parms
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int Execute(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing '" + query + "'");
try {
boolean b = stmt.execute(query);
if (b == false) {
n = stmt.getUpdateCount();
if (rs != null) rs.close();
} // endif b
if (DEBUG)
System.out.println("Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of Execute
public int GetResult() {
int ncol = 0;
try {
rs = stmt.getResultSet();
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG)
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif rs
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of GetResult
public int ExecuteQuery(String query) {
int ncol = 0;
if (DEBUG)
System.out.println("Executing query '" + query + "'");
try {
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG) {
System.out.println("Query '" + query + "' executed successfully");
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif DEBUG
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of ExecuteQuery
public int ExecuteUpdate(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing update query '" + query + "'");
try {
n = stmt.executeUpdate(query);
if (DEBUG)
System.out.println("Update Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecuteUpdate
public int ReadNext() {
if (rs != null) {
try {
return rs.next() ? 1 : 0;
} catch (SQLException se) {
SetErrmsg(se);
return -1;
} //end try/catch
} else
return 0;
} // end of ReadNext
public boolean Fetch(int row) {
if (rs != null) {
try {
return rs.absolute(row);
} catch (SQLException se) {
SetErrmsg(se);
return false;
} //end try/catch
} else
return false;
} // end of Fetch
public String ColumnName(int n) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnName
public int ColumnType(int n, String name) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
if (n == 0)
n = rs.findColumn(name);
return rsmd.getColumnType(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 666; // Not a type
} // end of ColumnType
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
public String StringField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getString(n) : rs.getString(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of StringField
public int IntField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getInt(n) : rs.getInt(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of IntField
public long BigintField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of BiginttField
public double DoubleField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDouble(n) : rs.getDouble(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0.;
} // end of DoubleField
public float FloatField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getFloat(n) : rs.getFloat(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of FloatField
public boolean BooleanField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getBoolean(n) : rs.getBoolean(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of DateField
public Time TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimestampField
public String ObjectField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getObject(n).toString() : rs.getObject(name).toString();
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ObjectField
public int GetDrivers(String[] s, int mxs) {
int n = 0;
List<Driver> drivers = Collections.list(DriverManager.getDrivers());
int size = Math.min(mxs, drivers.size());
for (int i = 0; i < size; i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
s[n++] = driver.getClass().getName();
// Get version info
s[n++] = driver.getMajorVersion() + "." + driver.getMinorVersion();
s[n++] = driver.jdbcCompliant() ? "Yes" : "No";
s[n++] = driver.toString();
} // endfor i
return size;
} // end of GetDrivers
/**
* Adds the specified path to the java library path
* from Fahd Shariff blog
*
* @param pathToAdd the path to add
static public int addLibraryPath(String pathToAdd) {
System.out.println("jpath = " + pathToAdd);
try {
Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
String[] paths = (String[])usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
System.out.println("path = " + path);
if (path.equals(pathToAdd))
return -5;
} // endfor path
//add the new path
String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[paths.length] = pathToAdd;
usrPathsField.set(null, newPaths);
System.setProperty("java.library.path",
System.getProperty("java.library.path") + File.pathSeparator + pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
SetErrmsg(e);
return -1;
} // end try/catch
return 0;
} // end of addLibraryPath
*/
} // end of class JdbcDSInterface
This diff was suppressed by a .gitattributes entry.
package wrappers;
import java.math.*;
import java.sql.*;
//import java.util.Arrays;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
//import java.io.File;
//import java.lang.reflect.Field;
import javax.sql.DataSource;
public class JdbcInterface {
// This is used by DS classes
static Hashtable<String,DataSource> dst = null;
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
......@@ -25,7 +30,7 @@ public class JdbcInterface {
DEBUG = b;
} // end of constructor
private void SetErrmsg(Exception e) {
protected void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
......@@ -74,27 +79,7 @@ public class JdbcInterface {
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
stmt = GetStmt(fsize, scrollable);
} catch(ClassNotFoundException e) {
SetErrmsg(e);
rc = -1;
......@@ -109,6 +94,34 @@ public class JdbcInterface {
return rc;
} // end of JdbcConnect
protected Statement GetStmt(int fsize, boolean scrollable) throws SQLException, Exception {
Statement stmt = null;
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
return stmt;
} // end of GetStmt
public int CreatePrepStmt(String sql) {
int rc = 0;
......@@ -227,7 +240,9 @@ public class JdbcInterface {
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
if (DEBUG)
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
......@@ -710,3 +725,4 @@ public class JdbcInterface {
*/
} // end of class JdbcInterface
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import org.mariadb.jdbc.MariaDbDataSource;
public class MariadbInterface extends JdbcInterface {
public MariadbInterface() {
this(true);
} // end of default constructor
public MariadbInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of default constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MariaDbDataSource ads = null;
if (DEBUG)
System.out.println("Connecting to MariaDB data source");
try {
if (url == null)
throw new Exception("URL cannot be null");
if ((ds = dst.get(url)) == null) {
ads = new MariaDbDataSource();
ads.setUrl(url);
if (parms[2] != null)
ads.setUser(parms[2]);
if (parms[3] != null)
ads.setPassword(parms[3]);
ds = ads;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
}
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
public class MysqlInterface extends JdbcInterface {
public MysqlInterface() {
this(true);
} // end of default constructor
public MysqlInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of default constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MysqlDataSource mds = null;
if (DEBUG)
System.out.println("Connecting to MySQL data source");
try {
if (url == null)
throw new Exception("URL cannot be null");
if ((ds = dst.get(url)) == null) {
mds = new MysqlDataSource();
mds.setUrl(url);
if (parms[2] != null)
mds.setUser(parms[2]);
if (parms[3] != null)
mds.setPassword(parms[3]);
ds = mds;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class MysqlInterface
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import oracle.jdbc.pool.OracleDataSource;
public class OracleInterface extends JdbcInterface {
public OracleInterface() {
this(true);
} // end of OracleInterface constructor
public OracleInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of OracleInterface constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
OracleDataSource ods = null;
if (DEBUG)
System.out.println("Connecting to Oracle data source");
try {
if (url == null)
throw new Exception("URL cannot be null");
if ((ds = dst.get(url)) == null) {
ods = new OracleDataSource();
ods.setURL(url);
if (parms[2] != null)
ods.setUser(parms[2]);
if (parms[3] != null)
ods.setPassword(parms[3]);
ds = ods;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class OracleInterface
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import org.postgresql.jdbc2.optional.PoolingDataSource;
public class PostgresqlInterface extends JdbcInterface {
public PostgresqlInterface() {
this(true);
} // end of constructor
public PostgresqlInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
PoolingDataSource pds = null;
if (DEBUG)
System.out.println("Connecting to Postgresql data source");
try {
if (url == null)
throw new Exception("URL cannot be null");
if ((ds = dst.get(url)) == null) {
pds = new PoolingDataSource();
pds.setUrl(url);
if (parms[2] != null)
pds.setUser(parms[2]);
if (parms[3] != null)
pds.setPassword(parms[3]);
ds = pds;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class PostgresqlInterface
......@@ -6880,7 +6880,7 @@ static MYSQL_SYSVAR_STR(java_wrapper, Wrapper,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java wrapper class",
// check_class_path, update_class_path,
NULL, NULL, "JdbcInterface");
NULL, NULL, "wrappers/JdbcInterface");
#endif // JDBC_SUPPORT
......
......@@ -616,7 +616,7 @@ PQRYRES JDBCPrimaryKeys(PGLOBAL g, JDBConn *op, char *dsn, char *table)
} // end of JDBCPrimaryKeys
#endif // 0
/***********************************************************************/
/************************************************Wrapper***********************/
/* JDBConn construction/destruction. */
/***********************************************************************/
JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
......@@ -634,6 +634,14 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
//m_QueryTimeout = DEFAULT_QUERY_TIMEOUT;
//m_UpdateOptions = 0;
Msg = NULL;
m_Wrap = (tdbp && tdbp->WrapName) ? tdbp->WrapName : Wrapper;
if (!strchr(m_Wrap, '/')) {
// Add the wrapper package name
char *wn = (char*)PlugSubAlloc(g, NULL, strlen(m_Wrap) + 10);
m_Wrap = strcat(strcpy(wn, "wrappers/"), m_Wrap);
} // endif m_Wrap
m_Driver = NULL;
m_Url = NULL;
m_User = NULL;
......@@ -890,7 +898,9 @@ bool JDBConn::GetJVM(PGLOBAL g)
/***********************************************************************/
int JDBConn::Open(PJPARM sop)
{
bool err = false;
jboolean jt = (trace > 0);
PGLOBAL& g = m_G;
// Link or check whether jvm library was linked
......@@ -1000,19 +1010,16 @@ int JDBConn::Open(PJPARM sop)
return RC_FX;
} // endswitch rc
//=============== Display JVM version ===============
jint ver = env->GetVersion();
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
} // endif rc
//=============== Display JVM version =======================================
#if defined(_DEBUG)
jint ver = env->GetVersion();
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
#endif //_DEBUG
// try to find the java wrapper class
jdi = env->FindClass(Wrapper);
jdi = env->FindClass(m_Wrap);
if (jdi == nullptr) {
sprintf(g->Message, "ERROR: class %s not found!", Wrapper);
sprintf(g->Message, "ERROR: class %s not found!", m_Wrap);
return RC_FX;
} // endif jdi
......@@ -1055,19 +1062,19 @@ int JDBConn::Open(PJPARM sop)
#endif // 0
// if class found, continue
jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V");
jmethodID ctor = env->GetMethodID(jdi, "<init>", "(Z)V");
if (ctor == nullptr) {
sprintf(g->Message, "ERROR: %s constructor not found!", Wrapper);
sprintf(g->Message, "ERROR: %s constructor not found!", m_Wrap);
return RC_FX;
} else
job = env->NewObject(jdi, ctor);
job = env->NewObject(jdi, ctor, jt);
// If the object is successfully constructed,
// we can then search for the method we want to call,
// and invoke it for the object:
if (job == nullptr) {
sprintf(g->Message, "%s class object not constructed!", Wrapper);
sprintf(g->Message, "%s class object not constructed!", m_Wrap);
return RC_FX;
} // endif job
......
......@@ -175,6 +175,7 @@ class JDBConn : public BLOCK {
//DWORD m_QueryTimeout;
//DWORD m_UpdateOptions;
char *Msg;
char *m_Wrap;
char m_IDQuoteChar[2];
PSZ m_Driver;
PSZ m_Url;
......
......@@ -96,7 +96,7 @@ bool ExactInfo(void);
/***********************************************************************/
JDBCDEF::JDBCDEF(void)
{
Driver = Url = Tabname = Tabschema = Username = Colpat = NULL;
Driver = Url = Wrapname =Tabname = Tabschema = Username = Colpat = NULL;
Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false;
......@@ -233,6 +233,7 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Read_Only = true;
Wrapname = GetStringCatInfo(g, "Wrapper", NULL);
Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL);
......@@ -331,6 +332,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
if (tdp) {
Ops.Driver = tdp->Driver;
Ops.Url = tdp->Url;
WrapName = tdp->Wrapname;
TableName = tdp->Tabname;
Schema = tdp->Tabschema;
Ops.User = tdp->Username;
......@@ -347,6 +349,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Memory = tdp->Memory;
Ops.Scrollable = tdp->Scrollable;
} else {
WrapName = NULL;
TableName = NULL;
Schema = NULL;
Ops.Driver = NULL;
......@@ -392,6 +395,7 @@ TDBJDBC::TDBJDBC(PTDBJDBC tdbp) : TDBASE(tdbp)
{
Jcp = tdbp->Jcp; // is that right ?
Cnp = tdbp->Cnp;
WrapName = tdbp->WrapName;
TableName = tdbp->TableName;
Schema = tdbp->Schema;
Ops = tdbp->Ops;
......
......@@ -54,6 +54,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
PSZ Driver; /* JDBC driver */
PSZ Url; /* JDBC driver URL */
PSZ Tabname; /* External table name */
PSZ Wrapname; /* Java wrapper name */
PSZ Tabschema; /* External table schema */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
......@@ -133,6 +134,7 @@ class TDBJDBC : public TDBASE {
JDBCCOL *Cnp; // Points to count(*) column
JDBCPARM Ops; // Additional parameters
PSTRG Query; // Constructed SQL query
char *WrapName; // Points to Java wrapper name
char *TableName; // Points to JDBC table name
char *Schema; // Points to JDBC table Schema
char *User; // User connect info
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
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