diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2016-07-14 20:12:22 +0200 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2016-07-14 20:12:22 +0200 |
commit | 44012db6350b51ad7e78f286dfa6e5d4ae84f807 (patch) | |
tree | 8dfef1aecad87a3a6f7e10c921120dc3f1d23a9c /storage/connect/JdbcInterface.java | |
parent | f2dded9bac48de391cdd796283769691872ba911 (diff) | |
download | mariadb-git-44012db6350b51ad7e78f286dfa6e5d4ae84f807.tar.gz |
All changes made on 10.1 for last 11 commits
Diffstat (limited to 'storage/connect/JdbcInterface.java')
-rw-r--r-- | storage/connect/JdbcInterface.java | 105 |
1 files changed, 74 insertions, 31 deletions
diff --git a/storage/connect/JdbcInterface.java b/storage/connect/JdbcInterface.java index f9a6e734454..793d29936c8 100644 --- a/storage/connect/JdbcInterface.java +++ b/storage/connect/JdbcInterface.java @@ -1,13 +1,19 @@ +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; + boolean CatisSchema = false; String Errmsg = "No error"; Connection conn = null; DatabaseMetaData dbmd = null; @@ -18,14 +24,14 @@ public class JdbcInterface { // === Constructors/finalize ========================================= public JdbcInterface() { - this(true); + this(false); } // end of default constructor public JdbcInterface(boolean b) { DEBUG = b; } // end of constructor - private void SetErrmsg(Exception e) { + protected void SetErrmsg(Exception e) { if (DEBUG) System.out.println(e.getMessage()); @@ -38,6 +44,22 @@ public class JdbcInterface { Errmsg = "No error"; return err; } // end of GetErrmsg + + protected void CheckURL(String url, String vendor) throws Exception { + if (url == null) + throw new Exception("URL cannot be null"); + + String[] tk = url.split(":", 3); + + if (!tk[0].equals("jdbc") || tk[1] == null) + throw new Exception("Invalid URL"); + + if (vendor != null && !tk[1].equals(vendor)) + throw new Exception("Wrong URL for this wrapper"); + + // Some drivers use Catalog as Schema + CatisSchema = tk[1].equals("mysql") || tk[1].equals("mariadb"); + } // end of CatalogIsSchema public int JdbcConnect(String[] parms, int fsize, boolean scrollable) { int rc = 0; @@ -58,6 +80,8 @@ public class JdbcInterface { if (DEBUG) System.out.println("URL=" + parms[1]); + + CheckURL(parms[1], null); if (parms[2] != null && !parms[2].isEmpty()) { if (DEBUG) @@ -74,27 +98,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 +113,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 +259,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); @@ -307,11 +341,15 @@ public class JdbcInterface { } // end of GetMaxValue public int GetColumns(String[] parms) { - int ncol = 0; + int ncol = -1; try { if (rs != null) rs.close(); - rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]); + + if (CatisSchema) + rs = dbmd.getColumns(parms[1], null, parms[2], parms[3]); + else + rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]); if (rs != null) { rsmd = rs.getMetaData(); @@ -326,7 +364,7 @@ public class JdbcInterface { } // end of GetColumns public int GetTables(String[] parms) { - int ncol = 0; + int ncol = -1; String[] typ = null; if (parms[3] != null) { @@ -336,7 +374,11 @@ public class JdbcInterface { try { if (rs != null) rs.close(); - rs = dbmd.getTables(parms[0], parms[1], parms[2], typ); + + if (CatisSchema) + rs = dbmd.getTables(parms[1], null, parms[2], typ); + else + rs = dbmd.getTables(parms[0], parms[1], parms[2], typ); if (rs != null) { rsmd = rs.getMetaData(); @@ -710,3 +752,4 @@ public class JdbcInterface { */ } // end of class JdbcInterface + |