From b3dd55c6517a6a9f531a7bab463e9bcf6291aa9b Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Wed, 14 Aug 2002 20:35:40 +0000 Subject: [PATCH] Added support for JDBC3. The driver will now build under JDBC3 (i.e. Java 1.4). This concludes my changes that restructured the code to support JDBC3. The jdbc unit tests were also resturctured to allow different tests between jdbc2 and jdbc3, although currently make check (aka ant test) for JDBC3 just runs the JDBC2 tests. Of special note the largeobject/PGblob and PGclob classes have been moved under the jdbc2/jdbc3 specific directories as they now differ by jdbc version. Also note that this checkin removes the PostgresqlDataSource and files in the xa directory. A recent checkin has added new datasource support that replaces the functionality provided by these classes. Modified Files: jdbc/build.xml 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/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/Jdbc2DatabaseMetaData.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/test/jdbc2/BatchExecuteTest.java jdbc/org/postgresql/test/jdbc2/BlobTest.java jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java jdbc/org/postgresql/test/jdbc2/ConnectionTest.java jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java jdbc/org/postgresql/test/jdbc2/DateTest.java jdbc/org/postgresql/test/jdbc2/DriverTest.java jdbc/org/postgresql/test/jdbc2/JBuilderTest.java jdbc/org/postgresql/test/jdbc2/MiscTest.java jdbc/org/postgresql/test/jdbc2/ResultSetTest.java jdbc/org/postgresql/test/jdbc2/TimeTest.java jdbc/org/postgresql/test/jdbc2/TimestampTest.java jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java Added Files: jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java jdbc/org/postgresql/jdbc2/Jdbc2Blob.java jdbc/org/postgresql/jdbc2/Jdbc2Clob.java jdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java jdbc/org/postgresql/jdbc3/AbstractJdbc3Clob.java jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java jdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java jdbc/org/postgresql/jdbc3/Jdbc3Blob.java jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java jdbc/org/postgresql/jdbc3/Jdbc3Clob.java jdbc/org/postgresql/jdbc3/Jdbc3Connection.java jdbc/org/postgresql/jdbc3/Jdbc3DatabaseMetaData.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/test/TestUtil.java jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java Removed Files: jdbc/org/postgresql/PostgresqlDataSource.java jdbc/org/postgresql/largeobject/PGblob.java jdbc/org/postgresql/largeobject/PGclob.java jdbc/org/postgresql/test/JDBC2Tests.java jdbc/org/postgresql/xa/ClientConnection.java jdbc/org/postgresql/xa/TwoPhaseConnection.java jdbc/org/postgresql/xa/TxConnection.java jdbc/org/postgresql/xa/XAConnectionImpl.java jdbc/org/postgresql/xa/XADataSourceImpl.java --- src/interfaces/jdbc/build.xml | 86 +- .../org/postgresql/PostgresqlDataSource.java | 605 -------- .../jdbc1/AbstractJdbc1DatabaseMetaData.java | 1 + .../jdbc1/AbstractJdbc1ResultSet.java | 3 +- .../jdbc1/AbstractJdbc1ResultSetMetaData.java | 1 + .../AbstractJdbc2Blob.java} | 21 +- .../AbstractJdbc2Clob.java} | 20 +- .../jdbc2/AbstractJdbc2ResultSet.java | 15 +- .../jdbc/org/postgresql/jdbc2/Array.java | 20 +- .../jdbc/org/postgresql/jdbc2/Jdbc2Blob.java | 12 + .../jdbc2/Jdbc2CallableStatement.java | 2 +- .../jdbc/org/postgresql/jdbc2/Jdbc2Clob.java | 12 + .../jdbc2/Jdbc2DatabaseMetaData.java | 2 +- .../jdbc2/Jdbc2PreparedStatement.java | 2 +- .../org/postgresql/jdbc2/Jdbc2ResultSet.java | 10 +- .../postgresql/jdbc3/AbstractJdbc3Blob.java | 90 ++ .../postgresql/jdbc3/AbstractJdbc3Clob.java | 107 ++ .../jdbc3/AbstractJdbc3Connection.java | 369 +++++ .../jdbc3/AbstractJdbc3DatabaseMetaData.java | 339 +++++ .../jdbc3/AbstractJdbc3ResultSet.java | 181 +++ .../jdbc3/AbstractJdbc3Statement.java | 1300 +++++++++++++++++ .../jdbc/org/postgresql/jdbc3/Jdbc3Blob.java | 14 + .../jdbc3/Jdbc3CallableStatement.java | 15 + .../jdbc/org/postgresql/jdbc3/Jdbc3Clob.java | 12 + .../org/postgresql/jdbc3/Jdbc3Connection.java | 61 + .../jdbc3/Jdbc3DatabaseMetaData.java | 12 + .../jdbc3/Jdbc3PreparedStatement.java | 15 + .../org/postgresql/jdbc3/Jdbc3ResultSet.java | 35 + .../jdbc3/Jdbc3ResultSetMetaData.java | 12 + .../org/postgresql/jdbc3/Jdbc3Statement.java | 19 + .../test/{JDBC2Tests.java => TestUtil.java} | 77 +- .../test/jdbc2/BatchExecuteTest.java | 10 +- .../org/postgresql/test/jdbc2/BlobTest.java | 18 +- .../test/jdbc2/CallableStmtTest.java | 6 +- .../postgresql/test/jdbc2/ConnectionTest.java | 44 +- .../test/jdbc2/DatabaseMetaDataTest.java | 40 +- .../org/postgresql/test/jdbc2/DateTest.java | 30 +- .../org/postgresql/test/jdbc2/DriverTest.java | 8 +- .../postgresql/test/jdbc2/JBuilderTest.java | 20 +- .../postgresql/test/jdbc2/Jdbc2TestSuite.java | 70 + .../org/postgresql/test/jdbc2/MiscTest.java | 18 +- .../postgresql/test/jdbc2/ResultSetTest.java | 10 +- .../org/postgresql/test/jdbc2/TimeTest.java | 26 +- .../postgresql/test/jdbc2/TimestampTest.java | 44 +- .../test/jdbc2/UpdateableResultTest.java | 14 +- .../postgresql/test/jdbc3/Jdbc3TestSuite.java | 23 + .../org/postgresql/xa/ClientConnection.java | 567 ------- .../org/postgresql/xa/TwoPhaseConnection.java | 116 -- .../jdbc/org/postgresql/xa/TxConnection.java | 129 -- .../org/postgresql/xa/XAConnectionImpl.java | 956 ------------ .../org/postgresql/xa/XADataSourceImpl.java | 489 ------- 51 files changed, 2955 insertions(+), 3153 deletions(-) delete mode 100644 src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java rename src/interfaces/jdbc/org/postgresql/{largeobject/PGblob.java => jdbc2/AbstractJdbc2Blob.java} (62%) rename src/interfaces/jdbc/org/postgresql/{largeobject/PGclob.java => jdbc2/AbstractJdbc2Clob.java} (64%) create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Clob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Blob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Clob.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Connection.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3DatabaseMetaData.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSetMetaData.java create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java rename src/interfaces/jdbc/org/postgresql/test/{JDBC2Tests.java => TestUtil.java} (59%) create mode 100644 src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java create mode 100644 src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java delete mode 100644 src/interfaces/jdbc/org/postgresql/xa/ClientConnection.java delete mode 100644 src/interfaces/jdbc/org/postgresql/xa/TwoPhaseConnection.java delete mode 100644 src/interfaces/jdbc/org/postgresql/xa/TxConnection.java delete mode 100644 src/interfaces/jdbc/org/postgresql/xa/XAConnectionImpl.java delete mode 100644 src/interfaces/jdbc/org/postgresql/xa/XADataSourceImpl.java diff --git a/src/interfaces/jdbc/build.xml b/src/interfaces/jdbc/build.xml index 845a7e3632..80f9ca9b63 100644 --- a/src/interfaces/jdbc/build.xml +++ b/src/interfaces/jdbc/build.xml @@ -6,7 +6,7 @@ This file now requires Ant 1.4.1. 2002-04-18 - $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.27 2002/07/30 13:22:02 davec Exp $ + $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.28 2002/08/14 20:35:39 barry Exp $ --> @@ -46,6 +46,25 @@ + + + + + + + + + + + + + + + + + + + @@ -89,18 +108,10 @@ - - - + - - - - - - - + @@ -128,8 +139,15 @@ - - + + + + + + + + + @@ -222,14 +240,31 @@ - + + + + - - + + + + + + + + + + + + + + + + - + @@ -240,4 +275,21 @@ + + + + + + + + + + + + + + + + + diff --git a/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java b/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java deleted file mode 100644 index 3b37f790cf..0000000000 --- a/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java +++ /dev/null @@ -1,605 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: PostgresqlDataSource.java,v 1.5 2001/11/19 23:16:45 momjian Exp $ -*/ - - -package org.postgresql; - - -import java.io.PrintWriter; -import java.io.Serializable; -import java.util.Properties; -import java.util.Hashtable; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.DriverManager; -import java.rmi.Remote; -import javax.sql.DataSource; -import javax.naming.Referenceable; -import javax.naming.Reference; -import javax.naming.StringRefAddr; -import javax.naming.RefAddr; -import javax.naming.Context; -import javax.naming.Name; -import javax.naming.NamingException; -import javax.naming.spi.ObjectFactory; -// FIXME -//import postgresql.util.PSQLException; -//import postgresql.xa.XADataSourceImpl; -import org.postgresql.util.PSQLException; -import org.postgresql.xa.XADataSourceImpl; -//--------- - -/* - * Implements a JDBC 2.0 {@link javax.sql.DataSource} for the - * PostgreSQL driver with JNDI persistance support. XA and pooled - * connection support is also available, but the application must - * used the designated DataSource interface to obtain them. - *

- * The supported data source properties are: - *

- * description		   (optional)
- * databaseName		   (required)
- * loginTimeout		   (optional)
- * user				   (optional)
- * password			   (optional)
- * serverName		   (optional)
- * portNumber		   (optional)
- * transactionTimeout  (optional for XA connections)
- * 
- * This data source may be serialized and stored in a JNDI - * directory. Example of how to create a new data source and - * register it with JNDI: - *
- * PostgresqlDataSource ds;
- * InitialContext		ctx;
- *
- * ds = new PostgresqlDataSource();
- * ds.setDatabaseName( "test" );
- * ds.setUser( "me" );
- * ds.setPassword( "secret" );
- * ctx = new InitialContext();
- * ctx.rebind( "/comp/jdbc/test", ds );
- * 
- * Example for obtaining the data source from JNDI and - * opening a new connections: - *
- * InitialContext		ctx;
- * DataSource			ds;
- *
- * ctx = new InitialContext();
- * ds = (DataSource) ctx.lookup( "/comp/jdbc/test" );
- * ds.getConnection();
- * 
- * - * - * @author Assaf Arkin - * @version 1.0 - * @see XADataSourceImpl - * @see DataSource - * @see Connection - */ -public class PostgresqlDataSource - extends XADataSourceImpl - implements DataSource, Referenceable, - ObjectFactory, Serializable -{ - - - /* - * Holds the timeout for opening a new connection, specified - * in seconds. The default is obtained from the JDBC driver. - */ - private int _loginTimeout; - - /* - * Holds the user's account name. - */ - private String _user; - - /* - * Holds the database password. - */ - private String _password; - - /* - * Holds the name of the particular database on the server. - */ - private String _databaseName; - - /* - * Description of this datasource. - */ - private String _description = "PostgreSQL DataSource"; - - /* - * Holds the database server name. If null, this is - * assumed to be the localhost. - */ - private String _serverName; - - /* - * Holds the port number where a server is listening. - * The default value will open a connection with an - * unspecified port. - */ - private int _portNumber = DEFAULT_PORT; - - /* - * The default port number. Since we open the connection - * without specifying the port if it's the default one, - * this value can be meaningless. - */ - private static final int DEFAULT_PORT = 0; - - /* - * Holds the log writer to which all messages should be - * printed. The default writer is obtained from the driver - * manager, but it can be specified at the datasource level - * and will be passed to the driver. May be null. - */ - private transient PrintWriter _logWriter; - - /* - * Each datasource maintains it's own driver, in case of - * driver-specific setup (e.g. pools, log writer). - */ - // FIXME - // private transient postgresql.Driver _driver; - private transient org.postgresql.Driver _driver; - - public PostgresqlDataSource() - { - _logWriter = DriverManager.getLogWriter(); - _loginTimeout = DriverManager.getLoginTimeout(); - } - - - public Connection getConnection() - throws SQLException - { - // Uses the username and password specified for the datasource. - return getConnection( _user, _password ); - } - - - public synchronized Connection getConnection( String user, String password ) - throws SQLException - { - Connection conn; - Properties info; - String url; - - if ( _driver == null ) - { - try - { - // Constructs a driver for use just by this data source - // which will produce TwoPhaseConnection-s. This driver - // is not registered with the driver manager. - // FIXME - // _driver = new postgresql.Driver(); - _driver = new org.postgresql.Driver(); - - //FIXME - // _driver.setLogWriter( _logWriter ); - // Method seems to be unavailable. Just commented it out. - } - catch ( SQLException except ) - { - if ( _logWriter != null ) - _logWriter.println( "DataSource: Failed to initialize JDBC driver: " + except ); - throw except; - } - } - - // Use info to supply properties that are not in the URL. - info = new Properties(); - info.put( "loginTimeout", Integer.toString( _loginTimeout ) ); - - // DriverManager will do that and not rely on the URL alone. - if ( user == null ) - { - user = _user; - password = _password; - } - if ( user == null || password == null ) - throw new PSQLException( "postgresql.ds.userpswd" ); - info.put( "user", user ); - info.put( "password", password ); - - if ( _serverName != null ) - info.put( "PGHOST", _serverName ); - if ( _portNumber != DEFAULT_PORT ) - info.put( "PGPORT", Integer.toString( _portNumber ) ); - if ( _databaseName != null ) - info.put( "PGDBNAME", _databaseName ); - - // Construct the URL suitable for this driver. - url = "jdbc:postgresql:"; - - // Attempt to establish a connection. Report a successful - // attempt or a failure. - try - { - conn = _driver.connect( url, info ); - // FIXME - // if ( ! ( conn instanceof postgresql.jdbc2.Connection ) ) { - if ( ! ( conn instanceof org.postgresql.jdbc2.Connection ) ) - { - if ( _logWriter != null ) - _logWriter.println( "DataSource: JDBC 1 connections not supported" ); - throw new PSQLException( "postgresql.ds.onlyjdbc2" ); - } - } - catch ( SQLException except ) - { - if ( _logWriter != null ) - _logWriter.println( "DataSource: getConnection failed " + except ); - throw except; - } - if ( conn != null && _logWriter != null ) - _logWriter.println( "DataSource: getConnection returning " + conn ); - return conn; - } - - - public PrintWriter getLogWriter() - { - return _logWriter; - } - - - public synchronized void setLogWriter( PrintWriter writer ) - { - // Once a log writer has been set, we cannot set it since some - // thread might be conditionally accessing it right now without - // synchronizing. - if ( writer != null ) - { - if ( _driver != null ) - // FIXME - // _driver.setLogWriter( writer ); - // Method seems to be unavailable. Commented it out. - _logWriter = writer; - } - } - - - public void setLoginTimeout( int seconds ) - { - _loginTimeout = seconds; - } - - - public synchronized int getLoginTimeout() - { - return _loginTimeout; - } - - - /* - * Sets the name of the particular database on the server. - * The standard name for this property is databaseName. - * - * @param databaseName The name of the particular database on the server - */ - public synchronized void setDatabaseName( String databaseName ) - { - if ( databaseName == null ) - throw new NullPointerException( "DataSource: Argument 'databaseName' is null" ); - _databaseName = databaseName; - } - - - /* - * Returns the name of the particular database on the server. - * The standard name for this property is databaseName. - * - * @return The name of the particular database on the server - */ - public String getDatabaseName() - { - return _databaseName; - } - - - /* - * Sets the description of this datasource. - * The standard name for this property is description. - * - * @param description The description of this datasource - */ - public synchronized void setDescription( String description ) - { - if ( description == null ) - throw new NullPointerException( "DataSource: Argument 'description' is null" ); - _description = description; - } - - - /* - * Returns the description of this datasource. - * The standard name for this property is description. - * - * @return The description of this datasource - */ - public String getDescription() - { - return _description; - } - - - /* - * Sets the database password. - * The standard name for this property is password. - * - * @param password The database password - */ - public synchronized void setPassword( String password ) - { - _password = password; - } - - - /* - * Returns the database password. - * The standard name for this property is password. - * - * @return The database password - */ - public String getPassword() - { - return _password; - } - - - /* - * Sets the port number where a server is listening. - * The standard name for this property is portNumber. - * - * @param portNumber The port number where a server is listening - */ - public synchronized void setPortNumber( int portNumber ) - { - _portNumber = portNumber; - } - - - /* - * Returns the port number where a server is listening. - * The standard name for this property is portNumber. - * - * @return The port number where a server is listening - */ - public int getPortNumber() - { - return _portNumber; - } - - - /* - * Sets the database server name. - - * The standard name for this property is serverName. - * - * @param serverName The database server name - */ - public synchronized void setServerName( String serverName ) - { - _serverName = serverName; - } - - - /* - * Returns the database server name. - * The standard name for this property is serverName. - * - * @return The database server name - */ - public String getServerName() - { - return _serverName; - } - - - /* - * Sets the user's account name. - * The standard name for this property is user. - * - * @param user The user's account name - */ - public synchronized void setUser( String user ) - { - _user = user; - } - - - /* - * Returns the user's account name. - * The standard name for this property is user. - * - * @return The user's account name - */ - public String getUser() - { - return _user; - } - - - /* - * Returns true if this datasource and the other are equal. - * The two datasources are equal if and only if they will produce - * the exact same connections. Connection properties like database - * name, user name, etc are comapred. Setup properties like - * description, log writer, etc are not compared. - */ - public synchronized boolean equals( Object other ) - { - if ( other == this ) - return true; - if ( other == null || ! ( other instanceof PostgresqlDataSource ) ) - return false; - - PostgresqlDataSource with; - - with = (PostgresqlDataSource) other; - if ( _databaseName != null && _databaseName.equals( with._databaseName ) ) - if ( _portNumber == with._portNumber && - ( ( _serverName == null && with._serverName == null ) || - ( _serverName != null && _serverName.equals( with._serverName ) ) ) ) - if ( ( _user == null && with._user == null ) || - ( _user != null && _password != null && _user.equals( with._user ) && - _password.equals( with._password ) ) ) - return true; - return false; - } - - - public String toString() - { - if ( _description != null ) - return _description; - else - { - String url; - - url = "jdbc:postgresql:"; - if ( _serverName != null ) - { - if ( _portNumber == DEFAULT_PORT ) - url = url + "//" + _serverName + "/"; - else - url = url + "//" + _serverName + ":" + _portNumber + "/"; - } - else if ( _portNumber != DEFAULT_PORT ) - url = url + "//localhost:" + _portNumber + "/"; - if ( _databaseName != null ) - url = url + _databaseName; - return "DataSource " + url; - } - } - - - public synchronized Reference getReference() - { - Reference ref; - - // We use same object as factory. - ref = new Reference( getClass().getName(), getClass().getName(), null ); - // Mandatory properties - ref.add( new StringRefAddr( "description", _description ) ); - ref.add( new StringRefAddr( "databaseName", _databaseName ) ); - ref.add( new StringRefAddr( "loginTimeout", Integer.toString( _loginTimeout ) ) ); - // Optional properties - if ( _user != null ) - ref.add( new StringRefAddr( "user", _user ) ); - if ( _password != null ) - ref.add( new StringRefAddr( "password", _password ) ); - if ( _serverName != null ) - ref.add( new StringRefAddr( "serverName", _serverName ) ); - if ( _portNumber != DEFAULT_PORT ) - ref.add( new StringRefAddr( "portNumber", Integer.toString( _portNumber ) ) ); - ref.add( new StringRefAddr( "transactionTimeout", Integer.toString( getTransactionTimeout() ) ) ); - return ref; - } - - - public Object getObjectInstance( Object refObj, Name name, Context nameCtx, Hashtable env ) - throws NamingException - { - Reference ref; - - // Can only reconstruct from a reference. - if ( refObj instanceof Reference ) - { - ref = (Reference) refObj; - // Make sure reference is of datasource class. - if ( ref.getClassName().equals( getClass().getName() ) ) - { - - PostgresqlDataSource ds; - RefAddr addr; - - try - { - ds = (PostgresqlDataSource) Class.forName( ref.getClassName() ).newInstance(); - } - catch ( Exception except ) - { - throw new NamingException( except.toString() ); - } - // Mandatory properties - ds._description = (String) ref.get( "description" ).getContent(); - ds._databaseName = (String) ref.get( "databaseName" ).getContent(); - ds._loginTimeout = Integer.parseInt( (String) ref.get( "loginTimeout" ).getContent() ); - // Optional properties - addr = ref.get( "user" ); - if ( addr != null ) - ds._user = (String) addr.getContent(); - addr = ref.get( "password" ); - if ( addr != null ) - ds._password = (String) addr.getContent(); - addr = ref.get( "serverName" ); - if ( addr != null ) - ds._serverName = (String) addr.getContent(); - addr = ref.get( "portNumber" ); - if ( addr != null ) - ds._portNumber = Integer.parseInt( (String) addr.getContent() ); - addr = ref.get( "transactionTimeout" ); - if ( addr != null ) - setTransactionTimeout( Integer.parseInt( (String) addr.getContent() ) ); - return ds; - - } - else - throw new NamingException( "DataSource: Reference not constructed from class " + getClass().getName() ); - } - else if ( refObj instanceof Remote ) - return refObj; - else - return null; - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java index 3fd64c8c36..6a8d20d669 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java @@ -8,6 +8,7 @@ import org.postgresql.util.PSQLException; public abstract class AbstractJdbc1DatabaseMetaData { + protected AbstractJdbc1Connection connection; // The connection association // These define various OID's. Hopefully they will stay constant. diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java index 3bb278a8e9..e3e75c1e19 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java @@ -13,13 +13,14 @@ import org.postgresql.largeobject.*; import org.postgresql.util.PGbytea; import org.postgresql.util.PSQLException; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.2 2002/07/25 22:45:27 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.3 2002/08/14 20:35:39 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 { + protected Vector rows; // The results protected Statement statement; protected Field fields[]; // The field descriptions diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSetMetaData.java index 2a598d3c39..bed9cc27e1 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSetMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSetMetaData.java @@ -10,6 +10,7 @@ import java.sql.Types; public abstract class AbstractJdbc1ResultSetMetaData { + protected Vector rows; protected Field[] fields; diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/PGblob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java similarity index 62% rename from src/interfaces/jdbc/org/postgresql/largeobject/PGblob.java rename to src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java index 87c1ac2477..cb6c5b01dc 100644 --- a/src/interfaces/jdbc/org/postgresql/largeobject/PGblob.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java @@ -1,10 +1,4 @@ -package org.postgresql.largeobject; - -// IMPORTANT NOTE: This file implements the JDBC 2 version of the driver. -// If you make any modifications to this file, you must make sure that the -// changes are also made (if relevent) to the related JDBC 1 class in the -// org.postgresql.jdbc1 package. - +package org.postgresql.jdbc2; import java.lang.*; import java.io.*; @@ -13,22 +7,15 @@ import java.text.*; import java.util.*; import java.sql.*; import org.postgresql.Field; -import org.postgresql.largeobject.*; +import org.postgresql.PGConnection; import org.postgresql.largeobject.*; -/* - * This implements the Blob interface, which is basically another way to - * access a LargeObject. - * - * $Id: PGblob.java,v 1.4 2002/07/23 03:59:55 barry Exp $ - * - */ -public class PGblob implements java.sql.Blob +public abstract class AbstractJdbc2Blob { private int oid; private LargeObject lo; - public PGblob(org.postgresql.PGConnection conn, int oid) throws SQLException + public AbstractJdbc2Blob(PGConnection conn, int oid) throws SQLException { this.oid = oid; LargeObjectManager lom = conn.getLargeObjectAPI(); diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/PGclob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java similarity index 64% rename from src/interfaces/jdbc/org/postgresql/largeobject/PGclob.java rename to src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java index 71c3f8a2f0..c185bb4f4f 100644 --- a/src/interfaces/jdbc/org/postgresql/largeobject/PGclob.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Clob.java @@ -1,9 +1,4 @@ -package org.postgresql.largeobject; - -// IMPORTANT NOTE: This file implements the JDBC 2 version of the driver. -// If you make any modifications to this file, you must make sure that the -// changes are also made (if relevent) to the related JDBC 1 class in the -// org.postgresql.jdbc1 package. +package org.postgresql.jdbc2; import java.lang.*; @@ -13,22 +8,15 @@ import java.text.*; import java.util.*; import java.sql.*; import org.postgresql.Field; -import org.postgresql.largeobject.*; +import org.postgresql.PGConnection; import org.postgresql.largeobject.*; -/* - * This implements the Blob interface, which is basically another way to - * access a LargeObject. - * - * $Id: PGclob.java,v 1.4 2002/07/23 03:59:55 barry Exp $ - * - */ -public class PGclob implements java.sql.Clob +public class AbstractJdbc2Clob { private int oid; private LargeObject lo; - public PGclob(org.postgresql.PGConnection conn, int oid) throws SQLException + public AbstractJdbc2Clob(PGConnection conn, int oid) throws SQLException { this.oid = oid; LargeObjectManager lom = conn.getLargeObjectAPI(); diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index 1a6379bf59..3b493de2f4 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java @@ -15,12 +15,13 @@ import org.postgresql.util.PGbytea; import org.postgresql.util.PSQLException; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.3 2002/07/25 22:45:28 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.4 2002/08/14 20:35:39 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 */ -public class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet { +public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet { + protected String sqlQuery = null; //needed for updateable result set support @@ -237,9 +238,7 @@ public class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1Re } - public Blob getBlob(int i) throws SQLException { - return new org.postgresql.largeobject.PGblob(connection, getInt(i)); - } + public abstract Blob getBlob(int i) throws SQLException; public java.io.Reader getCharacterStream(String columnName) throws SQLException { @@ -276,9 +275,7 @@ public class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1Re } - public Clob getClob(int i) throws SQLException { - return new org.postgresql.largeobject.PGclob(connection, getInt(i)); - } + public abstract Clob getClob(int i) throws SQLException; public int getConcurrency() throws SQLException { @@ -919,7 +916,7 @@ public class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.AbstractJdbc1Re selectStatement.setObject( i, ((PrimaryKey) primaryKeys.get(j)).getValue() ); } - Jdbc2ResultSet rs = (Jdbc2ResultSet) selectStatement.executeQuery(); + AbstractJdbc2ResultSet rs = (AbstractJdbc2ResultSet) selectStatement.executeQuery(); if ( rs.first() ) { rowBuffer = rs.rowBuffer; diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java index 99cbf0ea8c..6be102691b 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java @@ -124,33 +124,33 @@ public class Array implements java.sql.Array case Types.BIT: retVal = new boolean[ count ]; for ( ; count > 0; count-- ) - ((boolean[])retVal)[i++] = Jdbc2ResultSet.toBoolean( arrayContents[(int)index++] ); + ((boolean[])retVal)[i++] = AbstractJdbc2ResultSet.toBoolean( arrayContents[(int)index++] ); break; case Types.SMALLINT: case Types.INTEGER: retVal = new int[ count ]; for ( ; count > 0; count-- ) - ((int[])retVal)[i++] = Jdbc2ResultSet.toInt( arrayContents[(int)index++] ); + ((int[])retVal)[i++] = AbstractJdbc2ResultSet.toInt( arrayContents[(int)index++] ); break; case Types.BIGINT: retVal = new long[ count ]; for ( ; count > 0; count-- ) - ((long[])retVal)[i++] = Jdbc2ResultSet.toLong( arrayContents[(int)index++] ); + ((long[])retVal)[i++] = AbstractJdbc2ResultSet.toLong( arrayContents[(int)index++] ); break; case Types.NUMERIC: retVal = new BigDecimal[ count ]; for ( ; count > 0; count-- ) - ((BigDecimal[])retVal)[i++] = Jdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], 0 ); + ((BigDecimal[])retVal)[i++] = AbstractJdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], 0 ); break; case Types.REAL: retVal = new float[ count ]; for ( ; count > 0; count-- ) - ((float[])retVal)[i++] = Jdbc2ResultSet.toFloat( arrayContents[(int)index++] ); + ((float[])retVal)[i++] = AbstractJdbc2ResultSet.toFloat( arrayContents[(int)index++] ); break; case Types.DOUBLE: retVal = new double[ count ]; for ( ; count > 0; count-- ) - ((double[])retVal)[i++] = Jdbc2ResultSet.toDouble( arrayContents[(int)index++] ); + ((double[])retVal)[i++] = AbstractJdbc2ResultSet.toDouble( arrayContents[(int)index++] ); break; case Types.CHAR: case Types.VARCHAR: @@ -161,18 +161,18 @@ public class Array implements java.sql.Array case Types.DATE: retVal = new java.sql.Date[ count ]; for ( ; count > 0; count-- ) - ((java.sql.Date[])retVal)[i++] = Jdbc2ResultSet.toDate( arrayContents[(int)index++] ); + ((java.sql.Date[])retVal)[i++] = AbstractJdbc2ResultSet.toDate( arrayContents[(int)index++] ); break; case Types.TIME: retVal = new java.sql.Time[ count ]; for ( ; count > 0; count-- ) - ((java.sql.Time[])retVal)[i++] = Jdbc2ResultSet.toTime( arrayContents[(int)index++], rs, getBaseTypeName() ); + ((java.sql.Time[])retVal)[i++] = AbstractJdbc2ResultSet.toTime( arrayContents[(int)index++], rs, getBaseTypeName() ); break; case Types.TIMESTAMP: retVal = new Timestamp[ count ]; StringBuffer sbuf = null; for ( ; count > 0; count-- ) - ((java.sql.Timestamp[])retVal)[i++] = Jdbc2ResultSet.toTimestamp( arrayContents[(int)index++], rs, getBaseTypeName() ); + ((java.sql.Timestamp[])retVal)[i++] = AbstractJdbc2ResultSet.toTimestamp( arrayContents[(int)index++], rs, getBaseTypeName() ); break; // Other datatypes not currently supported. If you are really using other types ask @@ -340,7 +340,7 @@ public class Array implements java.sql.Array default: throw org.postgresql.Driver.notImplemented(); } - return ((Jdbc2Connection)conn).getResultSet(null, fields, rows, "OK", 1 ); + return ((AbstractJdbc2Connection)conn).getResultSet(null, fields, rows, "OK", 1 ); } public String toString() diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java new file mode 100644 index 0000000000..5f5d28a5e5 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Blob.java @@ -0,0 +1,12 @@ +package org.postgresql.jdbc2; + + +public class Jdbc2Blob extends AbstractJdbc2Blob implements java.sql.Blob +{ + + public Jdbc2Blob(org.postgresql.PGConnection conn, int oid) throws java.sql.SQLException + { + super(conn, oid); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java index c8bc1b7907..46ff83a1e0 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java @@ -3,7 +3,7 @@ package org.postgresql.jdbc2; import java.sql.*; -public class Jdbc2CallableStatement extends AbstractJdbc2Statement implements java.sql.CallableStatement +public class Jdbc2CallableStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.CallableStatement { public Jdbc2CallableStatement(Jdbc2Connection connection, String sql) throws SQLException diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java new file mode 100644 index 0000000000..71de2f5433 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Clob.java @@ -0,0 +1,12 @@ +package org.postgresql.jdbc2; + + +public class Jdbc2Clob extends AbstractJdbc2Clob implements java.sql.Clob +{ + + public Jdbc2Clob(org.postgresql.PGConnection conn, int oid) throws java.sql.SQLException + { + super(conn, oid); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java index 2e7171913e..7dbf8a0f17 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2DatabaseMetaData.java @@ -1,7 +1,7 @@ package org.postgresql.jdbc2; -public class Jdbc2DatabaseMetaData extends AbstractJdbc2DatabaseMetaData implements java.sql.DatabaseMetaData +public class Jdbc2DatabaseMetaData extends org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData implements java.sql.DatabaseMetaData { public Jdbc2DatabaseMetaData(Jdbc2Connection conn) { diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java index 0472007d3d..15fd8d9a75 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java @@ -3,7 +3,7 @@ package org.postgresql.jdbc2; import java.sql.*; -public class Jdbc2PreparedStatement extends AbstractJdbc2Statement implements java.sql.PreparedStatement +public class Jdbc2PreparedStatement extends org.postgresql.jdbc2.AbstractJdbc2Statement implements java.sql.PreparedStatement { public Jdbc2PreparedStatement(Jdbc2Connection connection, String sql) throws SQLException diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java index c6415f0f7a..1e9805be1d 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java @@ -5,7 +5,7 @@ import java.sql.*; import java.util.Vector; import org.postgresql.Field; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.3 2002/07/26 05:29:35 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.4 2002/08/14 20:35:39 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 @@ -23,5 +23,13 @@ public class Jdbc2ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet return new Jdbc2ResultSetMetaData(rows, fields); } + public java.sql.Clob getClob(int i) throws SQLException { + return new org.postgresql.jdbc2.Jdbc2Clob(connection, getInt(i)); + } + + public java.sql.Blob getBlob(int i) throws SQLException { + return new org.postgresql.jdbc2.Jdbc2Blob(connection, getInt(i)); + } + } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java new file mode 100644 index 0000000000..d293c7acf0 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java @@ -0,0 +1,90 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdbc2Blob +{ + + public AbstractJdbc3Blob(org.postgresql.PGConnection conn, int oid) throws SQLException + { + super(conn, oid); + } + + /** + * Writes the given array of bytes to the BLOB value that + * this Blob object represents, starting at position + * pos, and returns the number of bytes written. + * + * @param pos the position in the BLOB object at which + * to start writing + * @param bytes the array of bytes to be written to the BLOB + * value that this Blob object represents + * @return the number of bytes written + * @exception SQLException if there is an error accessing the + * BLOB value + * @see #getBytes + * @since 1.4 + */ + public int setBytes(long pos, byte[] bytes) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Writes all or part of the given byte array to the + * BLOB value that this Blob object represents + * and returns the number of bytes written. + * Writing starts at position pos in the BLOB + * value; len bytes from the given byte array are written. + * + * @param pos the position in the BLOB object at which + * to start writing + * @param bytes the array of bytes to be written to this BLOB + * object + * @param offset the offset into the array bytes at which + * to start reading the bytes to be set + * @param len the number of bytes to be written to the BLOB + * value from the array of bytes bytes + * @return the number of bytes written + * @exception SQLException if there is an error accessing the + * BLOB value + * @see #getBytes + * @since 1.4 + */ + public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a stream that can be used to write to the BLOB + * value that this Blob object represents. The stream begins + * at position pos. + * + * @param pos the position in the BLOB value at which + * to start writing + * @return a java.io.OutputStream object to which data can + * be written + * @exception SQLException if there is an error accessing the + * BLOB value + * @see #getBinaryStream + * @since 1.4 + */ + public java.io.OutputStream setBinaryStream(long pos) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Truncates the BLOB value that this Blob + * object represents to be len bytes in length. + * + * @param len the length, in bytes, to which the BLOB value + * that this Blob object represents should be truncated + * @exception SQLException if there is an error accessing the + * BLOB value + * @since 1.4 + */ + public void truncate(long len) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Clob.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Clob.java new file mode 100644 index 0000000000..525530b537 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Clob.java @@ -0,0 +1,107 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdbc2Clob +{ + + public AbstractJdbc3Clob(org.postgresql.PGConnection conn, int oid) throws SQLException + { + super(conn, oid); + } + + /** + * Writes the given Java String to the CLOB + * value that this Clob object designates at the position + * pos. + * + * @param pos the position at which to start writing to the CLOB + * value that this Clob object represents + * @param str the string to be written to the CLOB + * value that this Clob designates + * @return the number of characters written + * @exception SQLException if there is an error accessing the + * CLOB value + * + * @since 1.4 + */ + public int setString(long pos, String str) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Writes len characters of str, starting + * at character offset, to the CLOB value + * that this Clob represents. + * + * @param pos the position at which to start writing to this + * CLOB object + * @param str the string to be written to the CLOB + * value that this Clob object represents + * @param offset the offset into str to start reading + * the characters to be written + * @param len the number of characters to be written + * @return the number of characters written + * @exception SQLException if there is an error accessing the + * CLOB value + * + * @since 1.4 + */ + public int setString(long pos, String str, int offset, int len) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a stream to be used to write Ascii characters to the + * CLOB value that this Clob object represents, + * starting at position pos. + * + * @param pos the position at which to start writing to this + * CLOB object + * @return the stream to which ASCII encoded characters can be written + * @exception SQLException if there is an error accessing the + * CLOB value + * @see #getAsciiStream + * + * @since 1.4 + */ + public java.io.OutputStream setAsciiStream(long pos) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a stream to be used to write a stream of Unicode characters + * to the CLOB value that this Clob object + * represents, at position pos. + * + * @param pos the position at which to start writing to the + * CLOB value + * + * @return a stream to which Unicode encoded characters can be written + * @exception SQLException if there is an error accessing the + * CLOB value + * @see #getCharacterStream + * + * @since 1.4 + */ + public java.io.Writer setCharacterStream(long pos) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Truncates the CLOB value that this Clob + * designates to have a length of len + * characters. + * @param len the length, in bytes, to which the CLOB value + * should be truncated + * @exception SQLException if there is an error accessing the + * CLOB value + * + * @since 1.4 + */ + public void truncate(long len) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java new file mode 100644 index 0000000000..5988eddb4d --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Connection.java @@ -0,0 +1,369 @@ +package org.postgresql.jdbc3; + +import java.sql.*; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Connection.java,v 1.1 2002/08/14 20:35:39 barry Exp $ + * This class defines methods of the jdbc3 specification. This class extends + * org.postgresql.jdbc2.AbstractJdbc2Connection which provides the jdbc2 + * methods. The real Connection class (for jdbc3) is org.postgresql.jdbc3.Jdbc3Connection + */ +public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.AbstractJdbc2Connection +{ + + /** + * Changes the holdability of ResultSet objects + * created using this Connection object to the given + * holdability. + * + * @param holdability a ResultSet holdability constant; one of + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @throws SQLException if a database access occurs, the given parameter + * is not a ResultSet constant indicating holdability, + * or the given holdability is not supported + * @see #getHoldability + * @see ResultSet + * @since 1.4 + */ + public void setHoldability(int holdability) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the current holdability of ResultSet objects + * created using this Connection object. + * + * @return the holdability, one of + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @throws SQLException if a database access occurs + * @see #setHoldability + * @see ResultSet + * @since 1.4 + */ + public int getHoldability() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Creates an unnamed savepoint in the current transaction and + * returns the new Savepoint object that represents it. + * + * @return the new Savepoint object + * @exception SQLException if a database access error occurs + * or this Connection object is currently in + * auto-commit mode + * @see Savepoint + * @since 1.4 + */ + public Savepoint setSavepoint() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Creates a savepoint with the given name in the current transaction + * and returns the new Savepoint object that represents it. + * + * @param name a String containing the name of the savepoint + * @return the new Savepoint object + * @exception SQLException if a database access error occurs + * or this Connection object is currently in + * auto-commit mode + * @see Savepoint + * @since 1.4 + */ + public Savepoint setSavepoint(String name) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Undoes all changes made after the given Savepoint object + * was set. + *

+ * This method should be used only when auto-commit has been disabled. + * + * @param savepoint the Savepoint object to roll back to + * @exception SQLException if a database access error occurs, + * the Savepoint object is no longer valid, + * or this Connection object is currently in + * auto-commit mode + * @see Savepoint + * @see #rollback + * @since 1.4 + */ + public void rollback(Savepoint savepoint) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Removes the given Savepoint object from the current + * transaction. Any reference to the savepoint after it have been removed + * will cause an SQLException to be thrown. + * + * @param savepoint the Savepoint object to be removed + * @exception SQLException if a database access error occurs or + * the given Savepoint object is not a valid + * savepoint in the current transaction + * @since 1.4 + */ + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Creates a Statement object that will generate + * ResultSet objects with the given type, concurrency, + * and holdability. + * This method is the same as the createStatement method + * above, but it allows the default result set + * type, concurrency, and holdability to be overridden. + * + * @param resultSetType one of the following ResultSet + * constants: + * ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or + * ResultSet.TYPE_SCROLL_SENSITIVE + * @param resultSetConcurrency one of the following ResultSet + * constants: + * ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE + * @param resultSetHoldability one of the following ResultSet + * constants: + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @return a new Statement object that will generate + * ResultSet objects with the given type, + * concurrency, and holdability + * @exception SQLException if a database access error occurs + * or the given parameters are not ResultSet + * constants indicating type, concurrency, and holdability + * @see ResultSet + * @since 1.4 + */ + public Statement createStatement(int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Creates a PreparedStatement object that will generate + * ResultSet objects with the given type, concurrency, + * and holdability. + *

+ * This method is the same as the prepareStatement method + * above, but it allows the default result set + * type, concurrency, and holdability to be overridden. + * + * @param sql a String object that is the SQL statement to + * be sent to the database; may contain one or more ? IN + * parameters + * @param resultSetType one of the following ResultSet + * constants: + * ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or + * ResultSet.TYPE_SCROLL_SENSITIVE + * @param resultSetConcurrency one of the following ResultSet + * constants: + * ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE + * @param resultSetHoldability one of the following ResultSet + * constants: + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @return a new PreparedStatement object, containing the + * pre-compiled SQL statement, that will generate + * ResultSet objects with the given type, + * concurrency, and holdability + * @exception SQLException if a database access error occurs + * or the given parameters are not ResultSet + * constants indicating type, concurrency, and holdability + * @see ResultSet + * @since 1.4 + */ + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Creates a CallableStatement object that will generate + * ResultSet objects with the given type and concurrency. + * This method is the same as the prepareCall method + * above, but it allows the default result set + * type, result set concurrency type and holdability to be overridden. + * + * @param sql a String object that is the SQL statement to + * be sent to the database; may contain on or more ? parameters + * @param resultSetType one of the following ResultSet + * constants: + * ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or + * ResultSet.TYPE_SCROLL_SENSITIVE + * @param resultSetConcurrency one of the following ResultSet + * constants: + * ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE + * @param resultSetHoldability one of the following ResultSet + * constants: + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @return a new CallableStatement object, containing the + * pre-compiled SQL statement, that will generate + * ResultSet objects with the given type, + * concurrency, and holdability + * @exception SQLException if a database access error occurs + * or the given parameters are not ResultSet + * constants indicating type, concurrency, and holdability + * @see ResultSet + * @since 1.4 + */ + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + + /** + * Creates a default PreparedStatement object that has + * the capability to retrieve auto-generated keys. The given constant + * tells the driver whether it should make auto-generated keys + * available for retrieval. This parameter is ignored if the SQL + * statement is not an INSERT statement. + *

+ * Note: This method is optimized for handling + * parametric SQL statements that benefit from precompilation. If + * the driver supports precompilation, + * the method prepareStatement will send + * the statement to the database for precompilation. Some drivers + * may not support precompilation. In this case, the statement may + * not be sent to the database until the PreparedStatement + * object is executed. This has no direct effect on users; however, it does + * affect which methods throw certain SQLExceptions. + *

+ * Result sets created using the returned PreparedStatement + * object will by default be type TYPE_FORWARD_ONLY + * and have a concurrency level of CONCUR_READ_ONLY. + * + * @param sql an SQL statement that may contain one or more '?' IN + * parameter placeholders + * @param autoGeneratedKeys a flag indicating whether auto-generated keys + * should be returned; one of the following Statement + * constants: + * @param autoGeneratedKeys a flag indicating that auto-generated keys should be returned, one of + * Statement.RETURN_GENERATED_KEYS or + * Statement.NO_GENERATED_KEYS. + * @return a new PreparedStatement object, containing the + * pre-compiled SQL statement, that will have the capability of + * returning auto-generated keys + * @exception SQLException if a database access error occurs + * or the given parameter is not a Statement + * constant indicating whether auto-generated keys should be + * returned + * @since 1.4 + */ + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Creates a default PreparedStatement object capable + * of returning the auto-generated keys designated by the given array. + * This array contains the indexes of the columns in the target + * table that contain the auto-generated keys that should be made + * available. This array is ignored if the SQL + * statement is not an INSERT statement. + *

+ * An SQL statement with or without IN parameters can be + * pre-compiled and stored in a PreparedStatement object. This + * object can then be used to efficiently execute this statement + * multiple times. + *

+ * Note: This method is optimized for handling + * parametric SQL statements that benefit from precompilation. If + * the driver supports precompilation, + * the method prepareStatement will send + * the statement to the database for precompilation. Some drivers + * may not support precompilation. In this case, the statement may + * not be sent to the database until the PreparedStatement + * object is executed. This has no direct effect on users; however, it does + * affect which methods throw certain SQLExceptions. + *

+ * Result sets created using the returned PreparedStatement + * object will by default be type TYPE_FORWARD_ONLY + * and have a concurrency level of CONCUR_READ_ONLY. + * + * @param sql an SQL statement that may contain one or more '?' IN + * parameter placeholders + * @param columnIndexes an array of column indexes indicating the columns + * that should be returned from the inserted row or rows + * @return a new PreparedStatement object, containing the + * pre-compiled statement, that is capable of returning the + * auto-generated keys designated by the given array of column + * indexes + * @exception SQLException if a database access error occurs + * + * @since 1.4 + */ + public PreparedStatement prepareStatement(String sql, int columnIndexes[]) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Creates a default PreparedStatement object capable + * of returning the auto-generated keys designated by the given array. + * This array contains the names of the columns in the target + * table that contain the auto-generated keys that should be returned. + * This array is ignored if the SQL + * statement is not an INSERT statement. + *

+ * An SQL statement with or without IN parameters can be + * pre-compiled and stored in a PreparedStatement object. This + * object can then be used to efficiently execute this statement + * multiple times. + *

+ * Note: This method is optimized for handling + * parametric SQL statements that benefit from precompilation. If + * the driver supports precompilation, + * the method prepareStatement will send + * the statement to the database for precompilation. Some drivers + * may not support precompilation. In this case, the statement may + * not be sent to the database until the PreparedStatement + * object is executed. This has no direct effect on users; however, it does + * affect which methods throw certain SQLExceptions. + *

+ * Result sets created using the returned PreparedStatement + * object will by default be type TYPE_FORWARD_ONLY + * and have a concurrency level of CONCUR_READ_ONLY. + * + * @param sql an SQL statement that may contain one or more '?' IN + * parameter placeholders + * @param columnNames an array of column names indicating the columns + * that should be returned from the inserted row or rows + * @return a new PreparedStatement object, containing the + * pre-compiled statement, that is capable of returning the + * auto-generated keys designated by the given array of column + * names + * @exception SQLException if a database access error occurs + * + * @since 1.4 + */ + public PreparedStatement prepareStatement(String sql, String columnNames[]) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + +} + + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java new file mode 100644 index 0000000000..0c2e61d3a2 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java @@ -0,0 +1,339 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData +{ + + public AbstractJdbc3DatabaseMetaData(AbstractJdbc3Connection conn) + { + super(conn); + } + + + /** + * Retrieves whether this database supports savepoints. + * + * @return true if savepoints are supported; + * false otherwise + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public boolean supportsSavepoints() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves whether this database supports named parameters to callable + * statements. + * + * @return true if named parameters are supported; + * false otherwise + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public boolean supportsNamedParameters() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves whether it is possible to have multiple ResultSet objects + * returned from a CallableStatement object + * simultaneously. + * + * @return true if a CallableStatement object + * can return multiple ResultSet objects + * simultaneously; false otherwise + * @exception SQLException if a datanase access error occurs + * @since 1.4 + */ + public boolean supportsMultipleOpenResults() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves whether auto-generated keys can be retrieved after + * a statement has been executed. + * + * @return true if auto-generated keys can be retrieved + * after a statement has executed; false otherwise + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public boolean supportsGetGeneratedKeys() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a description of the user-defined type (UDT) hierarchies defined in a + * particular schema in this database. Only the immediate super type/ + * sub type relationship is modeled. + *

+ * Only supertype information for UDTs matching the catalog, + * schema, and type name is returned. The type name parameter + * may be a fully-qualified name. When the UDT name supplied is a + * fully-qualified name, the catalog and schemaPattern parameters are + * ignored. + *

+ * If a UDT does not have a direct super type, it is not listed here. + * A row of the ResultSet object returned by this method + * describes the designated UDT and a direct supertype. A row has the following + * columns: + *

    + *
  1. TYPE_CAT String => the UDT's catalog (may be null) + *
  2. TYPE_SCHEM String => UDT's schema (may be null) + *
  3. TYPE_NAME String => type name of the UDT + *
  4. SUPERTYPE_CAT String => the direct super type's catalog + * (may be null) + *
  5. SUPERTYPE_SCHEM String => the direct super type's schema + * (may be null) + *
  6. SUPERTYPE_NAME String => the direct super type's name + *
+ * + *

Note: If the driver does not support type hierarchies, an + * empty result set is returned. + * + * @param catalog a catalog name; "" retrieves those without a catalog; + * null means drop catalog name from the selection criteria + * @param schemaPattern a schema name pattern; "" retrieves those + * without a schema + * @param typeNamePattern a UDT name pattern; may be a fully-qualified + * name + * @return a ResultSet object in which a row gives information + * about the designated UDT + * @throws SQLException if a database access error occurs + * @since 1.4 + */ + public ResultSet getSuperTypes(String catalog, String schemaPattern, + String typeNamePattern) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a description of the table hierarchies defined in a particular + * schema in this database. + * + *

Only supertable information for tables matching the catalog, schema + * and table name are returned. The table name parameter may be a fully- + * qualified name, in which case, the catalog and schemaPattern parameters + * are ignored. If a table does not have a super table, it is not listed here. + * Supertables have to be defined in the same catalog and schema as the + * sub tables. Therefore, the type description does not need to include + * this information for the supertable. + * + *

Each type description has the following columns: + *

    + *
  1. TABLE_CAT String => the type's catalog (may be null) + *
  2. TABLE_SCHEM String => type's schema (may be null) + *
  3. TABLE_NAME String => type name + *
  4. SUPERTABLE_NAME String => the direct super type's name + *
+ * + *

Note: If the driver does not support type hierarchies, an + * empty result set is returned. + * + * @param catalog a catalog name; "" retrieves those without a catalog; + * null means drop catalog name from the selection criteria + * @param schemaPattern a schema name pattern; "" retrieves those + * without a schema + * @param tableNamePattern a table name pattern; may be a fully-qualified + * name + * @return a ResultSet object in which each row is a type description + * @throws SQLException if a database access error occurs + * @since 1.4 + */ + public ResultSet getSuperTables(String catalog, String schemaPattern, + String tableNamePattern) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves a description of the given attribute of the given type + * for a user-defined type (UDT) that is available in the given schema + * and catalog. + *

+ * Descriptions are returned only for attributes of UDTs matching the + * catalog, schema, type, and attribute name criteria. They are ordered by + * TYPE_SCHEM, TYPE_NAME and ORDINAL_POSITION. This description + * does not contain inherited attributes. + *

+ * The ResultSet object that is returned has the following + * columns: + *

    + *
  1. TYPE_CAT String => type catalog (may be null) + *
  2. TYPE_SCHEM String => type schema (may be null) + *
  3. TYPE_NAME String => type name + *
  4. ATTR_NAME String => attribute name + *
  5. DATA_TYPE short => attribute type SQL type from java.sql.Types + *
  6. ATTR_TYPE_NAME String => Data source dependent type name. + * For a UDT, the type name is fully qualified. For a REF, the type name is + * fully qualified and represents the target type of the reference type. + *
  7. ATTR_SIZE int => column size. For char or date + * types this is the maximum number of characters; for numeric or + * decimal types this is precision. + *
  8. DECIMAL_DIGITS int => the number of fractional digits + *
  9. NUM_PREC_RADIX int => Radix (typically either 10 or 2) + *
  10. NULLABLE int => whether NULL is allowed + *
      + *
    • attributeNoNulls - might not allow NULL values + *
    • attributeNullable - definitely allows NULL values + *
    • attributeNullableUnknown - nullability unknown + *
    + *
  11. REMARKS String => comment describing column (may be null) + *
  12. ATTR_DEF String => default value (may be null) + *
  13. SQL_DATA_TYPE int => unused + *
  14. SQL_DATETIME_SUB int => unused + *
  15. CHAR_OCTET_LENGTH int => for char types the + * maximum number of bytes in the column + *
  16. ORDINAL_POSITION int => index of column in table + * (starting at 1) + *
  17. IS_NULLABLE String => "NO" means column definitely + * does not allow NULL values; "YES" means the column might + * allow NULL values. An empty string means unknown. + *
  18. SCOPE_CATALOG String => catalog of table that is the + * scope of a reference attribute (null if DATA_TYPE isn't REF) + *
  19. SCOPE_SCHEMA String => schema of table that is the + * scope of a reference attribute (null if DATA_TYPE isn't REF) + *
  20. SCOPE_TABLE String => table name that is the scope of a + * reference attribute (null if the DATA_TYPE isn't REF) + *
  21. SOURCE_DATA_TYPE short => source type of a distinct type or user-generated + * Ref type,SQL type from java.sql.Types (null if DATA_TYPE + * isn't DISTINCT or user-generated REF) + *
+ * @param catalog a catalog name; must match the catalog name as it + * is stored in the database; "" retrieves those without a catalog; + * null means that the catalog name should not be used to narrow + * the search + * @param schemaPattern a schema name pattern; must match the schema name + * as it is stored in the database; "" retrieves those without a schema; + * null means that the schema name should not be used to narrow + * the search + * @param typeNamePattern a type name pattern; must match the + * type name as it is stored in the database + * @param attributeNamePattern an attribute name pattern; must match the attribute + * name as it is declared in the database + * @return a ResultSet object in which each row is an + * attribute description + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public ResultSet getAttributes(String catalog, String schemaPattern, + String typeNamePattern, String attributeNamePattern) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves whether this database supports the given result set holdability. + * + * @param holdability one of the following constants: + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @return true if so; false otherwise + * @exception SQLException if a database access error occurs + * @see Connection + * @since 1.4 + */ + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the default holdability of this ResultSet + * object. + * + * @return the default holdability; either + * ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public int getResultSetHoldability() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the major version number of the underlying database. + * + * @return the underlying database's major version + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public int getDatabaseMajorVersion() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the minor version number of the underlying database. + * + * @return underlying database's minor version + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public int getDatabaseMinorVersion() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the major JDBC version number for this + * driver. + * + * @return JDBC version major number + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public int getJDBCMajorVersion() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the minor JDBC version number for this + * driver. + * + * @return JDBC version minor number + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public int getJDBCMinorVersion() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Indicates whether the SQLSTATEs returned by SQLException.getSQLState + * is X/Open (now known as Open Group) SQL CLI or SQL99. + * @return the type of SQLSTATEs, one of: + * sqlStateXOpen or + * sqlStateSQL99 + * @throws SQLException if a database access error occurs + * @since 1.4 + */ + public int getSQLStateType() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Indicates whether updates made to a LOB are made on a copy or directly + * to the LOB. + * @return true if updates are made to a copy of the LOB; + * false if updates are made directly to the LOB + * @throws SQLException if a database access error occurs + * @since 1.4 + */ + public boolean locatorsUpdateCopy() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves weather this database supports statement pooling. + * + * @return true is so; + false otherwise + * @throws SQLExcpetion if a database access error occurs + * @since 1.4 + */ + public boolean supportsStatementPooling() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java new file mode 100644 index 0000000000..cc1609d646 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3ResultSet.java @@ -0,0 +1,181 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; +import java.util.Vector; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3ResultSet.java,v 1.1 2002/08/14 20:35:39 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 + */ +public abstract class AbstractJdbc3ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet { + + public AbstractJdbc3ResultSet(org.postgresql.PGConnection conn, Statement statement, org.postgresql.Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { + super (conn, statement, fields, tuples, status, updateCount, insertOID, binaryCursor); + } + + /** + * Retrieves the value of the designated column in the current row + * of this ResultSet object as a java.net.URL + * object in the Java programming language. + * + * @param columnIndex the index of the column 1 is the first, 2 is the second,... + * @return the column value as a java.net.URL object; + * if the value is SQL NULL, + * the value returned is null in the Java programming language + * @exception SQLException if a database access error occurs, + * or if a URL is malformed + * @since 1.4 + */ + public java.net.URL getURL(int columnIndex) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of the designated column in the current row + * of this ResultSet object as a java.net.URL + * object in the Java programming language. + * + * @param columnName the SQL name of the column + * @return the column value as a java.net.URL object; + * if the value is SQL NULL, + * the value returned is null in the Java programming language + * @exception SQLException if a database access error occurs + * or if a URL is malformed + * @since 1.4 + */ + public java.net.URL getURL(String columnName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Ref value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnIndex the first column is 1, the second is 2, ... + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Ref value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnName the name of the column + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateRef(String columnName, java.sql.Ref x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Blob value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnIndex the first column is 1, the second is 2, ... + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Blob value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnName the name of the column + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateBlob(String columnName, java.sql.Blob x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Clob value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnIndex the first column is 1, the second is 2, ... + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateClob(int columnIndex, java.sql.Clob x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Clob value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnName the name of the column + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateClob(String columnName, java.sql.Clob x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Array value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnIndex the first column is 1, the second is 2, ... + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateArray(int columnIndex, java.sql.Array x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Updates the designated column with a java.sql.Array value. + * The updater methods are used to update column values in the + * current row or the insert row. The updater methods do not + * update the underlying database; instead the updateRow or + * insertRow methods are called to update the database. + * + * @param columnName the name of the column + * @param x the new column value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void updateArray(String columnName, java.sql.Array x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + +} + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java new file mode 100644 index 0000000000..8b18e6153d --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java @@ -0,0 +1,1300 @@ +package org.postgresql.jdbc3; + + +import java.math.BigDecimal; +import java.sql.*; +import java.util.Calendar; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Statement.java,v 1.1 2002/08/14 20:35:39 barry Exp $ + * This class defines methods of the jdbc3 specification. This class extends + * org.postgresql.jdbc2.AbstractJdbc2Statement which provides the jdbc2 + * methods. The real Statement class (for jdbc2) is org.postgresql.jdbc3.Jdbc3Statement + */ +public abstract class AbstractJdbc3Statement extends org.postgresql.jdbc2.AbstractJdbc2Statement +{ + + public AbstractJdbc3Statement (AbstractJdbc3Connection c) + { + super(c); + } + + public AbstractJdbc3Statement(AbstractJdbc3Connection connection, String sql) throws SQLException + { + super(connection, sql); + } + + /** + * Moves to this Statement object's next result, deals with + * any current ResultSet object(s) according to the instructions + * specified by the given flag, and returns + * true if the next result is a ResultSet object. + * + *

There are no more results when the following is true: + *

+     *      (!getMoreResults() && (getUpdateCount() == -1)
+     * 
+ * + * @param current one of the following Statement + * constants indicating what should happen to current + * ResultSet objects obtained using the method + * getResultSetCLOSE_CURRENT_RESULT, + * KEEP_CURRENT_RESULT, or + * CLOSE_ALL_RESULTS + * @return true if the next result is a ResultSet + * object; false if it is an update count or there are no + * more results + * @exception SQLException if a database access error occurs + * @since 1.4 + * @see #execute + */ + public boolean getMoreResults(int current) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves any auto-generated keys created as a result of executing this + * Statement object. If this Statement object did + * not generate any keys, an empty ResultSet + * object is returned. + * + * @return a ResultSet object containing the auto-generated key(s) + * generated by the execution of this Statement object + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public ResultSet getGeneratedKeys() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement and signals the driver with the + * given flag about whether the + * auto-generated keys produced by this Statement object + * should be made available for retrieval. + * + * @param sql must be an SQL INSERT, UPDATE or + * DELETE statement or an SQL statement that + * returns nothing + * @param autoGeneratedKeys a flag indicating whether auto-generated keys + * should be made available for retrieval; + * one of the following constants: + * Statement.RETURN_GENERATED_KEYS + * Statement.NO_GENERATED_KEYS + * @return either the row count for INSERT, UPDATE + * or DELETE statements, or 0 for SQL + * statements that return nothing + * @exception SQLException if a database access error occurs, the given + * SQL statement returns a ResultSet object, or + * the given constant is not one of those allowed + * @since 1.4 + */ + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement and signals the driver that the + * auto-generated keys indicated in the given array should be made available + * for retrieval. The driver will ignore the array if the SQL statement + * is not an INSERT statement. + * + * @param sql an SQL INSERT, UPDATE or + * DELETE statement or an SQL statement that returns nothing, + * such as an SQL DDL statement + * @param columnIndexes an array of column indexes indicating the columns + * that should be returned from the inserted row + * @return either the row count for INSERT, UPDATE, + * or DELETE statements, or 0 for SQL statements + * that return nothing + * @exception SQLException if a database access error occurs or the SQL + * statement returns a ResultSet object + * @since 1.4 + */ + public int executeUpdate(String sql, int columnIndexes[]) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement and signals the driver that the + * auto-generated keys indicated in the given array should be made available + * for retrieval. The driver will ignore the array if the SQL statement + * is not an INSERT statement. + * + * @param sql an SQL INSERT, UPDATE or + * DELETE statement or an SQL statement that returns nothing + * @param columnNames an array of the names of the columns that should be + * returned from the inserted row + * @return either the row count for INSERT, UPDATE, + * or DELETE statements, or 0 for SQL statements + * that return nothing + * @exception SQLException if a database access error occurs + * + * @since 1.4 + */ + public int executeUpdate(String sql, String columnNames[]) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement, which may return multiple results, + * and signals the driver that any + * auto-generated keys should be made available + * for retrieval. The driver will ignore this signal if the SQL statement + * is not an INSERT statement. + *

+ * In some (uncommon) situations, a single SQL statement may return + * multiple result sets and/or update counts. Normally you can ignore + * this unless you are (1) executing a stored procedure that you know may + * return multiple results or (2) you are dynamically executing an + * unknown SQL string. + *

+ * The execute method executes an SQL statement and indicates the + * form of the first result. You must then use the methods + * getResultSet or getUpdateCount + * to retrieve the result, and getMoreResults to + * move to any subsequent result(s). + * + * @param sql any SQL statement + * @param autoGeneratedKeys a constant indicating whether auto-generated + * keys should be made available for retrieval using the method + * getGeneratedKeys; one of the following constants: + * Statement.RETURN_GENERATED_KEYS or + * Statement.NO_GENERATED_KEYS + * @return true if the first result is a ResultSet + * object; false if it is an update count or there are + * no results + * @exception SQLException if a database access error occurs + * @see #getResultSet + * @see #getUpdateCount + * @see #getMoreResults + * @see #getGeneratedKeys + * + * @since 1.4 + */ + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement, which may return multiple results, + * and signals the driver that the + * auto-generated keys indicated in the given array should be made available + * for retrieval. This array contains the indexes of the columns in the + * target table that contain the auto-generated keys that should be made + * available. The driver will ignore the array if the given SQL statement + * is not an INSERT statement. + *

+ * Under some (uncommon) situations, a single SQL statement may return + * multiple result sets and/or update counts. Normally you can ignore + * this unless you are (1) executing a stored procedure that you know may + * return multiple results or (2) you are dynamically executing an + * unknown SQL string. + *

+ * The execute method executes an SQL statement and indicates the + * form of the first result. You must then use the methods + * getResultSet or getUpdateCount + * to retrieve the result, and getMoreResults to + * move to any subsequent result(s). + * + * @param sql any SQL statement + * @param columnIndexes an array of the indexes of the columns in the + * inserted row that should be made available for retrieval by a + * call to the method getGeneratedKeys + * @return true if the first result is a ResultSet + * object; false if it is an update count or there + * are no results + * @exception SQLException if a database access error occurs + * @see #getResultSet + * @see #getUpdateCount + * @see #getMoreResults + * + * @since 1.4 + */ + public boolean execute(String sql, int columnIndexes[]) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Executes the given SQL statement, which may return multiple results, + * and signals the driver that the + * auto-generated keys indicated in the given array should be made available + * for retrieval. This array contains the names of the columns in the + * target table that contain the auto-generated keys that should be made + * available. The driver will ignore the array if the given SQL statement + * is not an INSERT statement. + *

+ * In some (uncommon) situations, a single SQL statement may return + * multiple result sets and/or update counts. Normally you can ignore + * this unless you are (1) executing a stored procedure that you know may + * return multiple results or (2) you are dynamically executing an + * unknown SQL string. + *

+ * The execute method executes an SQL statement and indicates the + * form of the first result. You must then use the methods + * getResultSet or getUpdateCount + * to retrieve the result, and getMoreResults to + * move to any subsequent result(s). + * + * @param sql any SQL statement + * @param columnNames an array of the names of the columns in the inserted + * row that should be made available for retrieval by a call to the + * method getGeneratedKeys + * @return true if the next result is a ResultSet + * object; false if it is an update count or there + * are no more results + * @exception SQLException if a database access error occurs + * @see #getResultSet + * @see #getUpdateCount + * @see #getMoreResults + * @see #getGeneratedKeys + * + * @since 1.4 + */ + public boolean execute(String sql, String columnNames[]) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the result set holdability for ResultSet objects + * generated by this Statement object. + * + * @return either ResultSet.HOLD_CURSORS_OVER_COMMIT or + * ResultSet.CLOSE_CURSORS_AT_COMMIT + * @exception SQLException if a database access error occurs + * + * @since 1.4 + */ + public int getResultSetHoldability() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.net.URL value. + * The driver converts this to an SQL DATALINK value + * when it sends it to the database. + * + * @param parameterIndex the first parameter is 1, the second is 2, ... + * @param x the java.net.URL object to be set + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setURL(int parameterIndex, java.net.URL x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the number, types and properties of this + * PreparedStatement object's parameters. + * + * @return a ParameterMetaData object that contains information + * about the number, types and properties of this + * PreparedStatement object's parameters + * @exception SQLException if a database access error occurs + * @see ParameterMetaData + * @since 1.4 + */ + public ParameterMetaData getParameterMetaData() throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Registers the OUT parameter named + * parameterName to the JDBC type + * sqlType. All OUT parameters must be registered + * before a stored procedure is executed. + *

+ * The JDBC type specified by sqlType for an OUT + * parameter determines the Java type that must be used + * in the get method to read the value of that parameter. + *

+ * If the JDBC type expected to be returned to this output parameter + * is specific to this particular database, sqlType + * should be java.sql.Types.OTHER. The method + * {@link #getObject} retrieves the value. + * @param parameterName the name of the parameter + * @param sqlType the JDBC type code defined by java.sql.Types. + * If the parameter is of JDBC type NUMERIC + * or DECIMAL, the version of + * registerOutParameter that accepts a scale value + * should be used. + * @exception SQLException if a database access error occurs + * @since 1.4 + * @see Types + */ + public void registerOutParameter(String parameterName, int sqlType) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Registers the parameter named + * parameterName to be of JDBC type + * sqlType. This method must be called + * before a stored procedure is executed. + *

+ * The JDBC type specified by sqlType for an OUT + * parameter determines the Java type that must be used + * in the get method to read the value of that parameter. + *

+ * This version of registerOutParameter should be + * used when the parameter is of JDBC type NUMERIC + * or DECIMAL. + * @param parameterName the name of the parameter + * @param sqlType SQL type code defined by java.sql.Types. + * @param scale the desired number of digits to the right of the + * decimal point. It must be greater than or equal to zero. + * @exception SQLException if a database access error occurs + * @since 1.4 + * @see Types + */ + public void registerOutParameter(String parameterName, int sqlType, int scale) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Registers the designated output parameter. This version of + * the method registerOutParameter + * should be used for a user-named or REF output parameter. Examples + * of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and + * named array types. + * + * Before executing a stored procedure call, you must explicitly + * call registerOutParameter to register the type from + * java.sql.Types for each + * OUT parameter. For a user-named parameter the fully-qualified SQL + * type name of the parameter should also be given, while a REF + * parameter requires that the fully-qualified type name of the + * referenced type be given. A JDBC driver that does not need the + * type code and type name information may ignore it. To be portable, + * however, applications should always provide these values for + * user-named and REF parameters. + * + * Although it is intended for user-named and REF parameters, + * this method may be used to register a parameter of any JDBC type. + * If the parameter does not have a user-named or REF type, the + * typeName parameter is ignored. + * + *

Note: When reading the value of an out parameter, you + * must use the getXXX method whose Java type XXX corresponds to the + * parameter's registered SQL type. + * + * @param parameterName the name of the parameter + * @param sqlType a value from {@link java.sql.Types} + * @param typeName the fully-qualified name of an SQL structured type + * @exception SQLException if a database access error occurs + * @see Types + * @since 1.4 + */ + public void registerOutParameter (String parameterName, int sqlType, String typeName) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of the designated JDBC DATALINK parameter as a + * java.net.URL object. + * + * @param parameterIndex the first parameter is 1, the second is 2,... + * @return a java.net.URL object that represents the + * JDBC DATALINK value used as the designated + * parameter + * @exception SQLException if a database access error occurs, + * or if the URL being returned is + * not a valid URL on the Java platform + * @see #setURL + * @since 1.4 + */ + public java.net.URL getURL(int parameterIndex) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.net.URL object. + * The driver converts this to an SQL DATALINK value when + * it sends it to the database. + * + * @param parameterName the name of the parameter + * @param val the parameter value + * @exception SQLException if a database access error occurs, + * or if a URL is malformed + * @see #getURL + * @since 1.4 + */ + public void setURL(String parameterName, java.net.URL val) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to SQL NULL. + * + *

Note: You must specify the parameter's SQL type. + * + * @param parameterName the name of the parameter + * @param sqlType the SQL type code defined in java.sql.Types + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setNull(String parameterName, int sqlType) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java boolean value. + * The driver converts this + * to an SQL BIT value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getBoolean + * @since 1.4 + */ + public void setBoolean(String parameterName, boolean x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java byte value. + * The driver converts this + * to an SQL TINYINT value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getByte + * @since 1.4 + */ + public void setByte(String parameterName, byte x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java short value. + * The driver converts this + * to an SQL SMALLINT value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getShort + * @since 1.4 + */ + public void setShort(String parameterName, short x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java int value. + * The driver converts this + * to an SQL INTEGER value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getInt + * @since 1.4 + */ + public void setInt(String parameterName, int x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java long value. + * The driver converts this + * to an SQL BIGINT value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getLong + * @since 1.4 + */ + public void setLong(String parameterName, long x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java float value. + * The driver converts this + * to an SQL FLOAT value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getFloat + * @since 1.4 + */ + public void setFloat(String parameterName, float x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java double value. + * The driver converts this + * to an SQL DOUBLE value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getDouble + * @since 1.4 + */ + public void setDouble(String parameterName, double x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given + * java.math.BigDecimal value. + * The driver converts this to an SQL NUMERIC value when + * it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getBigDecimal + * @since 1.4 + */ + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java String value. + * The driver converts this + * to an SQL VARCHAR or LONGVARCHAR value + * (depending on the argument's + * size relative to the driver's limits on VARCHAR values) + * when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getString + * @since 1.4 + */ + public void setString(String parameterName, String x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given Java array of bytes. + * The driver converts this to an SQL VARBINARY or + * LONGVARBINARY (depending on the argument's size relative + * to the driver's limits on VARBINARY values) when it sends + * it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getBytes + * @since 1.4 + */ + public void setBytes(String parameterName, byte x[]) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Date value. + * The driver converts this + * to an SQL DATE value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getDate + * @since 1.4 + */ + public void setDate(String parameterName, java.sql.Date x) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Time value. + * The driver converts this + * to an SQL TIME value when it sends it to the database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getTime + * @since 1.4 + */ + public void setTime(String parameterName, java.sql.Time x) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Timestamp value. + * The driver + * converts this to an SQL TIMESTAMP value when it sends it to the + * database. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @exception SQLException if a database access error occurs + * @see #getTimestamp + * @since 1.4 + */ + public void setTimestamp(String parameterName, java.sql.Timestamp x) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given input stream, which will have + * the specified number of bytes. + * When a very large ASCII value is input to a LONGVARCHAR + * parameter, it may be more practical to send it via a + * java.io.InputStream. Data will be read from the stream + * as needed until end-of-file is reached. The JDBC driver will + * do any necessary conversion from ASCII to the database char format. + * + *

Note: This stream object can either be a standard + * Java stream object or your own subclass that implements the + * standard interface. + * + * @param parameterName the name of the parameter + * @param x the Java input stream that contains the ASCII parameter value + * @param length the number of bytes in the stream + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setAsciiStream(String parameterName, java.io.InputStream x, int length) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given input stream, which will have + * the specified number of bytes. + * When a very large binary value is input to a LONGVARBINARY + * parameter, it may be more practical to send it via a + * java.io.InputStream object. The data will be read from the stream + * as needed until end-of-file is reached. + * + *

Note: This stream object can either be a standard + * Java stream object or your own subclass that implements the + * standard interface. + * + * @param parameterName the name of the parameter + * @param x the java input stream which contains the binary parameter value + * @param length the number of bytes in the stream + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setBinaryStream(String parameterName, java.io.InputStream x, + int length) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the value of the designated parameter with the given object. The second + * argument must be an object type; for integral values, the + * java.lang equivalent objects should be used. + * + *

The given Java object will be converted to the given targetSqlType + * before being sent to the database. + * + * If the object has a custom mapping (is of a class implementing the + * interface SQLData), + * the JDBC driver should call the method SQLData.writeSQL to write it + * to the SQL data stream. + * If, on the other hand, the object is of a class implementing + * Ref, Blob, Clob, Struct, + * or Array, the driver should pass it to the database as a + * value of the corresponding SQL type. + *

+ * Note that this method may be used to pass datatabase- + * specific abstract data types. + * + * @param parameterName the name of the parameter + * @param x the object containing the input parameter value + * @param targetSqlType the SQL type (as defined in java.sql.Types) to be + * sent to the database. The scale argument may further qualify this type. + * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, + * this is the number of digits after the decimal point. For all other + * types, this value will be ignored. + * @exception SQLException if a database access error occurs + * @see Types + * @see #getObject + * @since 1.4 + */ + public void setObject(String parameterName, Object x, int targetSqlType, int scale) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the value of the designated parameter with the given object. + * This method is like the method setObject + * above, except that it assumes a scale of zero. + * + * @param parameterName the name of the parameter + * @param x the object containing the input parameter value + * @param targetSqlType the SQL type (as defined in java.sql.Types) to be + * sent to the database + * @exception SQLException if a database access error occurs + * @see #getObject + * @since 1.4 + */ + public void setObject(String parameterName, Object x, int targetSqlType) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the value of the designated parameter with the given object. + * The second parameter must be of type Object; therefore, the + * java.lang equivalent objects should be used for built-in types. + * + *

The JDBC specification specifies a standard mapping from + * Java Object types to SQL types. The given argument + * will be converted to the corresponding SQL type before being + * sent to the database. + * + *

Note that this method may be used to pass datatabase- + * specific abstract data types, by using a driver-specific Java + * type. + * + * If the object is of a class implementing the interface SQLData, + * the JDBC driver should call the method SQLData.writeSQL + * to write it to the SQL data stream. + * If, on the other hand, the object is of a class implementing + * Ref, Blob, Clob, Struct, + * or Array, the driver should pass it to the database as a + * value of the corresponding SQL type. + *

+ * This method throws an exception if there is an ambiguity, for example, if the + * object is of a class implementing more than one of the interfaces named above. + * + * @param parameterName the name of the parameter + * @param x the object containing the input parameter value + * @exception SQLException if a database access error occurs or if the given + * Object parameter is ambiguous + * @see #getObject + * @since 1.4 + */ + public void setObject(String parameterName, Object x) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + + /** + * Sets the designated parameter to the given Reader + * object, which is the given number of characters long. + * When a very large UNICODE value is input to a LONGVARCHAR + * parameter, it may be more practical to send it via a + * java.io.Reader object. The data will be read from the stream + * as needed until end-of-file is reached. The JDBC driver will + * do any necessary conversion from UNICODE to the database char format. + * + *

Note: This stream object can either be a standard + * Java stream object or your own subclass that implements the + * standard interface. + * + * @param parameterName the name of the parameter + * @param reader the java.io.Reader object that + * contains the UNICODE data used as the designated parameter + * @param length the number of characters in the stream + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setCharacterStream(String parameterName, + java.io.Reader reader, + int length) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Date value, + * using the given Calendar object. The driver uses + * the Calendar object to construct an SQL DATE value, + * which the driver then sends to the database. With a + * a Calendar object, the driver can calculate the date + * taking into account a custom timezone. If no + * Calendar object is specified, the driver uses the default + * timezone, which is that of the virtual machine running the application. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @param cal the Calendar object the driver will use + * to construct the date + * @exception SQLException if a database access error occurs + * @see #getDate + * @since 1.4 + */ + public void setDate(String parameterName, java.sql.Date x, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Time value, + * using the given Calendar object. The driver uses + * the Calendar object to construct an SQL TIME value, + * which the driver then sends to the database. With a + * a Calendar object, the driver can calculate the time + * taking into account a custom timezone. If no + * Calendar object is specified, the driver uses the default + * timezone, which is that of the virtual machine running the application. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @param cal the Calendar object the driver will use + * to construct the time + * @exception SQLException if a database access error occurs + * @see #getTime + * @since 1.4 + */ + public void setTime(String parameterName, java.sql.Time x, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to the given java.sql.Timestamp value, + * using the given Calendar object. The driver uses + * the Calendar object to construct an SQL TIMESTAMP value, + * which the driver then sends to the database. With a + * a Calendar object, the driver can calculate the timestamp + * taking into account a custom timezone. If no + * Calendar object is specified, the driver uses the default + * timezone, which is that of the virtual machine running the application. + * + * @param parameterName the name of the parameter + * @param x the parameter value + * @param cal the Calendar object the driver will use + * to construct the timestamp + * @exception SQLException if a database access error occurs + * @see #getTimestamp + * @since 1.4 + */ + public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Sets the designated parameter to SQL NULL. + * This version of the method setNull should + * be used for user-defined types and REF type parameters. Examples + * of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and + * named array types. + * + *

Note: To be portable, applications must give the + * SQL type code and the fully-qualified SQL type name when specifying + * a NULL user-defined or REF parameter. In the case of a user-defined type + * the name is the type name of the parameter itself. For a REF + * parameter, the name is the type name of the referenced type. If + * a JDBC driver does not need the type code or type name information, + * it may ignore it. + * + * Although it is intended for user-defined and Ref parameters, + * this method may be used to set a null parameter of any JDBC type. + * If the parameter does not have a user-defined or REF type, the given + * typeName is ignored. + * + * + * @param paramName the name of the parameter + * @param sqlType a value from java.sql.Types + * @param typeName the fully-qualified name of an SQL user-defined type; + * ignored if the parameter is not a user-defined type or + * SQL REF value + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public void setNull (String parameterName, int sqlType, String typeName) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC CHAR, VARCHAR, + * or LONGVARCHAR parameter as a String in + * the Java programming language. + *

+ * For the fixed-length type JDBC CHAR, + * the String object + * returned has exactly the same value the JDBC + * CHAR value had in the + * database, including any padding added by the database. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is null. + * @exception SQLException if a database access error occurs + * @see #setString + * @since 1.4 + */ + public String getString(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC BIT parameter as a + * boolean in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is false. + * @exception SQLException if a database access error occurs + * @see #setBoolean + * @since 1.4 + */ + public boolean getBoolean(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC TINYINT parameter as a byte + * in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is 0. + * @exception SQLException if a database access error occurs + * @see #setByte + * @since 1.4 + */ + public byte getByte(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC SMALLINT parameter as a short + * in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is 0. + * @exception SQLException if a database access error occurs + * @see #setShort + * @since 1.4 + */ + public short getShort(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC INTEGER parameter as an int + * in the Java programming language. + * + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, + * the result is 0. + * @exception SQLException if a database access error occurs + * @see #setInt + * @since 1.4 + */ + public int getInt(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC BIGINT parameter as a long + * in the Java programming language. + * + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, + * the result is 0. + * @exception SQLException if a database access error occurs + * @see #setLong + * @since 1.4 + */ + public long getLong(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC FLOAT parameter as a float + * in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, + * the result is 0. + * @exception SQLException if a database access error occurs + * @see #setFloat + * @since 1.4 + */ + public float getFloat(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC DOUBLE parameter as a double + * in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, + * the result is 0. + * @exception SQLException if a database access error occurs + * @see #setDouble + * @since 1.4 + */ + public double getDouble(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC BINARY or VARBINARY + * parameter as an array of byte values in the Java + * programming language. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result is + * null. + * @exception SQLException if a database access error occurs + * @see #setBytes + * @since 1.4 + */ + public byte[] getBytes(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC DATE parameter as a + * java.sql.Date object. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is null. + * @exception SQLException if a database access error occurs + * @see #setDate + * @since 1.4 + */ + public java.sql.Date getDate(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC TIME parameter as a + * java.sql.Time object. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is null. + * @exception SQLException if a database access error occurs + * @see #setTime + * @since 1.4 + */ + public java.sql.Time getTime(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC TIMESTAMP parameter as a + * java.sql.Timestamp object. + * @param parameterName the name of the parameter + * @return the parameter value. If the value is SQL NULL, the result + * is null. + * @exception SQLException if a database access error occurs + * @see #setTimestamp + * @since 1.4 + */ + public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a parameter as an Object in the Java + * programming language. If the value is an SQL NULL, the + * driver returns a Java null. + *

+ * This method returns a Java object whose type corresponds to the JDBC + * type that was registered for this parameter using the method + * registerOutParameter. By registering the target JDBC + * type as java.sql.Types.OTHER, this method can be used + * to read database-specific abstract data types. + * @param parameterName the name of the parameter + * @return A java.lang.Object holding the OUT parameter value. + * @exception SQLException if a database access error occurs + * @see Types + * @see #setObject + * @since 1.4 + */ + public Object getObject(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC NUMERIC parameter as a + * java.math.BigDecimal object with as many digits to the + * right of the decimal point as the value contains. + * @param parameterName the name of the parameter + * @return the parameter value in full precision. If the value is + * SQL NULL, the result is null. + * @exception SQLException if a database access error occurs + * @see #setBigDecimal + * @since 1.4 + */ + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Returns an object representing the value of OUT parameter + * i and uses map for the custom + * mapping of the parameter value. + *

+ * This method returns a Java object whose type corresponds to the + * JDBC type that was registered for this parameter using the method + * registerOutParameter. By registering the target + * JDBC type as java.sql.Types.OTHER, this method can + * be used to read database-specific abstract data types. + * @param parameterName the name of the parameter + * @param map the mapping from SQL type names to Java classes + * @return a java.lang.Object holding the OUT parameter value + * @exception SQLException if a database access error occurs + * @see #setObject + * @since 1.4 + */ + public Object getObject (String parameterName, java.util.Map map) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC REF(<structured-type>) + * parameter as a {@link Ref} object in the Java programming language. + * + * @param parameterName the name of the parameter + * @return the parameter value as a Ref object in the + * Java programming language. If the value was SQL NULL, + * the value null is returned. + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public Ref getRef (String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC BLOB parameter as a + * {@link Blob} object in the Java programming language. + * + * @param parameterName the name of the parameter + * @return the parameter value as a Blob object in the + * Java programming language. If the value was SQL NULL, + * the value null is returned. + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public Blob getBlob (String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC CLOB parameter as a + * Clob object in the Java programming language. + * @param parameterName the name of the parameter + * @return the parameter value as a Clob object in the + * Java programming language. If the value was SQL NULL, + * the value null is returned. + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public Clob getClob (String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC ARRAY parameter as an + * {@link Array} object in the Java programming language. + * + * @param parameterName the name of the parameter + * @return the parameter value as an Array object in + * Java programming language. If the value was SQL NULL, + * the value null is returned. + * @exception SQLException if a database access error occurs + * @since 1.4 + */ + public Array getArray (String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC DATE parameter as a + * java.sql.Date object, using + * the given Calendar object + * to construct the date. + * With a Calendar object, the driver + * can calculate the date taking into account a custom timezone and locale. + * If no Calendar object is specified, the driver uses the + * default timezone and locale. + * + * @param parameterName the name of the parameter + * @param cal the Calendar object the driver will use + * to construct the date + * @return the parameter value. If the value is SQL NULL, + * the result is null. + * @exception SQLException if a database access error occurs + * @see #setDate + * @since 1.4 + */ + public java.sql.Date getDate(String parameterName, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC TIME parameter as a + * java.sql.Time object, using + * the given Calendar object + * to construct the time. + * With a Calendar object, the driver + * can calculate the time taking into account a custom timezone and locale. + * If no Calendar object is specified, the driver uses the + * default timezone and locale. + * + * @param parameterName the name of the parameter + * @param cal the Calendar object the driver will use + * to construct the time + * @return the parameter value; if the value is SQL NULL, the result is + * null. + * @exception SQLException if a database access error occurs + * @see #setTime + * @since 1.4 + */ + public java.sql.Time getTime(String parameterName, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC TIMESTAMP parameter as a + * java.sql.Timestamp object, using + * the given Calendar object to construct + * the Timestamp object. + * With a Calendar object, the driver + * can calculate the timestamp taking into account a custom timezone and locale. + * If no Calendar object is specified, the driver uses the + * default timezone and locale. + * + * + * @param parameterName the name of the parameter + * @param cal the Calendar object the driver will use + * to construct the timestamp + * @return the parameter value. If the value is SQL NULL, the result is + * null. + * @exception SQLException if a database access error occurs + * @see #setTimestamp + * @since 1.4 + */ + public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) + throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + + /** + * Retrieves the value of a JDBC DATALINK parameter as a + * java.net.URL object. + * + * @param parameterName the name of the parameter + * @return the parameter value as a java.net.URL object in the + * Java programming language. If the value was SQL NULL, the + * value null is returned. + * @exception SQLException if a database access error occurs, + * or if there is a problem with the URL + * @see #setURL + * @since 1.4 + */ + public java.net.URL getURL(String parameterName) throws SQLException { + throw org.postgresql.Driver.notImplemented(); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Blob.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Blob.java new file mode 100644 index 0000000000..9d0839898b --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Blob.java @@ -0,0 +1,14 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public class Jdbc3Blob extends org.postgresql.jdbc3.AbstractJdbc3Blob implements java.sql.Blob +{ + + public Jdbc3Blob(org.postgresql.PGConnection conn, int oid) throws SQLException + { + super(conn, oid); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java new file mode 100644 index 0000000000..eef5bd4fbc --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java @@ -0,0 +1,15 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public class Jdbc3CallableStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.CallableStatement +{ + + public Jdbc3CallableStatement(Jdbc3Connection connection, String sql) throws SQLException + { + super(connection, sql); + } + +} + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Clob.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Clob.java new file mode 100644 index 0000000000..b65ffc7082 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Clob.java @@ -0,0 +1,12 @@ +package org.postgresql.jdbc3; + + +public class Jdbc3Clob extends org.postgresql.jdbc3.AbstractJdbc3Clob implements java.sql.Clob +{ + + public Jdbc3Clob(org.postgresql.PGConnection conn, int oid) throws java.sql.SQLException + { + super(conn, oid); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Connection.java new file mode 100644 index 0000000000..b6f279d7e2 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Connection.java @@ -0,0 +1,61 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; +import java.util.Vector; +import java.util.Hashtable; +import org.postgresql.Field; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Connection.java,v 1.1 2002/08/14 20:35:40 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 + */ +public class Jdbc3Connection extends org.postgresql.jdbc3.AbstractJdbc3Connection implements java.sql.Connection +{ + + public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException + { + Jdbc3Statement s = new Jdbc3Statement(this); + s.setResultSetType(resultSetType); + s.setResultSetConcurrency(resultSetConcurrency); + return s; + } + + + public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + { + Jdbc3PreparedStatement s = new Jdbc3PreparedStatement(this, sql); + s.setResultSetType(resultSetType); + s.setResultSetConcurrency(resultSetConcurrency); + return s; + } + + public java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + { + Jdbc3CallableStatement s = new Jdbc3CallableStatement(this,sql); + s.setResultSetType(resultSetType); + s.setResultSetConcurrency(resultSetConcurrency); + return s; + } + + public java.sql.DatabaseMetaData getMetaData() throws SQLException + { + if (metadata == null) + metadata = new Jdbc3DatabaseMetaData(this); + return metadata; + } + + public java.sql.ResultSet getResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException + { + return new Jdbc3ResultSet(this, statement, fields, tuples, status, updateCount, insertOID, binaryCursor); + } + + public java.sql.ResultSet getResultSet(Statement statement, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException + { + return new Jdbc3ResultSet(this, statement, fields, tuples, status, updateCount, 0, false); + } + +} + + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3DatabaseMetaData.java new file mode 100644 index 0000000000..c242c63228 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3DatabaseMetaData.java @@ -0,0 +1,12 @@ +package org.postgresql.jdbc3; + + +public class Jdbc3DatabaseMetaData extends org.postgresql.jdbc3.AbstractJdbc3DatabaseMetaData implements java.sql.DatabaseMetaData +{ + + public Jdbc3DatabaseMetaData(Jdbc3Connection conn) + { + super(conn); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java new file mode 100644 index 0000000000..bc570129eb --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java @@ -0,0 +1,15 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +public class Jdbc3PreparedStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.PreparedStatement +{ + + public Jdbc3PreparedStatement(Jdbc3Connection connection, String sql) throws SQLException + { + super(connection, sql); + } + +} + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java new file mode 100644 index 0000000000..f2652ee1f5 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSet.java @@ -0,0 +1,35 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; +import java.util.Vector; +import org.postgresql.Field; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3ResultSet.java,v 1.1 2002/08/14 20:35:40 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 + */ +public class Jdbc3ResultSet extends org.postgresql.jdbc3.AbstractJdbc3ResultSet implements java.sql.ResultSet +{ + + public Jdbc3ResultSet(Jdbc3Connection conn, Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) + { + super(conn, statement, fields, tuples, status, updateCount, insertOID, binaryCursor); + } + + public java.sql.ResultSetMetaData getMetaData() throws SQLException + { + return new Jdbc3ResultSetMetaData(rows, fields); + } + + public java.sql.Clob getClob(int i) throws SQLException { + return new Jdbc3Clob(connection, getInt(i)); + } + + public java.sql.Blob getBlob(int i) throws SQLException { + return new Jdbc3Blob(connection, getInt(i)); + } + +} + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSetMetaData.java new file mode 100644 index 0000000000..5dd48a9846 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3ResultSetMetaData.java @@ -0,0 +1,12 @@ +package org.postgresql.jdbc3; + +public class Jdbc3ResultSetMetaData extends org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData implements java.sql.ResultSetMetaData +{ + + public Jdbc3ResultSetMetaData(java.util.Vector rows, org.postgresql.Field[] fields) + { + super(rows, fields); + } + +} + diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java new file mode 100644 index 0000000000..bf6a0d5155 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java @@ -0,0 +1,19 @@ +package org.postgresql.jdbc3; + + +import java.sql.*; + +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.1 2002/08/14 20:35:40 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 + */ +public class Jdbc3Statement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.Statement +{ + + public Jdbc3Statement (Jdbc3Connection c) + { + super(c); + } + +} diff --git a/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java b/src/interfaces/jdbc/org/postgresql/test/TestUtil.java similarity index 59% rename from src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java rename to src/interfaces/jdbc/org/postgresql/test/TestUtil.java index 33070c0d9b..a9f9dfdf3f 100644 --- a/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java +++ b/src/interfaces/jdbc/org/postgresql/test/TestUtil.java @@ -1,17 +1,12 @@ package org.postgresql.test; -import junit.framework.TestSuite; -import junit.framework.TestCase; -import junit.framework.Test; - -import org.postgresql.test.jdbc2.*; import java.sql.*; -import java.lang.reflect.Method; +import junit.framework.TestCase; /* - * Executes all known tests for JDBC2 and includes some utility methods. + * Utility class for JDBC tests */ -public class JDBC2Tests extends TestSuite +public class TestUtil { /* * Returns the Test database JDBC URL @@ -45,7 +40,7 @@ public class JDBC2Tests extends TestSuite try { Class.forName("org.postgresql.Driver"); - return java.sql.DriverManager.getConnection(JDBC2Tests.getURL(), JDBC2Tests.getUser(), JDBC2Tests.getPassword()); + return java.sql.DriverManager.getConnection(getURL(), getUser(), getPassword()); } catch (ClassNotFoundException ex) { @@ -180,68 +175,4 @@ public class JDBC2Tests extends TestSuite String s = "0000000000".substring(0, l) + Integer.toString(v); return s.substring(s.length() - l); } - - /* - * The main entry point for JUnit - */ - public static TestSuite suite() - { - TestSuite suite = new TestSuite(); - - // - // Add one line per class in our test cases. These should be in order of - // complexity. - - // ANTTest should be first as it ensures that test parameters are - // being sent to the suite. It also initialises the database (if required) - // with some simple global tables (will make each testcase use its own later). - // - suite.addTestSuite(ANTTest.class); - - // Basic Driver internals - suite.addTestSuite(DriverTest.class); - suite.addTestSuite(ConnectionTest.class); - suite.addTestSuite(DatabaseMetaDataTest.class); - suite.addTestSuite(EncodingTest.class); - - // Connectivity/Protocols - - // ResultSet - suite.addTestSuite(ResultSetTest.class); - - // Time, Date, Timestamp - suite.addTestSuite(DateTest.class); - suite.addTestSuite(TimeTest.class); - suite.addTestSuite(TimestampTest.class); - - // PreparedStatement - - // BatchExecute - suite.addTestSuite(BatchExecuteTest.class); - - // MetaData - - // Other misc tests, based on previous problems users have had or specific - // features some applications require. - suite.addTestSuite(JBuilderTest.class); - suite.addTestSuite(MiscTest.class); - - // Fastpath/LargeObject - suite.addTestSuite(BlobTest.class); - suite.addTestSuite( UpdateableResultTest.class ); - - suite.addTestSuite( CallableStmtTest.class ); - - // try to load the optional test classes - try { - Class cls = Class.forName("org.postgresql.test.jdbc2.optional.OptionalTestSuite"); - Method meth = cls.getMethod("suite", new Class[0]); - suite.addTest((Test)meth.invoke(null, new Object[0])); - } catch (Exception e) { - System.err.println("Excluding JDBC 2 Optional Package (DataSource) tests"); - } - - // That's all folks - return suite; - } } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java index 26229b8856..1c2569296b 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; @@ -26,12 +26,12 @@ public class BatchExecuteTest extends TestCase // a table for this test. protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); + con = TestUtil.openDB(); Statement stmt = con.createStatement(); // Drop the test table if it already exists for some reason. It is // not an error if it doesn't exist. - JDBC2Tests.createTable(con, "testbatch", "pk INTEGER, col1 INTEGER"); + TestUtil.createTable(con, "testbatch", "pk INTEGER, col1 INTEGER"); stmt.executeUpdate("INSERT INTO testbatch VALUES (1, 0)"); @@ -45,8 +45,8 @@ public class BatchExecuteTest extends TestCase { con.setAutoCommit(true); - JDBC2Tests.dropTable(con, "testbatch"); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, "testbatch"); + TestUtil.closeDB(con); } public void testSupportsBatchUpdates() throws Exception diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java index 45bab13b0e..7a33ae5392 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.io.*; import java.sql.*; @@ -8,7 +8,7 @@ import java.sql.*; import org.postgresql.largeobject.*; /* - * $Id: BlobTest.java,v 1.6 2002/07/23 03:59:55 barry Exp $ + * $Id: BlobTest.java,v 1.7 2002/08/14 20:35:40 barry Exp $ * * Some simple tests based on problems reported by users. Hopefully these will * help prevent previous problems from re-occuring ;-) @@ -30,14 +30,14 @@ public class BlobTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); - JDBC2Tests.createTable(con, "testblob", "id name,lo oid"); + con = TestUtil.openDB(); + TestUtil.createTable(con, "testblob", "id name,lo oid"); } protected void tearDown() throws Exception { - JDBC2Tests.dropTable(con, "testblob"); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, "testblob"); + TestUtil.closeDB(con); } /* @@ -131,7 +131,7 @@ public class BlobTest extends TestCase case JDBC_STREAM: File f = new File(file); - PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testblob", "?")); + PreparedStatement ps = con.prepareStatement(TestUtil.insertSQL("testblob", "?")); ps.setBinaryStream(1, fis, (int) f.length()); ps.execute(); break; @@ -145,7 +145,7 @@ public class BlobTest extends TestCase // Insert into the table Statement st = con.createStatement(); - st.executeUpdate(JDBC2Tests.insertSQL("testblob", "id,lo", "'" + file + "'," + oid)); + st.executeUpdate(TestUtil.insertSQL("testblob", "id,lo", "'" + file + "'," + oid)); con.commit(); st.close(); @@ -163,7 +163,7 @@ public class BlobTest extends TestCase LargeObjectManager lom = ((org.postgresql.PGConnection)con).getLargeObjectAPI(); Statement st = con.createStatement(); - ResultSet rs = st.executeQuery(JDBC2Tests.selectSQL("testblob", "id,lo")); + ResultSet rs = st.executeQuery(TestUtil.selectSQL("testblob", "id,lo")); assertNotNull(rs); while (rs.next()) diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java index 5c83d8cdf2..23cc28697f 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.io.*; import java.sql.*; @@ -20,7 +20,7 @@ public class CallableStmtTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); + con = TestUtil.openDB(); Statement stmt = con.createStatement (); stmt.execute ("CREATE OR REPLACE FUNCTION testspg__getString (varchar) " + "RETURNS varchar AS ' DECLARE inString alias for $1; begin "+ @@ -44,7 +44,7 @@ public class CallableStmtTest extends TestCase stmt.execute ("drop FUNCTION testspg__getDouble (float);"); stmt.execute ("drop FUNCTION testspg__getInt (int);"); stmt.execute ("drop FUNCTION testspg__getNumeric (numeric);"); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java index 682118b6c1..e2f70f1b64 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; @@ -10,7 +10,7 @@ import java.sql.*; * * PS: Do you know how difficult it is to type on a train? ;-) * - * $Id: ConnectionTest.java,v 1.8 2002/07/23 03:59:55 barry Exp $ + * $Id: ConnectionTest.java,v 1.9 2002/08/14 20:35:40 barry Exp $ */ public class ConnectionTest extends TestCase @@ -27,23 +27,23 @@ public class ConnectionTest extends TestCase // Set up the fixture for this testcase: the tables for this test. protected void setUp() throws Exception { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); - JDBC2Tests.createTable(con, "test_a", "imagename name,image oid,id int4"); - JDBC2Tests.createTable(con, "test_c", "source text,cost money,imageid int4"); + TestUtil.createTable(con, "test_a", "imagename name,image oid,id int4"); + TestUtil.createTable(con, "test_c", "source text,cost money,imageid int4"); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } // Tear down the fixture for this test case. protected void tearDown() throws Exception { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); - JDBC2Tests.dropTable(con, "test_a"); - JDBC2Tests.dropTable(con, "test_c"); + TestUtil.dropTable(con, "test_a"); + TestUtil.dropTable(con, "test_c"); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } /* @@ -53,7 +53,7 @@ public class ConnectionTest extends TestCase { try { - java.sql.Connection conn = JDBC2Tests.openDB(); + java.sql.Connection conn = TestUtil.openDB(); // A standard Statement java.sql.Statement stat = conn.createStatement(); @@ -79,7 +79,7 @@ public class ConnectionTest extends TestCase { try { - java.sql.Connection conn = JDBC2Tests.openDB(); + java.sql.Connection conn = TestUtil.openDB(); String sql = "select source,cost,imageid from test_c"; @@ -121,7 +121,7 @@ public class ConnectionTest extends TestCase { try { - java.sql.Connection con = JDBC2Tests.openDB(); + java.sql.Connection con = TestUtil.openDB(); java.sql.Statement st; java.sql.ResultSet rs; @@ -155,7 +155,7 @@ public class ConnectionTest extends TestCase assertEquals(9876, rs.getInt(1)); // Should not change! rs.close(); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch (SQLException ex) { @@ -170,12 +170,12 @@ public class ConnectionTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); // Should not say closed assertTrue(!con.isClosed()); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); // Should now say closed assertTrue(con.isClosed()); @@ -194,7 +194,7 @@ public class ConnectionTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); String testStr = "This Is OuR TeSt message"; @@ -216,7 +216,7 @@ public class ConnectionTest extends TestCase con.clearWarnings(); assertTrue(con.getWarnings() == null); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch (SQLException ex) { @@ -231,7 +231,7 @@ public class ConnectionTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); // PostgreSQL defaults to READ COMMITTED assertEquals(Connection.TRANSACTION_READ_COMMITTED, @@ -301,7 +301,7 @@ public class ConnectionTest extends TestCase assertEquals(Connection.TRANSACTION_READ_COMMITTED, con.getTransactionIsolation()); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch ( SQLException ex ) { @@ -316,7 +316,7 @@ public class ConnectionTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); // preserve the current map java.util.Map oldmap = con.getTypeMap(); @@ -330,7 +330,7 @@ public class ConnectionTest extends TestCase con.setTypeMap(oldmap); assertEquals(oldmap, con.getTypeMap()); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch (SQLException ex) { diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java index 772743c347..85a6afe60b 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; @@ -9,7 +9,7 @@ import java.sql.*; * * PS: Do you know how difficult it is to type on a train? ;-) * - * $Id: DatabaseMetaDataTest.java,v 1.10 2002/07/30 13:22:38 davec Exp $ + * $Id: DatabaseMetaDataTest.java,v 1.11 2002/08/14 20:35:40 barry Exp $ */ public class DatabaseMetaDataTest extends TestCase @@ -26,14 +26,14 @@ public class DatabaseMetaDataTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); - JDBC2Tests.createTable( con, "testmetadata", "id int4, name text, updated timestamp" ); + con = TestUtil.openDB(); + TestUtil.createTable( con, "testmetadata", "id int4, name text, updated timestamp" ); } protected void tearDown() throws Exception { - JDBC2Tests.dropTable( con, "testmetadata" ); + TestUtil.dropTable( con, "testmetadata" ); - JDBC2Tests.closeDB( con ); + TestUtil.closeDB( con ); } /* * The spec says this may return null, but we always do! @@ -233,11 +233,11 @@ public class DatabaseMetaDataTest extends TestCase { try { - Connection con1 = JDBC2Tests.openDB(); + Connection con1 = TestUtil.openDB(); - JDBC2Tests.createTable( con1, "vv", "a int not null, b int not null, primary key ( a, b )" ); + TestUtil.createTable( con1, "vv", "a int not null, b int not null, primary key ( a, b )" ); - JDBC2Tests.createTable( con1, "ww", "m int not null, n int not null, primary key ( m, n ), foreign key ( m, n ) references vv ( a, b )" ); + TestUtil.createTable( con1, "ww", "m int not null, n int not null, primary key ( m, n ), foreign key ( m, n ) references vv ( a, b )" ); DatabaseMetaData dbmd = con.getMetaData(); @@ -271,8 +271,8 @@ public class DatabaseMetaDataTest extends TestCase } - JDBC2Tests.dropTable( con1, "vv" ); - JDBC2Tests.dropTable( con1, "ww" ); + TestUtil.dropTable( con1, "vv" ); + TestUtil.dropTable( con1, "ww" ); } catch (SQLException ex) @@ -284,11 +284,11 @@ public class DatabaseMetaDataTest extends TestCase { try { - Connection con1 = JDBC2Tests.openDB(); - JDBC2Tests.createTable( con1, "people", "id int4 primary key, name text" ); - JDBC2Tests.createTable( con1, "policy", "id int4 primary key, name text" ); + Connection con1 = TestUtil.openDB(); + TestUtil.createTable( con1, "people", "id int4 primary key, name text" ); + TestUtil.createTable( con1, "policy", "id int4 primary key, name text" ); - JDBC2Tests.createTable( con1, "users", "id int4 primary key, people_id int4, policy_id int4,"+ + TestUtil.createTable( con1, "users", "id int4 primary key, people_id int4, policy_id int4,"+ "CONSTRAINT people FOREIGN KEY (people_id) references people(id),"+ "constraint policy FOREIGN KEY (policy_id) references policy(id)" ); @@ -337,9 +337,9 @@ public class DatabaseMetaDataTest extends TestCase assertTrue( rs.getString( "FK_NAME" ).equals( "people" ) ); - JDBC2Tests.dropTable( con1, "users" ); - JDBC2Tests.dropTable( con1, "people" ); - JDBC2Tests.dropTable( con1, "policy" ); + TestUtil.dropTable( con1, "users" ); + TestUtil.dropTable( con1, "people" ); + TestUtil.dropTable( con1, "policy" ); } catch (SQLException ex) @@ -405,8 +405,8 @@ public class DatabaseMetaDataTest extends TestCase DatabaseMetaData dbmd = con.getMetaData(); assertNotNull(dbmd); - assertTrue(dbmd.getURL().equals(JDBC2Tests.getURL())); - assertTrue(dbmd.getUserName().equals(JDBC2Tests.getUser())); + assertTrue(dbmd.getURL().equals(TestUtil.getURL())); + assertTrue(dbmd.getUserName().equals(TestUtil.getUser())); } catch (SQLException ex) diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DateTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DateTest.java index 300d1549bb..7c1f01a950 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DateTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DateTest.java @@ -1,11 +1,11 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; /* - * $Id: DateTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $ + * $Id: DateTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $ * * Some simple tests based on problems reported by users. Hopefully these will * help prevent previous problems from re-occuring ;-) @@ -23,14 +23,14 @@ public class DateTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); - JDBC2Tests.createTable(con, "testdate", "dt date"); + con = TestUtil.openDB(); + TestUtil.createTable(con, "testdate", "dt date"); } protected void tearDown() throws Exception { - JDBC2Tests.dropTable(con, "testdate"); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, "testdate"); + TestUtil.closeDB(con); } /* @@ -42,10 +42,10 @@ public class DateTest extends TestCase { Statement stmt = con.createStatement(); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testdate", "'1950-02-07'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testdate", "'1970-06-02'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testdate", "'1999-08-11'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testdate", "'2001-02-13'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1950-02-07'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1970-06-02'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1999-08-11'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2001-02-13'"))); /* dateTest() contains all of the tests */ dateTest(); @@ -67,7 +67,7 @@ public class DateTest extends TestCase try { Statement stmt = con.createStatement(); - PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testdate", "?")); + PreparedStatement ps = con.prepareStatement(TestUtil.insertSQL("testdate", "?")); ps.setDate(1, makeDate(1950, 2, 7)); assertEquals(1, ps.executeUpdate()); @@ -104,7 +104,7 @@ public class DateTest extends TestCase ResultSet rs; java.sql.Date d; - rs = st.executeQuery(JDBC2Tests.selectSQL("testdate", "dt")); + rs = st.executeQuery(TestUtil.selectSQL("testdate", "dt")); assertNotNull(rs); assertTrue(rs.next()); @@ -135,8 +135,8 @@ public class DateTest extends TestCase private java.sql.Date makeDate(int y, int m, int d) { - return java.sql.Date.valueOf(JDBC2Tests.fix(y, 4) + "-" + - JDBC2Tests.fix(m, 2) + "-" + - JDBC2Tests.fix(d, 2)); + return java.sql.Date.valueOf(TestUtil.fix(y, 4) + "-" + + TestUtil.fix(m, 2) + "-" + + TestUtil.fix(d, 2)); } } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java index f2ec356c5a..d8e0ca56ef 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java @@ -1,11 +1,11 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; /* - * $Id: DriverTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $ + * $Id: DriverTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $ * * Tests the dynamically created class org.postgresql.Driver * @@ -63,12 +63,12 @@ public class DriverTest extends TestCase Class.forName("org.postgresql.Driver"); // Test with the url, username & password - con = DriverManager.getConnection(JDBC2Tests.getURL(), JDBC2Tests.getUser(), JDBC2Tests.getPassword()); + con = DriverManager.getConnection(TestUtil.getURL(), TestUtil.getUser(), TestUtil.getPassword()); assertNotNull(con); con.close(); // Test with the username in the url - con = DriverManager.getConnection(JDBC2Tests.getURL() + "?user=" + JDBC2Tests.getUser() + "&password=" + JDBC2Tests.getPassword()); + con = DriverManager.getConnection(TestUtil.getURL() + "?user=" + TestUtil.getUser() + "&password=" + TestUtil.getPassword()); assertNotNull(con); con.close(); } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java index 456a514613..ee4a0ebd5a 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java @@ -1,12 +1,12 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; import java.math.BigDecimal; /* - * $Id: JBuilderTest.java,v 1.5 2001/11/19 22:33:39 momjian Exp $ + * $Id: JBuilderTest.java,v 1.6 2002/08/14 20:35:40 barry Exp $ * * Some simple tests to check that the required components needed for JBuilder * stay working @@ -23,20 +23,20 @@ public class JBuilderTest extends TestCase // Set up the fixture for this testcase: the tables for this test. protected void setUp() throws Exception { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); - JDBC2Tests.createTable( con, "test_c", + TestUtil.createTable( con, "test_c", "source text,cost money,imageid int4" ); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } // Tear down the fixture for this test case. protected void tearDown() throws Exception { - Connection con = JDBC2Tests.openDB(); - JDBC2Tests.dropTable(con, "test_c"); - JDBC2Tests.closeDB(con); + Connection con = TestUtil.openDB(); + TestUtil.dropTable(con, "test_c"); + TestUtil.closeDB(con); } /* @@ -46,7 +46,7 @@ public class JBuilderTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select cost from test_c"); @@ -60,7 +60,7 @@ public class JBuilderTest extends TestCase rs.close(); st.close(); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch (Exception ex) { diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java new file mode 100644 index 0000000000..64dd44848a --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java @@ -0,0 +1,70 @@ +package org.postgresql.test.jdbc2; + +import junit.framework.TestSuite; +import junit.framework.TestCase; +import junit.framework.Test; + +import java.sql.*; +import java.lang.reflect.Method; + +/* + * Executes all known tests for JDBC2 and includes some utility methods. + */ +public class Jdbc2TestSuite extends TestSuite +{ + + /* + * The main entry point for JUnit + */ + public static TestSuite suite() + { + TestSuite suite = new TestSuite(); + + // + // Add one line per class in our test cases. These should be in order of + // complexity. + + // ANTTest should be first as it ensures that test parameters are + // being sent to the suite. It also initialises the database (if required) + // with some simple global tables (will make each testcase use its own later). + // + suite.addTestSuite(ANTTest.class); + + // Basic Driver internals + suite.addTestSuite(DriverTest.class); + suite.addTestSuite(ConnectionTest.class); + suite.addTestSuite(DatabaseMetaDataTest.class); + suite.addTestSuite(EncodingTest.class); + + // Connectivity/Protocols + + // ResultSet + suite.addTestSuite(ResultSetTest.class); + + // Time, Date, Timestamp + suite.addTestSuite(DateTest.class); + suite.addTestSuite(TimeTest.class); + suite.addTestSuite(TimestampTest.class); + + // PreparedStatement + + // BatchExecute + suite.addTestSuite(BatchExecuteTest.class); + + // MetaData + + // Other misc tests, based on previous problems users have had or specific + // features some applications require. + suite.addTestSuite(JBuilderTest.class); + suite.addTestSuite(MiscTest.class); + + // Fastpath/LargeObject + suite.addTestSuite(BlobTest.class); + suite.addTestSuite( UpdateableResultTest.class ); + + suite.addTestSuite( CallableStmtTest.class ); + + // That's all folks + return suite; + } +} diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java index 753d33a3e6..7164327f04 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java @@ -1,11 +1,11 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; /* - * $Id: MiscTest.java,v 1.6 2002/06/14 10:56:13 davec Exp $ + * $Id: MiscTest.java,v 1.7 2002/08/14 20:35:40 barry Exp $ * * Some simple tests based on problems reported by users. Hopefully these will * help prevent previous problems from re-occuring ;-) @@ -30,7 +30,7 @@ public class MiscTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select datname from pg_database"); @@ -44,7 +44,7 @@ public class MiscTest extends TestCase rs.close(); st.close(); - JDBC2Tests.closeDB(con); + TestUtil.closeDB(con); } catch (Exception ex) { @@ -54,7 +54,7 @@ public class MiscTest extends TestCase public void testError() { - Connection con = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); try { @@ -81,17 +81,17 @@ public class MiscTest extends TestCase System.out.println("testing lock"); try { - Connection con = JDBC2Tests.openDB(); - Connection con2 = JDBC2Tests.openDB(); + Connection con = TestUtil.openDB(); + Connection con2 = TestUtil.openDB(); - JDBC2Tests.createTable(con, "test_lock", "name text"); + TestUtil.createTable(con, "test_lock", "name text"); Statement st = con.createStatement(); Statement st2 = con2.createStatement(); con.setAutoCommit(false); st.execute("lock table test_lock"); st2.executeUpdate( "insert into test_lock ( name ) values ('hello')" ); con.commit(); - JDBC2Tests.dropTable(con, "test_lock"); + TestUtil.dropTable(con, "test_lock"); con.close(); } catch ( Exception ex ) diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java index 49af9e5ce9..0a818c529b 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java @@ -1,6 +1,6 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.io.*; import java.sql.*; @@ -19,10 +19,10 @@ public class ResultSetTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); + con = TestUtil.openDB(); Statement stmt = con.createStatement(); - JDBC2Tests.createTable(con, "testrs", "id integer"); + TestUtil.createTable(con, "testrs", "id integer"); stmt.executeUpdate("INSERT INTO testrs VALUES (1)"); stmt.executeUpdate("INSERT INTO testrs VALUES (2)"); @@ -36,8 +36,8 @@ public class ResultSetTest extends TestCase protected void tearDown() throws Exception { - JDBC2Tests.dropTable(con, "testrs"); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, "testrs"); + TestUtil.closeDB(con); } public void testAbsolute() throws Exception diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimeTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimeTest.java index 88ba63f76a..9f2dc1600f 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimeTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimeTest.java @@ -1,11 +1,11 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; /* - * $Id: TimeTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $ + * $Id: TimeTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $ * * Some simple tests based on problems reported by users. Hopefully these will * help prevent previous problems from re-occuring ;-) @@ -23,14 +23,14 @@ public class TimeTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); - JDBC2Tests.createTable(con, "testtime", "tm time"); + con = TestUtil.openDB(); + TestUtil.createTable(con, "testtime", "tm time"); } protected void tearDown() throws Exception { - JDBC2Tests.dropTable(con, "testtime"); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, "testtime"); + TestUtil.closeDB(con); } /* @@ -42,8 +42,8 @@ public class TimeTest extends TestCase { Statement stmt = con.createStatement(); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtime", "'01:02:03'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtime", "'23:59:59'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'01:02:03'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'23:59:59'"))); // Fall through helper timeTest(); @@ -64,7 +64,7 @@ public class TimeTest extends TestCase { try { - PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testtime", "?")); + PreparedStatement ps = con.prepareStatement(TestUtil.insertSQL("testtime", "?")); Statement stmt = con.createStatement(); ps.setTime(1, makeTime(1, 2, 3)); @@ -95,7 +95,7 @@ public class TimeTest extends TestCase ResultSet rs; java.sql.Time t; - rs = st.executeQuery(JDBC2Tests.selectSQL("testtime", "tm")); + rs = st.executeQuery(TestUtil.selectSQL("testtime", "tm")); assertNotNull(rs); assertTrue(rs.next()); @@ -115,8 +115,8 @@ public class TimeTest extends TestCase private java.sql.Time makeTime(int h, int m, int s) { - return java.sql.Time.valueOf(JDBC2Tests.fix(h, 2) + ":" + - JDBC2Tests.fix(m, 2) + ":" + - JDBC2Tests.fix(s, 2)); + return java.sql.Time.valueOf(TestUtil.fix(h, 2) + ":" + + TestUtil.fix(m, 2) + ":" + + TestUtil.fix(s, 2)); } } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimestampTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimestampTest.java index 37eff6c5b7..444427f13f 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimestampTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/TimestampTest.java @@ -1,11 +1,11 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; /* - * $Id: TimestampTest.java,v 1.7 2002/07/23 03:59:55 barry Exp $ + * $Id: TimestampTest.java,v 1.8 2002/08/14 20:35:40 barry Exp $ * * Test get/setTimestamp for both timestamp with time zone and * timestamp without time zone datatypes @@ -23,18 +23,18 @@ public class TimestampTest extends TestCase protected void setUp() throws Exception { - con = JDBC2Tests.openDB(); + con = TestUtil.openDB(); Statement stmt = con.createStatement(); - JDBC2Tests.createTable(con, TSWTZ_TABLE, "ts timestamp with time zone"); - JDBC2Tests.createTable(con, TSWOTZ_TABLE, "ts timestamp without time zone"); + TestUtil.createTable(con, TSWTZ_TABLE, "ts timestamp with time zone"); + TestUtil.createTable(con, TSWOTZ_TABLE, "ts timestamp without time zone"); } protected void tearDown() throws Exception { - JDBC2Tests.dropTable(con, TSWTZ_TABLE); - JDBC2Tests.dropTable(con, TSWOTZ_TABLE); - JDBC2Tests.closeDB(con); + TestUtil.dropTable(con, TSWTZ_TABLE); + TestUtil.dropTable(con, TSWOTZ_TABLE); + TestUtil.closeDB(con); } /* @@ -49,9 +49,9 @@ public class TimestampTest extends TestCase Statement stmt = con.createStatement(); //Insert the three timestamp values in raw pg format - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWTZ_TABLE,"'" + TS1WTZ_PGFORMAT + "'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWTZ_TABLE,"'" + TS2WTZ_PGFORMAT + "'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWTZ_TABLE,"'" + TS3WTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE,"'" + TS1WTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE,"'" + TS2WTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE,"'" + TS3WTZ_PGFORMAT + "'"))); // Fall through helper timestampTestWTZ(); @@ -77,7 +77,7 @@ public class TimestampTest extends TestCase try { Statement stmt = con.createStatement(); - PreparedStatement pstmt = con.prepareStatement(JDBC2Tests.insertSQL(TSWTZ_TABLE, "?")); + PreparedStatement pstmt = con.prepareStatement(TestUtil.insertSQL(TSWTZ_TABLE, "?")); pstmt.setTimestamp(1, TS1WTZ); assertEquals(1, pstmt.executeUpdate()); @@ -114,9 +114,9 @@ public class TimestampTest extends TestCase Statement stmt = con.createStatement(); //Insert the three timestamp values in raw pg format - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWOTZ_TABLE,"'" + TS1WOTZ_PGFORMAT + "'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWOTZ_TABLE,"'" + TS2WOTZ_PGFORMAT + "'"))); - assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL(TSWOTZ_TABLE,"'" + TS3WOTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE,"'" + TS1WOTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE,"'" + TS2WOTZ_PGFORMAT + "'"))); + assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE,"'" + TS3WOTZ_PGFORMAT + "'"))); // Fall through helper timestampTestWOTZ(); @@ -143,7 +143,7 @@ public class TimestampTest extends TestCase try { Statement stmt = con.createStatement(); - PreparedStatement pstmt = con.prepareStatement(JDBC2Tests.insertSQL(TSWOTZ_TABLE, "?")); + PreparedStatement pstmt = con.prepareStatement(TestUtil.insertSQL(TSWOTZ_TABLE, "?")); pstmt.setTimestamp(1, TS1WOTZ); assertEquals(1, pstmt.executeUpdate()); @@ -240,12 +240,12 @@ public class TimestampTest extends TestCase java.text.DateFormat l_df; try { String l_ts; - l_ts = JDBC2Tests.fix(y, 4) + "-" + - JDBC2Tests.fix(m, 2) + "-" + - JDBC2Tests.fix(d, 2) + " " + - JDBC2Tests.fix(h, 2) + ":" + - JDBC2Tests.fix(mn, 2) + ":" + - JDBC2Tests.fix(se, 2) + " "; + l_ts = TestUtil.fix(y, 4) + "-" + + TestUtil.fix(m, 2) + "-" + + TestUtil.fix(d, 2) + " " + + TestUtil.fix(h, 2) + ":" + + TestUtil.fix(mn, 2) + ":" + + TestUtil.fix(se, 2) + " "; if (tz == null) { l_df = new java.text.SimpleDateFormat("y-M-d H:m:s"); diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java index 056e68eba0..8fd45c29f0 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java @@ -3,7 +3,7 @@ package org.postgresql.test.jdbc2; import java.sql.*; import junit.framework.TestCase; -import org.postgresql.test.JDBC2Tests; +import org.postgresql.test.TestUtil; /** *

Title:

*

Description:

@@ -25,12 +25,12 @@ public class UpdateableResultTest extends TestCase { try { - Connection con = JDBC2Tests.openDB(); - JDBC2Tests.createTable(con, "updateable","id int primary key, name text, notselected text"); - JDBC2Tests.createTable(con, "second","id1 int primary key, name1 text"); + Connection con = TestUtil.openDB(); + TestUtil.createTable(con, "updateable","id int primary key, name text, notselected text"); + TestUtil.createTable(con, "second","id1 int primary key, name1 text"); Statement st1 = con.createStatement(); boolean retVal = st1.execute( "insert into updateable ( id, name, notselected ) values (1, 'jake', 'avalue')" ); - assert( retVal== false ); + assertTrue(!retVal); retVal = st1.execute( "insert into second (id1, name1) values (1, 'jake')" ); assertTrue( !retVal ); @@ -121,8 +121,8 @@ public class UpdateableResultTest extends TestCase st.close(); - JDBC2Tests.dropTable( con,"updateable" ); - JDBC2Tests.closeDB( con ); + TestUtil.dropTable( con,"updateable" ); + TestUtil.closeDB( con ); } catch (Exception ex) { diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java new file mode 100644 index 0000000000..5e01e4ffe8 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java @@ -0,0 +1,23 @@ +package org.postgresql.test.jdbc3; + +import junit.framework.TestSuite; +import junit.framework.TestCase; +import junit.framework.Test; + +import java.sql.*; + +/* + * Executes all known tests for JDBC3 + */ +public class Jdbc3TestSuite extends TestSuite +{ + + /* + * The main entry point for JUnit + */ + public static TestSuite suite() + { + //Currently there are no specific jdbc3 tests so just run the jdbc2 tests + return org.postgresql.test.jdbc2.Jdbc2TestSuite.suite(); + } +} diff --git a/src/interfaces/jdbc/org/postgresql/xa/ClientConnection.java b/src/interfaces/jdbc/org/postgresql/xa/ClientConnection.java deleted file mode 100644 index dc46c873e8..0000000000 --- a/src/interfaces/jdbc/org/postgresql/xa/ClientConnection.java +++ /dev/null @@ -1,567 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: ClientConnection.java,v 1.4 2001/11/19 23:19:21 momjian Exp $ -*/ - - -package org.postgresql.xa; - - -import java.util.*; -import java.sql.*; - - -/* - * Encapsulates an application's view of an XA/pooled connection. - * The XA connection is managed by the application server through it's - * {@link javax.sql.XAConnection} interface. The underlying JDBC - * connection is a standard JDBC connection. The application's - * JDBC connection gives access to the underlying JDBC connection but - * is managed by the application server. The application is given an - * instance of this class and not the underlying connection directly. - * - * - * @author Assaf Arkin - * @version 1.0 - * @see XAConnectionImpl - * @see XADataSourceImpl - * @see Connection - */ -final class ClientConnection - implements Connection -{ - - - /* - * The pooled XA connection that created this client connection - * and should be used to report closure and fatal errors. - */ - private XAConnectionImpl _xaConn; - - - /* - * This identifier was handed on to use when we were created by - * {@link XAConnection}. If since then the XA connection was asked - * to create another connection or was closed, our identifier will - * no longer be valid and any call to {@link - * XAConnection#getUnderlying} will throw an exception. Previously, - * the XA connection would hold a reference to use and tell us to - * terminate, but that prevented ClientConnection from being - * finalized. - */ - private int _clientId; - - - - - /* - * Construct a new client connection to provide access to the - * underlying JDBC connection (underlying) on behalf of - * an XA/pooled connection (xaConn). The pooled connection - * is required to notify of connection closure and fatal errors. - * - * @param xaConn The XA/pooled connection that created this - * client connection - * @param clientId A unique identifier handed to us by - * {@link XAConnection} - * @param underlying The underlying JDBC connection - */ - ClientConnection( XAConnectionImpl xaConn, int clientId ) - { - _xaConn = xaConn; - _clientId = clientId; - } - - - public Statement createStatement() - throws SQLException - { - try - { - return getUnderlying().createStatement(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public Statement createStatement( int resultSetType, int resultSetConcurrency ) - throws SQLException - { - try - { - return getUnderlying().createStatement( resultSetType, resultSetConcurrency ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public PreparedStatement prepareStatement( String sql ) - throws SQLException - { - try - { - return getUnderlying().prepareStatement( sql ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency ) - throws SQLException - { - try - { - return getUnderlying().prepareStatement( sql, resultSetType, resultSetConcurrency ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public CallableStatement prepareCall( String sql ) - throws SQLException - { - try - { - return getUnderlying().prepareCall( sql ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency ) - throws SQLException - { - try - { - return getUnderlying().prepareCall( sql, resultSetType, resultSetConcurrency ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public String nativeSQL( String sql ) - throws SQLException - { - try - { - return getUnderlying().nativeSQL( sql ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public DatabaseMetaData getMetaData() - throws SQLException - { - try - { - return getUnderlying().getMetaData(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void setCatalog( String catalog ) - throws SQLException - { - try - { - getUnderlying().setCatalog( catalog ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public String getCatalog() - throws SQLException - { - try - { - return getUnderlying().getCatalog(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public SQLWarning getWarnings() - throws SQLException - { - try - { - return getUnderlying().getWarnings(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void clearWarnings() - throws SQLException - { - try - { - getUnderlying().clearWarnings(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public Map getTypeMap() - throws SQLException - { - try - { - return getUnderlying().getTypeMap(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void setTypeMap( Map map ) - throws SQLException - { - try - { - getUnderlying().setTypeMap( map ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void setAutoCommit( boolean autoCommit ) - throws SQLException - { - // Cannot set auto-commit inside a transaction. - if ( _xaConn.insideGlobalTx() ) - throw new SQLException( "Cannot commit/rollback a connection managed by the transaction manager" ); - try - { - getUnderlying().setAutoCommit( autoCommit ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public boolean getAutoCommit() - throws SQLException - { - try - { - return getUnderlying().getAutoCommit(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void commit() - throws SQLException - { - // Cannot commit directly if we're inside a global transaction. - if ( _xaConn.insideGlobalTx() ) - throw new SQLException( "Cannot commit/rollback a connection managed by the transaction manager" ); - // Cannot commit a read-only transaction. - if ( isReadOnly() ) - throw new SQLException( "Cannot commit/rollback a read-only transaction" ); - - // This only occurs if not inside a local transaction. - try - { - getUnderlying().commit(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - - public void rollback() - throws SQLException - { - // Cannot commit directly if we're inside a global transaction. - if ( _xaConn.insideGlobalTx() ) - throw new SQLException( "Cannot commit/rollback a connection managed by the transaction manager" ); - - // This only occurs if not inside a local transaction. - try - { - getUnderlying().rollback(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void setReadOnly( boolean readOnly ) - throws SQLException - { - try - { - getUnderlying().setReadOnly( readOnly ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public boolean isReadOnly() - throws SQLException - { - try - { - return getUnderlying().isReadOnly(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public void setTransactionIsolation( int level ) - throws SQLException - { - try - { - getUnderlying().setTransactionIsolation( level ); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public int getTransactionIsolation() - throws SQLException - { - try - { - return getUnderlying().getTransactionIsolation(); - } - catch ( SQLException except ) - { - notifyError( except ); - throw except; - } - } - - - public synchronized void close() - throws SQLException - { - if ( _xaConn == null ) - return; - - // Notify the XA connection that we are no longer going - // to be used. Whether the underlying connection is released, - // held until the transaction terminates, etc is not - // a concern of us. - _xaConn.notifyClose( _clientId ); - _xaConn = null; - } - - - public synchronized boolean isClosed() - { - // Simple way of determining if this connection is closed. - // The actual connection is never closed, it is pooled. - return ( _xaConn == null ); - } - - - /* - * Called by {@link XAConnectionImpl} to terminate this connection - * by dissociating it from the underlying JDBC connection. - * The application would call {@link #close} but {@link - * XAConnectionImpl} cannot, since pooled connection requirements - * will cause an inifinite loop. This method should not attempt - * to notify either a closure or fatal error, but rather throw an - * exception if it fails. - */ - /* Deprecated: see XAConnection._clientId - void terminate() -{ - _xaConn = null; -} - */ - - - protected void finalize() - throws Throwable - { - close(); - } - - - public String toString() - { - try - { - return getUnderlying().toString(); - } - catch ( SQLException except ) - { - return "XAConnection: Connection closed"; - } - } - - - /* - * Called when an exception is thrown by the underlying connection - * to determine whether the exception is critical or not. If the - * exception is critical, notifies the XA connection to forget - * about this connection. - * - * @param except The exception thrown by the underlying - * connection - */ - void notifyError( SQLException except ) - { - if ( _xaConn != null ) - _xaConn.notifyError( _clientId, except ); - } - - - /* - * Called to retrieve the underlying JDBC connection. Actual JDBC - * operations are performed against it. Throws an SQLException if - * this connection has been closed. - */ - Connection getUnderlying() - throws SQLException - { - if ( _xaConn == null ) - throw new SQLException( "This connection has been closed" ); - // Must pass the client identifier so XAConnection can determine - // whether we are still valid. If it tells us we're no longer - // valid, we have little to do. - try - { - return _xaConn.getUnderlying( _clientId ); - } - catch ( SQLException except ) - { - _xaConn = null; - throw except; - } - } - - -} - - - diff --git a/src/interfaces/jdbc/org/postgresql/xa/TwoPhaseConnection.java b/src/interfaces/jdbc/org/postgresql/xa/TwoPhaseConnection.java deleted file mode 100644 index 7b0ce88f49..0000000000 --- a/src/interfaces/jdbc/org/postgresql/xa/TwoPhaseConnection.java +++ /dev/null @@ -1,116 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: TwoPhaseConnection.java,v 1.3 2001/11/19 22:33:39 momjian Exp $ -*/ - - -package org.postgresql.xa; - - -import java.sql.SQLException; - - -/* - * Defines two-phase commit support for a JDBC connection used by - * {@link XAConnection}. A JDBC connection that can implement any of - * these features should extend this interface and attempt to - * implement as much as it can. - *

- * {@link #prepare} is used as part of the two phase commit protocol - * to determine whether the transaction can commit or must rollback. - * Failure to implement this method will cause all connections to vote - * for commit, whether or not they can actually commit, leading to - * mixed heuristics. - *

- * {@link #enableSQLTransactions} allows the SQL begin/commit/rollback - * commands to be disabled for the duration of a transaction managed - * through an {@link javax.transaction.xaXAResource}, preventing the - * application from demarcating transactions directly. - *

- * {@link #isCriticalError} is used to tell if an exception thrown by - * the connection is fatal and the connection should not be returned - * to the pool. - * - * - * @author Assaf Arkin - * @version 1.0 - */ -public interface TwoPhaseConnection -{ - - - /* - * Enables or disables transaction demarcation through SQL commit - * and rollback. When the connection falls under control of - * {@link XAConnection}, SQL commit/rollback commands will be - * disabled to prevent direct transaction demarcation. - * - * @param flag True to enable SQL transactions (the default) - */ - public void enableSQLTransactions( boolean flag ); - - - /* - * Called to prepare the transaction for commit. Returns true if - * the transaction is prepared, false if the transaction is - * read-only. If the transaction has been marked for rollback, - * throws a {@link RollbackException}. - * - * @return True if can commit, false if read-only - * @throws SQLException If transaction has been marked for - * rollback or cannot commit for any other reason - */ - public boolean prepare() - throws SQLException; - - - /* - * Returns true if the error issued by this connection is a - * critical error and the connection should be terminated. - * - * @param except The exception thrown by this connection - */ - public boolean isCriticalError( SQLException except ); - - -} diff --git a/src/interfaces/jdbc/org/postgresql/xa/TxConnection.java b/src/interfaces/jdbc/org/postgresql/xa/TxConnection.java deleted file mode 100644 index ef2179285f..0000000000 --- a/src/interfaces/jdbc/org/postgresql/xa/TxConnection.java +++ /dev/null @@ -1,129 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: TxConnection.java,v 1.3 2001/11/19 22:33:39 momjian Exp $ -*/ - - -package org.postgresql.xa; - - -import java.sql.Connection; -import javax.transaction.xa.Xid; - - -/* - * Describes an open connection associated with a transaction. When a - * transaction is opened for a connection, this record is created for - * the connection. It indicates the underlying JDBC connection and - * transaction Xid. Multiple XA connection that fall under the same - * transaction Xid will share the same TxConnection object. - * - * - * @author Assaf Arkin - * @version 1.0 - * @see Xid - * @see XAConnectionImpl - */ -final class TxConnection -{ - - - /* - * The Xid of the transactions. Connections that are not - * associated with a transaction are not represented here. - */ - Xid xid; - - - /* - * Holds the underlying JDBC connection for as long as this - * connection is useable. If the connection has been rolled back, - * timed out or had any other error, this variable will null - * and the connection is considered failed. - */ - Connection conn; - - - - /* - * Indicates the clock time (in ms) when the transaction should - * time out. The transaction times out when - * System.currentTimeMillis() > timeout. - */ - long timeout; - - - /* - * Indicates the clock time (in ms) when the transaction started. - */ - long started; - - - /* - * Reference counter indicates how many XA connections share this - * underlying connection and transaction. Always one or more. - */ - int count; - - - /* - * True if the transaction has failed due to time out. - */ - boolean timedOut; - - - /* - * True if the transaction has already been prepared. - */ - boolean prepared; - - - /* - * True if the transaction has been prepared and found out to be - * read-only. Read-only transactions do not require commit/rollback. - */ - boolean readOnly; - - -} - diff --git a/src/interfaces/jdbc/org/postgresql/xa/XAConnectionImpl.java b/src/interfaces/jdbc/org/postgresql/xa/XAConnectionImpl.java deleted file mode 100644 index 776badfd6d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/xa/XAConnectionImpl.java +++ /dev/null @@ -1,956 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: XAConnectionImpl.java,v 1.4 2001/11/19 23:19:21 momjian Exp $ -*/ - - -package org.postgresql.xa; - - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Vector; -import javax.sql.XAConnection; -import javax.sql.PooledConnection; -import javax.sql.ConnectionEvent; -import javax.sql.ConnectionEventListener; -import javax.transaction.RollbackException; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; -import javax.transaction.xa.XAException; - - -/* - * Implements an X/A connection that can be pooled and managed from - * inside a transaction monitor. This is the XA connection returned - * to the application server from the {@link XADataSourceImpl} and - * will be used to obtain {@link ClientConnection} for the - * application. - *

- * If the transaction is managed through the JDBC interface, this - * connection will reference the underlying JDBC connection directly. - * If this resource is enlisted with a global transaction through - * the {@link XAResource} interface, it will reference a transactional - * connection, or {@link TxConnection}. Such a connection may be - * shared by two or more XA connections enlisted with the same - * transaction. - * - * - * @author Assaf Arkin - * @version 1.0 - * @see ClientConnection - * @see ConnectionEventListener - * @see TxConnection - */ -public final class XAConnectionImpl - implements XAConnection, XAResource -{ - - - /* - * This is the underlying JDBC connection represented - * by this pooled connection. This variable may initially be null, - * in which case {@link #getUnderlying} will return a new - * connection and set this variable. This variable is mutually - * exclusive with {@link #_txConn} and is always null for - * connections inside a transaction. - */ - Connection _underlying; - - - /* - * If this connection is part of a global transaction, this - * object identifies the transaction. The transaction's - * underlying JDBC connection is exposed through this object and - * {@link #_underlying} is null. If this connection is closed, - * then the connection has been timedout. Commit/rollback will - * always set this variable to null. - */ - private TxConnection _txConn; - - - /* - * The client connection last handed to the application. If the - * application calls {@link #getConnection} again, we should hand - * out a new client connection and render the previous one closed. - */ - // No longer in use, see _clientId - //private ClientConnection _clientConn; - - - /* - * An event listener can be registered and notified when the - * client connection has been closed by the application or a - * fatal error rendered it unuseable. - */ - private ConnectionEventListener _listener; - - - /* - * The resource manager is used to share connections within the - * same transaction. - */ - private XADataSourceImpl _resManager; - - - /* - * This is an identifier we hand to the client connection when we - * create it. When the client connection asks for the underlying - * connection, we compare the identifiers. If since that point we - * created a new client connection, we regard an old client - * connection as discarded and do not hand it the underlying - * connection. - *

- * Previously, when a new client connection was created, we used - * a reference to the old one to terminate it. This proved to - * not work well, since the client connection could never be - * finalized. - */ - private int _clientId = 1; - - - /* - * Construct a new XA/pooled connection with the underlying JDBC - * connection suitable for this driver only. This is a one to one - * mapping between this connection and the underlying connection. - * The underlying connection is only provided for pooled - * connections. XA connections are suspect of being enlisted with - * a global transaction which might already bear an underlying - * connection. If not, one will be created later on. - */ - XAConnectionImpl( XADataSourceImpl resManager, - Connection underlying ) - { - _underlying = underlying; - _resManager = resManager; - } - - - public synchronized void close() - throws SQLException - { - // This is our indication that this connection has been - // closed programmatically. - if ( _resManager == null ) - throw new SQLException( "This connection has been closed" ); - - // The client connection is no longer useable. - /* Deprecated: see _clientId - if ( _clientConn != null ) - _clientConn.terminate(); - */ - _clientId = -1; - - // The underlying connection is closed and this connection - // is no longer useable. This method can be called any number - // of times (e.g. we use it in finalizer). We do not handle - // transactions, we just kill the connection. - try - { - if ( _underlying != null ) - { - _underlying.commit(); - _underlying.close(); - } - else if ( _txConn != null ) - { - try - { - end( _txConn.xid, TMSUCCESS ); - } - catch ( XAException except ) - { } - } - } - finally - { - _resManager = null; - _underlying = null; - _txConn = null; - _listener = null; - } - } - - - public XAResource getXAResource() - { - // The connection acts as it's own resource manager - return this; - } - - - public synchronized void addConnectionEventListener( ConnectionEventListener listener ) - { - if ( listener == null ) - throw new NullPointerException( "XAConnection: Argument 'listener' is null" ); - if ( _listener != null ) - throw new IllegalStateException( "XAConnection: Only one listener supported per connection" ); - _listener = listener; - } - - - public synchronized void removeConnectionEventListener( ConnectionEventListener listener ) - { - if ( listener == null ) - throw new NullPointerException( "XAConnection: Argument 'listener' is null" ); - if ( _listener == null || _listener != listener ) - throw new IllegalStateException( "XAConnection: Listener never registered with this pooled connection" ); - _listener = null; - } - - - public synchronized java.sql.Connection getConnection() - throws SQLException - { - // If this pooled connection has been closed, throw an exception. - if ( _resManager == null ) - throw new SQLException( "This connection has been closed" ); - - // If getConnection() was called before and the underlying - // connection was not closed, we take it away from the previous - // recieved as per the PooledConnection design. - /* Deprecated: see _clientId - if ( _clientConn != null ) - _clientConn.terminate(); - */ - - // If we are handling an underlying connection, we commit the - // old transaction and are ready to work for a new one. - // If we are part of a global transaction we hope that end/ - // start were called properly, but we're not longer in that - // transaction. - if ( _underlying != null ) - { - try - { - _underlying.commit(); - } - catch ( SQLException except ) - { - ConnectionEvent event; - - if ( _listener != null ) - { - event = new ConnectionEvent( this, except ); - _listener.connectionErrorOccurred( event ); - } - } - } - - // Create a new ClientConnection which will be returned to the - // application. The ClientConnection cannot be closed directly - // and cannot manage it's own transactions. - /* Deprecated: see _clientId - _clientConn = new ClientConnection( this ); - return _clientConn; - */ - return new ClientConnection( this, ++_clientId ); - } - - - /* - * Called by {@link ClientConnection} to notify that the application - * has attempted to close the connection. After this call, the client - * connection is no longer useable and this pooled connection can be - * reused. The event listener is notified immediately. - * - * @param clientId The {@link ClientConnection} identifier - */ - synchronized void notifyClose( int clientId ) - { - ConnectionEvent event; - - // ClientConnection has been closed, we dissociated it from - // the underlying connection and notify any listener that this - // pooled connection can be reused. - /* Deprecated: see clientId - _clientConn.terminate(); - _clientConn = null; - */ - // We have to expect being called by a ClientConnection that we - // no longer regard as valid. That's acceptable, we just ignore. - if ( clientId != _clientId ) - return; - - // If we are handling an underlying connection, we commit the - // old transaction and are ready to work for a new one. - // If we are part of a global transaction we hope that end/ - // start were called properly. - if ( _underlying != null ) - { - try - { - _underlying.commit(); - } - catch ( SQLException except ) - { - if ( _listener != null ) - { - event = new ConnectionEvent( this, except ); - _listener.connectionErrorOccurred( event ); - } - return; - } - } - // Notify the listener. - if ( _listener != null ) - { - event = new ConnectionEvent( this ); - _listener.connectionClosed( event ); - } - } - - - /* - * Called by {@link ClientConnection} to notify that an error - * occured with the underlying connection. If the error is - * critical, the underlying connection is closed and the listener - * is notified. - * - * @param clientId The {@link ClientConnection} identifier - * @param except The exception raised by the underlying connection - */ - synchronized void notifyError( int clientId, SQLException except ) - { - ConnectionEvent event; - - if ( clientId != _clientId ) - return; - - // If the connection is not two-phase commit we cannot determine - // whether the error is critical, we just return. If the connection - // is two phase commit, but the error is not critical, we return. - if ( _underlying != null ) - { - if ( ! ( _underlying instanceof TwoPhaseConnection ) || - ! ( (TwoPhaseConnection) _underlying ).isCriticalError( except ) ) - return; - if ( _txConn.conn == null || - ! ( _txConn.conn instanceof TwoPhaseConnection ) || - ! ( (TwoPhaseConnection) _txConn.conn ).isCriticalError( except ) ) - return; - } - - // The client connection is no longer useable, the underlying - // connection (if used) is closed, the TxConnection (if used) - // is rolledback and this connection dies (but close() may - // still be called). - ++_clientId; - if ( _underlying != null ) - { - try - { - _underlying.close(); - } - catch ( SQLException e2 ) - { - // Ignore that, we know there's an error. - } - _underlying = null; - } - else if ( _txConn != null ) - { - try - { - end( _txConn.xid, TMFAIL ); - } - catch ( XAException e2 ) - { - // Ignore that, we know there's an error. - } - _txConn = null; - } - - // Notify the listener. - if ( _listener != null ) - { - event = new ConnectionEvent( this, except ); - _listener.connectionErrorOccurred( event ); - } - } - - - protected void finalize() - throws Throwable - { - // We are no longer referenced by anyone (including the - // connection pool). Time to close down. - close(); - } - - - public String toString() - { - if ( _underlying != null ) - return "XAConnection: " + _underlying; - else - return "XAConnection: unused"; - } - - - public synchronized void start( Xid xid, int flags ) - throws XAException - { - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - if ( _txConn != null ) - throw new XAException( XAException.XAER_OUTSIDE ); - - synchronized ( _resManager ) - { - if ( flags == TMNOFLAGS ) - { - // Starting a new transaction. First, make sure it is - // not shared with any other connection (need to join - // for that). - if ( _resManager.getTxConnection( xid ) != null ) - throw new XAException( XAException.XAER_DUPID ); - - // Create a new TxConnection to describe this - // connection in the context of a transaction and - // register it with the resource manager so it can - // be shared. - try - { - _txConn = new TxConnection(); - if ( _underlying != null ) - { - _txConn.conn = _underlying; - _underlying = null; - } - else - _txConn.conn = _resManager.newConnection(); - _txConn.xid = xid; - _txConn.count = 1; - _txConn.started = System.currentTimeMillis(); - _txConn.timeout = _txConn.started + ( _resManager.getTransactionTimeout() * 1000 ); - _resManager.setTxConnection( xid, _txConn ); - } - catch ( SQLException except ) - { - // If error occured at this point, we can only - // report it as resource manager error. - if ( _resManager.getLogWriter() != null ) - _resManager.getLogWriter().println( "XAConnection: failed to begin a transaction: " + except ); - throw new XAException( XAException.XAER_RMERR ); - } - - try - { - _txConn.conn.setAutoCommit( false ); - try - { - if ( _resManager.isolationLevel() != Connection.TRANSACTION_NONE ) - _txConn.conn.setTransactionIsolation( _resManager.isolationLevel() ); - } - catch ( SQLException e ) - { - // The underlying driver might not support this - // isolation level that we use by default. - } - if ( _txConn.conn instanceof TwoPhaseConnection ) - ( (TwoPhaseConnection) _txConn.conn ).enableSQLTransactions( false ); - } - catch ( SQLException except ) - { - // If error occured at this point, we can only - // report it as resource manager error. - if ( _resManager.getLogWriter() != null ) - _resManager.getLogWriter().println( "XAConnection: failed to begin a transaction: " + except ); - throw new XAException( XAException.XAER_RMERR ); - } - } - else if ( flags == TMJOIN || flags == TMRESUME ) - { - // We are joining another transaction with an - // existing TxConnection. - _txConn = _resManager.getTxConnection( xid ); - if ( _txConn == null ) - throw new XAException( XAException.XAER_INVAL ); - - // Update the number of XAConnections sharing this - // transaction connection. - if ( flags == TMJOIN && _txConn.count == 0 ) - throw new XAException( XAException.XAER_PROTO ); - ++_txConn.count; - - // If we already have an underlying connection (as we can - // expect to), we should release that underlying connection - // and make it available to the resource manager. - if ( _underlying != null ) - { - _resManager.releaseConnection( _underlying ); - _underlying = null; - } - } - else - // No other flags supported in start(). - throw new XAException( XAException.XAER_INVAL ); - } - } - - - public synchronized void end( Xid xid, int flags ) - throws XAException - { - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - // Note: we could get end with success or failure even it - // we were previously excluded from the transaction. - if ( _txConn == null && flags == TMSUSPEND ) - throw new XAException( XAException.XAER_NOTA ); - - synchronized ( _resManager ) - { - if ( flags == TMSUCCESS || flags == TMFAIL) - { - // We are now leaving a transaction we started or - // joined before. We can expect any of prepare/ - // commit/rollback to be called next, so TxConnection - // is still valid. - - // If we were suspended from the transaction, we'll - // join it for the duration of this operation. - // Make sure the reference count reaches zero by the - // time we get to prepare. - if ( _txConn == null ) - { - _txConn = _resManager.getTxConnection( xid ); - if ( _txConn == null ) - throw new XAException( XAException.XAER_NOTA ); - } - else - { - if ( _txConn.xid != null && ! _txConn.xid.equals( xid ) ) - throw new XAException( XAException.XAER_NOTA ); - --_txConn.count; - } - - // If transaction failed, we can rollback the - // transaction and release the underlying connection. - // We can expect all other resources to recieved the - // same end notification. We don't expect forget to happen. - if ( flags == TMFAIL && _txConn.conn != null ) - { - try - { - if ( _txConn.conn instanceof TwoPhaseConnection ) - ( (TwoPhaseConnection) _txConn.conn ).enableSQLTransactions( true ); - _txConn.conn.rollback(); - _resManager.releaseConnection( _txConn.conn ); - } - catch ( SQLException except ) - { - // There is a problem with the underlying - // connection, but it was not added to the poll. - } - _resManager.setTxConnection( _txConn.xid, null ); - _txConn.conn = null; - _txConn.xid = null; - } - - if ( flags == TMSUCCESS) - { - // We should be looking for a new transaction. - // Next thing we might be participating in a new - // transaction while the current one is being - // rolled back. - _txConn = null; - } - } - else if ( flags == TMSUSPEND ) - { - // We no longer take part in this transaction. - // Possibly we'll be asked to resume later on, but - // right now we have to forget about the transaction - // and the underlying connection. - --_txConn.count; - _txConn = null; - } - else - // No other flags supported in end(). - throw new XAException( XAException.XAER_INVAL ); - } - } - - - public synchronized void forget( Xid xid ) - throws XAException - { - TxConnection txConn; - - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - synchronized ( _resManager ) - { - // We have to forget about the transaction, meaning the - // transaction no longer exists for this or any other - // connection. We might be called multiple times. - txConn = _resManager.setTxConnection( xid, null ); - if ( _txConn == txConn ) - _txConn = null; - if ( txConn != null ) - { - if ( txConn.conn != null ) - { - _resManager.releaseConnection( txConn.conn ); - txConn.conn = null; - } - txConn.xid = null; - } - } - } - - - public synchronized int prepare( Xid xid ) - throws XAException - { - TxConnection txConn; - - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - - synchronized ( _resManager ) - { - // Technically, prepare may be called for any connection, - // not just this one. - txConn = _resManager.getTxConnection( xid ); - if ( txConn == null ) - throw new XAException( XAException.XAER_NOTA ); - - // This is an error and should never happen. All other - // parties in the transaction should have left it before. - if ( txConn.count > 0 ) - throw new XAException( XAException.XAER_PROTO ); - - // If the transaction failed, we have to force a rollback. - // We track the case of failure due to a timeout. - if ( txConn.timedOut ) - throw new XAException( XAException.XA_RBTIMEOUT ); - if ( txConn.conn == null ) - throw new XAException( XAException.XA_RBROLLBACK ); - - // Since there is no preparation mechanism in a generic - // JDBC driver, we only test for read-only transaction - // but do not commit at this point. - try - { - txConn.prepared = true; - if ( txConn.conn instanceof TwoPhaseConnection ) - { - // For 2pc connection we ask it to prepare and determine - // whether it's commiting or read-only. If a rollback - // exception happens, we report it. - try - { - if ( ( (TwoPhaseConnection) txConn.conn ).prepare() ) - return XA_OK; - else - { - txConn.readOnly = true; - return XA_RDONLY; - } - } - catch ( SQLException except ) - { - throw new XAException( XAException.XA_RBROLLBACK ); - } - } - else - { - // For standard connection we cannot prepare, we can - // only guess if it's read only. - if ( txConn.conn.isReadOnly() ) - { - txConn.readOnly = true; - return XA_RDONLY; - } - return XA_OK; - } - } - catch ( SQLException except ) - { - try - { - // Fatal error in the connection, kill it. - txConn.conn.close(); - } - catch ( SQLException e ) - { } - txConn.conn = null; - if ( _resManager.getLogWriter() != null ) - _resManager.getLogWriter().println( "XAConnection: failed to commit a transaction: " + except ); - // If we cannot commit the transaction, force a rollback. - throw new XAException( XAException.XA_RBROLLBACK ); - } - } - } - - - public Xid[] recover( int flags ) - throws XAException - { - synchronized ( _resManager ) - { - return _resManager.getTxRecover(); - } - } - - - public synchronized void commit( Xid xid, boolean onePhase ) - throws XAException - { - TxConnection txConn; - - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - - synchronized ( _resManager ) - { - // Technically, commit may be called for any connection, - // not just this one. - txConn = _resManager.getTxConnection( xid ); - if ( txConn == null ) - throw new XAException( XAException.XAER_NOTA ); - - // If the transaction failed, we have to force - // a rollback. - if ( txConn.conn == null ) - throw new XAException( XAException.XA_RBROLLBACK ); - - // If connection has been prepared and is read-only, - // nothing to do at this stage. - if ( txConn.readOnly ) - return; - - // This must be a one-phase commite, or the connection - // should have been prepared before. - if ( onePhase || txConn.prepared ) - { - try - { - // Prevent multiple commit attempts. - txConn.readOnly = true; - if ( txConn.conn instanceof TwoPhaseConnection ) - ( (TwoPhaseConnection) txConn.conn ).enableSQLTransactions( true ); - txConn.conn.commit(); - } - catch ( SQLException except ) - { - try - { - // Unknown error in the connection, better kill it. - txConn.conn.close(); - } - catch ( SQLException e ) - { } - txConn.conn = null; - if ( _resManager.getLogWriter() != null ) - _resManager.getLogWriter().println( "XAConnection: failed to commit a transaction: " + except ); - // If we cannot commit the transaction, a heuristic tollback. - throw new XAException( XAException.XA_HEURRB ); - } - } - else - { - // 2pc we should have prepared before. - if ( ! txConn.prepared ) - throw new XAException( XAException.XAER_PROTO ); - } - } - } - - - public synchronized void rollback( Xid xid ) - throws XAException - { - TxConnection txConn; - - - // General checks. - if ( xid == null ) - throw new XAException( XAException.XAER_INVAL ); - - synchronized ( _resManager ) - { - // Technically, rollback may be called for any connection, - // not just this one. - txConn = _resManager.getTxConnection( xid ); - if ( txConn == null ) - throw new XAException( XAException.XAER_NOTA ); - - // If connection has been prepared and is read-only, - // nothing to do at this stage. If connection has - // been terminated any other way, nothing to do - // either. - if ( txConn.readOnly || txConn.conn == null ) - return; - - try - { - txConn.prepared = false; - if ( txConn.conn instanceof TwoPhaseConnection ) - ( (TwoPhaseConnection) txConn.conn ).enableSQLTransactions( true ); - txConn.conn.rollback(); - } - catch ( SQLException except ) - { - try - { - // Unknown error in the connection, better kill it. - txConn.conn.close(); - } - catch ( SQLException e ) - { } - txConn.conn = null; - if ( _resManager.getLogWriter() != null ) - _resManager.getLogWriter().println( "XAConnection: failed to rollback a transaction: " + except ); - // If we cannot commit the transaction, a heuristic tollback. - throw new XAException( XAException.XA_RBROLLBACK ); - } - finally - { - forget( xid ); - } - } - } - - - public synchronized boolean isSameRM( XAResource xaRes ) - throws XAException - { - // Two resource managers are equal if they produce equivalent - // connection (i.e. same database, same user). If the two are - // equivalent they would share a transaction by joining. - if ( xaRes == null || ! ( xaRes instanceof XAConnectionImpl ) ) - return false; - if ( _resManager.equals( ( (XAConnectionImpl) xaRes )._resManager ) ) - return true; - return false; - } - - - public synchronized boolean setTransactionTimeout( int seconds ) - throws XAException - { - if ( seconds < 0 ) - throw new XAException( XAException.XAER_INVAL ); - // Zero resets to the default for all transactions. - if ( seconds == 0 ) - seconds = _resManager.getTransactionTimeout(); - // If a transaction has started, change it's timeout to the new value. - if ( _txConn != null ) - { - _txConn.timeout = _txConn.started + ( seconds * 1000 ); - return true; - } - return false; - } - - - public int getTransactionTimeout() - { - long timeout; - - if ( _txConn == null ) - return 0; - return (int) ( _txConn.timeout - _txConn.started ) / 1000; - } - - - /* - * Returns true if this connection is inside a global transaction. - * If the connection is inside a global transaction it will not - * allow commit/rollback directly from the {@link - * java.sql.Connection} interface. - */ - boolean insideGlobalTx() - { - return ( _txConn != null ); - } - - /* - * Called to obtain the underlying connections. If this connection - * is part of a transaction, the transction's underlying connection - * is returned, or an exception is thrown if the connection was - * terminated due to timeout. If this connection is not part of a - * transaction, a non-transactional connection is returned. - * - * @param clientId The {@link ClientConnection} identifier - */ - Connection getUnderlying( int clientId ) - throws SQLException - { - // If we were notified of the client closing, or have been - // requested to have a new client connection since then, - // the client id will not match to that of the caller. - // We use that to decide that the caller has been closed. - if ( clientId != _clientId ) - throw new SQLException( "This application connection has been closed" ); - - if ( _txConn != null ) - { - if ( _txConn.timedOut ) - throw new SQLException( "The transaction has timed out and has been rolledback and closed" ); - if ( _txConn.conn == null ) - throw new SQLException( "The transaction has been terminated and this connection has been closed" ); - return _txConn.conn; - } - if ( _underlying == null ) - { - _underlying = _resManager.newConnection(); - _underlying.setAutoCommit( true ); - } - return _underlying; - } - - -} - - - diff --git a/src/interfaces/jdbc/org/postgresql/xa/XADataSourceImpl.java b/src/interfaces/jdbc/org/postgresql/xa/XADataSourceImpl.java deleted file mode 100644 index ae34143cb2..0000000000 --- a/src/interfaces/jdbc/org/postgresql/xa/XADataSourceImpl.java +++ /dev/null @@ -1,489 +0,0 @@ -/* -* Redistribution and use of this software and associated documentation -* ("Software"), with or without modification, are permitted provided -* that the following conditions are met: -* -* 1. Redistributions of source code must retain copyright -* statements and notices. Redistributions must also contain a -* copy of this document. -* -* 2. Redistributions in binary form must reproduce the -* above copyright notice, this list of conditions and the -* following disclaimer in the documentation and/or other -* materials provided with the distribution. -* -* 3. The name "Exolab" must not be used to endorse or promote -* products derived from this Software without prior written -* permission of Exoffice Technologies. For written permission, -* please contact info@exolab.org. -* -* 4. Products derived from this Software may not be called "Exolab" -* nor may "Exolab" appear in their names without prior written -* permission of Exoffice Technologies. Exolab is a registered -* trademark of Exoffice Technologies. -* -* 5. Due credit should be given to the Exolab Project -* (http://www.exolab.org/). -* -* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS -* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -* OF THE POSSIBILITY OF SUCH DAMAGE. -* -* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. -* -* $Id: XADataSourceImpl.java,v 1.4 2001/11/19 23:16:46 momjian Exp $ -*/ - - -package org.postgresql.xa; - - -import java.io.Serializable; -import java.io.PrintWriter; -import java.util.Hashtable; -import java.util.Vector; -import java.util.Stack; -import java.util.Enumeration; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; -import javax.sql.PooledConnection; -import javax.sql.ConnectionPoolDataSource; -import javax.sql.XAConnection; -import javax.sql.XADataSource; -import javax.transaction.xa.Xid; - - - -/* - * Implements a JDBC 2.0 {@link XADataSource} for any JDBC driver - * with JNDI persistance support. The base implementation is actually - * provided by a different {@link DataSource} class; although this is - * the super class, it only provides the pooling and XA specific - * implementation. - * - * - * @author Assaf Arkin - * @version 1.0 - */ -public abstract class XADataSourceImpl - implements DataSource, ConnectionPoolDataSource, - XADataSource, Serializable, Runnable -{ - - - /* - * Maps underlying JDBC connections into global transaction Xids. - */ - private transient Hashtable _txConnections = new Hashtable(); - - - /* - * This is a pool of free underlying JDBC connections. If two - * XA connections are used in the same transaction, the second - * one will make its underlying JDBC connection available to - * the pool. This is not a real connection pool, only a marginal - * efficiency solution for dealing with shared transactions. - */ - private transient Stack _pool = new Stack(); - - - /* - * A background deamon thread terminating connections that have - * timed out. - */ - private transient Thread _background; - - - /* - * The default timeout for all new transactions. - */ - private int _txTimeout = DEFAULT_TX_TIMEOUT; - - - /* - * The default timeout for all new transactions is 10 seconds. - */ - public final static int DEFAULT_TX_TIMEOUT = 10; - - - - - /* - * Implementation details: - * If two XAConnections are associated with the same transaction - * (one with a start the other with a join) they must use the - * same underlying JDBC connection. They lookup the underlying - * JDBC connection based on the transaction's Xid in the - * originating XADataSource. - * - * Currently the XADataSource must be the exact same object, - * this should be changed so all XADataSources that are equal - * share a table of all enlisted connections - * - * To test is two connections should fall under the same - * transaction we match the resource managers by comparing the - * database/user they fall under using a comparison of the - * XADataSource properties. - */ - - - public XADataSourceImpl() - { - super(); - - // Create a background thread that will track transactions - // that timeout, abort them and release the underlying - // connections to the pool. - _background = new Thread( this, "XADataSource Timeout Daemon" ); - _background.setPriority( Thread.MIN_PRIORITY ); - _background.setDaemon( true ); - _background.start(); - } - - - public XAConnection getXAConnection() - throws SQLException - { - // Construct a new XAConnection with no underlying connection. - // When a JDBC method requires an underlying connection, one - // will be created. We don't create the underlying connection - // beforehand, as it might be coming from an existing - // transaction. - return new XAConnectionImpl( this, null ); - } - - - public XAConnection getXAConnection( String user, String password ) - throws SQLException - { - // Since we create the connection on-demand with newConnection - // or obtain it from a transaction, we cannot support XA - // connections with a caller specified user name. - throw new SQLException( "XAConnection does not support connections with caller specified user name" ); - } - - - public PooledConnection getPooledConnection() - throws SQLException - { - // Construct a new pooled connection and an underlying JDBC - // connection to go along with it. - return new XAConnectionImpl( this, getConnection() ); - } - - - public PooledConnection getPooledConnection( String user, String password ) - throws SQLException - { - // Construct a new pooled connection and an underlying JDBC - // connection to go along with it. - return new XAConnectionImpl( this, getConnection( user, password ) ); - } - - - /* - * Returns the default timeout for all transactions. - */ - public int getTransactionTimeout() - { - return _txTimeout; - } - - - /* - * This method is defined in the interface and implemented in the - * derived class, we re-define it just to make sure it does not - * throw an {@link SQLException} and that we do not need to - * catch one. - */ - public abstract java.io.PrintWriter getLogWriter(); - - - /* - * Sets the default timeout for all transactions. The timeout is - * specified in seconds. Use zero for the default timeout. Calling - * this method does not affect transactions in progress. - * - * @param seconds The timeout in seconds - */ - public void setTransactionTimeout( int seconds ) - { - if ( seconds <= 0 ) - _txTimeout = DEFAULT_TX_TIMEOUT; - else - _txTimeout = seconds; - _background.interrupt(); - } - - - /* - * Returns an underlying connection for the global transaction, - * if one has been associated before. - * - * @param xid The transaction Xid - * @return A connection associated with that transaction, or null - */ - TxConnection getTxConnection( Xid xid ) - { - return (TxConnection) _txConnections.get( xid ); - } - - - /* - * Associates the global transaction with an underlying connection, - * or dissociate it when null is passed. - * - * @param xid The transaction Xid - * @param conn The connection to associate, null to dissociate - */ - TxConnection setTxConnection( Xid xid, TxConnection txConn ) - { - if ( txConn == null ) - return (TxConnection) _txConnections.remove( xid ); - else - return (TxConnection) _txConnections.put( xid, txConn ); - } - - - /* - * Release an unused connection back to the pool. If an XA - * connection has been asked to join an existing transaction, - * it will no longer use it's own connection and make it available - * to newly created connections. - * - * @param conn An open connection that is no longer in use - */ - void releaseConnection( Connection conn ) - { - _pool.push( conn ); - } - - - /* - * Creates a new underlying connection. Used by XA connection - * that lost it's underlying connection when joining a - * transaction and is now asked to produce a new connection. - * - * @return An open connection ready for use - * @throws SQLException An error occured trying to open - * a connection - */ - Connection newConnection() - throws SQLException - { - Connection conn; - - // Check in the pool first. - if ( ! _pool.empty() ) - { - conn = (Connection) _pool.pop(); - return conn; - } - return getConnection(); - } - - - /* - * XXX Not fully implemented yet and no code to really - * test it. - */ - Xid[] getTxRecover() - { - Vector list; - Enumeration enum; - TxConnection txConn; - - list = new Vector(); - enum = _txConnections.elements(); - while ( enum.hasMoreElements() ) - { - txConn = (TxConnection) enum.nextElement(); - if ( txConn.conn != null && txConn.prepared ) - list.add( txConn.xid ); - } - return (Xid[]) list.toArray(); - } - - - /* - * Returns the transaction isolation level to use with all newly - * created transactions, or {@link Connection#TRANSACTION_NONE} - * if using the driver's default isolation level. - */ - public int isolationLevel() - { - return Connection.TRANSACTION_NONE; - } - - - public void run() - { - Enumeration enum; - int reduce; - long timeout; - TxConnection txConn; - - while ( true ) - { - // Go to sleep for the duration of a transaction - // timeout. This mean transactions will timeout on average - // at _txTimeout * 1.5. - try - { - Thread.sleep( _txTimeout * 1000 ); - } - catch ( InterruptedException except ) - {} - - try - { - // Check to see if there are any pooled connections - // we can release. We release 10% of the pooled - // connections each time, so in a heavy loaded - // environment we don't get to release that many, but - // as load goes down we do. These are not actually - // pooled connections, but connections that happen to - // get in and out of a transaction, not that many. - reduce = _pool.size() - ( _pool.size() / 10 ) - 1; - if ( reduce >= 0 && _pool.size() > reduce ) - { - if ( getLogWriter() != null ) - getLogWriter().println( "DataSource " + toString() + - ": Reducing internal connection pool size from " + - _pool.size() + " to " + reduce ); - while ( _pool.size() > reduce ) - { - try - { - ( (Connection) _pool.pop() ).close(); - } - catch ( SQLException except ) - { } - } - } - } - catch ( Exception except ) - { } - - // Look for all connections inside a transaction that - // should have timed out by now. - - - timeout = System.currentTimeMillis(); - enum = _txConnections.elements(); - while ( enum.hasMoreElements() ) - { - txConn = (TxConnection) enum.nextElement(); - // If the transaction timed out, we roll it back and - // invalidate it, but do not remove it from the transaction - // list yet. We wait for the next iteration, minimizing the - // chance of a NOTA exception. - if ( txConn.conn == null ) - { - _txConnections.remove( txConn.xid ); - // Chose not to use an iterator so we must - // re-enumerate the list after removing - // an element from it. - enum = _txConnections.elements(); - } - else if ( txConn.timeout < timeout ) - { - - try - { - Connection underlying; - - synchronized ( txConn ) - { - if ( txConn.conn == null ) - continue; - if ( getLogWriter() != null ) - getLogWriter().println( "DataSource " + toString() + - ": Transaction timed out and being aborted: " + - txConn.xid ); - // Remove the connection from the transaction - // association. XAConnection will now have - // no underlying connection and attempt to - // create a new one. - underlying = txConn.conn; - txConn.conn = null; - txConn.timedOut = true; - - // Rollback the underlying connection to - // abort the transaction and release the - // underlying connection to the pool. - try - { - underlying.rollback(); - releaseConnection( underlying ); - } - catch ( SQLException except ) - { - if ( getLogWriter() != null ) - getLogWriter().println( "DataSource " + toString() + - ": Error aborting timed out transaction: " + except ); - try - { - underlying.close(); - } - catch ( SQLException e2 ) - { } - } - } - } - catch ( Exception except ) - { } - - } - } - } - } - - - - public void debug( PrintWriter writer ) - { - Enumeration enum; - TxConnection txConn; - StringBuffer buffer; - - writer.println( "Debug info for XADataSource:" ); - enum = _txConnections.elements(); - if ( ! enum.hasMoreElements() ) - writer.println( "Empty" ); - while ( enum.hasMoreElements() ) - { - buffer = new StringBuffer(); - txConn = (TxConnection) enum.nextElement(); - buffer.append( "TxConnection " ); - if ( txConn.xid != null ) - buffer.append( txConn.xid ); - if ( txConn.conn != null ) - buffer.append( ' ' ).append( txConn.conn ); - buffer.append( " count: " ).append( txConn.count ); - if ( txConn.prepared ) - buffer.append( " prepared" ); - if ( txConn.timedOut ) - buffer.append( " timed-out" ); - if ( txConn.readOnly ) - buffer.append( " read-only" ); - writer.println( buffer.toString() ); - } - enum = _pool.elements(); - while ( enum.hasMoreElements() ) - writer.println( "Pooled underlying: " + enum.nextElement().toString() ); - } - - -} -- 2.40.0