Cleanup and reorganization.

- Added a private api layer (org.postgresql.core.Base*)
  - Cleaned up public api (org.postgresql.PG*)
  - Added consistent headers and copywrite info
  - Removed deprecated Serialize functionality
  - Cleaned up imports
  - Moved some files to more appropriate locations

 Modified Files:
 	jdbc/org/postgresql/Driver.java.in
 	jdbc/org/postgresql/PGConnection.java
 	jdbc/org/postgresql/PGNotification.java
 	jdbc/org/postgresql/PGStatement.java
 	jdbc/org/postgresql/core/Encoding.java
 	jdbc/org/postgresql/core/Notification.java
 	jdbc/org/postgresql/core/QueryExecutor.java
 	jdbc/org/postgresql/core/StartupPacket.java
 	jdbc/org/postgresql/fastpath/Fastpath.java
 	jdbc/org/postgresql/fastpath/FastpathArg.java
 	jdbc/org/postgresql/geometric/PGbox.java
 	jdbc/org/postgresql/geometric/PGcircle.java
 	jdbc/org/postgresql/geometric/PGline.java
 	jdbc/org/postgresql/geometric/PGlseg.java
 	jdbc/org/postgresql/geometric/PGpath.java
 	jdbc/org/postgresql/geometric/PGpoint.java
 	jdbc/org/postgresql/geometric/PGpolygon.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSetMetaData.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
 	jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java
 	jdbc/org/postgresql/jdbc1/Jdbc1Connection.java
 	jdbc/org/postgresql/jdbc1/Jdbc1DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java
 	jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java
 	jdbc/org/postgresql/jdbc1/Jdbc1ResultSetMetaData.java
 	jdbc/org/postgresql/jdbc1/Jdbc1Statement.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
 	jdbc/org/postgresql/jdbc2/Array.java
 	jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java
 	jdbc/org/postgresql/jdbc2/Jdbc2Connection.java
 	jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java
 	jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java
 	jdbc/org/postgresql/jdbc2/Jdbc2ResultSetMetaData.java
 	jdbc/org/postgresql/jdbc2/Jdbc2Statement.java
 	jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java
 	jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java
 	jdbc/org/postgresql/jdbc3/Jdbc3Connection.java
 	jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java
 	jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java
 	jdbc/org/postgresql/jdbc3/Jdbc3ResultSetMetaData.java
 	jdbc/org/postgresql/jdbc3/Jdbc3Statement.java
 	jdbc/org/postgresql/largeobject/BlobInputStream.java
 	jdbc/org/postgresql/largeobject/BlobOutputStream.java
 	jdbc/org/postgresql/largeobject/LargeObject.java
 	jdbc/org/postgresql/largeobject/LargeObjectManager.java
 	jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
 	jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
 	jdbc/org/postgresql/util/MD5Digest.java
 	jdbc/org/postgresql/util/MessageTranslator.java
 	jdbc/org/postgresql/util/PGbytea.java
 	jdbc/org/postgresql/util/PGmoney.java
 	jdbc/org/postgresql/util/PGobject.java
 	jdbc/org/postgresql/util/PGtokenizer.java
 	jdbc/org/postgresql/util/PSQLException.java
 	jdbc/org/postgresql/util/UnixCrypt.java
 Added Files:
 	jdbc/org/postgresql/core/BaseConnection.java
 	jdbc/org/postgresql/core/BaseResultSet.java
 	jdbc/org/postgresql/core/BaseStatement.java
 	jdbc/org/postgresql/core/Field.java
 	jdbc/org/postgresql/core/PGStream.java
 Removed Files:
 	jdbc/org/postgresql/Field.java
 	jdbc/org/postgresql/PG_Stream.java
 	jdbc/org/postgresql/test/jdbc2/SerializeObject.java
 	jdbc/org/postgresql/test/jdbc2/SerializeTest.java
 	jdbc/org/postgresql/util/Serialize.java
This commit is contained in:
Barry Lind 2003-03-07 18:39:46 +00:00
parent 2e6887df63
commit 6ee060f201
72 changed files with 1130 additions and 1527 deletions

View File

@ -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;
}

View File

@ -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.
*
* <p>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;
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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
{

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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;

View File

@ -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.
*
* <p>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);
}
}

View File

@ -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);

View File

@ -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.
*
* <p>This is a means of executing functions imbeded in the org.postgresql backend
* from within a java application.
* <p>This is a means of executing functions imbeded in the org.postgresql
* backend from within a java application.
*
* <p>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
*
* <p><b>Important Notice</b>
* <br>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.
*
* <p>The org.postgresql.LargeObject class performs a query upon it's startup,
* <p>The org.postgresql.largeobject.LargeObject class performs a query upon it's startup,
* and passes the returned ResultSet to the addFunctions() method here.
*
* <p>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
{

View File

@ -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.
*
* <p>This class implements methods needed to provide this capability.
*
* <p>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)
{

View File

@ -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
{
/*

View File

@ -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
{
/*

View File

@ -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.
*/

View File

@ -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
{
/*

View File

@ -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
{
/*

View File

@ -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.
*
* <p>It maps to the point datatype in org.postgresql.
*/
public class PGpoint extends PGobject implements Serializable, Cloneable
{

View File

@ -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
{
/*

View File

@ -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 <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
throw new PSQLException ("postgresql.con.refused");
}
catch (IOException e)
{
throw new PSQLException ("postgresql.con.failed", e);
}
// Now we need to construct and send a cancel packet
try
{
cancelStream.SendInteger(16, 4);
cancelStream.SendInteger(80877102, 4);
cancelStream.SendInteger(pid, 4);
cancelStream.SendInteger(ckey, 4);
cancelStream.flush();
}
catch (IOException e)
{
throw new PSQLException("postgresql.con.failed", e);
}
finally
{
try
{
if (cancelStream != null)
cancelStream.close();
}
catch (IOException e)
{} // Ignore
}
}
//Methods to support postgres notifications
public void addNotification(org.postgresql.PGNotification p_notification)
{

View File

@ -3,7 +3,8 @@ package org.postgresql.jdbc1;
import java.sql.*;
import java.util.*;
import org.postgresql.Field;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.util.PSQLException;
import org.postgresql.Driver;
@ -1915,7 +1916,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
}
rs.close();
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -2207,7 +2208,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
v.addElement(tuple);
}
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -2381,7 +2382,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
}
rs.close();
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -2494,7 +2495,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
}
rs.close();
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -2596,7 +2597,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
}
rs.close();
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
private static void sortStringArray(String s[]) {
@ -2790,7 +2791,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
v.addElement(tuple);
}
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -2860,7 +2861,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
/* Perhaps we should check that the given
* catalog.schema.table actually exists. -KJ
*/
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*
@ -3183,7 +3184,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
tuples.addElement(tuple);
}
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, tuples, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, tuples, "OK", 1, 0, false);
}
/*
@ -3469,7 +3470,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
}
rs.close();
return ((AbstractJdbc1Statement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
return (ResultSet) ((BaseStatement)connection.createStatement()).createResultSet(f, v, "OK", 1, 0, false);
}
/*

View File

@ -7,27 +7,28 @@ import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Vector;
import org.postgresql.Field;
import org.postgresql.Driver;
import org.postgresql.core.BaseConnection;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.core.Encoding;
import org.postgresql.core.QueryExecutor;
import org.postgresql.largeobject.*;
import org.postgresql.util.PGbytea;
import org.postgresql.util.PGtokenizer;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.9 2003/02/04 09:20:08 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.10 2003/03/07 18:39:44 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet
*/
public abstract class AbstractJdbc1ResultSet
public abstract class AbstractJdbc1ResultSet implements BaseResultSet
{
protected Vector rows; // The results
protected Statement statement;
public org.postgresql.PGStatement getPGStatement() {
return (org.postgresql.PGStatement) statement;
}
protected BaseStatement statement;
protected Field fields[]; // The field descriptions
protected String status; // Status of the result
protected boolean binaryCursor = false; // is the data binary or Strings
@ -35,19 +36,20 @@ public abstract class AbstractJdbc1ResultSet
protected long insertOID; // The oid of an inserted row
protected int current_row; // Our pointer to where we are at
protected byte[][] this_row; // the current row result
protected org.postgresql.PGConnection connection; // the connection which we returned from
protected BaseConnection connection; // the connection which we returned from
protected SQLWarning warnings = null; // The warning chain
protected boolean wasNullFlag = false; // the flag for wasNull()
// We can chain multiple resultSets together - this points to
// next resultSet in the chain.
protected ResultSet next = null;
protected BaseResultSet next = null;
protected StringBuffer sbuf = null;
private StringBuffer sbuf = null;
public byte[][] rowBuffer = null;
public abstract ResultSetMetaData getMetaData() throws SQLException;
public AbstractJdbc1ResultSet(Statement statement,
public AbstractJdbc1ResultSet(BaseStatement statement,
Field[] fields,
Vector tuples,
String status,
@ -55,7 +57,7 @@ public abstract class AbstractJdbc1ResultSet
long insertOID,
boolean binaryCursor)
{
this.connection = ((org.postgresql.jdbc1.AbstractJdbc1Statement)statement).getPGConnection();
this.connection = statement.getPGConnection();
this.statement = statement;
this.fields = fields;
this.rows = tuples;
@ -68,6 +70,17 @@ public abstract class AbstractJdbc1ResultSet
this.binaryCursor = binaryCursor;
}
public BaseStatement getPGStatement() {
return statement;
}
public StringBuffer getStringBuffer() {
return sbuf;
}
//This is implemented in jdbc2
public void setStatement(BaseStatement statement) {
}
//method to reinitialize a result set with more data
public void reInit (Field[] fields, Vector tuples, String status,
@ -93,7 +106,7 @@ public abstract class AbstractJdbc1ResultSet
if (++current_row >= rows.size())
{
int fetchSize = ((AbstractJdbc1Statement)statement).fetchSize;
int fetchSize = statement.getFetchSize();
// Must be false if we weren't batching.
if (fetchSize == 0)
return false;
@ -104,11 +117,11 @@ public abstract class AbstractJdbc1ResultSet
String[] sql = new String[1];
String[] binds = new String[0];
// Is this the correct query???
String cursorName = ((AbstractJdbc1Statement)statement).m_statementName;
String cursorName = statement.getStatementName();
sql[0] = "FETCH FORWARD " + fetchSize + " FROM " + cursorName;
org.postgresql.core.QueryExecutor.execute(sql,
QueryExecutor.execute(sql,
binds,
(java.sql.ResultSet)this);
this);
// Test the new rows array.
if (rows.size() == 0)
@ -242,7 +255,7 @@ public abstract class AbstractJdbc1ResultSet
//If the data is already binary then just return it
return this_row[columnIndex - 1];
}
else if (((AbstractJdbc1Connection)connection).haveMinimumCompatibleVersion("7.2"))
else if (connection.haveMinimumCompatibleVersion("7.2"))
{
//Version 7.2 supports the bytea datatype for byte arrays
if (fields[columnIndex - 1].getPGType().equals("bytea"))
@ -282,12 +295,12 @@ public abstract class AbstractJdbc1ResultSet
public Time getTime(int columnIndex) throws SQLException
{
return toTime( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex - 1].getPGType() );
return toTime( getString(columnIndex), this, fields[columnIndex - 1].getPGType() );
}
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
return toTimestamp( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex - 1].getPGType() );
return toTimestamp( getString(columnIndex), this, fields[columnIndex - 1].getPGType() );
}
public InputStream getAsciiStream(int columnIndex) throws SQLException
@ -297,7 +310,7 @@ public abstract class AbstractJdbc1ResultSet
if (wasNullFlag)
return null;
if (((AbstractJdbc1Connection)connection).haveMinimumCompatibleVersion("7.2"))
if (connection.haveMinimumCompatibleVersion("7.2"))
{
//Version 7.2 supports AsciiStream for all the PG text types
//As the spec/javadoc for this method indicate this is to be used for
@ -328,7 +341,7 @@ public abstract class AbstractJdbc1ResultSet
if (wasNullFlag)
return null;
if (((AbstractJdbc1Connection)connection).haveMinimumCompatibleVersion("7.2"))
if (connection.haveMinimumCompatibleVersion("7.2"))
{
//Version 7.2 supports AsciiStream for all the PG text types
//As the spec/javadoc for this method indicate this is to be used for
@ -359,7 +372,7 @@ public abstract class AbstractJdbc1ResultSet
if (wasNullFlag)
return null;
if (((AbstractJdbc1Connection)connection).haveMinimumCompatibleVersion("7.2"))
if (connection.haveMinimumCompatibleVersion("7.2"))
{
//Version 7.2 supports BinaryStream for all PG bytea type
//As the spec/javadoc for this method indicate this is to be used for
@ -485,7 +498,7 @@ public abstract class AbstractJdbc1ResultSet
public String getCursorName() throws SQLException
{
return ((AbstractJdbc1Connection)connection).getCursorName();
return (connection.getCursorName());
}
/*
@ -600,21 +613,21 @@ public abstract class AbstractJdbc1ResultSet
*
* @return the next ResultSet, or null if there are none
*/
public java.sql.ResultSet getNext()
public ResultSet getNext()
{
return (java.sql.ResultSet)next;
return (ResultSet)next;
}
/*
* This following method allows us to add a ResultSet object
* to the end of the current chain.
*/
public void append(AbstractJdbc1ResultSet r)
public void append(BaseResultSet r)
{
if (next == null)
next = (java.sql.ResultSet)r;
next = r;
else
((AbstractJdbc1ResultSet)next).append(r);
next.append(r);
}
/*
@ -705,7 +718,7 @@ public abstract class AbstractJdbc1ResultSet
// Handle Money
if (s.charAt(0) == '(')
{
s = "-" + org.postgresql.util.PGtokenizer.removePara(s).substring(1);
s = "-" + PGtokenizer.removePara(s).substring(1);
}
if (s.charAt(0) == '$')
{
@ -846,7 +859,7 @@ public abstract class AbstractJdbc1ResultSet
}
}
public static Time toTime(String s, java.sql.ResultSet resultSet, String pgDataType) throws SQLException
public static Time toTime(String s, BaseResultSet resultSet, String pgDataType) throws SQLException
{
if (s == null)
return null; // SQL NULL
@ -912,10 +925,10 @@ public abstract class AbstractJdbc1ResultSet
*
* @throws SQLException if there is a problem parsing s.
**/
public static Timestamp toTimestamp(String s, java.sql.ResultSet resultSet, String pgDataType)
public static Timestamp toTimestamp(String s, BaseResultSet resultSet, String pgDataType)
throws SQLException
{
AbstractJdbc1ResultSet rs = (AbstractJdbc1ResultSet)resultSet;
BaseResultSet rs = resultSet;
if (s == null)
return null;
@ -924,20 +937,21 @@ public abstract class AbstractJdbc1ResultSet
// SimpleDateFormat objects
synchronized (rs)
{
StringBuffer l_sbuf = rs.getStringBuffer();
SimpleDateFormat df = null;
if ( org.postgresql.Driver.logDebug )
org.postgresql.Driver.debug("the data from the DB is " + s);
if ( Driver.logDebug )
Driver.debug("the data from the DB is " + s);
// If first time, create the buffer, otherwise clear it.
if (rs.sbuf == null)
rs.sbuf = new StringBuffer(32);
if (l_sbuf == null)
l_sbuf = new StringBuffer(32);
else
{
rs.sbuf.setLength(0);
l_sbuf.setLength(0);
}
// Copy s into sbuf for parsing.
rs.sbuf.append(s);
l_sbuf.append(s);
int slen = s.length();
// For a Timestamp, the fractional seconds are stored in the
@ -955,7 +969,7 @@ public abstract class AbstractJdbc1ResultSet
// cut the copy to second value "2001-12-07 16:29:22"
int i = 19;
rs.sbuf.setLength(i);
l_sbuf.setLength(i);
char c = s.charAt(i++);
if (c == '.')
@ -996,14 +1010,14 @@ public abstract class AbstractJdbc1ResultSet
{
// prepend the GMT part and then add the remaining bit of
// the string.
rs.sbuf.append(" GMT");
rs.sbuf.append(c);
rs.sbuf.append(s.substring(i, slen));
l_sbuf.append(" GMT");
l_sbuf.append(c);
l_sbuf.append(s.substring(i, slen));
// Lastly, if the tz part doesn't specify the :MM part then
// we add ":00" for java.
if (slen - i < 5)
rs.sbuf.append(":00");
l_sbuf.append(":00");
// we'll use this dateformat string to parse the result.
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
@ -1014,7 +1028,7 @@ public abstract class AbstractJdbc1ResultSet
//If timestamptz then we use GMT, else local timezone
if (pgDataType.equals("timestamptz"))
{
rs.sbuf.append(" GMT");
l_sbuf.append(" GMT");
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
}
else
@ -1029,7 +1043,7 @@ public abstract class AbstractJdbc1ResultSet
//If timestamptz then we use GMT, else local timezone
if (pgDataType.equals("timestamptz"))
{
rs.sbuf.append(" GMT");
l_sbuf.append(" GMT");
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
}
else
@ -1057,12 +1071,12 @@ public abstract class AbstractJdbc1ResultSet
try
{
// All that's left is to parse the string and return the ts.
if ( org.postgresql.Driver.logDebug )
org.postgresql.Driver.debug("the data after parsing is "
+ rs.sbuf.toString() + " with " + nanos + " nanos");
if ( Driver.logDebug )
Driver.debug("the data after parsing is "
+ l_sbuf.toString() + " with " + nanos + " nanos");
Timestamp result =
new Timestamp(df.parse(rs.sbuf.toString()).getTime());
new Timestamp(df.parse(l_sbuf.toString()).getTime());
result.setNanos(nanos);
return result;
}

View File

@ -3,7 +3,7 @@ package org.postgresql.jdbc1;
import java.lang.*;
import java.util.*;
import org.postgresql.*;
import org.postgresql.core.Field;
import org.postgresql.util.*;
import java.sql.SQLException;
import java.sql.Types;

View File

@ -5,23 +5,24 @@ import java.io.*;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseConnection;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.core.QueryExecutor;
import org.postgresql.largeobject.*;
import org.postgresql.util.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.17 2003/02/09 23:14:55 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.18 2003/03/07 18:39:44 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
*/
public abstract class AbstractJdbc1Statement implements org.postgresql.PGStatement
public abstract class AbstractJdbc1Statement implements BaseStatement
{
// The connection who created us
protected AbstractJdbc1Connection connection;
public org.postgresql.PGConnection getPGConnection() {
return connection;
}
protected BaseConnection connection;
/** The warnings chain. */
protected SQLWarning warnings = null;
@ -38,7 +39,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
protected boolean replaceProcessingEnabled = true;
/** The current results */
protected java.sql.ResultSet result = null;
protected BaseResultSet result = null;
// Static variables for parsing SQL when replaceProcessing is true.
private static final short IN_SQLCODE = 0;
@ -76,19 +77,31 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
protected Object callResult;
public abstract java.sql.ResultSet createResultSet(org.postgresql.Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
public abstract BaseResultSet createResultSet(Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
public AbstractJdbc1Statement (AbstractJdbc1Connection connection)
public AbstractJdbc1Statement (BaseConnection connection)
{
this.connection = connection;
}
public AbstractJdbc1Statement (AbstractJdbc1Connection connection, String p_sql) throws SQLException
public AbstractJdbc1Statement (BaseConnection connection, String p_sql) throws SQLException
{
this.connection = connection;
parseSqlStmt(p_sql); // this allows Callable stmt to override
}
public BaseConnection getPGConnection() {
return connection;
}
public String getStatementName() {
return m_statementName;
}
public int getFetchSize() throws SQLException {
return fetchSize;
}
protected void parseSqlStmt (String p_sql) throws SQLException
{
String l_sql = p_sql;
@ -146,7 +159,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
try
{
((AbstractJdbc1Connection)connection).execSQL("DEALLOCATE " + m_statementName);
connection.execSQL("DEALLOCATE " + m_statementName);
}
catch (Exception e)
{
@ -175,11 +188,11 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
else
this.execute();
while (result != null && !((AbstractJdbc1ResultSet)result).reallyResultSet())
result = ((AbstractJdbc1ResultSet)result).getNext();
while (result != null && !result.reallyResultSet())
result = (BaseResultSet) result.getNext();
if (result == null)
throw new PSQLException("postgresql.stat.noresult");
return result;
return (ResultSet) result;
}
/*
@ -199,7 +212,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
//If we have already created a server prepared statement, we need
//to deallocate the existing one
if (m_statementName != null) {
((AbstractJdbc1Connection)connection).execSQL("DEALLOCATE " + m_statementName);
connection.execSQL("DEALLOCATE " + m_statementName);
m_statementName = null;
m_origSqlFragments = null;
m_executeSqlFragments = null;
@ -219,7 +232,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
public int executeUpdate() throws SQLException
{
this.execute();
if (((AbstractJdbc1ResultSet)result).reallyResultSet())
if (result.reallyResultSet())
throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
@ -243,7 +256,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
//If we have already created a server prepared statement, we need
//to deallocate the existing one
if (m_statementName != null) {
((AbstractJdbc1Connection)connection).execSQL("DEALLOCATE " + m_statementName);
connection.execSQL("DEALLOCATE " + m_statementName);
m_statementName = null;
m_origSqlFragments = null;
m_executeSqlFragments = null;
@ -341,14 +354,14 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
}
// New in 7.1, pass Statement so that ExecSQL can customise to it
result = org.postgresql.core.QueryExecutor.execute(m_sqlFragments,
result = QueryExecutor.execute(m_sqlFragments,
m_binds,
(java.sql.Statement)this);
this);
//If we are executing a callable statement function set the return data
if (isFunction)
{
if (!((AbstractJdbc1ResultSet)result).reallyResultSet())
if (!result.reallyResultSet())
throw new PSQLException("postgresql.call.noreturnval");
if (!result.next ())
throw new PSQLException ("postgresql.call.noreturnval");
@ -363,7 +376,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
}
else
{
return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
return (result != null && result.reallyResultSet());
}
}
@ -432,14 +445,14 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
m_sqlFragments[m_sqlFragments.length - 1] += (";" + endCurs);
}
result = org.postgresql.core.QueryExecutor.execute(m_sqlFragments,
result = QueryExecutor.execute(m_sqlFragments,
m_binds,
(java.sql.Statement)this);
this);
//If we are executing a callable statement function set the return data
if (isFunction)
{
if (!((AbstractJdbc1ResultSet)result).reallyResultSet())
if (!result.reallyResultSet())
throw new PSQLException("postgresql.call.noreturnval");
if (!result.next ())
throw new PSQLException ("postgresql.call.noreturnval");
@ -458,7 +471,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
}
else
{
return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
return (result != null && result.reallyResultSet());
}
}
@ -484,7 +497,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
*/
public void setCursorName(String name) throws SQLException
{
((AbstractJdbc1Connection)connection).setCursorName(name);
connection.setCursorName(name);
}
@ -502,9 +515,9 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
return -1;
if (isFunction)
return 1;
if (((AbstractJdbc1ResultSet)result).reallyResultSet())
if (result.reallyResultSet())
return -1;
return ((AbstractJdbc1ResultSet)result).getResultCount();
return result.getResultCount();
}
/*
@ -516,8 +529,8 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
*/
public boolean getMoreResults() throws SQLException
{
result = ((AbstractJdbc1ResultSet)result).getNext();
return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
result = (BaseResultSet) result.getNext();
return (result != null && result.reallyResultSet());
}
@ -532,7 +545,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
if (result == null)
return null;
return ((AbstractJdbc1ResultSet)result).getStatusString();
return result.getStatusString();
}
/*
@ -689,8 +702,8 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
*/
public java.sql.ResultSet getResultSet() throws SQLException
{
if (result != null && ((AbstractJdbc1ResultSet) result).reallyResultSet())
return result;
if (result != null && result.reallyResultSet())
return (ResultSet) result;
return null;
}
@ -715,7 +728,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
// If using server prepared statements deallocate them
if (m_useServerPrepare && m_statementName != null) {
((AbstractJdbc1Connection)connection).execSQL("DEALLOCATE " + m_statementName);
connection.execSQL("DEALLOCATE " + m_statementName);
}
// Disasociate it from us (For Garbage Collection)
@ -806,7 +819,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
/*
*
* The following methods are postgres extensions and are defined
* in the interface org.postgresql.Statement
* in the interface BaseStatement
*
*/
@ -819,7 +832,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
if (result == null)
return 0;
return (int)((AbstractJdbc1ResultSet)result).getLastOID();
return (int) result.getLastOID();
}
/*
@ -831,7 +844,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
if (result == null)
return 0;
return ((AbstractJdbc1ResultSet)result).getLastOID();
return result.getLastOID();
}
/*
@ -1522,9 +1535,6 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
/*
* This stores an Object into a parameter.
* <p>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: <oid>::<tablename>
// Note that postgres support for tablerow data types is incomplete/broken.
// This cannot be just a plain OID because then there would be ambiguity
// between when you want the oid itself and when you want the object
// an oid references.
bind(parameterIndex, Long.toString(x) + "::" + tablename, PG_TEXT );
}
/**
* this method will turn a string of the form
* {? = call <some_function> (?, [?,..]) }
@ -2056,7 +2050,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
//If turning server prepared statements off deallocate statement
//and reset statement name
if (m_useServerPrepare != flag && !flag)
((AbstractJdbc1Connection)connection).execSQL("DEALLOCATE " + m_statementName);
connection.execSQL("DEALLOCATE " + m_statementName);
m_statementName = null;
m_useServerPrepare = flag;
} else {

View File

@ -2,6 +2,9 @@ package org.postgresql.jdbc1;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc1CallableStatement extends AbstractJdbc1Statement implements java.sql.CallableStatement
{
@ -11,7 +14,7 @@ public class Jdbc1CallableStatement extends AbstractJdbc1Statement implements ja
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -3,10 +3,10 @@ package org.postgresql.jdbc1;
import java.util.Vector;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.core.Field;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.6 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.7 2003/03/07 18:39:44 barry Exp $
* This class implements the java.sql.Connection interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Connection

View File

@ -3,7 +3,7 @@ package org.postgresql.jdbc1;
import java.sql.*;
import java.util.*;
import org.postgresql.Field;
import org.postgresql.core.Field;
import org.postgresql.util.PSQLException;
public class Jdbc1DatabaseMetaData extends AbstractJdbc1DatabaseMetaData implements java.sql.DatabaseMetaData

View File

@ -2,6 +2,8 @@ package org.postgresql.jdbc1;
import java.sql.*;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc1PreparedStatement extends AbstractJdbc1Statement implements PreparedStatement
{
@ -11,7 +13,7 @@ public class Jdbc1PreparedStatement extends AbstractJdbc1Statement implements Pr
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -3,9 +3,10 @@ package org.postgresql.jdbc1;
import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.5 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.6 2003/03/07 18:39:44 barry Exp $
* This class implements the java.sql.ResultSet interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1ResultSet
@ -13,7 +14,7 @@ import org.postgresql.Field;
public class Jdbc1ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet implements java.sql.ResultSet
{
public Jdbc1ResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
public Jdbc1ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super(statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -1,8 +1,11 @@
package org.postgresql.jdbc1;
import java.util.Vector;
import org.postgresql.core.Field;
public class Jdbc1ResultSetMetaData extends AbstractJdbc1ResultSetMetaData implements java.sql.ResultSetMetaData
{
public Jdbc1ResultSetMetaData(java.util.Vector rows, org.postgresql.Field[] fields)
public Jdbc1ResultSetMetaData(Vector rows, Field[] fields)
{
super(rows, fields);
}

View File

@ -2,8 +2,11 @@ package org.postgresql.jdbc1;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.4 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.5 2003/03/07 18:39:44 barry Exp $
* This class implements the java.sql.Statement interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Statement
@ -16,7 +19,7 @@ public class Jdbc1Statement extends org.postgresql.jdbc1.AbstractJdbc1Statement
super(c);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -6,7 +6,6 @@ import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.PGConnection;
import org.postgresql.largeobject.*;

View File

@ -7,7 +7,6 @@ import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.PGConnection;
import org.postgresql.largeobject.*;

View File

@ -6,7 +6,7 @@ import java.net.ConnectException;
import java.sql.*;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.3 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.4 2003/03/07 18:39:44 barry Exp $
* This class defines methods of the jdbc2 specification. This class extends
* org.postgresql.jdbc1.AbstractJdbc1Connection which provides the jdbc1
* methods. The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection
@ -52,51 +52,6 @@ public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.Abstr
typemap = map;
}
public void cancelQuery() throws SQLException
{
org.postgresql.PG_Stream cancelStream = null;
try
{
cancelStream = new org.postgresql.PG_Stream(PG_HOST, PG_PORT);
}
catch (ConnectException cex)
{
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
throw new PSQLException ("postgresql.con.refused");
}
catch (IOException e)
{
throw new PSQLException ("postgresql.con.failed", e);
}
// Now we need to construct and send a cancel packet
try
{
cancelStream.SendInteger(16, 4);
cancelStream.SendInteger(80877102, 4);
cancelStream.SendInteger(pid, 4);
cancelStream.SendInteger(ckey, 4);
cancelStream.flush();
}
catch (IOException e)
{
throw new PSQLException("postgresql.con.failed", e);
}
finally
{
try
{
if (cancelStream != null)
cancelStream.close();
}
catch (IOException e)
{} // Ignore
}
}
/*
* This overides the standard internal getObject method so that we can
* check the jdbc2 type map first

View File

@ -5,7 +5,7 @@ import java.sql.*;
import java.util.*;
import org.postgresql.Driver;
import org.postgresql.Field;
import org.postgresql.core.Field;
import org.postgresql.util.PSQLException;
public abstract class AbstractJdbc2DatabaseMetaData extends org.postgresql.jdbc1.AbstractJdbc1DatabaseMetaData

View File

@ -8,14 +8,15 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import org.postgresql.Driver;
import org.postgresql.Field;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.core.Encoding;
import org.postgresql.largeobject.*;
import org.postgresql.util.PGbytea;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.14 2003/02/27 05:56:27 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.15 2003/03/07 18:39:45 barry Exp $
* This class defines methods of the jdbc2 specification. This class extends
* org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the jdbc1
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2ResultSet
@ -39,7 +40,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
private PreparedStatement selectStatement = null;
public AbstractJdbc2ResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
public AbstractJdbc2ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super (statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
@ -236,7 +237,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
if (i < 1 || i > fields.length)
throw new PSQLException("postgresql.res.colrange");
return (java.sql.Array) new org.postgresql.jdbc2.Array( connection, i, fields[i - 1], (java.sql.ResultSet) this );
return (java.sql.Array) new org.postgresql.jdbc2.Array( connection, i, fields[i - 1], this );
}
@ -414,7 +415,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
// This one needs some thought, as not all ResultSets come from a statement
public Statement getStatement() throws SQLException
{
return statement;
return (Statement) statement;
}
@ -1444,7 +1445,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
}
public void setStatement(Statement statement)
public void setStatement(BaseStatement statement)
{
this.statement = statement;
}

View File

@ -4,7 +4,7 @@ package org.postgresql.jdbc2;
import java.lang.*;
import java.sql.*;
import java.util.*;
import org.postgresql.*;
import org.postgresql.core.Field;
import org.postgresql.util.*;
public abstract class AbstractJdbc2ResultSetMetaData extends org.postgresql.jdbc1.AbstractJdbc1ResultSetMetaData

View File

@ -5,10 +5,11 @@ import java.io.*;
import java.math.*;
import java.sql.*;
import java.util.Vector;
import org.postgresql.Driver;
import org.postgresql.largeobject.*;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.11 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.12 2003/03/07 18:39:45 barry Exp $
* This class defines methods of the jdbc2 specification. This class extends
* org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
@ -23,8 +24,8 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
public AbstractJdbc2Statement (AbstractJdbc2Connection c)
{
super(c);
resultsettype = java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE;
concurrency = java.sql.ResultSet.CONCUR_READ_ONLY;
resultsettype = ResultSet.TYPE_SCROLL_INSENSITIVE;
concurrency = ResultSet.CONCUR_READ_ONLY;
}
public AbstractJdbc2Statement(AbstractJdbc2Connection connection, String sql) throws SQLException
@ -48,7 +49,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
boolean l_return = super.execute();
//Now do the jdbc2 specific stuff
//required for ResultSet.getStatement() to work and updateable resultsets
((AbstractJdbc2ResultSet)result).setStatement((Statement)this);
result.setStatement(this);
return l_return;
}
@ -118,12 +119,12 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
public void cancel() throws SQLException
{
((AbstractJdbc2Connection)connection).cancelQuery();
connection.cancelQuery();
}
public java.sql.Connection getConnection() throws SQLException
public Connection getConnection() throws SQLException
{
return (java.sql.Connection)connection;
return (Connection) connection;
}
public int getFetchDirection() throws SQLException
@ -131,11 +132,6 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
throw new PSQLException("postgresql.psqlnotimp");
}
public int getFetchSize() throws SQLException
{
return super.fetchSize;
}
public int getResultSetConcurrency() throws SQLException
{
return concurrency;
@ -150,7 +146,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
{
// I don't think this should happen, since it's a hint it should just
// fail quietly.
// throw org.postgresql.Driver.notImplemented();
// throw Driver.notImplemented();
}
public void setFetchSize(int rows) throws SQLException
@ -187,9 +183,9 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
batch.addElement(l_statement);
}
public java.sql.ResultSetMetaData getMetaData() throws SQLException
public ResultSetMetaData getMetaData() throws SQLException
{
java.sql.ResultSet rs = getResultSet();
ResultSet rs = getResultSet();
if (rs != null)
return rs.getMetaData();
@ -336,7 +332,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
public void setRef(int i, Ref x) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public void setDate(int i, java.sql.Date d, java.util.Calendar cal) throws SQLException
@ -376,7 +372,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
public java.sql.Array getArray(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException
@ -387,43 +383,43 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
public Blob getBlob(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public Clob getClob(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public Object getObject(int i, java.util.Map map) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public Ref getRef(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public Time getTime(int i, java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
public Timestamp getTimestamp(int i, java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}
// no custom types allowed yet..
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
throw Driver.notImplemented();
}

View File

@ -4,7 +4,10 @@ import java.text.*;
import java.sql.*;
import java.util.*;
import java.math.BigDecimal;
import org.postgresql.Field;
import org.postgresql.core.BaseConnection;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.util.*;
/*
@ -25,9 +28,9 @@ import org.postgresql.util.*;
public class Array implements java.sql.Array
{
private org.postgresql.PGConnection conn = null;
private org.postgresql.Field field = null;
private ResultSet rs;
private BaseConnection conn = null;
private Field field = null;
private BaseResultSet rs;
private int idx = 0;
private String rawString = null;
@ -39,14 +42,14 @@ public class Array implements java.sql.Array
* @param field the Field descriptor for the field to load into this Array
* @param rs the ResultSet from which to get the data for this Array
*/
public Array( org.postgresql.PGConnection conn, int idx, Field field, ResultSet rs )
public Array(BaseConnection conn, int idx, Field field, BaseResultSet rs )
throws SQLException
{
this.conn = conn;
this.field = field;
this.rs = rs;
this.idx = idx;
this.rawString = ((AbstractJdbc2ResultSet)rs).getFixedString(idx);
this.rawString = rs.getFixedString(idx);
}
public Object getArray() throws SQLException
@ -343,8 +346,8 @@ public class Array implements java.sql.Array
default:
throw org.postgresql.Driver.notImplemented();
}
java.sql.Statement stat = ((AbstractJdbc2Connection)conn).createStatement();
return ((AbstractJdbc2Statement)stat).createResultSet(fields, rows, "OK", 1, 0, false);
BaseStatement stat = (BaseStatement) conn.createStatement();
return (ResultSet) stat.createResultSet(fields, rows, "OK", 1, 0, false);
}
public String toString()

View File

@ -2,6 +2,9 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc2CallableStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.CallableStatement
{
@ -11,7 +14,7 @@ public class Jdbc2CallableStatement extends org.postgresql.jdbc2.AbstractJdbc2St
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -4,9 +4,9 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import java.util.Hashtable;
import org.postgresql.Field;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Connection.java,v 1.6 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Connection.java,v 1.7 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.Connection interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2Connection or one of it's parents

View File

@ -2,6 +2,9 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc2PreparedStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.PreparedStatement
{
@ -11,7 +14,7 @@ public class Jdbc2PreparedStatement extends org.postgresql.jdbc2.AbstractJdbc2St
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -3,9 +3,10 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.7 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.8 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.ResultSet interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2ResultSet or one of it's parents
@ -13,12 +14,12 @@ import org.postgresql.Field;
public class Jdbc2ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet implements java.sql.ResultSet
{
public Jdbc2ResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
public Jdbc2ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super(statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
public java.sql.ResultSetMetaData getMetaData() throws SQLException
public ResultSetMetaData getMetaData() throws SQLException
{
return new Jdbc2ResultSetMetaData(rows, fields);
}

View File

@ -1,8 +1,11 @@
package org.postgresql.jdbc2;
import java.util.Vector;
import org.postgresql.core.Field;
public class Jdbc2ResultSetMetaData extends AbstractJdbc2ResultSetMetaData implements java.sql.ResultSetMetaData
{
public Jdbc2ResultSetMetaData(java.util.Vector rows, org.postgresql.Field[] fields)
public Jdbc2ResultSetMetaData(Vector rows, Field[] fields)
{
super(rows, fields);
}

View File

@ -2,8 +2,11 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Statement.java,v 1.4 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Statement.java,v 1.5 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.Statement interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2Statement or one of it's parents
@ -16,7 +19,7 @@ public class Jdbc2Statement extends org.postgresql.jdbc2.AbstractJdbc2Statement
super(c);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -3,8 +3,11 @@ package org.postgresql.jdbc3;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3ResultSet.java,v 1.3 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3ResultSet.java,v 1.4 2003/03/07 18:39:45 barry Exp $
* This class defines methods of the jdbc3 specification. This class extends
* org.postgresql.jdbc2.AbstractJdbc2ResultSet which provides the jdbc2
* methods. The real Statement class (for jdbc3) is org.postgresql.jdbc3.Jdbc3ResultSet
@ -12,7 +15,7 @@ import java.util.Vector;
public abstract class AbstractJdbc3ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet
{
public AbstractJdbc3ResultSet(Statement statement, org.postgresql.Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
public AbstractJdbc3ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super (statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -2,6 +2,9 @@ package org.postgresql.jdbc3;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc3CallableStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.CallableStatement
{
@ -11,7 +14,7 @@ public class Jdbc3CallableStatement extends org.postgresql.jdbc3.AbstractJdbc3St
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -4,9 +4,9 @@ package org.postgresql.jdbc3;
import java.sql.*;
import java.util.Vector;
import java.util.Hashtable;
import org.postgresql.Field;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Connection.java,v 1.3 2003/02/04 09:20:10 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Connection.java,v 1.4 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.Connection interface for JDBC3.
* However most of the implementation is really done in
* org.postgresql.jdbc3.AbstractJdbc3Connection or one of it's parents

View File

@ -2,6 +2,8 @@ package org.postgresql.jdbc3;
import java.sql.*;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
public class Jdbc3PreparedStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.PreparedStatement
{
@ -11,7 +13,7 @@ public class Jdbc3PreparedStatement extends org.postgresql.jdbc3.AbstractJdbc3St
super(connection, sql);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -3,9 +3,10 @@ package org.postgresql.jdbc3;
import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
import org.postgresql.core.Field;
import org.postgresql.core.BaseStatement;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3ResultSet.java,v 1.4 2003/02/04 09:20:11 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3ResultSet.java,v 1.5 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.ResultSet interface for JDBC3.
* However most of the implementation is really done in
* org.postgresql.jdbc3.AbstractJdbc3ResultSet or one of it's parents
@ -13,7 +14,7 @@ import org.postgresql.Field;
public class Jdbc3ResultSet extends org.postgresql.jdbc3.AbstractJdbc3ResultSet implements java.sql.ResultSet
{
public Jdbc3ResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
public Jdbc3ResultSet(BaseStatement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super(statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -1,9 +1,11 @@
package org.postgresql.jdbc3;
import org.postgresql.core.Field;
public class Jdbc3ResultSetMetaData extends org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData implements java.sql.ResultSetMetaData
{
public Jdbc3ResultSetMetaData(java.util.Vector rows, org.postgresql.Field[] fields)
public Jdbc3ResultSetMetaData(java.util.Vector rows, Field[] fields)
{
super(rows, fields);
}

View File

@ -2,8 +2,11 @@ package org.postgresql.jdbc3;
import java.sql.*;
import java.util.Vector;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.3 2003/02/04 09:20:11 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.4 2003/03/07 18:39:45 barry Exp $
* This class implements the java.sql.Statement interface for JDBC3.
* However most of the implementation is really done in
* org.postgresql.jdbc3.AbstractJdbc3Statement or one of it's parents
@ -16,7 +19,7 @@ public class Jdbc3Statement extends org.postgresql.jdbc3.AbstractJdbc3Statement
super(c);
}
public java.sql.ResultSet createResultSet (org.postgresql.Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
public BaseResultSet createResultSet (Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}

View File

@ -1,14 +1,21 @@
/*-------------------------------------------------------------------------
*
* BlobInputStream.java
* This is an implementation of an InputStream from a large object.
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/BlobInputStream.java,v 1.5 2003/03/07 18:39:45 barry Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.largeobject;
import java.io.InputStream;
import java.io.IOException;
import java.sql.SQLException;
/*
* This is an initial implementation of an InputStream from a large object.
* For now, the bare minimum is implemented. Later (after 7.1) we will overide
* the other read methods to optimise them.
*/
public class BlobInputStream extends InputStream
{
/*

View File

@ -1,12 +1,21 @@
/*-------------------------------------------------------------------------
*
* BlobOutputStream.java
* This implements a basic output stream that writes to a LargeObject
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/BlobOutputStream.java,v 1.6 2003/03/07 18:39:45 barry Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.largeobject;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
/*
* This implements a basic output stream that writes to a LargeObject
*/
public class BlobOutputStream extends OutputStream
{
/*

View File

@ -1,17 +1,26 @@
/*-------------------------------------------------------------------------
*
* LargeObject.java
* This class implements the large object interface to org.postgresql.
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/LargeObject.java,v 1.10 2003/03/07 18:39:45 barry Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.largeobject;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.postgresql.fastpath.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.fastpath.FastpathArg;
/*
* This class implements the large object interface to org.postgresql.
*
* <p>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

View File

@ -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();
* </pre>
*
* <p>Normally, client code would use the getAsciiStream, getBinaryStream,
@ -43,13 +59,6 @@ import org.postgresql.util.*;
* <p>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
//

View File

@ -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 );

View File

@ -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;
}

View File

@ -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());
}
}
}

View File

@ -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)

View File

@ -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.*;

View File

@ -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
{

View File

@ -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
{

View File

@ -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)

View File

@ -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
*
* <p>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;

View File

@ -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.
*
* <p>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

View File

@ -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;

View File

@ -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.<p>
*
* 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.<p>
*
* 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:<br>
* CREATE TABLE myclass( var1 TEXT, var2 INTEGER );<br>
* CREATE TABLE othertable( field1 TEXT, field2 myclass );<br>
* INSERT INTO myclass VALUES ('Hello', 1);<br>
* INSERT INTO othertable VALUES ('World', xxxx::myclass);<br>
* where xxxx is the OID of a row in myclass<br>
* 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.<p>
*
* Queries like:<br>
* SELECT othertable.field2.var1 FROM othertable;<br>
* will not work but were suggested in the original Postgres
* design documents.<p>
* 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:<br>
* CREATE othertable( field1 TEXT, field2 myclass, myclassOID oid);<br>
* 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.<p>
*
* 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.<p>
*
* There are a number of limitations placed on the java class to be
* used by Serialize:
* <ul>
* <li>The class name must be less than 64 chars long and must be all lowercase.
* This is due to limitations in Postgres about the size of table names.
* The name must be all lowercase since table names in Postgres are
* case insensitive and the relname is stored in lowercase. Unless some
* additional table were to be maintained about the names of java classes,
* there is no way to know how to go from a Postgres table name back to
* a java class name with knowledge of case of the letters in the name.
* <li>The class name must not contain the underscore '_' character since
* any dots in a java class name are converted to an underscore in
* its table name and vice versa going back.
* <li>The class should only contain java primitive types and String.
* Support for recursively "serializing" a class is not tested but
* some code for this does exist and you may wish to take a look at it.
* <li>Only the public fields of the class will be stored in and fetched from
* the database. Protected and private fields are ignored.
* <li>Must have a no-arg constructor so that Class.newInstance() may
* instantiate the class in fetch().
* <li>Should implement the Serializable interface. This interface
* may be used more in future releases or in providing an alternative
* method of storing the java classes in the database. The Serializable
* interface allows a class instance to be written out as a binary
* stream of data and is a standard java feature.
* <li>The class should contain a field defined as:<br>
* int oid = 0;<br>
* This field is actually optional and its use by jdbc2.PreparedStatement.setObject()
* is as follows:<br>
* 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.<p>
* </ul>
*
* Suggested usage:
* <ol>
* <li>Create your javaclass and include an int oid = 0; field.
* <li>Run Serialize.create( conn, javaclass ) to create the table for javaclass (once).
* <li>Create mytable in the database with fields like: jclassoid INTEGER, jclass JAVACLASS<br>
* <li>Use a jdbc2.PreparedStatement to insert, update, or select from mytable.
* Use setObject(2, jclass), followed by setInt(1, jclass.oid) to setup an insert.
* <li>Use jclass.oid and jclassoid to do queries since the jclass field cannot be used
* for anything but fetching the javaclass instance with getObject("jclass").
* </ol>
* 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.<p>
* 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.<p>
*
* 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
* _<p>
*
* Because of this, a Class name may not have _ in the name.<p>
* 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 _ <p>
*
* @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
* .<p>
*
* @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('_', '.');
}
}

View File

@ -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
*
* <P>Contains static methods to encrypt and compare
* passwords with Unix encrypted passwords.</P>
*
* <P>See <A HREF="http://www.zeh.com/local/jfd/crypt.html">
* John Dumas's Java Crypt page</A> for the original source.</P>
*