diff options
author | Peter Mount | 1999-09-14 05:50:44 +0000 |
---|---|---|
committer | Peter Mount | 1999-09-14 05:50:44 +0000 |
commit | 24c82830cf8e7cc6d378c622ef1028937a4ee488 (patch) | |
tree | 7850bdf877e854d555422f705cc42830ddba9611 /src/interfaces/jdbc/postgresql | |
parent | 4197aaa8ae50410cce73fef871b6c5740b705f0c (diff) |
Patches for 6.5.2
Diffstat (limited to 'src/interfaces/jdbc/postgresql')
-rw-r--r-- | src/interfaces/jdbc/postgresql/Connection.java | 15 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/Driver.java | 39 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/PG_Stream.java | 15 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/errors.properties | 1 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/jdbc1/Connection.java | 35 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java | 43 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/jdbc2/Connection.java | 33 | ||||
-rw-r--r-- | src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java | 37 |
8 files changed, 148 insertions, 70 deletions
diff --git a/src/interfaces/jdbc/postgresql/Connection.java b/src/interfaces/jdbc/postgresql/Connection.java index fc30b4dfd6c..5433e336c7b 100644 --- a/src/interfaces/jdbc/postgresql/Connection.java +++ b/src/interfaces/jdbc/postgresql/Connection.java @@ -10,7 +10,7 @@ import postgresql.largeobject.*; import postgresql.util.*; /** - * $Id: Connection.java,v 1.17 1999/05/18 23:17:15 peter Exp $ + * $Id: Connection.java,v 1.18 1999/09/14 05:50:33 peter Exp $ * * This abstract class is used by postgresql.Driver to open either the JDBC1 or * JDBC2 versions of the Connection class. @@ -692,4 +692,17 @@ public abstract class Connection * version (from jdbc1 or jdbc2) are returned. */ protected abstract java.sql.ResultSet getResultSet(postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException; + + /** + * Overides finalize(). If called, it closes the connection. + * + * This was done at the request of Rachel Greenham + * <rachel@enlarion.demon.co.uk> who hit a problem where multiple + * clients didn't close the connection, and once a fortnight enough + * clients were open to kill the postgres server. + */ + public void finalize() throws Throwable + { + close(); + } } diff --git a/src/interfaces/jdbc/postgresql/Driver.java b/src/interfaces/jdbc/postgresql/Driver.java index 06c89030979..67d06e8129d 100644 --- a/src/interfaces/jdbc/postgresql/Driver.java +++ b/src/interfaces/jdbc/postgresql/Driver.java @@ -31,9 +31,6 @@ public class Driver implements java.sql.Driver static final int MAJORVERSION = 6; static final int MINORVERSION = 5; - // Cache the version of the JDK in use - static String connectClass; - static { try { @@ -56,11 +53,27 @@ public class Driver implements java.sql.Driver { // Set the connectClass variable so that future calls will handle the correct // base class - if(System.getProperty("java.version").startsWith("1.1")) { - connectClass = "postgresql.jdbc1.Connection"; - } else { - connectClass = "postgresql.jdbc2.Connection"; - } + //if(System.getProperty("java.version").startsWith("1.1")) { + //connectClass = "postgresql.jdbc1.Connection"; + //} else { + //connectClass = "postgresql.jdbc2.Connection"; + //} + + // Ok, when the above code was introduced in 6.5 it's intention was to allow + // the driver to automatically detect which version of JDBC was being used + // and to detect the version of the JVM accordingly. + // + // It did this by using the java.version parameter. + // + // However, it was quickly discovered that not all JVM's returned an easily + // parseable version number (ie "1.2") and some don't return a value at all. + // The latter came from a discussion on the advanced java list. + // + // So, to solve this, I've moved the decision out of the driver, and it's now + // a compile time parameter. + // + // For this to work, the Makefile creates a pseudo class which contains the class + // name that will actually make the connection. } /** @@ -96,10 +109,10 @@ public class Driver implements java.sql.Driver if((props = parseURL(url,info))==null) return null; - DriverManager.println("Using "+connectClass); + DriverManager.println("Using "+DriverClass.connectClass); try { - postgresql.Connection con = (postgresql.Connection)(Class.forName(connectClass).newInstance()); + postgresql.Connection con = (postgresql.Connection)(Class.forName(DriverClass.connectClass).newInstance()); con.openConnection (host(), port(), props, database(), url, this); return (java.sql.Connection)con; } catch(ClassNotFoundException ex) { @@ -302,8 +315,10 @@ public class Driver implements java.sql.Driver // PM June 29 1997 // This now outputs the properties only if we are logging - if(DriverManager.getLogStream() != null) - urlProps.list(DriverManager.getLogStream()); + // PM Sep 13 1999 Commented out, as it throws a Deprecation warning + // when compiled under JDK1.2. + //if(DriverManager.getLogStream() != null) + // urlProps.list(DriverManager.getLogStream()); return urlProps; diff --git a/src/interfaces/jdbc/postgresql/PG_Stream.java b/src/interfaces/jdbc/postgresql/PG_Stream.java index e2ee91ac2f7..d5816b634c9 100644 --- a/src/interfaces/jdbc/postgresql/PG_Stream.java +++ b/src/interfaces/jdbc/postgresql/PG_Stream.java @@ -39,8 +39,9 @@ public class PG_Stream // improvement on FreeBSD machines (caused by a bug in their TCP Stack) connection.setTcpNoDelay(true); - pg_input = connection.getInputStream(); - pg_output = new BufferedOutputStream(connection.getOutputStream()); + // Buffer sizes submitted by Sverre H Huseby <sverrehu@online.no> + pg_input = new BufferedInputStream(connection.getInputStream(), 8192); + pg_output = new BufferedOutputStream(connection.getOutputStream(), 8192); } /** @@ -51,9 +52,13 @@ public class PG_Stream */ public void SendChar(int val) throws IOException { - byte b[] = new byte[1]; - b[0] = (byte)val; - pg_output.write(b); + // Original code + //byte b[] = new byte[1]; + //b[0] = (byte)val; + //pg_output.write(b); + + // Optimised version by Sverre H. Huseby Aug 22 1999 Applied Sep 13 1999 + pg_output.write((byte)val); } /** diff --git a/src/interfaces/jdbc/postgresql/errors.properties b/src/interfaces/jdbc/postgresql/errors.properties index 53b43c4227e..1c295ccc6d6 100644 --- a/src/interfaces/jdbc/postgresql/errors.properties +++ b/src/interfaces/jdbc/postgresql/errors.properties @@ -15,6 +15,7 @@ postgresql.con.refused:Connection refused. Check that the hostname and port is c postgresql.con.strobj:The object could not be stored. Check that any tables required have already been created in the database. postgresql.con.strobjex:Failed to store object - {0} postgresql.con.toolong:The SQL Statement is too long - {0} +postgresql.con.isolevel:Transaction isolation level {0} is not supported. postgresql.con.tuple:Tuple received before MetaData. postgresql.con.type:Unknown Response Type {0} postgresql.con.user:The user property is missing. It is mandatory. diff --git a/src/interfaces/jdbc/postgresql/jdbc1/Connection.java b/src/interfaces/jdbc/postgresql/jdbc1/Connection.java index f7c88c579a2..7a83e6f114e 100644 --- a/src/interfaces/jdbc/postgresql/jdbc1/Connection.java +++ b/src/interfaces/jdbc/postgresql/jdbc1/Connection.java @@ -17,7 +17,7 @@ import postgresql.largeobject.*; import postgresql.util.*; /** - * $Id: Connection.java,v 1.2 1999/05/18 23:17:21 peter Exp $ + * $Id: Connection.java,v 1.3 1999/09/14 05:50:39 peter Exp $ * * A Connection represents a session with a specific database. Within the * context of a Connection, SQL statements are executed and results are @@ -216,7 +216,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec pg_stream = null; } } - + /** * Tests to see if a Connection is closed * @@ -311,9 +311,23 @@ public class Connection extends postgresql.Connection implements java.sql.Connec */ public void setTransactionIsolation(int level) throws SQLException { - throw postgresql.Driver.notImplemented(); + String q = "SET TRANSACTION ISOLATION LEVEL"; + + switch(level) { + + case java.sql.Connection.TRANSACTION_READ_COMMITTED: + ExecSQL(q + " READ COMMITTED"); + return; + + case java.sql.Connection.TRANSACTION_SERIALIZABLE: + ExecSQL(q + " SERIALIZABLE"); + return; + + default: + throw new PSQLException("postgresql.con.isolevel",new Integer(level)); + } } - + /** * Get this Connection's current transaction isolation mode. * @@ -322,9 +336,18 @@ public class Connection extends postgresql.Connection implements java.sql.Connec */ public int getTransactionIsolation() throws SQLException { - return java.sql.Connection.TRANSACTION_SERIALIZABLE; + ExecSQL("show xactisolevel"); + + SQLWarning w = getWarnings(); + if (w != null) { + if (w.getMessage().indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else + if (w.getMessage().indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else + if (w.getMessage().indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else + if (w.getMessage().indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE; + } + return java.sql.Connection.TRANSACTION_READ_COMMITTED; } - + /** * The first warning reported by calls on this Connection is * returned. diff --git a/src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java b/src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java index b7e90e8768a..84130f2cb46 100644 --- a/src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java +++ b/src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java @@ -179,7 +179,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public String getDatabaseProductVersion() throws SQLException { - return ("6.4"); + return ("6.5.2"); } /** @@ -1350,7 +1350,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public int getDefaultTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_SERIALIZABLE; + return Connection.TRANSACTION_READ_COMMITTED; } /** @@ -1368,7 +1368,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData /** * Does the database support the given transaction isolation level? - * We only support TRANSACTION_SERIALIZABLE + * We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED * * @param level the values are defined in java.sql.Connection * @return true if so @@ -1377,10 +1377,11 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - if (level == Connection.TRANSACTION_SERIALIZABLE) - return true; - else - return false; + if (level == Connection.TRANSACTION_SERIALIZABLE || + level == Connection.TRANSACTION_READ_COMMITTED) + return true; + else + return false; } /** @@ -2151,21 +2152,19 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { return connection.createStatement().executeQuery("SELECT " + - "'' as TABLE_CAT," + - "'' AS TABLE_SCHEM," + - "bc.relname AS TABLE_NAME," + - "ic.relname AS COLUMN_NAME," + - "'1' as KEY_SEQ,"+ // -- fake it as a String for now - "t.typname as PK_NAME " + - " FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t " + - " WHERE bc.relkind = 'r' " + // -- not indices - " and bc.relname ~ '"+table+"'" + - " and i.indrelid = bc.oid" + - " and i.indexrelid = ic.oid" + - " and i.indkey[0] = a.attnum" + - " and i.indproc = '0'::oid" + - " and a.attrelid = bc.oid" + - " ORDER BY TABLE_NAME, COLUMN_NAME;" + " '' as TABLE_CAT," + + " '' AS TABLE_SCHEM," + + " bc.relname AS TABLE_NAME," + + " a.attname AS COLUMN_NAME," + + " a.attnum as KEY_SEQ," + + " ic.relname as PK_NAME" + + " from pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t" + + " where bc.relkind = 'r'"+ + " and upper(bc.relname) = upper('test')" + + " and i.indrelid = bc.oid" + + " and i.indexrelid = ic.oid and a.attrelid = ic.oid"+ + " and i.indisprimary='t'"+ + " order by table_name, pk_name,key_seq;" ); } diff --git a/src/interfaces/jdbc/postgresql/jdbc2/Connection.java b/src/interfaces/jdbc/postgresql/jdbc2/Connection.java index 7e086435b20..32ffce81ee2 100644 --- a/src/interfaces/jdbc/postgresql/jdbc2/Connection.java +++ b/src/interfaces/jdbc/postgresql/jdbc2/Connection.java @@ -17,7 +17,7 @@ import postgresql.largeobject.*; import postgresql.util.*; /** - * $Id: Connection.java,v 1.2 1999/05/18 23:17:26 peter Exp $ + * $Id: Connection.java,v 1.3 1999/09/14 05:50:44 peter Exp $ * * A Connection represents a session with a specific database. Within the * context of a Connection, SQL statements are executed and results are @@ -216,7 +216,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec pg_stream = null; } } - + /** * Tests to see if a Connection is closed * @@ -311,7 +311,21 @@ public class Connection extends postgresql.Connection implements java.sql.Connec */ public void setTransactionIsolation(int level) throws SQLException { - throw postgresql.Driver.notImplemented(); + String q = "SET TRANSACTION ISOLATION LEVEL"; + + switch(level) { + + case java.sql.Connection.TRANSACTION_READ_COMMITTED: + ExecSQL(q + " READ COMMITTED"); + return; + + case java.sql.Connection.TRANSACTION_SERIALIZABLE: + ExecSQL(q + " SERIALIZABLE"); + return; + + default: + throw new PSQLException("postgresql.con.isolevel",new Integer(level)); + } } /** @@ -322,9 +336,18 @@ public class Connection extends postgresql.Connection implements java.sql.Connec */ public int getTransactionIsolation() throws SQLException { - return java.sql.Connection.TRANSACTION_SERIALIZABLE; + ExecSQL("show xactisolevel"); + + SQLWarning w = getWarnings(); + if (w != null) { + if (w.getMessage().indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else + if (w.getMessage().indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else + if (w.getMessage().indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else + if (w.getMessage().indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE; + } + return java.sql.Connection.TRANSACTION_READ_COMMITTED; } - + /** * The first warning reported by calls on this Connection is * returned. diff --git a/src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java b/src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java index 9a73f22d81f..b6550654efd 100644 --- a/src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java +++ b/src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java @@ -179,7 +179,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public String getDatabaseProductVersion() throws SQLException { - return ("6.4"); + return ("6.5.2"); } /** @@ -1350,7 +1350,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public int getDefaultTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_SERIALIZABLE; + return Connection.TRANSACTION_READ_COMMITTED; } /** @@ -1368,7 +1368,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData /** * Does the database support the given transaction isolation level? - * We only support TRANSACTION_SERIALIZABLE + * We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED * * @param level the values are defined in java.sql.Connection * @return true if so @@ -1377,7 +1377,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData */ public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - if (level == Connection.TRANSACTION_SERIALIZABLE) + if (level == Connection.TRANSACTION_SERIALIZABLE || + level == Connection.TRANSACTION_READ_COMMITTED) return true; else return false; @@ -2151,21 +2152,19 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { return connection.createStatement().executeQuery("SELECT " + - "'' as TABLE_CAT," + - "'' AS TABLE_SCHEM," + - "bc.relname AS TABLE_NAME," + - "ic.relname AS COLUMN_NAME," + - "'1' as KEY_SEQ,"+ // -- fake it as a String for now - "t.typname as PK_NAME " + - " FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t " + - " WHERE bc.relkind = 'r' " + // -- not indices - " and bc.relname ~ '"+table+"'" + - " and i.indrelid = bc.oid" + - " and i.indexrelid = ic.oid" + - " and i.indkey[0] = a.attnum" + - " and i.indproc = '0'::oid" + - " and a.attrelid = bc.oid" + - " ORDER BY TABLE_NAME, COLUMN_NAME;" + " '' as TABLE_CAT," + + " '' AS TABLE_SCHEM," + + " bc.relname AS TABLE_NAME," + + " a.attname AS COLUMN_NAME," + + " a.attnum as KEY_SEQ," + + " ic.relname as PK_NAME" + + " from pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t" + + " where bc.relkind = 'r'"+ + " and upper(bc.relname) = upper('test')" + + " and i.indrelid = bc.oid" + + " and i.indexrelid = ic.oid and a.attrelid = ic.oid"+ + " and i.indisprimary='t'"+ + " order by table_name, pk_name,key_seq;" ); } |