1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-28 18:48:04 +03:00

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