+ - PG_Stream.SendChar() optimised, increased default buffer size of
+ output stream to 8k, and introduced an 8k buffer on the input stream
+ Sverre H Huseby
+ - Added a finalize() method to Connection class in both drivers so that
+ the connection to the backend is really closed.
+ - Due to many JVM's not returning a meaningful value for java.version
+ the decision for building the JDBC1.2 or JDBC2 driver is now a
+ compile time option.
+ - Replaced $$(cmd...) with `cmd...` in the Makefile. This should allow
+ the driver to compile when using shells other than Bash.
+
+ - added support for getTransactionIsolation and setTransactionIsolation
+
Sun Jun 27 12:00:00 BST 1999
- Fixed typo in postgresql.Driver that prevented compilation
- Implemented getTimestamp() fix submitted by Philipp Matthias Hahn
# Makefile for Java JDBC interface
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.14 1999/06/23 05:56:17 peter Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.15 1999/09/14 05:50:27 peter Exp $
#
#-------------------------------------------------------------------------
IDL2JAVA = idltojava -fno-cpp -fno-tie
JAR = jar
JAVA = java
-JAVAC = javac
+JAVAC = javac -g
JAVADOC = javadoc
RM = rm -f
TOUCH = touch
$(JAVAC) $<
.SUFFIXES: .class .java
-.PHONY: all clean doc examples
+.PHONY: all clean doc examples msg
# In 6.5, the all rule builds the makeVersion class which then calls make using
# the jdbc1 or jdbc2 rules
-all: makeVersion.class
- make $$($(JAVA) makeVersion)
+all:
+ @echo ------------------------------------------------------------
+ @echo Due to problems with some JVMs that dont return a meaningful
+ @echo version number, we have had to make the choice of what jdbc
+ @echo version is built as a compile time option.
+ @echo
+ @echo If you are using JDK1.1.x, you will need the JDBC1.2 driver.
+ @echo To compile, type:
+ @echo " make jdbc1"
+ @echo
+ @echo "If you are using JDK1.2 (aka Java2) you need the JDBC2."
+ @echo To compile, type:
+ @echo " make jdbc2"
+ @echo ------------------------------------------------------------
+
+msg:
@echo ------------------------------------------------------------
@echo The JDBC driver has now been built. To make it available to
@echo other applications, copy the postgresql.jar file to a public
postgresql/jdbc2/ResultSetMetaData.class \
postgresql/jdbc2/Statement.class
-# This rule should never occur, but will be called when makeVersion fails to
-# understand the java.version property correctly.
-jdbc0:
- @echo
- @echo FATAL ERROR!
- @echo
- @echo makeVersion has not been able to determine what version of
- @echo the JDK you are using, and hence what version of the driver
- @echo to compile.
- @echo
- @echo There are two versions available, one that conforms to the
- @echo JDBC 1 specification, and one to the JDBC 2 specification.
- @echo
- @echo To build the driver for JDBC 1 (usually for JDK 1.1 thru 1.1.7)
- @echo then type: make jdbc1
- @echo
- @echo To build the driver for JDBC 2 (usually for JDK 1.2 and later)
- @echo then type: make jdbc2
- @echo
- @echo If you still have problems, then please email the interfaces
- @echo
-
# This rule builds the JDBC1 compliant driver
-jdbc1: $(OBJ_COMMON) $(OBJ_JDBC1) postgresql.jar
+jdbc1:
+ (echo "package postgresql;" ;\
+ echo "public class DriverClass {" ;\
+ echo "public static String connectClass=\"postgresql.jdbc1.Connection\";" ;\
+ echo "}" \
+ ) >postgresql/DriverClass.java
+ @$(MAKE) jdbc1real
+
+jdbc2real: postgresql/DriverClass.class \
+ $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar msg
# This rule builds the JDBC2 compliant driver
-jdbc2: $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar
+jdbc2:
+ (echo "package postgresql;" ;\
+ echo "public class DriverClass {" ;\
+ echo "public static String connectClass=\"postgresql.jdbc2.Connection\";" ;\
+ echo "}" \
+ ) >postgresql/DriverClass.java
+ @$(MAKE) jdbc2real
+
+jdbc2real: postgresql/DriverClass.class \
+ $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar msg
# If you have problems with this rule, replace the $( ) with ` ` as some
# shells (mainly sh under Solaris) doesn't recognise $( )
# directory. We use this later for compiling the dual-mode driver.
#
postgresql.jar: $(OBJ) $(OBJ_COMMON)
- $(JAR) -c0f $@ $$($(FIND) postgresql -name "*.class" -print) \
+ $(JAR) -c0f $@ `$(FIND) postgresql -name "*.class" -print` \
$(wildcard postgresql/*.properties)
# This rule removes any temporary and compiled files from the source tree.
+++ /dev/null
-/**
- * This class is used by the makefile to determine which version of the
- * JDK is currently in use, and if it's using JDK1.1.x then it returns JDBC1
- * and if later, it returns JDBC2
- *
- * $Id: makeVersion.java,v 1.1 1999/01/17 04:51:49 momjian Exp $
- */
-public class makeVersion
-{
- public static void main(String[] args) {
- String key = "java.version";
- String version = System.getProperty(key);
-
- //System.out.println(key+" = \""+version+"\"");
-
- // Tip: use print not println here as println breaks the make that
- // comes with CygWin-B20.1
-
- if(version.startsWith("1.0")) {
- // This will trigger the unknown rule in the makefile
- System.out.print("jdbc0");
- } else if(version.startsWith("1.1")) {
- // This will trigger the building of the JDBC 1 driver
- System.out.print("jdbc1");
- } else {
- // This will trigger the building of the JDBC 2 driver
- System.out.print("jdbc2");
- }
- }
-}
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.
* 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
+ * 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();
+ }
}
static final int MAJORVERSION = 6;
static final int MINORVERSION = 5;
- // Cache the version of the JDK in use
- static String connectClass;
-
static
{
try {
{
// 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.
}
/**
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) {
// 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;
// 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
+ pg_input = new BufferedInputStream(connection.getInputStream(), 8192);
+ pg_output = new BufferedOutputStream(connection.getOutputStream(), 8192);
}
/**
*/
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);
}
/**
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.
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
pg_stream = null;
}
}
-
+
/**
* Tests to see if a Connection is closed
*
*/
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.
*
*/
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.
*/
public String getDatabaseProductVersion() throws SQLException
{
- return ("6.4");
+ return ("6.5.2");
}
/**
*/
public int getDefaultTransactionIsolation() throws SQLException
{
- return Connection.TRANSACTION_SERIALIZABLE;
+ return Connection.TRANSACTION_READ_COMMITTED;
}
/**
/**
* 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
*/
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;
}
/**
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;"
);
}
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
pg_stream = null;
}
}
-
+
/**
* Tests to see if a Connection is closed
*
*/
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));
+ }
}
/**
*/
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.
*/
public String getDatabaseProductVersion() throws SQLException
{
- return ("6.4");
+ return ("6.5.2");
}
/**
*/
public int getDefaultTransactionIsolation() throws SQLException
{
- return Connection.TRANSACTION_SERIALIZABLE;
+ return Connection.TRANSACTION_READ_COMMITTED;
}
/**
/**
* 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
*/
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;
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;"
);
}