diff --git a/src/interfaces/jdbc/org/postgresql/Driver.java.in b/src/interfaces/jdbc/org/postgresql/Driver.java.in index 5d72467850e..197993c2e22 100644 --- a/src/interfaces/jdbc/org/postgresql/Driver.java.in +++ b/src/interfaces/jdbc/org/postgresql/Driver.java.in @@ -1,3 +1,15 @@ +/*------------------------------------------------------------------------- + * + * Driver.java(.in) + * The Postgresql JDBC Driver implementation + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.27 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql; import java.io.*; @@ -22,7 +34,7 @@ import org.postgresql.util.PSQLException; * and register it with the DriverManager. This means that a user can load * and register a driver by doing Class.forName("foo.bah.Driver") * - * @see org.postgresql.Connection + * @see org.postgresql.PGConnection * @see java.sql.Driver */ public class Driver implements java.sql.Driver @@ -460,7 +472,7 @@ public class Driver implements java.sql.Driver } - public static void makeSSL(PG_Stream p_stream) throws IOException { + public static void makeSSL(org.postgresql.core.PGStream p_stream) throws IOException { @SSL@ if (logDebug) @SSL@ debug("converting regular socket connection to ssl"); @SSL@ javax.net.ssl.SSLSocketFactory factory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(); @@ -477,6 +489,6 @@ public class Driver implements java.sql.Driver //The build number should be incremented for every new build - private static int m_buildNumber = 202; + private static int m_buildNumber = 203; } diff --git a/src/interfaces/jdbc/org/postgresql/PGConnection.java b/src/interfaces/jdbc/org/postgresql/PGConnection.java index a45fddcb1cf..1a10347a18f 100644 --- a/src/interfaces/jdbc/org/postgresql/PGConnection.java +++ b/src/interfaces/jdbc/org/postgresql/PGConnection.java @@ -1,3 +1,18 @@ +/*------------------------------------------------------------------------- + * + * PGConnection.java + * The public interface definition for a Postgresql Connection + * This interface defines PostgreSQL extentions to the java.sql.Connection + * interface. Any java.sql.Connection object returned by the driver will + * also implement this interface + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.4 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql; import java.sql.*; @@ -7,75 +22,46 @@ import org.postgresql.core.Encoding; import org.postgresql.fastpath.Fastpath; import org.postgresql.largeobject.LargeObjectManager; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.3 2002/09/06 21:23:05 momjian Exp $ - * This interface defines PostgreSQL extentions to the java.sql.Connection interface. - * Any java.sql.Connection object returned by the driver will also implement this - * interface - */ public interface PGConnection { - /* - * Get the character encoding to use for this connection. - */ - public Encoding getEncoding() throws SQLException; - - /* - * This method returns the java.sql.Types type for a postgres datatype name - */ - public int getSQLType(String pgTypeName) throws SQLException; - - /* - * This returns the java.sql.Types type for a postgres datatype OID - */ - public int getSQLType(int oid) throws SQLException; - - /* - * This returns the postgres datatype name from the - * postgres datatype OID - */ - public String getPGType(int oid) throws SQLException; - - /* - * This returns the postgres datatype OID from the - * postgres datatype name - */ - public int getPGType(String typeName) throws SQLException; - - /* - * This returns the LargeObject API for the current connection. - */ - public LargeObjectManager getLargeObjectAPI() throws SQLException; - - /* - * This returns the Fastpath API for the current connection. - */ - public Fastpath getFastpathAPI() throws SQLException; - - /* - * This method is used internally to return an object based around - * org.postgresql's more unique data types. - * - *
It uses an internal Hashtable to get the handling class. If the - * type is not supported, then an instance of org.postgresql.util.PGobject - * is returned. - * - * You can use the getValue() or setValue() methods to handle the returned - * object. Custom objects can have their own methods. - * - * @return PGobject for this type, and set to value - * @exception SQLException if value is not correct for this type - * @see org.postgresql.util.Serialize - */ - public Object getObject(String type, String value) throws SQLException; - - - /* + /** * This method returns any notifications that have been received * since the last call to this method. * Returns null if there have been no notifications. + * @since 7.3 */ public PGNotification[] getNotifications(); + /** + * This returns the LargeObject API for the current connection. + * @since 7.3 + */ + public LargeObjectManager getLargeObjectAPI() throws SQLException; + + /** + * This returns the Fastpath API for the current connection. + * @since 7.3 + */ + public Fastpath getFastpathAPI() throws SQLException; + + + /** @deprecated */ + public Encoding getEncoding() throws SQLException; + + /** @deprecated */ + public int getSQLType(String pgTypeName) throws SQLException; + + /** @deprecated */ + public int getSQLType(int oid) throws SQLException; + + /** @deprecated */ + public String getPGType(int oid) throws SQLException; + + /** @deprecated */ + public int getPGType(String typeName) throws SQLException; + + /** @deprecated */ + public Object getObject(String type, String value) throws SQLException; } diff --git a/src/interfaces/jdbc/org/postgresql/PGNotification.java b/src/interfaces/jdbc/org/postgresql/PGNotification.java index dbcd6fbe6a0..7a439d40c67 100644 --- a/src/interfaces/jdbc/org/postgresql/PGNotification.java +++ b/src/interfaces/jdbc/org/postgresql/PGNotification.java @@ -1,18 +1,29 @@ +/*------------------------------------------------------------------------- + * + * PGNotification.java + * This interface defines public PostgreSQL extention for Notifications + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGNotification.java,v 1.3 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGNotification.java,v 1.2 2002/09/06 21:23:05 momjian Exp $ - * This interface defines PostgreSQL extention for Notifications - */ public interface PGNotification { - /* + /** * Returns name of this notification + * @since 7.3 */ public String getName(); - /* + /** * Returns the process id of the backend process making this notification + * @since 7.3 */ public int getPID(); diff --git a/src/interfaces/jdbc/org/postgresql/PGStatement.java b/src/interfaces/jdbc/org/postgresql/PGStatement.java index 44de8222074..be59e7f7fc5 100644 --- a/src/interfaces/jdbc/org/postgresql/PGStatement.java +++ b/src/interfaces/jdbc/org/postgresql/PGStatement.java @@ -1,25 +1,43 @@ +/*------------------------------------------------------------------------- + * + * PGStatement.java + * This interface defines PostgreSQL extentions to the java.sql.Statement + * interface. Any java.sql.Statement object returned by the driver will + * also implement this interface + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGStatement.java,v 1.7 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql; import java.sql.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGStatement.java,v 1.6 2002/09/08 00:15:28 barry Exp $ - * This interface defines PostgreSQL extentions to the java.sql.Statement interface. - * Any java.sql.Statement object returned by the driver will also implement this - * interface - */ public interface PGStatement { - /* + /** * Returns the Last inserted/updated oid. * @return OID of last insert - * @since 7.3 + * @since 7.3 */ public long getLastOID() throws SQLException; + /** + * Turn on the use of prepared statements in the server (server side + * prepared statements are unrelated to jdbc PreparedStatements) + * @since 7.3 + */ public void setUseServerPrepare(boolean flag) throws SQLException; + /** + * Is this statement using server side prepared statements + * @since 7.3 + */ public boolean isUseServerPrepare(); } diff --git a/src/interfaces/jdbc/org/postgresql/core/BaseConnection.java b/src/interfaces/jdbc/org/postgresql/core/BaseConnection.java new file mode 100644 index 00000000000..d4ee0d4a858 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/core/BaseConnection.java @@ -0,0 +1,44 @@ +/*------------------------------------------------------------------------- + * + * BaseConnection.java + * The internal interface definition for a jdbc connection + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseConnection.java,v 1.1 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ +package org.postgresql.core; + +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.SQLException; +import org.postgresql.PGConnection; +import org.postgresql.PGNotification; + +public interface BaseConnection extends PGConnection +{ + + public void addNotification(PGNotification p_notification); + public void addWarning(String msg); + public void cancelQuery() throws SQLException; + public Statement createStatement() throws SQLException; + public BaseResultSet execSQL(String s) throws SQLException; + public String getCursorName() throws SQLException; + public Encoding getEncoding() throws SQLException; + public DatabaseMetaData getMetaData() throws SQLException; + public Object getObject(String type, String value) throws SQLException; + public PGStream getPGStream(); + public String getPGType(int oid) throws SQLException; + public int getPGType(String pgTypeName) throws SQLException; + public int getSQLType(int oid) throws SQLException; + public int getSQLType(String pgTypeName) throws SQLException; + public boolean haveMinimumCompatibleVersion(String ver) throws SQLException; + public boolean haveMinimumServerVersion(String ver) throws SQLException; + public void setCursorName(String cursor) throws SQLException; + +} + diff --git a/src/interfaces/jdbc/org/postgresql/core/BaseResultSet.java b/src/interfaces/jdbc/org/postgresql/core/BaseResultSet.java new file mode 100644 index 00000000000..af9830dccaf --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/core/BaseResultSet.java @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * BaseResultSet.java + * The internal interface definition for a jdbc result set + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseResultSet.java,v 1.1 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ +package org.postgresql.core; + + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Vector; + +public interface BaseResultSet +{ + public BaseStatement getPGStatement(); + + public void append(BaseResultSet r); + public void close() throws SQLException; + public int getColumnCount(); + public String getCursorName() throws SQLException; + public String getFixedString(int col) throws SQLException; + public long getLastOID(); + public ResultSetMetaData getMetaData() throws SQLException; + public ResultSet getNext(); + public Object getObject(int columnIndex) throws SQLException; + public int getResultCount(); + public String getStatusString(); + public String getString(int columnIndex) throws SQLException; + public StringBuffer getStringBuffer(); + public int getTupleCount(); + public boolean next() throws SQLException; + public boolean reallyResultSet(); + public void reInit (Field[] fields, Vector tuples, String status, + int updateCount, long insertOID, boolean binaryCursor); + public void setStatement(BaseStatement statement); + +} diff --git a/src/interfaces/jdbc/org/postgresql/core/BaseStatement.java b/src/interfaces/jdbc/org/postgresql/core/BaseStatement.java new file mode 100644 index 00000000000..c7432d2016f --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/core/BaseStatement.java @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * + * BaseStatement.java + * The internal interface definition for a jdbc statement + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseStatement.java,v 1.1 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ +package org.postgresql.core; + + +import java.sql.*; +import java.util.Vector; + +public interface BaseStatement extends org.postgresql.PGStatement +{ + public BaseResultSet createResultSet(Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException; + + public BaseConnection getPGConnection(); + + /* + * The maxRows limit is set to limit the number of rows that + * any ResultSet can contain. If the limit is exceeded, the + * excess rows are silently dropped. + */ + public int getFetchSize() throws SQLException; + public int getMaxRows() throws SQLException; + public int getResultSetConcurrency() throws SQLException; + public String getStatementName(); + +} diff --git a/src/interfaces/jdbc/org/postgresql/core/Encoding.java b/src/interfaces/jdbc/org/postgresql/core/Encoding.java index 262fb81933d..1aa888c3bdc 100644 --- a/src/interfaces/jdbc/org/postgresql/core/Encoding.java +++ b/src/interfaces/jdbc/org/postgresql/core/Encoding.java @@ -1,15 +1,24 @@ +/*------------------------------------------------------------------------- + * + * Encoding.java + * Converts to and from the character encoding used by the backend. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Encoding.java,v 1.10 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.core; -import java.io.*; -import java.util.*; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; import java.sql.SQLException; -import org.postgresql.util.*; - -/* - * Converts to and from the character encoding used by the backend. - * - * $Id: Encoding.java,v 1.9 2003/02/09 23:14:55 barry Exp $ - */ +import java.util.Hashtable; +import org.postgresql.util.PSQLException; public class Encoding { diff --git a/src/interfaces/jdbc/org/postgresql/Field.java b/src/interfaces/jdbc/org/postgresql/core/Field.java similarity index 70% rename from src/interfaces/jdbc/org/postgresql/Field.java rename to src/interfaces/jdbc/org/postgresql/core/Field.java index 1dbaa72c097..71d9dee9043 100644 --- a/src/interfaces/jdbc/org/postgresql/Field.java +++ b/src/interfaces/jdbc/org/postgresql/core/Field.java @@ -1,14 +1,24 @@ -package org.postgresql; +/*------------------------------------------------------------------------- + * + * Field.java + * Field is a class used to describe fields in a PostgreSQL ResultSet + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Field.java,v 1.1 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ +package org.postgresql.core; import java.lang.*; import java.sql.*; import java.util.*; -import org.postgresql.*; -import org.postgresql.util.*; +import org.postgresql.core.BaseConnection; +import org.postgresql.util.PSQLException; /* - * org.postgresql.Field is a class used to describe fields in a PostgreSQL - * ResultSet */ public class Field { @@ -17,7 +27,7 @@ public class Field private int mod; // type modifier of this field private String name; // Name of this field - private org.postgresql.PGConnection conn; // Connection Instantation + private BaseConnection conn; // Connection Instantation /* @@ -28,7 +38,7 @@ public class Field * @param oid the OID of the field * @param len the length of the field */ - public Field(org.postgresql.PGConnection conn, String name, int oid, int length, int mod) + public Field(BaseConnection conn, String name, int oid, int length, int mod) { this.conn = conn; this.name = name; @@ -45,7 +55,7 @@ public class Field * @param oid the OID of the field * @param len the length of the field */ - public Field(org.postgresql.PGConnection conn, String name, int oid, int length) + public Field(BaseConnection conn, String name, int oid, int length) { this(conn, name, oid, length, 0); } diff --git a/src/interfaces/jdbc/org/postgresql/core/Notification.java b/src/interfaces/jdbc/org/postgresql/core/Notification.java index 464e167b8c8..8e39beea588 100644 --- a/src/interfaces/jdbc/org/postgresql/core/Notification.java +++ b/src/interfaces/jdbc/org/postgresql/core/Notification.java @@ -1,10 +1,20 @@ +/*------------------------------------------------------------------------- + * + * Notification.java + * This is the implementation of the PGNotification interface + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Notification.java,v 1.3 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.core; +import org.postgresql.PGNotification; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Notification.java,v 1.2 2002/09/06 21:23:05 momjian Exp $ - * This is the implementation of the PGNotification interface - */ -public class Notification implements org.postgresql.PGNotification +public class Notification implements PGNotification { public Notification(String p_name, int p_pid) { diff --git a/src/interfaces/jdbc/org/postgresql/PG_Stream.java b/src/interfaces/jdbc/org/postgresql/core/PGStream.java similarity index 91% rename from src/interfaces/jdbc/org/postgresql/PG_Stream.java rename to src/interfaces/jdbc/org/postgresql/core/PGStream.java index 0c92bff9449..bbe96d9a423 100644 --- a/src/interfaces/jdbc/org/postgresql/PG_Stream.java +++ b/src/interfaces/jdbc/org/postgresql/core/PGStream.java @@ -1,24 +1,28 @@ -package org.postgresql; - -import java.io.*; -import java.lang.*; -import java.net.*; -import java.util.*; -import java.sql.*; -import org.postgresql.*; -import org.postgresql.core.*; -import org.postgresql.util.*; - -/* - * $Id: PG_Stream.java,v 1.18 2003/02/27 05:45:44 barry Exp $ +/*------------------------------------------------------------------------- * - * This class is used by Connection & PGlobj for communicating with the - * backend. + * PGStream.java + * This class is used by Connection for communicating with the + * backend. * - * @see java.sql.Connection + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/PGStream.java,v 1.1 2003/03/07 18:39:41 barry Exp $ + * + *------------------------------------------------------------------------- */ -// This class handles all the Streamed I/O for a org.postgresql connection -public class PG_Stream +package org.postgresql.core; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.net.Socket; +import java.sql.*; +import org.postgresql.util.PSQLException; + + +public class PGStream { public String host; public int port; @@ -35,7 +39,7 @@ public class PG_Stream * @param port the port number that the postmaster is sitting on * @exception IOException if an IOException occurs below it. */ - public PG_Stream(String p_host, int p_port) throws IOException + public PGStream(String p_host, int p_port) throws IOException { host = p_host; port = p_port; diff --git a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java index 8285dc14148..7714f0230cf 100644 --- a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java +++ b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java @@ -1,31 +1,32 @@ - +/*------------------------------------------------------------------------- + * + * QueryExecutor.java + * Executes a query on the backend. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.20 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.core; import java.util.Vector; import java.io.IOException; import java.sql.*; -import org.postgresql.*; import org.postgresql.util.PSQLException; import org.postgresql.jdbc1.AbstractJdbc1Connection; import org.postgresql.jdbc1.AbstractJdbc1ResultSet; import org.postgresql.jdbc1.AbstractJdbc1Statement; -/* - * Executes a query on the backend. - * - *
The lifetime of a QueryExecutor object is from sending the query - * until the response has been received from the backend. - * - * $Id: QueryExecutor.java,v 1.19 2003/02/04 11:01:52 davec Exp $ - */ - public class QueryExecutor { //This version of execute does not take an existing result set, but //creates a new one for the results of the query - public static ResultSet execute (String[] p_sqlFrags, + public static BaseResultSet execute(String[] p_sqlFrags, Object[] p_binds, - java.sql.Statement statement) + BaseStatement statement) throws SQLException { QueryExecutor qe = new QueryExecutor(); @@ -37,8 +38,8 @@ public class QueryExecutor else qe.maxRows = 0; - qe.connection = (AbstractJdbc1Connection)((AbstractJdbc1Statement)statement).getPGConnection(); - qe.pg_stream = qe.connection.getPGStream(); + qe.connection = statement.getPGConnection(); + qe.pgStream = qe.connection.getPGStream(); return qe.execute(); } @@ -46,23 +47,23 @@ public class QueryExecutor //This version of execute reuses an existing result set for the query //results, this is used when a result set is backed by a cursor and //more results are fetched - public static void execute (String[] p_sqlFrags, + public static void execute(String[] p_sqlFrags, Object[] p_binds, - java.sql.ResultSet rs) + BaseResultSet rs) throws SQLException { QueryExecutor qe = new QueryExecutor(); qe.m_sqlFrags = p_sqlFrags; qe.m_binds = p_binds; qe.rs = rs; - qe.statement = (java.sql.Statement)((AbstractJdbc1ResultSet)qe.rs).getPGStatement(); + qe.statement = qe.rs.getPGStatement(); if (qe.statement != null) qe.maxRows = qe.statement.getMaxRows(); else qe.maxRows = 0; - qe.connection = (AbstractJdbc1Connection)((AbstractJdbc1Statement)qe.statement).getPGConnection(); - qe.pg_stream = qe.connection.getPGStream(); + qe.connection = qe.statement.getPGConnection(); + qe.pgStream = qe.connection.getPGStream(); qe.execute(); } @@ -74,11 +75,11 @@ public class QueryExecutor private String[] m_sqlFrags; private Object[] m_binds; - private java.sql.Statement statement; - private java.sql.ResultSet rs; + private BaseStatement statement; + private BaseResultSet rs; - private AbstractJdbc1Connection connection; - private PG_Stream pg_stream; + private BaseConnection connection; + private PGStream pgStream; private Field[] fields = null; private Vector tuples = new Vector(); @@ -93,17 +94,17 @@ public class QueryExecutor * Execute a query on the backend. * */ - private java.sql.ResultSet execute() throws SQLException + private BaseResultSet execute() throws SQLException { StringBuffer errorMessage = null; - if (pg_stream == null) + if (pgStream == null) { throw new PSQLException("postgresql.con.closed"); } - synchronized (pg_stream) + synchronized (pgStream) { sendQuery(); @@ -112,13 +113,13 @@ public class QueryExecutor boolean l_endQuery = false; while (!l_endQuery) { - c = pg_stream.ReceiveChar(); + c = pgStream.ReceiveChar(); switch (c) { case 'A': // Asynchronous Notify - int pid = pg_stream.ReceiveInteger(4); - String msg = pg_stream.ReceiveString(connection.getEncoding()); + int pid = pgStream.ReceiveInteger(4); + String msg = pgStream.ReceiveString(connection.getEncoding()); connection.addNotification(new org.postgresql.core.Notification(msg, pid)); break; case 'B': // Binary Data Transfer @@ -140,17 +141,17 @@ public class QueryExecutor if ( errorMessage == null ) errorMessage = new StringBuffer(); - errorMessage.append(pg_stream.ReceiveString(connection.getEncoding())); + errorMessage.append(pgStream.ReceiveString(connection.getEncoding())); // keep processing break; case 'I': // Empty Query - int t = pg_stream.ReceiveChar(); + int t = pgStream.ReceiveChar(); break; case 'N': // Error Notification - connection.addWarning(pg_stream.ReceiveString(connection.getEncoding())); + connection.addWarning(pgStream.ReceiveString(connection.getEncoding())); break; case 'P': // Portal Name - String pname = pg_stream.ReceiveString(connection.getEncoding()); + String pname = pgStream.ReceiveString(connection.getEncoding()); break; case 'T': // MetaData Field Description receiveFields(); @@ -174,11 +175,11 @@ public class QueryExecutor //create a new one if (rs != null) { - ((org.postgresql.jdbc1.AbstractJdbc1ResultSet)rs).reInit(fields, tuples, status, update_count, insert_oid, binaryCursor); + rs.reInit(fields, tuples, status, update_count, insert_oid, binaryCursor); } else { - rs = ((AbstractJdbc1Statement)statement).createResultSet(fields, tuples, status, update_count, insert_oid, binaryCursor); + rs = statement.createResultSet(fields, tuples, status, update_count, insert_oid, binaryCursor); } return rs; } @@ -196,16 +197,16 @@ public class QueryExecutor } try { - pg_stream.SendChar('Q'); + pgStream.SendChar('Q'); for (int i = 0 ; i < m_binds.length ; ++i) { - pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[i])); - pg_stream.Send(connection.getEncoding().encode(m_binds[i].toString())); + pgStream.Send(connection.getEncoding().encode(m_sqlFrags[i])); + pgStream.Send(connection.getEncoding().encode(m_binds[i].toString())); } - pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[m_binds.length])); - pg_stream.SendChar(0); - pg_stream.flush(); + pgStream.Send(connection.getEncoding().encode(m_sqlFrags[m_binds.length])); + pgStream.SendChar(0); + pgStream.flush(); } catch (IOException e) @@ -223,7 +224,7 @@ public class QueryExecutor { if (fields == null) throw new PSQLException("postgresql.con.tuple"); - Object tuple = pg_stream.ReceiveTuple(fields.length, isBinary); + Object tuple = pgStream.ReceiveTuple(fields.length, isBinary); if (isBinary) binaryCursor = true; if (maxRows == 0 || tuples.size() < maxRows) @@ -236,7 +237,7 @@ public class QueryExecutor private void receiveCommandStatus() throws SQLException { - status = pg_stream.ReceiveString(connection.getEncoding()); + status = pgStream.ReceiveString(connection.getEncoding()); try { @@ -265,15 +266,15 @@ public class QueryExecutor if (fields != null) throw new PSQLException("postgresql.con.multres"); - int size = pg_stream.ReceiveIntegerR(2); + int size = pgStream.ReceiveIntegerR(2); fields = new Field[size]; for (int i = 0; i < fields.length; i++) { - String typeName = pg_stream.ReceiveString(connection.getEncoding()); - int typeOid = pg_stream.ReceiveIntegerR(4); - int typeLength = pg_stream.ReceiveIntegerR(2); - int typeModifier = pg_stream.ReceiveIntegerR(4); + String typeName = pgStream.ReceiveString(connection.getEncoding()); + int typeOid = pgStream.ReceiveIntegerR(4); + int typeLength = pgStream.ReceiveIntegerR(2); + int typeModifier = pgStream.ReceiveIntegerR(4); fields[i] = new Field(connection, typeName, typeOid, typeLength, typeModifier); } } diff --git a/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java b/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java index 38ddc15f44c..74ad6ffc395 100644 --- a/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java +++ b/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java @@ -1,12 +1,11 @@ package org.postgresql.core; -import org.postgresql.PG_Stream; import java.io.IOException; /** * Sent to the backend to initialize a newly created connection. * - * $Id: StartupPacket.java,v 1.2 2002/09/06 21:23:05 momjian Exp $ + * $Id: StartupPacket.java,v 1.3 2003/03/07 18:39:42 barry Exp $ */ public class StartupPacket @@ -30,7 +29,7 @@ public class StartupPacket this.database = database; } - public void writeTo(PG_Stream stream) throws IOException + public void writeTo(PGStream stream) throws IOException { stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4); stream.SendInteger(protocolMajor, 2); diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java index 56676a40eca..1e094e15cf7 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java @@ -1,26 +1,34 @@ +/*------------------------------------------------------------------------- + * + * Fastpath.java + * This class implements the Fastpath api. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.12 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.fastpath; +import java.io.IOException; +import java.sql.SQLException; +import java.sql.ResultSet; +import java.util.Hashtable; import org.postgresql.Driver; -import java.io.*; -import java.lang.*; -import java.net.*; -import java.util.*; -import java.sql.*; -import org.postgresql.util.*; - -// Important: There are a lot of debug code commented out. Please do not -// delete these. +import org.postgresql.core.BaseConnection; +import org.postgresql.core.PGStream; +import org.postgresql.util.PSQLException; /* * This class implements the Fastpath api. * - *
This is a means of executing functions imbeded in the org.postgresql backend - * from within a java application. + *
This is a means of executing functions imbeded in the org.postgresql + * backend from within a java application. * *
It is based around the file src/interfaces/libpq/fe-exec.c * - * @see org.postgresql.FastpathFastpathArg - * @see org.postgresql.LargeObject */ public class Fastpath { @@ -28,20 +36,16 @@ public class Fastpath // to a connection). protected Hashtable func = new Hashtable(); - protected org.postgresql.PGConnection conn; // our connection - protected org.postgresql.PG_Stream stream; // the network stream + protected BaseConnection conn; // our connection + protected PGStream stream; // the network stream /* * Initialises the fastpath system * - *
Important Notice
- *
This is called from org.postgresql.Connection, and should not be called
- * from client code.
- *
- * @param conn org.postgresql.Connection to attach to
+ * @param conn BaseConnection to attach to
* @param stream The network stream to the backend
*/
- public Fastpath(org.postgresql.PGConnection conn, org.postgresql.PG_Stream stream)
+ public Fastpath(BaseConnection conn, PGStream stream)
{
this.conn = conn;
this.stream = stream;
@@ -113,7 +117,7 @@ public class Fastpath
//------------------------------
// Notice from backend
case 'N':
- ((org.postgresql.jdbc1.AbstractJdbc1Connection)conn).addWarning(stream.ReceiveString(conn.getEncoding()));
+ conn.addWarning(stream.ReceiveString(conn.getEncoding()));
break;
case 'V':
@@ -164,7 +168,7 @@ public class Fastpath
* This is the prefered method to call, as function id's can/may change
* between versions of the backend.
*
- * For an example of how this works, refer to org.postgresql.LargeObject
+ * For an example of how this works, refer to org.postgresql.largeobject.LargeObject
*
* @param name Function name
* @param resulttype True if the result is an integer, false for other
@@ -173,7 +177,7 @@ public class Fastpath
* @return null if no data, Integer if an integer result, or byte[] otherwise
* @exception SQLException if name is unknown or if a database-access error
* occurs.
- * @see org.postgresql.LargeObject
+ * @see org.postgresql.largeobject.LargeObject
*/
public Object fastpath(String name, boolean resulttype, FastpathArg[] args) throws SQLException
{
@@ -242,7 +246,7 @@ public class Fastpath
* the function's required are entered into this table, keeping connection
* times as fast as possible.
*
- *
The org.postgresql.LargeObject class performs a query upon it's startup, + *
The org.postgresql.largeobject.LargeObject class performs a query upon it's startup, * and passes the returned ResultSet to the addFunctions() method here. * *
Once this has been done, the LargeObject api refers to the functions by @@ -255,7 +259,7 @@ public class Fastpath * * @param rs ResultSet * @exception SQLException if a database-access error occurs. - * @see org.postgresql.LargeObjectManager + * @see org.postgresql.largeobject.LargeObjectManager */ public void addFunctions(ResultSet rs) throws SQLException { diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java b/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java index 1539ee8a144..7e59ce2387d 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java @@ -1,25 +1,20 @@ +/*------------------------------------------------------------------------- + * + * FastpathArg.java + * Each fastpath call requires an array of arguments, the number and type + * dependent on the function being called. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/FastpathArg.java,v 1.4 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.fastpath; -import java.io.*; -import java.lang.*; -import java.net.*; -import java.util.*; -import java.sql.*; -import org.postgresql.util.*; +import java.io.IOException; -/* - * Each fastpath call requires an array of arguments, the number and type - * dependent on the function being called. - * - *
This class implements methods needed to provide this capability. - * - *
For an example on how to use this, refer to the org.postgresql.largeobject - * package - * - * @see org.postgresql.fastpath.Fastpath - * @see org.postgresql.largeobject.LargeObjectManager - * @see org.postgresql.largeobject.LargeObject - */ public class FastpathArg { /* @@ -90,7 +85,7 @@ public class FastpathArg * @param s output stream * @exception IOException if something failed on the network stream */ - protected void send(org.postgresql.PG_Stream s) throws IOException + protected void send(org.postgresql.core.PGStream s) throws IOException { if (type) { diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGbox.java b/src/interfaces/jdbc/org/postgresql/geometric/PGbox.java index e57297c7dd3..242a29413fd 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGbox.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGbox.java @@ -1,12 +1,23 @@ +/*------------------------------------------------------------------------- + * + * PGbox.java + * This represents the box datatype within org.postgresql. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGbox.java,v 1.4 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; -import java.io.*; -import java.sql.*; -import org.postgresql.util.*; +import java.sql.SQLException; +import java.io.Serializable; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; -/* - * This represents the box datatype within org.postgresql. - */ public class PGbox extends PGobject implements Serializable, Cloneable { /* diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGcircle.java b/src/interfaces/jdbc/org/postgresql/geometric/PGcircle.java index 05e60c55267..a6456c16b95 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGcircle.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGcircle.java @@ -1,13 +1,25 @@ +/*------------------------------------------------------------------------- + * + * PGcircle.java + * This represents org.postgresql's circle datatype, consisting of a point + * and a radius + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGcircle.java,v 1.4 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; -import java.io.*; -import java.sql.*; -import org.postgresql.util.*; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.Hashtable; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; -/* - * This represents org.postgresql's circle datatype, consisting of a point and - * a radius - */ public class PGcircle extends PGobject implements Serializable, Cloneable { /* diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGline.java b/src/interfaces/jdbc/org/postgresql/geometric/PGline.java index e91f416be22..5a108bd0b7a 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGline.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGline.java @@ -1,12 +1,24 @@ +/*------------------------------------------------------------------------- + * + * PGline.java + * This implements a line consisting of two points. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGline.java,v 1.4 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; -import java.io.*; -import java.sql.*; -import org.postgresql.util.*; +import java.io.Serializable; +import java.sql.SQLException; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; /* - * This implements a line consisting of two points. - * * Currently line is not yet implemented in the backend, but this class * ensures that when it's done were ready for it. */ diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGlseg.java b/src/interfaces/jdbc/org/postgresql/geometric/PGlseg.java index 6d5af7e7d7b..c29aac4b98e 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGlseg.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGlseg.java @@ -1,12 +1,23 @@ +/*------------------------------------------------------------------------- + * + * PGlseg.java + * This implements a lseg (line segment) consisting of two points + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGlseg.java,v 1.4 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; -import java.io.*; -import java.sql.*; -import org.postgresql.util.*; +import java.io.Serializable; +import java.sql.SQLException; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; -/* - * This implements a lseg (line segment) consisting of two points - */ public class PGlseg extends PGobject implements Serializable, Cloneable { /* diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java b/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java index 60a4c924883..0c40ce301ba 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java @@ -1,12 +1,23 @@ +/*------------------------------------------------------------------------- + * + * PGpath.java + * This implements a path (a multiple segmented line, which may be closed) + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGpath.java,v 1.5 2003/03/07 18:39:42 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; -import java.io.*; -import java.sql.*; -import org.postgresql.util.*; +import java.io.Serializable; +import java.sql.SQLException; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; -/* - * This implements a path (a multiple segmented line, which may be closed) - */ public class PGpath extends PGobject implements Serializable, Cloneable { /* diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java b/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java index c7df1362bed..58ddb5f6f19 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java @@ -1,16 +1,29 @@ +/*------------------------------------------------------------------------- + * + * PGline.java + * It maps to the point datatype in org.postgresql. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGpoint.java,v 1.4 2003/03/07 18:39:43 barry Exp $ + * + *------------------------------------------------------------------------- + */ package org.postgresql.geometric; import java.awt.Point; -import java.io.*; -import java.sql.*; +import java.io.Serializable; +import java.sql.SQLException; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; import org.postgresql.util.*; /* * This implements a version of java.awt.Point, except it uses double * to represent the coordinates. - * - *
It maps to the point datatype in org.postgresql.
*/
public class PGpoint extends PGobject implements Serializable, Cloneable
{
diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java b/src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java
index 5ae18ed3f4d..d70233ba4c2 100644
--- a/src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java
+++ b/src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java
@@ -1,12 +1,23 @@
+/*-------------------------------------------------------------------------
+ *
+ * PGline.java
+ * This implements the polygon datatype within PostgreSQL.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGpolygon.java,v 1.4 2003/03/07 18:39:43 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.geometric;
-import java.io.*;
-import java.sql.*;
-import org.postgresql.util.*;
+import java.io.Serializable;
+import java.sql.SQLException;
+import org.postgresql.util.PGobject;
+import org.postgresql.util.PGtokenizer;
+import org.postgresql.util.PSQLException;
-/*
- * This implements the polygon datatype within PostgreSQL.
- */
public class PGpolygon extends PGobject implements Serializable, Cloneable
{
/*
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
index 328a5371eba..9c874489fc9 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
@@ -1,3 +1,18 @@
+/*-------------------------------------------------------------------------
+ *
+ * AbstractJdbc1Connection.java
+ * This class defines methods of the jdbc1 specification. This class is
+ * extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds
+ * the jdbc2 methods. The real Connection class (for jdbc1) is
+ * org.postgresql.jdbc1.Jdbc1Connection
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.17 2003/03/07 18:39:43 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.jdbc1;
@@ -7,25 +22,27 @@ import java.sql.*;
import java.util.*;
import org.postgresql.Driver;
import org.postgresql.PGNotification;
-import org.postgresql.PG_Stream;
-import org.postgresql.core.*;
+import org.postgresql.core.BaseConnection;
+import org.postgresql.core.BaseResultSet;
+import org.postgresql.core.BaseStatement;
+import org.postgresql.core.Encoding;
+import org.postgresql.core.PGStream;
+import org.postgresql.core.QueryExecutor;
+import org.postgresql.core.StartupPacket;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager;
-import org.postgresql.util.*;
+import org.postgresql.util.MD5Digest;
+import org.postgresql.util.PGobject;
+import org.postgresql.util.PSQLException;
+import org.postgresql.util.UnixCrypt;
-
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.16 2003/02/27 05:45:44 barry Exp $
- * This class defines methods of the jdbc1 specification. This class is
- * extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
- * methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
- */
-public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnection
+public abstract class AbstractJdbc1Connection implements BaseConnection
{
// This is the network stream associated with this connection
- private PG_Stream pg_stream;
+ private PGStream pgStream;
- public PG_Stream getPGStream() {
- return pg_stream;
+ public PGStream getPGStream() {
+ return pgStream;
}
protected String PG_HOST;
@@ -55,7 +72,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public boolean autoCommit = true;
public boolean readOnly = false;
- public org.postgresql.Driver this_driver;
+ public Driver this_driver;
private String this_url;
private String cursor = null; // The positioned update cursor name
@@ -84,10 +101,11 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
/*
* Cache of the current isolation level
*/
- private int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED;
+ private int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
- public abstract java.sql.Statement createStatement() throws SQLException;
+ public abstract Statement createStatement() throws SQLException;
+ public abstract DatabaseMetaData getMetaData() throws SQLException;
/*
* This method actually opens the connection. It is called by Driver.
@@ -100,7 +118,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
* @param d the Driver instantation of the connection
* @exception SQLException if a database access error occurs
*/
- public void openConnection(String host, int port, Properties info, String database, String url, org.postgresql.Driver d) throws SQLException
+ public void openConnection(String host, int port, Properties info, String database, String url, Driver d) throws SQLException
{
firstWarning = null;
@@ -110,7 +128,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
if (info.getProperty("user") == null)
throw new PSQLException("postgresql.con.user");
- this_driver = (org.postgresql.Driver)d;
+ this_driver = (Driver)d;
this_url = url;
PG_DATABASE = database;
@@ -148,7 +166,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
try
{
l_logLevel = Integer.parseInt(l_logLevelProp);
- if (l_logLevel > org.postgresql.Driver.DEBUG || l_logLevel < org.postgresql.Driver.INFO)
+ if (l_logLevel > Driver.DEBUG || l_logLevel < Driver.INFO)
{
l_logLevel = 0;
}
@@ -159,23 +177,23 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
}
if (l_logLevel > 0)
{
- org.postgresql.Driver.setLogLevel(l_logLevel);
+ Driver.setLogLevel(l_logLevel);
enableDriverManagerLogging();
}
//Print out the driver version number
- if (org.postgresql.Driver.logInfo)
- org.postgresql.Driver.info(org.postgresql.Driver.getVersion());
- if (org.postgresql.Driver.logDebug) {
- org.postgresql.Driver.debug(" ssl = " + useSSL);
- org.postgresql.Driver.debug(" compatible = " + compatible);
- org.postgresql.Driver.debug(" loglevel = " + l_logLevel);
+ if (Driver.logInfo)
+ Driver.info(Driver.getVersion());
+ if (Driver.logDebug) {
+ Driver.debug(" ssl = " + useSSL);
+ Driver.debug(" compatible = " + compatible);
+ Driver.debug(" loglevel = " + l_logLevel);
}
// Now make the initial connection
try
{
- pg_stream = new PG_Stream(host, port);
+ pgStream = new PGStream(host, port);
}
catch (ConnectException cex)
{
@@ -193,19 +211,19 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
try
{
if (useSSL) {
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("Asking server if it supports ssl");
- pg_stream.SendInteger(8,4);
- pg_stream.SendInteger(80877103,4);
+ if (Driver.logDebug)
+ Driver.debug("Asking server if it supports ssl");
+ pgStream.SendInteger(8,4);
+ pgStream.SendInteger(80877103,4);
// now flush the ssl packets to the backend
- pg_stream.flush();
+ pgStream.flush();
// Now get the response from the backend, either an error message
// or an authentication request
- int beresp = pg_stream.ReceiveChar();
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("Server response was (S=Yes,N=No): "+(char)beresp);
+ int beresp = pgStream.ReceiveChar();
+ if (Driver.logDebug)
+ Driver.debug("Server response was (S=Yes,N=No): "+(char)beresp);
switch (beresp)
{
case 'E':
@@ -215,7 +233,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// The most common one to be thrown here is:
// "User authentication failed"
//
- throw new PSQLException("postgresql.con.misc", pg_stream.ReceiveString(encoding));
+ throw new PSQLException("postgresql.con.misc", pgStream.ReceiveString(encoding));
case 'N':
// Server does not support ssl
@@ -223,9 +241,9 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
case 'S':
// Server supports ssl
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("server does support ssl");
- org.postgresql.Driver.makeSSL(pg_stream);
+ if (Driver.logDebug)
+ Driver.debug("server does support ssl");
+ Driver.makeSSL(pgStream);
break;
default:
@@ -245,17 +263,17 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
new StartupPacket(PG_PROTOCOL_LATEST_MAJOR,
PG_PROTOCOL_LATEST_MINOR,
PG_USER,
- database).writeTo(pg_stream);
+ database).writeTo(pgStream);
// now flush the startup packets to the backend
- pg_stream.flush();
+ pgStream.flush();
// Now get the response from the backend, either an error message
// or an authentication request
int areq = -1; // must have a value here
do
{
- int beresp = pg_stream.ReceiveChar();
+ int beresp = pgStream.ReceiveChar();
String salt = null;
byte [] md5Salt = new byte[4];
switch (beresp)
@@ -267,33 +285,33 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// The most common one to be thrown here is:
// "User authentication failed"
//
- throw new PSQLException("postgresql.con.misc", pg_stream.ReceiveString(encoding));
+ throw new PSQLException("postgresql.con.misc", pgStream.ReceiveString(encoding));
case 'R':
// Get the type of request
- areq = pg_stream.ReceiveIntegerR(4);
+ areq = pgStream.ReceiveIntegerR(4);
// Get the crypt password salt if there is one
if (areq == AUTH_REQ_CRYPT)
{
byte[] rst = new byte[2];
- rst[0] = (byte)pg_stream.ReceiveChar();
- rst[1] = (byte)pg_stream.ReceiveChar();
+ rst[0] = (byte)pgStream.ReceiveChar();
+ rst[1] = (byte)pgStream.ReceiveChar();
salt = new String(rst, 0, 2);
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("Crypt salt=" + salt);
+ if (Driver.logDebug)
+ Driver.debug("Crypt salt=" + salt);
}
// Or get the md5 password salt if there is one
if (areq == AUTH_REQ_MD5)
{
- md5Salt[0] = (byte)pg_stream.ReceiveChar();
- md5Salt[1] = (byte)pg_stream.ReceiveChar();
- md5Salt[2] = (byte)pg_stream.ReceiveChar();
- md5Salt[3] = (byte)pg_stream.ReceiveChar();
+ md5Salt[0] = (byte)pgStream.ReceiveChar();
+ md5Salt[1] = (byte)pgStream.ReceiveChar();
+ md5Salt[2] = (byte)pgStream.ReceiveChar();
+ md5Salt[3] = (byte)pgStream.ReceiveChar();
salt = new String(md5Salt, 0, 4);
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("MD5 salt=" + salt);
+ if (Driver.logDebug)
+ Driver.debug("MD5 salt=" + salt);
}
// now send the auth packet
@@ -303,42 +321,42 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
break;
case AUTH_REQ_KRB4:
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("postgresql: KRB4");
+ if (Driver.logDebug)
+ Driver.debug("postgresql: KRB4");
throw new PSQLException("postgresql.con.kerb4");
case AUTH_REQ_KRB5:
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("postgresql: KRB5");
+ if (Driver.logDebug)
+ Driver.debug("postgresql: KRB5");
throw new PSQLException("postgresql.con.kerb5");
case AUTH_REQ_PASSWORD:
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("postgresql: PASSWORD");
- pg_stream.SendInteger(5 + password.length(), 4);
- pg_stream.Send(password.getBytes());
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
+ if (Driver.logDebug)
+ Driver.debug("postgresql: PASSWORD");
+ pgStream.SendInteger(5 + password.length(), 4);
+ pgStream.Send(password.getBytes());
+ pgStream.SendInteger(0, 1);
+ pgStream.flush();
break;
case AUTH_REQ_CRYPT:
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("postgresql: CRYPT");
+ if (Driver.logDebug)
+ Driver.debug("postgresql: CRYPT");
String crypted = UnixCrypt.crypt(salt, password);
- pg_stream.SendInteger(5 + crypted.length(), 4);
- pg_stream.Send(crypted.getBytes());
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
+ pgStream.SendInteger(5 + crypted.length(), 4);
+ pgStream.Send(crypted.getBytes());
+ pgStream.SendInteger(0, 1);
+ pgStream.flush();
break;
case AUTH_REQ_MD5:
- if (org.postgresql.Driver.logDebug)
- org.postgresql.Driver.debug("postgresql: MD5");
+ if (Driver.logDebug)
+ Driver.debug("postgresql: MD5");
byte[] digest = MD5Digest.encode(PG_USER, password, md5Salt);
- pg_stream.SendInteger(5 + digest.length, 4);
- pg_stream.Send(digest);
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
+ pgStream.SendInteger(5 + digest.length, 4);
+ pgStream.Send(digest);
+ pgStream.SendInteger(0, 1);
+ pgStream.flush();
break;
default:
@@ -363,17 +381,17 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
int beresp;
do
{
- beresp = pg_stream.ReceiveChar();
+ beresp = pgStream.ReceiveChar();
switch (beresp)
{
case 'K':
- pid = pg_stream.ReceiveIntegerR(4);
- ckey = pg_stream.ReceiveIntegerR(4);
+ pid = pgStream.ReceiveIntegerR(4);
+ ckey = pgStream.ReceiveIntegerR(4);
break;
case 'E':
- throw new PSQLException("postgresql.con.backend", pg_stream.ReceiveString(encoding));
+ throw new PSQLException("postgresql.con.backend", pgStream.ReceiveString(encoding));
case 'N':
- addWarning(pg_stream.ReceiveString(encoding));
+ addWarning(pgStream.ReceiveString(encoding));
break;
default:
throw new PSQLException("postgresql.con.setup");
@@ -384,16 +402,16 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// Expect ReadyForQuery packet
do
{
- beresp = pg_stream.ReceiveChar();
+ beresp = pgStream.ReceiveChar();
switch (beresp)
{
case 'Z':
break;
case 'N':
- addWarning(pg_stream.ReceiveString(encoding));
+ addWarning(pgStream.ReceiveString(encoding));
break;
case 'E':
- throw new PSQLException("postgresql.con.backend", pg_stream.ReceiveString(encoding));
+ throw new PSQLException("postgresql.con.backend", pgStream.ReceiveString(encoding));
default:
throw new PSQLException("postgresql.con.setup");
}
@@ -419,7 +437,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// more than one round trip to the backend during connection startup.
- java.sql.ResultSet resultSet
+ BaseResultSet resultSet
= execSQL("set datestyle to 'ISO'; select version(), " + encodingQuery + ";");
if (! resultSet.next())
@@ -441,7 +459,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
//support is now always included
if (haveMinimumServerVersion("7.3"))
{
- java.sql.ResultSet acRset =
+ BaseResultSet acRset =
execSQL("set client_encoding = 'UNICODE'; show autocommit");
//set encoding to be unicode
@@ -473,7 +491,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
* Return the instance of org.postgresql.Driver
* that created this connection
*/
- public org.postgresql.Driver getDriver()
+ public Driver getDriver()
{
return this_driver;
}
@@ -509,10 +527,10 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
/** Simple query execution.
*/
- public java.sql.ResultSet execSQL (String s) throws SQLException
+ public BaseResultSet execSQL (String s) throws SQLException
{
final Object[] nullarr = new Object[0];
- java.sql.Statement stat = createStatement();
+ BaseStatement stat = (BaseStatement) createStatement();
return QueryExecutor.execute(new String[] { s },
nullarr,
stat);
@@ -607,7 +625,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public Fastpath getFastpathAPI() throws SQLException
{
if (fastpath == null)
- fastpath = new Fastpath(this, pg_stream);
+ fastpath = new Fastpath(this, pgStream);
return fastpath;
}
@@ -636,7 +654,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public LargeObjectManager getLargeObjectAPI() throws SQLException
{
if (largeobject == null)
- largeobject = new LargeObjectManager((java.sql.Connection)this);
+ largeobject = new LargeObjectManager(this);
return largeobject;
}
@@ -654,13 +672,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
* You can use the getValue() or setValue() methods to handle the returned
* object. Custom objects can have their own methods.
*
- * In 6.4, this is extended to use the org.postgresql.util.Serialize class to
- * allow the Serialization of Java Objects into the database without using
- * Blobs. Refer to that class for details on how this new feature works.
- *
* @return PGobject for this type, and set to value
* @exception SQLException if value is not correct for this type
- * @see org.postgresql.util.Serialize
*/
public Object getObject(String type, String value) throws SQLException
{
@@ -668,22 +681,13 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
{
Object o = objectTypes.get(type);
- // If o is null, then the type is unknown, so check to see if type
- // is an actual table name. If it does, see if a Class is known that
- // can handle it
- if (o == null)
- {
- Serialize ser = new Serialize((java.sql.Connection)this, type);
- objectTypes.put(type, ser);
- return ser.fetch(Integer.parseInt(value));
- }
-
+ // If o is null, then the type is unknown.
// If o is not null, and it is a String, then its a class name that
// extends PGobject.
//
// This is used to implement the org.postgresql unique types (like lseg,
// point, etc).
- if (o instanceof String)
+ if (o != null && o instanceof String)
{
// 6.3 style extending PG_Object
PGobject obj = null;
@@ -692,13 +696,6 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
obj.setValue(value);
return (Object)obj;
}
- else
- {
- // If it's an object, it should be an instance of our Serialize class
- // If so, then call it's fetch method.
- if (o instanceof Serialize)
- return ((Serialize)o).fetch(Integer.parseInt(value));
- }
}
catch (SQLException sx)
{
@@ -715,63 +712,6 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
return null;
}
- /*
- * This stores an object into the database. This method was
- * deprecated in 7.2 bacause an OID can be larger than the java signed
- * int returned by this method.
- * @deprecated Replaced by storeObject() in 7.2
- */
- public int putObject(Object o) throws SQLException
- {
- return (int) storeObject(o);
- }
-
- /*
- * This stores an object into the database.
- * @param o Object to store
- * @return OID of the new rectord
- * @exception SQLException if value is not correct for this type
- * @see org.postgresql.util.Serialize
- * @since 7.2
- */
- public long storeObject(Object o) throws SQLException
- {
- try
- {
- String type = o.getClass().getName();
- Object x = objectTypes.get(type);
-
- // If x is null, then the type is unknown, so check to see if type
- // is an actual table name. If it does, see if a Class is known that
- // can handle it
- if (x == null)
- {
- Serialize ser = new Serialize((java.sql.Connection)this, type);
- objectTypes.put(type, ser);
- return ser.storeObject(o);
- }
-
- // If it's an object, it should be an instance of our Serialize class
- // If so, then call it's fetch method.
- if (x instanceof Serialize)
- return ((Serialize)x).storeObject(o);
-
- // Thow an exception because the type is unknown
- throw new PSQLException("postgresql.con.strobj");
-
- }
- catch (SQLException sx)
- {
- // rethrow the exception. Done because we capture any others next
- sx.fillInStackTrace();
- throw sx;
- }
- catch (Exception ex)
- {
- throw new PSQLException("postgresql.con.strobjex", ex);
- }
- }
-
/*
* This allows client code to add a handler for one of org.postgresql's
* more unique data types.
@@ -836,19 +776,19 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
*/
public void close() throws SQLException
{
- if (pg_stream != null)
+ if (pgStream != null)
{
try
{
- pg_stream.SendChar('X');
- pg_stream.flush();
- pg_stream.close();
+ pgStream.SendChar('X');
+ pgStream.flush();
+ pgStream.close();
}
catch (IOException e)
{}
finally
{
- pg_stream = null;
+ pgStream = null;
}
}
}
@@ -1062,7 +1002,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
String sql = "show transaction isolation level";
String level = null;
if (haveMinimumServerVersion("7.3")) {
- ResultSet rs = execSQL(sql);
+ BaseResultSet rs = execSQL(sql);
if (rs.next()) {
level = rs.getString(1);
}
@@ -1079,15 +1019,15 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
}
if (level != null) {
if (level.indexOf("READ COMMITTED") != -1)
- return java.sql.Connection.TRANSACTION_READ_COMMITTED;
+ return Connection.TRANSACTION_READ_COMMITTED;
else if (level.indexOf("READ UNCOMMITTED") != -1)
- return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
+ return Connection.TRANSACTION_READ_UNCOMMITTED;
else if (level.indexOf("REPEATABLE READ") != -1)
- return java.sql.Connection.TRANSACTION_REPEATABLE_READ;
+ return Connection.TRANSACTION_REPEATABLE_READ;
else if (level.indexOf("SERIALIZABLE") != -1)
- return java.sql.Connection.TRANSACTION_SERIALIZABLE;
+ return Connection.TRANSACTION_SERIALIZABLE;
}
- return java.sql.Connection.TRANSACTION_READ_COMMITTED;
+ return Connection.TRANSACTION_READ_COMMITTED;
}
/*
@@ -1123,10 +1063,10 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
isolationLevelSQL = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ";
switch (isolationLevel)
{
- case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+ case Connection.TRANSACTION_READ_COMMITTED:
isolationLevelSQL += "READ COMMITTED";
break;
- case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+ case Connection.TRANSACTION_SERIALIZABLE:
isolationLevelSQL += "SERIALIZABLE";
break;
default:
@@ -1158,11 +1098,11 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
switch (isolationLevel)
{
- case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+ case Connection.TRANSACTION_READ_COMMITTED:
sb.append(" READ COMMITTED");
break;
- case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+ case Connection.TRANSACTION_SERIALIZABLE:
sb.append(" SERIALIZABLE");
break;
@@ -1327,8 +1267,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
} else {
sql = "SELECT typname FROM pg_type WHERE oid = " +oid;
}
- ResultSet result = execSQL(sql);
- if (((AbstractJdbc1ResultSet)result).getColumnCount() != 1 || ((AbstractJdbc1ResultSet)result).getTupleCount() != 1) {
+ BaseResultSet result = execSQL(sql);
+ if (result.getColumnCount() != 1 || result.getTupleCount() != 1) {
throw new PSQLException("postgresql.unexpected");
}
result.next();
@@ -1368,8 +1308,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
} else {
sql = "SELECT oid FROM pg_type WHERE typname='" + typeName + "'";
}
- ResultSet result = execSQL(sql);
- if (((AbstractJdbc1ResultSet)result).getColumnCount() != 1 || ((AbstractJdbc1ResultSet)result).getTupleCount() != 1)
+ BaseResultSet result = execSQL(sql);
+ if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
throw new PSQLException("postgresql.unexpected");
result.next();
oid = Integer.parseInt(result.getString(1));
@@ -1420,7 +1360,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
*/
public boolean isClosed() throws SQLException
{
- return (pg_stream == null);
+ return (pgStream == null);
}
/*
@@ -1492,6 +1432,51 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP
};
+ public void cancelQuery() throws SQLException
+ {
+ org.postgresql.core.PGStream cancelStream = null;
+ try
+ {
+ cancelStream = new org.postgresql.core.PGStream(PG_HOST, PG_PORT);
+ }
+ catch (ConnectException cex)
+ {
+ // Added by Peter Mount New for 6.4, if the object is not recognised, but it is
- * Serializable, then the object is serialised using the
- * org.postgresql.util.Serialize class.
*/
public void setObject(int parameterIndex, Object x) throws SQLException
{
@@ -1588,8 +1598,8 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
else if (x instanceof PGobject)
setString(parameterIndex, ((PGobject)x).getValue(), PG_TEXT);
else
- // Try to store java object in database
- setSerialize(parameterIndex, connection.storeObject(x), x.getClass().getName() );
+ // Try to store as a string in database
+ setString(parameterIndex, x.toString(), PG_TEXT);
}
/*
@@ -1884,6 +1894,12 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
return callResult;
}
+ //This method is implemeted in jdbc2
+ public int getResultSetConcurrency() throws SQLException
+ {
+ return 0;
+ }
+
/*
* Returns the SQL statement with the current template values
* substituted.
@@ -1930,28 +1946,6 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
m_bindTypes[paramIndex - 1] = type;
}
- /*
- * Set a parameter to a tablerow-type oid reference.
- *
- * @param parameterIndex the first parameter is 1...
- * @param x the oid of the object from org.postgresql.util.Serialize.store
- * @param classname the classname of the java object x
- * @exception SQLException if a database access error occurs
- */
- private void setSerialize(int parameterIndex, long x, String classname) throws SQLException
- {
- // converts . to _, toLowerCase, and ensures length < max name length
- String tablename = Serialize.toPostgreSQL((java.sql.Connection)connection, classname );
- DriverManager.println("setSerialize: setting " + x + "::" + tablename );
-
- // OID reference to tablerow-type must be cast like: It provides the basic methods required to run the interface, plus
+ * This class provides the basic methods required to run the interface, plus
* a pair of methods that provide InputStream and OutputStream classes
* for this object.
*
@@ -27,12 +36,6 @@ import org.postgresql.fastpath.*;
* to a Large Object, or how to create one.
*
* @see org.postgresql.largeobject.LargeObjectManager
- * @see org.postgresql.ResultSet#getAsciiStream
- * @see org.postgresql.ResultSet#getBinaryStream
- * @see org.postgresql.ResultSet#getUnicodeStream
- * @see org.postgresql.PreparedStatement#setAsciiStream
- * @see org.postgresql.PreparedStatement#setBinaryStream
- * @see org.postgresql.PreparedStatement#setUnicodeStream
* @see java.sql.ResultSet#getAsciiStream
* @see java.sql.ResultSet#getBinaryStream
* @see java.sql.ResultSet#getUnicodeStream
diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java
index b2bbebc949c..48743467db7 100644
--- a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java
+++ b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java
@@ -1,14 +1,30 @@
+/*-------------------------------------------------------------------------
+ *
+ * LargeObjectManager.java
+ * This class implements the large object interface to org.postgresql.
+ *
+ * It provides methods that allow client code to create, open and delete
+ * large objects from the database. When opening an object, an instance of
+ * org.postgresql.largeobject.LargeObject is returned, and its methods
+ * then allow access to the object.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/LargeObjectManager.java,v 1.10 2003/03/07 18:39:45 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.largeobject;
-import org.postgresql.Driver;
-import java.io.*;
-import java.lang.*;
-import java.net.*;
-import java.util.*;
-import java.sql.*;
-import org.postgresql.fastpath.*;
-import org.postgresql.util.*;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import org.postgresql.Driver;
+import org.postgresql.core.BaseConnection;
+import org.postgresql.fastpath.Fastpath;
+import org.postgresql.fastpath.FastpathArg;
+import org.postgresql.util.PSQLException;
/*
* This class implements the large object interface to org.postgresql.
@@ -29,7 +45,7 @@ import org.postgresql.util.*;
*
* ... code that opens a connection ...
*
- * lobj = ((org.postgresql.Connection)myconn).getLargeObjectAPI();
+ * lobj = ((org.postgresql.PGConnection)myconn).getLargeObjectAPI();
*
*
* Normally, client code would use the getAsciiStream, getBinaryStream,
@@ -43,13 +59,6 @@ import org.postgresql.util.*;
* Refer to org.postgresql.largeobject.LargeObject on how to manipulate the
* contents of a Large Object.
*
- * @see org.postgresql.largeobject.LargeObject
- * @see org.postgresql.ResultSet#getAsciiStream
- * @see org.postgresql.ResultSet#getBinaryStream
- * @see org.postgresql.ResultSet#getUnicodeStream
- * @see org.postgresql.PreparedStatement#setAsciiStream
- * @see org.postgresql.PreparedStatement#setBinaryStream
- * @see org.postgresql.PreparedStatement#setUnicodeStream
* @see java.sql.ResultSet#getAsciiStream
* @see java.sql.ResultSet#getBinaryStream
* @see java.sql.ResultSet#getUnicodeStream
@@ -94,10 +103,10 @@ public class LargeObjectManager
* org.postgresql.Connection class keeps track of the various extension API's
* and it's advised you use those to gain access, and not going direct.
*/
- public LargeObjectManager(Connection conn) throws SQLException
+ public LargeObjectManager(BaseConnection conn) throws SQLException
{
// We need Fastpath to do anything
- this.fp = ((org.postgresql.PGConnection)conn).getFastpathAPI();
+ this.fp = conn.getFastpathAPI();
// Now get the function oid's for the api
//
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
index 1d0b7c3a36a..8976aefe702 100644
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
@@ -63,7 +63,6 @@ public class Jdbc2TestSuite extends TestSuite
// Fastpath/LargeObject
suite.addTestSuite(BlobTest.class);
- suite.addTestSuite(SerializeTest.class);
suite.addTestSuite(UpdateableResultTest.class );
suite.addTestSuite(CallableStmtTest.class );
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeObject.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeObject.java
deleted file mode 100644
index c2dd6ccf489..00000000000
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeObject.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.postgresql.test.jdbc2;
-
-import java.io.Serializable;
-
-public class SerializeObject implements Serializable {
-
- public int intcol;
- public double doublecol;
- public String stringcol;
-
-}
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeTest.java
deleted file mode 100644
index 73d512f5889..00000000000
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/SerializeTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.postgresql.test.jdbc2;
-
-import org.postgresql.test.TestUtil;
-import junit.framework.TestCase;
-import java.sql.*;
-import org.postgresql.util.Serialize;
-
-public class SerializeTest extends TestCase {
-
- private Connection conn;
- private SerializeObject serobj;
- private Serialize ser;
-
- public SerializeTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- conn = TestUtil.openDB();
- serobj = new SerializeObject();
- serobj.intcol = 1;
- serobj.doublecol = 3.4;
- serobj.stringcol = "Hello";
- TestUtil.dropTable(conn,Serialize.toPostgreSQL(conn,serobj.getClass().getName()));
- Serialize.create(conn, serobj);
- Serialize.create(conn, serobj);
- ser = new Serialize(conn,serobj);
- }
-
- protected void tearDown() throws Exception {
- TestUtil.dropTable(conn,Serialize.toPostgreSQL(conn,serobj.getClass().getName()));
- }
-
- public void testCreateSerialize() {
- try {
- long oid = ser.storeObject(serobj);
- SerializeObject serobj2 = (SerializeObject)ser.fetch(oid);
- assertNotNull(serobj2);
- assertEquals(serobj.intcol,serobj2.intcol);
- assertTrue(Math.abs(serobj.doublecol-serobj2.doublecol) < 0.0001);
- assertTrue(serobj.stringcol.equals(serobj2.stringcol));
- } catch (SQLException sqle) {
- fail(sqle.getMessage());
- }
- }
-
-}
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
index 403d9b2b68e..75157a81ccc 100644
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
@@ -17,7 +17,7 @@ import javax.naming.*;
* tests.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public abstract class BaseDataSourceTest extends TestCase
{
@@ -189,7 +189,7 @@ public abstract class BaseDataSourceTest extends TestCase
try
{
con = getDataSourceConnection();
- ((PGConnection)con).getEncoding().name();
+ ((PGConnection)con).getNotifications();
con.close();
}
catch (Exception e)
diff --git a/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java b/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java
index df2be5645d2..fcee601faab 100644
--- a/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java
+++ b/src/interfaces/jdbc/org/postgresql/util/MD5Digest.java
@@ -1,10 +1,20 @@
+/*-------------------------------------------------------------------------
+ *
+ * MD5Digest.java
+ * MD5-based utility function to obfuscate passwords before network
+ * transmission
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/MD5Digest.java,v 1.5 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
/*
- * MD5-based utility function to obfuscate passwords before network transmission
- *
* @author Jeremy Wohl
- * $Id: MD5Digest.java,v 1.4 2002/08/16 19:35:46 davec Exp $
*/
import java.security.*;
diff --git a/src/interfaces/jdbc/org/postgresql/util/MessageTranslator.java b/src/interfaces/jdbc/org/postgresql/util/MessageTranslator.java
index 4e16d012ab4..bd1408fb6ac 100644
--- a/src/interfaces/jdbc/org/postgresql/util/MessageTranslator.java
+++ b/src/interfaces/jdbc/org/postgresql/util/MessageTranslator.java
@@ -1,11 +1,21 @@
+/*-------------------------------------------------------------------------
+ *
+ * MessageTranslator.java
+ * A singleton class to translate JDBC driver messages in SQLException's.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/MessageTranslator.java,v 1.4 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
-import java.util.*;
-import java.text.*;
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
-/*
- * A singleton class to translate JDBC driver messages in SQLException's.
- */
public class MessageTranslator
{
diff --git a/src/interfaces/jdbc/org/postgresql/util/PGbytea.java b/src/interfaces/jdbc/org/postgresql/util/PGbytea.java
index 21e204dec5d..d754cbfd683 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PGbytea.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PGbytea.java
@@ -1,13 +1,19 @@
+/*-------------------------------------------------------------------------
+ *
+ * PGbytea.java
+ * Converts to and from the postgresql bytea datatype used by the backend.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PGbytea.java,v 1.7 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
import java.sql.*;
-/*
- * Converts to and from the postgresql bytea datatype used by the backend.
- *
- * $Id: PGbytea.java,v 1.6 2002/09/06 21:23:06 momjian Exp $
- */
-
public class PGbytea
{
diff --git a/src/interfaces/jdbc/org/postgresql/util/PGmoney.java b/src/interfaces/jdbc/org/postgresql/util/PGmoney.java
index 77e019d7240..970c8367b7f 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PGmoney.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PGmoney.java
@@ -1,11 +1,21 @@
+/*-------------------------------------------------------------------------
+ *
+ * PGmoney.java
+ * This implements a class that handles the PostgreSQL money and cash types
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PGmoney.java,v 1.5 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
-import java.io.*;
-import java.sql.*;
-/*
- * This implements a class that handles the PostgreSQL money and cash types
- */
+import java.io.Serializable;
+import java.sql.SQLException;
+
public class PGmoney extends PGobject implements Serializable, Cloneable
{
/*
@@ -22,12 +32,6 @@ public class PGmoney extends PGobject implements Serializable, Cloneable
val = value;
}
- /*
- * This is called mainly from the other geometric types, when a
- * point is imbeded within their definition.
- *
- * @param value Definition of this point in PostgreSQL's syntax
- */
public PGmoney(String value) throws SQLException
{
this();
@@ -42,10 +46,6 @@ public class PGmoney extends PGobject implements Serializable, Cloneable
setType("money");
}
- /*
- * @param s Definition of this point in PostgreSQL's syntax
- * @exception SQLException on conversion failure
- */
public void setValue(String s) throws SQLException
{
try
@@ -76,10 +76,6 @@ public class PGmoney extends PGobject implements Serializable, Cloneable
}
}
- /*
- * @param obj Object to compare with
- * @return true if the two boxes are identical
- */
public boolean equals(Object obj)
{
if (obj instanceof PGmoney)
@@ -98,9 +94,6 @@ public class PGmoney extends PGobject implements Serializable, Cloneable
return new PGmoney(val);
}
- /*
- * @return the PGpoint in the syntax expected by org.postgresql
- */
public String getValue()
{
if (val < 0)
diff --git a/src/interfaces/jdbc/org/postgresql/util/PGobject.java b/src/interfaces/jdbc/org/postgresql/util/PGobject.java
index 3370c66eefd..247c21c9cad 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PGobject.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PGobject.java
@@ -1,18 +1,21 @@
+/*-------------------------------------------------------------------------
+ *
+ * PGobject.java
+ * PGobject is a class used to describe unknown types
+ * An unknown type is any type that is unknown by JDBC Standards
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PGobject.java,v 1.4 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
-import java.io.*;
-import java.lang.*;
-import java.sql.*;
-import java.util.*;
+import java.io.Serializable;
+import java.sql.SQLException;
-/*
- * org.postgresql.PG_Object is a class used to describe unknown types
- * An unknown type is any type that is unknown by JDBC Standards
- *
- * As of PostgreSQL 6.3, this allows user code to add their own
- * handlers via a call to org.postgresql.Connection. These handlers
- * must extend this class.
- */
public class PGobject implements Serializable, Cloneable
{
protected String type;
diff --git a/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java b/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java
index fc4efc4c31a..96aa532a9c1 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PGtokenizer.java
@@ -1,12 +1,22 @@
+/*-------------------------------------------------------------------------
+ *
+ * PGtokenizer.java
+ * This class is used to tokenize the text output of org.postgres.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PGtokenizer.java,v 1.6 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
import java.sql.*;
import java.util.*;
/*
- * This class is used to tokenize the text output of org.postgres.
- *
- * It's mainly used by the geometric classes, but is useful in parsing any
+ * It's mainly used by the geometric classes, but is useful in parsing any
* output from custom data types output from org.postgresql.
*
* @see org.postgresql.geometric.PGbox
diff --git a/src/interfaces/jdbc/org/postgresql/util/PSQLException.java b/src/interfaces/jdbc/org/postgresql/util/PSQLException.java
index d8fabd904a5..c718f699a31 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PSQLException.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PSQLException.java
@@ -1,11 +1,22 @@
+/*-------------------------------------------------------------------------
+ *
+ * PSQLException.java
+ * This class extends SQLException, and provides our internationalisation
+ * handling
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PSQLException.java,v 1.9 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
-import java.io.*;
-import java.sql.*;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.sql.SQLException;
-/*
- * This class extends SQLException, and provides our internationalisation handling
- */
public class PSQLException extends SQLException
{
private String message;
diff --git a/src/interfaces/jdbc/org/postgresql/util/Serialize.java b/src/interfaces/jdbc/org/postgresql/util/Serialize.java
deleted file mode 100644
index d4bf01fb643..00000000000
--- a/src/interfaces/jdbc/org/postgresql/util/Serialize.java
+++ /dev/null
@@ -1,666 +0,0 @@
-package org.postgresql.util;
-
-import org.postgresql.Driver;
-import java.io.*;
-import java.lang.*;
-import java.lang.reflect.*;
-import java.net.*;
-import java.util.*;
-import java.sql.*;
-
-/*
- * This class uses PostgreSQL's object oriented features to store Java Objects.
- *
- * It does this by mapping a Java Class name to a table in the database. Each
- * entry in this new table then represents a Serialized instance of this
- * class. As each entry has an OID (Object IDentifier), this OID can be
- * included in another table.
- *
- * Serialize depends on a feature of Postgres that allows
- * a table to be used as a data type. However, Postgres support of
- * this feature is incomplete. The basic ability to create and use
- * a table as a field type in another table exists:
- *
- * Queries like:
- * Because support is incomplete for table data types, tables
- * such as othertable that hold java instances should also
- * hold an oid field for the same java instance:
- *
- * The myclass table represents a java class. This table is created
- * by Serialize.create(). Serialize.create() must be called before
- * the first use of the myclass java class in PreparedStatement.setObject()
- * calls. This is a one-time initialization step.
- *
- * There are a number of limitations placed on the java class to be
- * used by Serialize:
- *
- *
- * This method was deprecated in 7.2 because the value of an OID
- * can be larger than a java signed int.
- * @deprecated Replaced by storeObject() in 7.2
- */
- public int store(Object o) throws SQLException
- {
- return (int) storeObject(o);
- }
-
- /*
- * This stores an object into a table, returning it's OID.
- *
- * If the object has an int called OID, and it is > 0, then
- * that value is used for the OID, and the table will be updated.
- * If the value of OID is 0, then a new row will be created, and the
- * value of OID will be set in the object. This enables an object's
- * value in the database to be updateable.
- *
- * If the object has no int called OID, then the object is stored. However
- * if the object is later retrieved, amended and stored again, it's new
- * state will be appended to the table, and will not overwrite the old
- * entries.
- *
- * @param o Object to store (must implement Serializable)
- * @return oid of stored object
- * @exception SQLException on error
- * @since 7.2
- */
- public long storeObject(Object o) throws SQLException
- {
- try
- {
- // NB: we use java.lang.reflect here to prevent confusion with
- // the org.postgresql.Field
-
- // don't save private fields since we would not be able to fetch them
- java.lang.reflect.Field f[] = ourClass.getFields();
-
- boolean hasOID = false;
- int oidFIELD = -1;
- boolean update = false;
-
- // Find out if we have an oid value
- for (int i = 0;i < f.length;i++)
- {
- String n = f[i].getName();
- if (n.equals("oid"))
- {
- hasOID = true;
- oidFIELD = i;
- // Do update if oid != 0
- update = f[i].getInt(o) > 0;
- }
- }
-
- StringBuffer sb = new StringBuffer(update ? "update " + tableName + " set" : "insert into " + tableName + " ");
- char sep = update ? ' ' : '(';
- for (int i = 0;i < f.length;i++)
- {
- String n = f[i].getName();
- // oid cannot be updated!
- if ( n.equals("oid") )
- continue;
- sb.append(sep);
- sep = ',';
- sb.append(n);
- if (update)
- {
- sb.append('=');
- // handle unset values
- if (f[i].get(o) == null)
- sb.append("null");
- else if (
- f[i].getType().getName().equals("java.lang.String")
- || f[i].getType().getName().equals("char") )
- {
- sb.append('\'');
- // don't allow single qoutes or newlines in the string
- sb.append(fixString(f[i].get(o).toString()));
- sb.append('\'');
- }
- else
- sb.append(f[i].get(o).toString());
- }
- }
-
- if (update)
- sb.append(" where oid = " + f[oidFIELD].getInt(o) );
-
- if (!update)
- {
- sb.append(") values ");
- sep = '(';
- for (int i = 0;i < f.length;i++)
- {
- String n = f[i].getName();
- // oid cannot be set!
- if ( n.equals("oid") )
- continue;
- sb.append(sep);
- sep = ',';
- // handle unset values
- if (f[i].get(o) == null)
- sb.append("null");
- else if (
- f[i].getType().getName().equals("java.lang.String")
- || f[i].getType().getName().equals("char"))
- {
- sb.append('\'');
- // don't allow single quotes or newlines in the string
- sb.append(fixString(f[i].get(o).toString()));
- sb.append('\'');
- }
- else
- sb.append(f[i].get(o).toString());
- }
- sb.append(')');
- }
-
- if (Driver.logDebug)
- Driver.debug("Serialize.store: " + sb.toString() );
- ResultSet rs = ((org.postgresql.jdbc1.AbstractJdbc1Connection)conn).execSQL(sb.toString());
-
- // fetch the OID for returning
- if (update)
- {
- // object has oid already, so return it
- if (rs != null)
- rs.close();
- return f[oidFIELD].getInt(o);
- }
- else
- {
- // new record inserted has new oid; rs should be not null
- long newOID = ((org.postgresql.jdbc1.AbstractJdbc1ResultSet)rs).getLastOID();
- rs.close();
- // update the java object's oid field if it has the oid field
- if (hasOID)
- f[oidFIELD].setLong(o, newOID);
- // new object stored, return newly inserted oid
- return newOID;
- }
-
- }
- catch (IllegalAccessException iae)
- {
- throw new SQLException(iae.toString());
- }
- }
-
- /*
- * Escape literal single quote and backslashes embedded in strings/chars.
- * Otherwise, postgres will bomb on the single quote and remove the
- * the backslashes.
- */
- private String fixString(String s)
- {
- int idx = -1;
-
- // handle null
- if (s == null)
- return "";
-
- // if the string has single quotes in it escape them as ''
- if ((idx = s.indexOf("'")) > -1)
- {
- StringBuffer buf = new StringBuffer();
- StringTokenizer tok = new StringTokenizer(s, "'");
- // handle quote as 1St charater
- if (idx > 0)
- buf.append(tok.nextToken());
-
- while (tok.hasMoreTokens())
- buf.append("''").append(tok.nextToken());
-
- s = buf.toString();
- }
-
- // if the string has backslashes in it escape them them as \\
- if ((idx = s.indexOf("\\")) > -1)
- {
- StringBuffer buf = new StringBuffer();
- StringTokenizer tok = new StringTokenizer(s, "\\");
- if (idx > 0)
- buf.append(tok.nextToken());
-
- while (tok.hasMoreTokens())
- buf.append("\\\\").append(tok.nextToken());
-
- s = buf.toString();
- }
-
- return s;
- }
-
- /*
- * This method is not used by the driver, but it creates a table, given
- * a Serializable Java Object. It should be used before serializing any
- * objects.
- * @param c Connection to database
- * @param o Object to base table on
- * @exception SQLException on error
- */
- public static void create(Connection con, Object o) throws SQLException
- {
- create(con, o.getClass());
- }
-
- /*
- * This method is not used by the driver, but it creates a table, given
- * a Serializable Java Object. It should be used before serializing any
- * objects.
- * @param c Connection to database
- * @param o Class to base table on
- * @exception SQLException on error
- */
- public static void create(Connection conn, Class c) throws SQLException
- {
- if (c.isInterface())
- throw new PSQLException("postgresql.serial.interface");
-
- // See if the table exists
- String tableName = toPostgreSQL(conn,c.getName());
-
- String sql;
- if (conn.getMetaData().supportsSchemasInTableDefinitions()) {
- sql = "SELECT 1 FROM pg_catalog.pg_class WHERE relkind='r' AND relname='" + tableName + "' AND pg_table_is_visible(oid) ";
- } else {
- sql = "SELECT 1 FROM pg_class WHERE relkind='r' AND relname='"+tableName+"'";
- }
-
- ResultSet rs = conn.createStatement().executeQuery(sql);
- if ( rs.next() )
- {
- if (Driver.logDebug)
- Driver.debug("Serialize.create: table " + tableName + " exists, skipping");
- rs.close();
- return ;
- }
-
- // else table not found, so create it
- if (Driver.logDebug)
- Driver.debug("Serialize.create: table " + tableName + " not found, creating" );
- // No entries returned, so the table doesn't exist
-
- StringBuffer sb = new StringBuffer("create table ");
- sb.append(tableName);
- char sep = '(';
-
- // java.lang.reflect.Field[] fields = c.getDeclaredFields();
- // Only store public fields, another limitation!
- java.lang.reflect.Field[] fields = c.getFields();
- for (int i = 0;i < fields.length;i++)
- {
- Class type = fields[i].getType();
- // oid is a special field
- if (!fields[i].getName().equals("oid"))
- {
- sb.append(sep);
- sb.append(fields[i].getName());
- sb.append(' ');
- sep = ',';
-
- if (type.isArray())
- {
- // array handling
- }
- else
- {
- // convert the java type to org.postgresql, recursing if a class
- // is found
- String n = type.getName();
- int j = 0;
- for (;j < tp.length && !tp[j][0].equals(n);j++)
- ;
- if (j < tp.length)
- sb.append(tp[j][1]);
- else
- {
- create(conn, type);
- sb.append(toPostgreSQL(conn,n));
- }
- }
- }
- }
- sb.append(")");
-
- // Now create the table
- if (Driver.logDebug)
- Driver.debug("Serialize.create: " + sb );
- conn.createStatement().executeUpdate(sb.toString());
- }
-
- // This is used to translate between Java primitives and PostgreSQL types.
- private static final String tp[][] = {
- // {"boolean", "int1"},
- {"boolean", "bool"},
- {"double", "float8"},
- {"float", "float4"},
- {"int", "int4"},
- // {"long", "int4"},
- {"long", "int8"},
- {"short", "int2"},
- {"java.lang.String", "text"},
- {"java.lang.Integer", "int4"},
- {"java.lang.Float", "float4"},
- {"java.lang.Double", "float8"},
- {"java.lang.Short", "int2"},
- {"char", "char"},
- {"byte", "int2"}
- };
-
- /**
- * This converts a Java Class name to a org.postgresql table, by replacing . with
- * _
- *
- * Because of this, a Class name may not have _ in the name.
- * Another limitation, is that the entire class name (including packages)
- * cannot be longer than the maximum table name length.
- *
- * @param con The database connection
- * @param name Class name
- * @return PostgreSQL table name
- * @exception SQLException on error
- * @since 7.3
- */
- public static String toPostgreSQL(Connection con, String name) throws SQLException
- {
- DatabaseMetaData dbmd = con.getMetaData();
- int maxNameLength = dbmd.getMaxTableNameLength();
- return toPostgreSQL(maxNameLength,name);
- }
-
- /**
- * Convert a Java Class Name to an org.postgresql table name, by replacing .
- * with _
- *
- * @deprecated Replaced by toPostgresql(connection, name) in 7.3
- */
- public static String toPostgreSQL(String name) throws SQLException {
- return toPostgreSQL(31,name);
- }
-
- private static String toPostgreSQL(int maxNameLength, String name) throws SQLException {
-
- name = name.toLowerCase();
-
- if (name.indexOf("_") > -1)
- throw new PSQLException("postgresql.serial.underscore");
-
- // Postgres table names can only be so many characters long.
- // If the full class name with package is too long
- // then just use the class name. If the class name is
- // too long throw an exception.
- //
- if ( name.length() > maxNameLength )
- {
- name = name.substring(name.lastIndexOf(".") + 1);
- if ( name.length() > maxNameLength )
- throw new PSQLException("postgresql.serial.namelength", name, new Integer(name.length()));
- }
- return name.replace('.', '_');
- }
-
-
- /*
- * This converts a org.postgresql table to a Java Class name, by replacing _ with
- * .
- *
- * @param name PostgreSQL table name
- * @return Class name
- * @exception SQLException on error
- */
- public static String toClassName(String name) throws SQLException
- {
- name = name.toLowerCase();
- return name.replace('_', '.');
- }
-
-}
diff --git a/src/interfaces/jdbc/org/postgresql/util/UnixCrypt.java b/src/interfaces/jdbc/org/postgresql/util/UnixCrypt.java
index 049cb80c1e9..2aa2946429f 100644
--- a/src/interfaces/jdbc/org/postgresql/util/UnixCrypt.java
+++ b/src/interfaces/jdbc/org/postgresql/util/UnixCrypt.java
@@ -1,12 +1,19 @@
+/*-------------------------------------------------------------------------
+ *
+ * UnixCrypt.java
+ * Contains static methods to encrypt and compare
+ * passwords with Unix encrypted passwords.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/UnixCrypt.java,v 1.4 2003/03/07 18:39:46 barry Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
package org.postgresql.util;
/*
- * This class provides us with the ability to encrypt passwords when sent
- * over the network stream
- *
- * Contains static methods to encrypt and compare
- * passwords with Unix encrypted passwords. See
* John Dumas's Java Crypt page for the original source.
- * CREATE TABLE myclass( var1 TEXT, var2 INTEGER );
- * CREATE TABLE othertable( field1 TEXT, field2 myclass );
- * INSERT INTO myclass VALUES ('Hello', 1);
- * INSERT INTO othertable VALUES ('World', xxxx::myclass);
- * where xxxx is the OID of a row in myclass
- * This lets othertable reference a myclass instance but
- * the support to actually make any use of the myclass data type
- * is not there. For instance, you cannot compare the myclass field
- * with ANY other data type, not even with other myclass values.
- * Casting to and from the myclass type will also not work.
- * From the limited testing done, only the literal xxxx::myclass
- * syntax appears to work.
- * SELECT othertable.field2.var1 FROM othertable;
- * will not work but were suggested in the original Postgres
- * design documents.
- * CREATE othertable( field1 TEXT, field2 myclass, myclassOID oid);
- * This oid-type field would be set with setInt() immediately after
- * setting the myclass-type field with setObject(). The order of these
- * set calls matters since the oid is not available until after
- * setting the object when inserting a new object. With the oid,
- * queries and comparisons etc. can be done to locate a myclass.
- * Read below about how to include an int oid field in your java class
- * that is updated by setObject() when it is inserted.
- *
- *
- * Suggested usage:
- *
- * int oid = 0;
- * This field is actually optional and its use by jdbc2.PreparedStatement.setObject()
- * is as follows:
- * If oid does not exist in the class, the class instance is stored in a new table row
- * everytime setObject() is called on it. If oid field exists and is 0, then the class
- * instance is stored into a new row in the table and that row's oid is set in the class by setObject().
- * If oid field exists and is > 0, then the existing table row for the class instance is
- * updated. The oid field should be thought of as read-only unless you want to set it to 0
- * so that a new instance is created in the database rather than doing an update.
- *
- * Finally, Serialize is a work in progress and being a utility class, it is not supported.
- * You are "on your own" if you use it. If you use it and make any enhancements,
- * please consider joining the email lists pgsql-jdbc@postgresql.org and pgsql-patches@postgresql.org
- * and contributing your additions.
- */
-public class Serialize
-{
- // This is the connection that the instance refers to
- protected Connection conn;
-
- // This is the table name
- protected String tableName;
-
- // This is the class name
- protected String className;
-
- // This is the Class for this serialzed object
- protected Class ourClass;
-
- /*
- * This creates an instance that can be used to serialize or deserialize
- * a Java object from a PostgreSQL table.
- */
- public Serialize(Connection conn, String type) throws SQLException
- {
- try
- {
- this.conn = conn;
- if (Driver.logDebug)
- Driver.debug("Serialize: initializing instance for type: " + type);
- tableName = toPostgreSQL(conn,type);
- className = type;
- ourClass = Class.forName(className);
- }
- catch (ClassNotFoundException cnfe)
- {
- if (Driver.logDebug)
- Driver.debug("Serialize: " + className + " java class not found");
- throw new PSQLException("postgresql.serial.noclass", type);
- }
-
- // Second check, the type must be a table
- boolean status = false;
- String sql;
- if (conn.getMetaData().supportsSchemasInTableDefinitions()) {
- sql = "SELECT 1 FROM pg_catalog.pg_type t, pg_catalog.pg_class c WHERE t.typrelid=c.oid AND c.relkind='r' AND t.typname='" + tableName + "' AND pg_table_is_visible(c.oid) ";
- } else {
- sql = "SELECT 1 FROM pg_type t, pg_class c WHERE t.typrelid=c.oid AND c.relkind='r' AND t.typname='"+tableName+"'";
- }
-
- ResultSet rs = conn.createStatement().executeQuery(sql);
- if (rs != null)
- {
- if (rs.next())
- {
- status = true;
- if (Driver.logDebug)
- Driver.debug("Serialize: " + tableName + " table found");
- }
- rs.close();
- }
- // This should never occur, as org.postgresql has it's own internal checks
- if (!status)
- {
- if (Driver.logDebug)
- Driver.debug("Serialize: " + tableName + " table not found");
- throw new PSQLException("postgresql.serial.table", type);
- }
- // Finally cache the fields within the table
- }
-
- /*
- * Constructor when Object is passed in
- */
- public Serialize(Connection c, Object o) throws SQLException
- {
- this(c, o.getClass().getName());
- }
-
- /*
- * Constructor when Class is passed in
- */
- public Serialize(Connection c, Class cls) throws SQLException
- {
- this(c, cls.getName());
- }
-
- /*
- * This fetches an object from a table, given it's OID
- * @param oid The oid of the object
- * @return Object relating to oid
- * @exception SQLException on error
- */
- public Object fetch(long oid) throws SQLException
- {
- try
- {
- if (Driver.logDebug)
- Driver.debug("Serialize.fetch: " + "attempting to instantiate object of type: " + ourClass.getName() );
- Object obj = ourClass.newInstance();
- if (Driver.logDebug)
- Driver.debug("Serialize.fetch: " + "instantiated object of type: " + ourClass.getName() );
-
- // NB: we use java.lang.reflect here to prevent confusion with
- // the org.postgresql.Field
-
- // used getFields to get only public fields. We have no way to set values
- // for other declarations. Maybe look for setFieldName() methods?
- java.lang.reflect.Field f[] = ourClass.getFields();
- boolean hasOID = false;
- int oidFIELD = -1;
-
- StringBuffer sb = new StringBuffer("select");
- char sep = ' ';
- // build a select for the fields. Look for the oid field to use in the where
- for (int i = 0;i < f.length;i++)
- {
- String n = f[i].getName();
- if (n.equals("oid"))
- {
- hasOID = true;
- oidFIELD = i;
- }
- sb.append(sep);
- sb.append(n);
- sep = ',';
- }
- sb.append(" from ");
- sb.append(tableName);
- sb.append(" where oid=");
- sb.append(oid);
-
- if (Driver.logDebug)
- Driver.debug("Serialize.fetch: " + sb.toString());
- ResultSet rs = conn.createStatement().executeQuery(sb.toString());
-
- if (rs != null)
- {
- if (rs.next())
- {
- for (int i = 0;i < f.length;i++)
- {
- if ( !Modifier.isFinal(f[i].getModifiers()) )
- {
- if ( f[i].getType().getName().equals("short") )
- f[i].setShort(obj, rs.getShort(i + 1));
- else if ( f[i].getType().getName().equals("char") )
- f[i].setChar(obj, rs.getString(i + 1).toCharArray()[0]);
- else if ( f[i].getType().getName().equals("byte"))
- f[i].setByte(obj, rs.getByte(i + 1));
- else if ( f[i].getType().getName().equals("boolean") )
- {
- // booleans come out of pgsql as a t or an f
- if ( rs.getString(i + 1).equals("t") )
- f[i].setBoolean(obj, true);
- else
- f[i].setBoolean(obj, false);
- }
- else
- f[i].set(obj, rs.getObject(i + 1));
- }
- }
- }
- rs.close();
- }
- else
- throw new PSQLException("postgresql.unexpected");
-
- return obj;
-
- }
- catch (IllegalAccessException iae)
- {
- throw new SQLException(iae.toString());
- }
- catch (InstantiationException ie)
- {
- throw new SQLException(ie.toString());
- }
- }
-
- /*
- * This stores an object into a table, returning it's OID.
- *