From: <mro...@us...> - 2012-08-05 15:12:25
|
Revision: 56994 http://firebird.svn.sourceforge.net/firebird/?rev=56994&view=rev Author: mrotteveel Date: 2012-08-05 15:12:19 +0000 (Sun, 05 Aug 2012) Log Message: ----------- Revert deletion of folders as these are still used for Java 5 Added Paths: ----------- client-java/trunk/src/jca_jdk1_4/ client-java/trunk/src/pool_jdk1_4/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-05 17:21:39
|
Revision: 56996 http://firebird.svn.sourceforge.net/firebird/?rev=56996&view=rev Author: mrotteveel Date: 2012-08-05 17:21:32 +0000 (Sun, 05 Aug 2012) Log Message: ----------- JDBC-195 Remove obsolete code for JDK 1.4 and earlier, JDBC 2.0 and earlier from the codebase (interface cleanup) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdBlob.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdParameterMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdSavepoint.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdStatement.java client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -84,7 +84,7 @@ // It is used to close them before the connection is closed protected HashSet activeStatements = new HashSet(); - private int resultSetHoldability = FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT; + private int resultSetHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT; private boolean autoCommit; @@ -104,9 +104,9 @@ FBConnectionRequestInfo cri = (FBConnectionRequestInfo)mc.getConnectionRequestInfo(); if (cri.hasArgument(DatabaseParameterBufferExtension.RESULT_SET_HOLDABLE)) - resultSetHoldability = FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT; + resultSetHoldability = ResultSet.HOLD_CURSORS_OVER_COMMIT; else - resultSetHoldability = FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT; + resultSetHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT; } public FBObjectListener.StatementListener getStatementListener() { @@ -828,7 +828,7 @@ public synchronized Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - if (resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT && + if (resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT && resultSetType == ResultSet.TYPE_FORWARD_ONLY) { addWarning(new FBSQLWarning("Holdable result set must be scrollable.")); @@ -864,7 +864,7 @@ */ private void checkHoldability(int resultSetType, int resultSetHoldability) throws SQLException { boolean holdable = - resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT; + resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT; boolean notScrollable = resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE; @@ -1125,7 +1125,7 @@ return prepareStatement(query.getQueryString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT, + ResultSet.CLOSE_CURSORS_AT_COMMIT, false, true); } else { return prepareStatement(query.getQueryString()); @@ -1155,7 +1155,7 @@ { PreparedStatement stmt; - if (resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT && + if (resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT && resultSetType == ResultSet.TYPE_FORWARD_ONLY) { addWarning(new FBSQLWarning("Holdable result set must be scrollable.")); @@ -1223,7 +1223,7 @@ { AbstractCallableStatement stmt; - if (resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT && + if (resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT && resultSetType == ResultSet.TYPE_FORWARD_ONLY) { addWarning(new FBSQLWarning("Holdable result set must be scrollable.")); Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -5650,8 +5650,8 @@ * @exception SQLException if a database access error occurs */ public boolean supportsResultSetHoldability(int holdability) throws SQLException { - return holdability == FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT || - holdability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT; + return holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT || + holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT; } /** @@ -5661,7 +5661,7 @@ * @exception SQLException if a database access error occurs */ public int getResultSetHoldability() throws SQLException { - return FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT; + return ResultSet.CLOSE_CURSORS_AT_COMMIT; } /** @@ -6234,7 +6234,7 @@ s = FBStatementFactory.createPreparedStatement(gdsHelper, sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT, + ResultSet.CLOSE_CURSORS_AT_COMMIT, metaDataTransactionCoordinator, metaDataTransactionCoordinator, true, true, false); } else { Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -38,7 +38,7 @@ * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> */ -public abstract class AbstractResultSet implements ResultSet, Synchronizable, FBObjectListener.FetcherListener { +public abstract class AbstractResultSet implements FirebirdResultSet, Synchronizable, FBObjectListener.FetcherListener { private AbstractStatement fbStatement; private FBFetcher fbFetcher; @@ -70,7 +70,7 @@ private int rsType = ResultSet.TYPE_FORWARD_ONLY; private int rsConcurrency = ResultSet.CONCUR_READ_ONLY; - private int rsHoldability = FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT; + private int rsHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT; /* (non-Javadoc) * @see org.firebirdsql.jdbc.FBObjectListener.FetcherListener#allRowsFetched(org.firebirdsql.jdbc.FBFetcher) @@ -214,7 +214,7 @@ * @throws SQLException if statement is closed. */ protected void checkCursorMove() throws SQLException { - if (closed && rsHoldability != FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT) + if (closed && rsHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) throw new FBSQLException("The result set is closed"); closeFields(); @@ -313,7 +313,7 @@ } - if (rsHoldability != FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT) + if (rsHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) fbFetcher = null; } } @@ -629,7 +629,7 @@ * Factory method for the field access objects */ public FBField getField(int columnIndex, boolean checkRowPosition) throws SQLException { - if (closed && rsHoldability != FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT) + if (closed && rsHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) throw new FBSQLException("The resultSet is closed"); if (checkRowPosition && row == null && rowUpdater == null) @@ -655,7 +655,7 @@ * @throws SQLException if the field cannot be retrieved */ public FBField getField(String columnName) throws SQLException { - if (closed && rsHoldability != FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT) + if (closed && rsHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) throw new FBSQLException("The resultSet is closed"); if (row == null && rowUpdater == null) Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -72,7 +72,7 @@ private int rsConcurrency; private int rsType; - private int rsHoldability = FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT; + private int rsHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT; private FBObjectListener.ResultSetListener resultSetListener = new RSListener(); @@ -1155,15 +1155,6 @@ return rsType; } - /** - * Retrieves the result set holdability for <code>ResultSet</code> objects - * generated by this <code>Statement</code> object. - * - * @return either {@link FirebirdResultSet#HOLD_CURSORS_OVER_COMMIT} or - * {@link FirebirdResultSet#CLOSE_CURSORS_AT_COMMIT} - * - * @throws SQLException if a database access error occurs - */ public int getResultSetHoldability() throws SQLException { return rsHoldability; } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdBlob.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdBlob.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdBlob.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -253,21 +253,5 @@ * otherwise <code>false</code> */ boolean isSegmented() throws SQLException; - - /** - * Retrieves a stream that can be used to write to the Blob value that this - * object represents. The stream begins at position <code>position</code>. - * <p> - * This method is directly copied from JDBC 3.0 classes to make it available - * in JDBC 2.0 environment. - * - * @param position the position in the <code>BLOB</code> value at which - * to start writing; currently only position 0 is supported. - * - * @return a <code>java.io.OutputStream</code> object to which data can - * be written - * - * @throws SQLException if something went wrong. - */ - OutputStream setBinaryStream(long position) throws SQLException; + } \ No newline at end of file Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdDatabaseMetaData.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdDatabaseMetaData.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdDatabaseMetaData.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -70,26 +70,7 @@ */ public String getViewSourceCode(String viewName) throws SQLException; - - // ---- Backported for JDK 1.3 compatibility ---- - /** - * Retrieves the major version number of the underlying database. - * - * @return the underlying database's major version - * @throws SQLException if a database access error occurs - */ - int getDatabaseMajorVersion() throws SQLException; - - /** - * Retrieves the minor version number of the underlying database. - * - * @return underlying database's minor version - * @throws SQLException if a database access error occurs - */ - int getDatabaseMinorVersion() throws SQLException; - - /** * Get the major version of the ODS (On-Disk Structure) of the database. * * @return The major version number of the database itself Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdParameterMetaData.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdParameterMetaData.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdParameterMetaData.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -26,151 +26,10 @@ package org.firebirdsql.jdbc; import java.sql.ParameterMetaData; -import java.sql.SQLException; +/** + * Firebird extension to the {@link java.sql.ParameterMetaData} interface. + */ public interface FirebirdParameterMetaData extends ParameterMetaData { - /** - * Retrieves the number of parameters in the <code>PreparedStatement</code> - * object for which this <code>ParameterMetaData</code> object contains - * information. - * - * @return the number of parameters - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - int getParameterCount() throws SQLException; - /** - * Retrieves whether null values are allowed in the designated parameter. - * - * @param param the first parameter is 1, the second is 2, ... - * @return the nullability status of the given parameter; one of - * <code>ParameterMetaData.parameterNoNulls</code>, - * <code>ParameterMetaData.parameterNullable</code>, or - * <code>ParameterMetaData.parameterNullableUnknown</code> - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - int isNullable(int param) throws SQLException; - - /** - * The constant indicating that a - * parameter will not allow <code>NULL</code> values. - */ - int parameterNoNulls = 0; - - /** - * The constant indicating that a - * parameter will allow <code>NULL</code> values. - */ - int parameterNullable = 1; - - /** - * The constant indicating that the - * nullability of a parameter is unknown. - */ - int parameterNullableUnknown = 2; - - /** - * Retrieves whether values for the designated parameter can be signed numbers. - * - * @param param the first parameter is 1, the second is 2, ... - * @return <code>true</code> if so; <code>false</code> otherwise - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - boolean isSigned(int param) throws SQLException; - - /** - * Retrieves the designated parameter's number of decimal digits. - * - * @param param the first parameter is 1, the second is 2, ... - * @return precision - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - int getPrecision(int param) throws SQLException; - - /** - * Retrieves the designated parameter's number of digits to right of the decimal point. - * - * @param param the first parameter is 1, the second is 2, ... - * @return scale - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - int getScale(int param) throws SQLException; - - /** - * Retrieves the designated parameter's SQL type. - * - * @param param the first parameter is 1, the second is 2, ... - * @return SQL type from <code>java.sql.Types</code> - * @exception SQLException if a database access error occurs - * @since 1.4 - * @see java.sql.Types - */ - int getParameterType(int param) throws SQLException; - - /** - * Retrieves the designated parameter's database-specific type name. - * - * @param param the first parameter is 1, the second is 2, ... - * @return type the name used by the database. If the parameter type is - * a user-defined type, then a fully-qualified type name is returned. - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - String getParameterTypeName(int param) throws SQLException; - - - /** - * Retrieves the fully-qualified name of the Java class whose instances - * should be passed to the method <code>PreparedStatement.setObject</code>. - * - * @param param the first parameter is 1, the second is 2, ... - * @return the fully-qualified name of the class in the Java programming - * language that would be used by the method - * <code>PreparedStatement.setObject</code> to set the value - * in the specified parameter. This is the class name used - * for custom mapping. - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - String getParameterClassName(int param) throws SQLException; - - /** - * The constant indicating that the mode of the parameter is unknown. - */ - int parameterModeUnknown = 0; - - /** - * The constant indicating that the parameter's mode is IN. - */ - int parameterModeIn = 1; - - /** - * The constant indicating that the parameter's mode is INOUT. - */ - int parameterModeInOut = 2; - - /** - * The constant indicating that the parameter's mode is OUT. - */ - int parameterModeOut = 4; - - /** - * Retrieves the designated parameter's mode. - * - * @param param the first parameter is 1, the second is 2, ... - * @return mode of the parameter; one of - * <code>ParameterMetaData.parameterModeIn</code>, - * <code>ParameterMetaData.parameterModeOut</code>, or - * <code>ParameterMetaData.parameterModeInOut</code> - * <code>ParameterMetaData.parameterModeUnknown</code>. - * @exception SQLException if a database access error occurs - * @since 1.4 - */ - int getParameterMode(int param) throws SQLException; - } \ No newline at end of file Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdResultSet.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdResultSet.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdResultSet.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -25,28 +25,15 @@ */ package org.firebirdsql.jdbc; +import java.sql.ResultSet; import java.sql.SQLException; +/** + * Firebird-specific extensions to the {@link java.sql.ResultSet} interface. + */ +public interface FirebirdResultSet extends ResultSet { -public interface FirebirdResultSet { - /** - * The constant indicating that <code>ResultSet</code> objects should not - * be closed when the method <code>Connection.commit</code> is called. - * - * Copied from JDBC 3.0 declaration to let code run in JDK 1.3. - */ - int HOLD_CURSORS_OVER_COMMIT = 1; - - /** - * The constant indicating that <code>ResultSet</code> objects should be - * closed when the method <code>Connection.commit</code> is called. - * - * Copied from JDBC 3.0 declaration to let code run in JDK 1.3. - */ - int CLOSE_CURSORS_AT_COMMIT = 2; - - /** * Get execution plan for the specified result set. * * @return execution plan for this query. Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdSavepoint.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdSavepoint.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdSavepoint.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -30,12 +30,11 @@ import java.sql.Savepoint; /** - * Savepoint interface, corresponds to the <code>java.sql.Savepoint</code> - * interface defined in JDBC 3.0, but can be used in JDBC 2.0 applications. + * Firebird-specific extensions to the {@link java.sql.Savepoint} interface. * - * @deprecated This interface will be removed in Jaybird 2.3, switch to {@link java.sql.Savepoint} + * TODO Remove deprecated annotation after JDBC-211 is done */ @Deprecated public interface FirebirdSavepoint extends Savepoint { - /* Empty interface retained for backwards compatibility */ + } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdStatement.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdStatement.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -36,48 +36,7 @@ */ public interface FirebirdStatement extends Statement { - /** - * The constant indicating that the current <code>ResultSet</code> object - * should be closed when calling <code>getMoreResults</code>. - * <p> - * Copied from JDBC 3.0 definition - */ - int CLOSE_CURRENT_RESULT = 1; - /** - * The constant indicating that the current <code>ResultSet</code> object - * should not be closed when calling <code>getMoreResults</code>. - * <p> - * Copied from JDBC 3.0 definition - */ - int KEEP_CURRENT_RESULT = 2; - - /** - * The constant indicating that all <code>ResultSet</code> objects that - * have previously been kept open should be closed when calling - * <code>getMoreResults</code>. - * <p> - * Copied from JDBC 3.0 definition - */ - int CLOSE_ALL_RESULTS = 3; - - /** - * The constant indicating that generated keys should be made - * available for retrieval. - * - * @since 1.4 - */ - int RETURN_GENERATED_KEYS = 1; - - /** - * The constant indicating that generated keys should not be made - * available for retrieval. - * - * @since 1.4 - */ - int NO_GENERATED_KEYS = 2; - - /** * Get number of inserted rows. You can call this method multiple times, * it does not affect the JDBC result number. * Modified: client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -418,8 +418,7 @@ public PreparedStatement getPreparedStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return getPreparedStatement(sql, resultSetType, resultSetConcurrency, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT); + return getPreparedStatement(sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT); } public PreparedStatement getPreparedStatement(String statement, int[] keyIndexes, @@ -522,7 +521,7 @@ return prepareStatement( new XPreparedStatementModel(sql, resultSetType, resultSetConcurrency, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT), cached); + ResultSet.CLOSE_CURSORS_AT_COMMIT), cached); } private XCachablePreparedStatement prepareStatementNoGeneratedKeys( Modified: client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -37,7 +37,6 @@ import java.util.List; import org.firebirdsql.jdbc.FBSQLException; -import org.firebirdsql.jdbc.FirebirdResultSet; import org.firebirdsql.jdbc.FirebirdStatement; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -229,7 +228,7 @@ statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT); + ResultSet.CLOSE_CURSORS_AT_COMMIT); } else if (method.equals(CONNECTION_PREPARE_STATEMENT2)) { String statement = (String)args[0]; @@ -239,7 +238,7 @@ statement, resultSetType.intValue(), resultSetConcurrency.intValue(), - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT); + ResultSet.CLOSE_CURSORS_AT_COMMIT); } else if (method.equals(CONNECTION_PREPARE_STATEMENT3)) { String statement = (String)args[0]; @@ -266,7 +265,7 @@ statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - FirebirdResultSet.CLOSE_CURSORS_AT_COMMIT); + ResultSet.CLOSE_CURSORS_AT_COMMIT); } else if (method.equals(CONNECTION_PREPARE_STATEMENT_GENKEYS2)) { String statement = (String)args[0]; Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -363,7 +363,7 @@ try { AbstractStatement stmt1 = (AbstractStatement)connection.createStatement(); - assertEquals(FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT, stmt1.getResultSetHoldability()); + assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stmt1.getResultSetHoldability()); Statement stmt2 = connection.createStatement(); Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java 2012-08-05 16:12:18 UTC (rev 56995) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java 2012-08-05 17:21:32 UTC (rev 56996) @@ -983,7 +983,7 @@ } public void testHoldability() throws Exception { - ((FirebirdConnection)connection).setHoldability(FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT); + ((FirebirdConnection)connection).setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); Statement stmt = connection.createStatement( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-05 17:51:56
|
Revision: 56997 http://firebird.svn.sourceforge.net/firebird/?rev=56997&view=rev Author: mrotteveel Date: 2012-08-05 17:51:50 +0000 (Sun, 05 Aug 2012) Log Message: ----------- JDBC-195: Remove further reference to Firebird-specific interfaces, where java.sql interfaces suffice. Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementModel.java client-java/trunk/src/test/org/firebirdsql/jca/TestFBDatabaseMetaData.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBEncodings.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -1337,6 +1337,6 @@ } public ParameterMetaData getParameterMetaData() throws SQLException { - return new FBParameterMetaData(fixedStmt.getInSqlda().sqlvar, gdsHelper); + return getFirebirdParameterMetaData(); } } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -1010,15 +1010,15 @@ * @see #execute */ public boolean getMoreResults() throws SQLException { - return getMoreResults(FirebirdStatement.CLOSE_ALL_RESULTS); + return getMoreResults(Statement.CLOSE_ALL_RESULTS); } public boolean getMoreResults(int mode) throws SQLException { hasMoreResults = false; - boolean closeResultSet = mode == FirebirdStatement.CLOSE_ALL_RESULTS - || mode == FirebirdStatement.CLOSE_CURRENT_RESULT; + boolean closeResultSet = mode == Statement.CLOSE_ALL_RESULTS + || mode == Statement.CLOSE_CURRENT_RESULT; if (closeResultSet && currentRs != null) { try { Modified: client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -427,7 +427,7 @@ if (!isStatementPooling()) { if (keyIndexes == null && keyColumns == null) return jdbcConnection.prepareStatement( - statement, FirebirdStatement.RETURN_GENERATED_KEYS); + statement, Statement.RETURN_GENERATED_KEYS); else if (keyIndexes != null) return jdbcConnection.prepareStatement(statement, keyIndexes); @@ -442,7 +442,7 @@ XPreparedStatementModel key; if (keyIndexes == null && keyColumns == null) - key = new XPreparedStatementModel(statement, FirebirdStatement.RETURN_GENERATED_KEYS); + key = new XPreparedStatementModel(statement, Statement.RETURN_GENERATED_KEYS); else if (keyIndexes != null) key = new XPreparedStatementModel(statement, keyIndexes); @@ -540,7 +540,7 @@ PreparedStatement stmt; if (key.getKeyIndexes() == null && key.getKeyColumns() == null) stmt = jdbcConnection.prepareStatement( - key.getSql(), FirebirdStatement.RETURN_GENERATED_KEYS); + key.getSql(), Statement.RETURN_GENERATED_KEYS); else if (key.getKeyIndexes() != null) stmt = jdbcConnection.prepareStatement(key.getSql(), key.getKeyIndexes()); Modified: client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -37,7 +37,6 @@ import java.util.List; import org.firebirdsql.jdbc.FBSQLException; -import org.firebirdsql.jdbc.FirebirdStatement; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; import org.firebirdsql.util.SQLExceptionChainBuilder; @@ -258,7 +257,7 @@ String statement = (String)args[0]; Integer returnGeneratedKeys = (Integer)args[1]; - if (returnGeneratedKeys.intValue() == FirebirdStatement.RETURN_GENERATED_KEYS) + if (returnGeneratedKeys.intValue() == Statement.RETURN_GENERATED_KEYS) return handlePrepareStatement(statement, null, null); else return handlePrepareStatement( Modified: client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementModel.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementModel.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementModel.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -18,10 +18,9 @@ */ package org.firebirdsql.pool; +import java.sql.Statement; import java.util.Arrays; -import org.firebirdsql.jdbc.FirebirdStatement; - /** * Object containing all information that is needed to prepare the statement. * @@ -49,7 +48,7 @@ public XPreparedStatementModel(String sql, int generatedKeys) { this.sql = sql; - this.generatedKeys = generatedKeys == FirebirdStatement.RETURN_GENERATED_KEYS; + this.generatedKeys = generatedKeys == Statement.RETURN_GENERATED_KEYS; } public XPreparedStatementModel(String sql, int[] keyIndexes) { Modified: client-java/trunk/src/test/org/firebirdsql/jca/TestFBDatabaseMetaData.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jca/TestFBDatabaseMetaData.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/test/org/firebirdsql/jca/TestFBDatabaseMetaData.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -154,7 +154,7 @@ } int sysTableCount; - FirebirdDatabaseMetaData metaData = (FirebirdDatabaseMetaData) c.getMetaData(); + DatabaseMetaData metaData = c.getMetaData(); if (metaData.getDatabaseMajorVersion() < 2) sysTableCount = 32; else if (metaData.getDatabaseMajorVersion() == 2 && metaData.getDatabaseMinorVersion() == 0) Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBEncodings.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBEncodings.java 2012-08-05 17:21:32 UTC (rev 56996) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBEncodings.java 2012-08-05 17:51:50 UTC (rev 56997) @@ -22,6 +22,7 @@ import org.firebirdsql.common.FBTestBase; import java.sql.Connection; +import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -410,8 +411,9 @@ assertFalse("Upper(Cyrl_field) must be != Cyrl_field ", cyrlValue.equals(cyrlValueUpper)); assertFalse("Upper(Win1251_field) must be != Win1251_field ", win1251Value.equals(win1251ValueUpper)); // Unicode only uppercase ASCII characters (until Firebird 2.0) - if (((FirebirdDatabaseMetaData) connection.getMetaData()).getDatabaseMajorVersion() < 2) - assertTrue("Upper(unicode) must be == Unicode_field ", unicodeValue.equals(unicodeValueUpper)); + DatabaseMetaData metaData = connection.getMetaData(); + if (metaData.getDatabaseMajorVersion() < 2) + assertEquals("Upper(unicode) must be == Unicode_field ", unicodeValue, unicodeValueUpper); assertEquals("Upper(win1251_field) must == upper test string ", CYRL_TEST_STRING_UPPER, win1251ValueUpper); // The CYRL charset fails because the mapping is 1251 and the uppercase @@ -421,7 +423,7 @@ // unicode does not uppercase (until FB 2.0) - if (((FirebirdDatabaseMetaData) connection.getMetaData()).getDatabaseMajorVersion() < 2) + if (metaData.getDatabaseMajorVersion() < 2) assertFalse("Upper(Unicode_field) must be != upper test string ", unicodeValueUpper.equals(CYRL_TEST_STRING_UPPER)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-06 08:00:58
|
Revision: 56999 http://firebird.svn.sourceforge.net/firebird/?rev=56999&view=rev Author: mrotteveel Date: 2012-08-06 08:00:47 +0000 (Mon, 06 Aug 2012) Log Message: ----------- JDBC-262 Move tests in src/test_30 to src/test if they are not specific to JDBC 3.0 Modified Paths: -------------- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java Added Paths: ----------- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBParameterMetaData.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBSavepoint.java Removed Paths: ------------- client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBParameterMetaData.java client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBResultSet3_0.java client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBSavepoint.java Copied: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBParameterMetaData.java (from rev 56994, client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBParameterMetaData.java) =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBParameterMetaData.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBParameterMetaData.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -0,0 +1,123 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ + +package org.firebirdsql.jdbc; + +import org.firebirdsql.common.FBTestBase; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ParameterMetaData; +import java.sql.Statement; +import java.util.Properties; + +/** + * This method tests correctness of {@link FBParameterMetaData} class. + * + * @author <a href="mailto:sk...@us...">Nickolay Samofatov</a> + * @version 1.0 + */ +public class TestFBParameterMetaData extends FBTestBase { + + public static String CREATE_TABLE = + "CREATE TABLE test_p_metadata (" + + " id INTEGER, " + + " simple_field VARCHAR(60) CHARACTER SET WIN1251 COLLATE PXW_CYRL, " + + " two_byte_field VARCHAR(60) CHARACTER SET BIG_5, " + + " three_byte_field VARCHAR(60) CHARACTER SET UNICODE_FSS, " + + " long_field numeric(18,0), " + // This is BIGINT alias for FB1 + " int_field INTEGER, " + + " short_field SMALLINT " + + ")"; + + public static final String TEST_QUERY = + "insert into test_p_metadata(" + + "simple_field, two_byte_field, three_byte_field, " + + "long_field, int_field, short_field) " + + "values (?,?,?,?,?,?)"; + + public static String DROP_TABLE = + "DROP TABLE test_p_metadata"; + + public TestFBParameterMetaData(String testName) { + super(testName); + } + + + protected void setUp() throws Exception { + super.setUp(); + + Class.forName(FBDriver.class.getName()); + + Properties props = new Properties(); + props.putAll(this.getDefaultPropertiesForConnection()); + props.put("lc_ctype", "UNICODE_FSS"); + + Connection connection = DriverManager.getConnection(this.getUrl(), props); + + Statement stmt = connection.createStatement(); + try { + stmt.executeUpdate(DROP_TABLE); + } + catch (Exception e) {} + + stmt.executeUpdate(CREATE_TABLE); + stmt.close(); + + connection.close(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testParameterMetaData() throws Exception { + Properties props = new Properties(); + props.putAll(this.getDefaultPropertiesForConnection()); + props.put("lc_ctype", "UNICODE_FSS"); + + Connection connection = DriverManager.getConnection(this.getUrl(), props); + + FirebirdPreparedStatement stmt = + (FirebirdPreparedStatement)connection.prepareStatement(TEST_QUERY); + + ParameterMetaData metaData = stmt.getParameterMetaData(); + + assertTrue("simple_field must have size 60", + metaData.getPrecision(1) == 60); + + assertTrue("two_byte_field must have size 60", + metaData.getPrecision(2) == 60); + + assertTrue("three_byte_field must have size 60", + metaData.getPrecision(3) == 60); + + assertTrue("long_field must have precision 19", + metaData.getPrecision(4) == 19); + + assertTrue("int_field must have precision 10", + metaData.getPrecision(5) == 10); + + assertTrue("short_field must have precision 5", + metaData.getPrecision(6) == 5); + + stmt.close(); + connection.close(); + } +} Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java 2012-08-05 18:59:13 UTC (rev 56998) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBResultSet.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -1176,7 +1176,52 @@ } } - public static void main(String[] args) { + public void testUpdatableHoldableResultSet() throws Exception { + + connection.setAutoCommit(true); + + int recordCount = 10; + PreparedStatement ps = connection.prepareStatement("INSERT INTO test_table(" + + "id, long_str) VALUES (?, ?)"); + + try { + for (int i = 0; i < recordCount; i++) { + ps.setInt(1, i); + ps.setString(2, "oldString" + i); + ps.executeUpdate(); + } + } finally { + ps.close(); + } + + connection.setAutoCommit(false); + + Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT); + + try { + ResultSet rs = stmt.executeQuery("SELECT id, long_str FROM test_table"); + + while (rs.next()) { + rs.updateString(2, rs.getString(2) + "a"); + rs.updateRow(); + connection.commit(); + } + + int counter = 0; + + rs = stmt.executeQuery("SELECT id, long_str FROM test_table"); + while (rs.next()) { + assertEquals("oldString" + counter + "a", rs.getString(2)); + counter++; + } + + } finally { + stmt.close(); + } + } + + public static void main(String[] args) { TestRunner.run(new TestFBResultSet("testMemoryGrowth")); } Copied: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBSavepoint.java (from rev 56994, client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBSavepoint.java) =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBSavepoint.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBSavepoint.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -0,0 +1,239 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.sql.*; + +import org.firebirdsql.common.FBTestBase; + +/** + * Tests for savepoint handling. + * + * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> + */ +public class TestFBSavepoint extends FBTestBase { + + + private FirebirdConnection connection; + + public TestFBSavepoint(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + + Class.forName(FBDriver.class.getName()); + + connection = (FirebirdConnection)getConnectionViaDriverManager(); + + Statement stmt = connection.createStatement(); + try { + stmt.execute("DROP TABLE test_svpt"); + } catch(SQLException ex) { + // do nothing + } + + try { + stmt.execute("CREATE TABLE test_svpt(id INTEGER)"); + } catch(SQLException ex) { + // ignore, most likely table exists + } finally { + stmt.close(); + } + } + + protected void tearDown() throws Exception { + + Statement stmt = connection.createStatement(); + + try { + stmt.execute("DROP TABLE test_svpt"); + } catch(SQLException ex) { + ex.printStackTrace(); + } finally { + stmt.close(); + } + + connection.close(); + + super.tearDown(); + } + + /** + * Test if basic savepoint handling works. + * + * @throws Exception if something went wrong. + */ + public void testBasicSavepoint() throws Exception { + + connection.setAutoCommit(true); + try { + connection.setSavepoint(); + assertTrue("Setting savepoint should not work in auto-commit mode", false); + } catch(SQLException e) { + // everything is fine + } + + connection.setAutoCommit(false); + + PreparedStatement stmt = connection.prepareStatement( + "INSERT INTO test_svpt VALUES(?)"); + + try { + stmt.setInt(1, 1); + stmt.execute(); + + Savepoint svpt1 = connection.setSavepoint(); + + try { + svpt1.getSavepointName(); + } catch(SQLException ex) { + // everything is fine + } + + stmt.clearParameters(); + + stmt.setInt(1, 2); + stmt.execute(); + + connection.rollback(svpt1); + connection.commit(); + + checkRowCount(1); + + } finally { + stmt.close(); + } + } + + /** + * Test if named savepoint handling works. + * + * @throws Exception if something went wrong. + */ + public void testNamedSavepoint() throws Exception { + + connection.setAutoCommit(false); + + PreparedStatement stmt = connection.prepareStatement( + "INSERT INTO test_svpt VALUES(?)"); + + try { + stmt.setInt(1, 1); + stmt.execute(); + + Savepoint svpt1 = connection.setSavepoint("test"); + + try { + svpt1.getSavepointId(); + } catch(SQLException ex) { + // everything is fine + } + + stmt.clearParameters(); + + stmt.setInt(1, 2); + stmt.execute(); + + Savepoint svpt2 = connection.setSavepoint("test"); + + assertTrue("Savepoints should be equal.", svpt1.equals(svpt2)); + + stmt.clearParameters(); + stmt.setInt(1, 3); + stmt.execute(); + + connection.rollback(svpt1); + connection.commit(); + + checkRowCount(2); + + } finally { + stmt.close(); + } + } + + /** + * Test if savepoints are released correctly. + * + * @throws Exception if something went wrong. + */ + public void testSavepointRelease() throws Exception { + connection.setAutoCommit(false); + + Savepoint svpt1 = connection.setSavepoint("test"); + + connection.releaseSavepoint(svpt1); + + checkInvalidSavepoint(svpt1); + + Savepoint svpt2 = connection.setSavepoint(); + + connection.releaseSavepoint(svpt2); + + checkInvalidSavepoint(svpt2); + + Savepoint svpt3 = connection.setSavepoint(); + + connection.commit(); + + checkInvalidSavepoint(svpt3); + } + + private void checkInvalidSavepoint(Savepoint savepoint) { + try { + connection.rollback(savepoint); + assertTrue("Released savepoint should not work.", false); + } catch(SQLException ex) { + // everything is fine + } + + try { + connection.releaseSavepoint(savepoint); + assertTrue("Released savepoint should not work.", false); + } catch(SQLException ex) { + // everything is fine + } + } + + /** + * Check if table contains correct number of rows. + * + * @param testRowCount expected number of rows. + * + * @throws SQLException if something went wrong when counting rows. + */ + private void checkRowCount(int testRowCount) throws SQLException { + Statement stmt = connection.createStatement(); + try { + ResultSet rs = stmt.executeQuery("SELECT * FROM test_svpt"); + + int counter = 0; + while(rs.next()) + counter++; + + assertTrue("Incorrect result set, expecting " + testRowCount + + " rows, obtained " + counter + ".", testRowCount == counter); + + } finally { + stmt.close(); + } + } +} Deleted: client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBParameterMetaData.java =================================================================== --- client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBParameterMetaData.java 2012-08-05 18:59:13 UTC (rev 56998) +++ client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBParameterMetaData.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -1,123 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ - -package org.firebirdsql.jdbc; - -import org.firebirdsql.common.FBTestBase; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ParameterMetaData; -import java.sql.Statement; -import java.util.Properties; - -/** - * This method tests correctness of {@link FBParameterMetaData} class. - * - * @author <a href="mailto:sk...@us...">Nickolay Samofatov</a> - * @version 1.0 - */ -public class TestFBParameterMetaData extends FBTestBase { - - public static String CREATE_TABLE = - "CREATE TABLE test_p_metadata (" + - " id INTEGER, " + - " simple_field VARCHAR(60) CHARACTER SET WIN1251 COLLATE PXW_CYRL, " + - " two_byte_field VARCHAR(60) CHARACTER SET BIG_5, " + - " three_byte_field VARCHAR(60) CHARACTER SET UNICODE_FSS, " + - " long_field numeric(18,0), " + // This is BIGINT alias for FB1 - " int_field INTEGER, " + - " short_field SMALLINT " + - ")"; - - public static final String TEST_QUERY = - "insert into test_p_metadata(" + - "simple_field, two_byte_field, three_byte_field, " + - "long_field, int_field, short_field) " + - "values (?,?,?,?,?,?)"; - - public static String DROP_TABLE = - "DROP TABLE test_p_metadata"; - - public TestFBParameterMetaData(String testName) { - super(testName); - } - - - protected void setUp() throws Exception { - super.setUp(); - - Class.forName(FBDriver.class.getName()); - - Properties props = new Properties(); - props.putAll(this.getDefaultPropertiesForConnection()); - props.put("lc_ctype", "UNICODE_FSS"); - - Connection connection = DriverManager.getConnection(this.getUrl(), props); - - Statement stmt = connection.createStatement(); - try { - stmt.executeUpdate(DROP_TABLE); - } - catch (Exception e) {} - - stmt.executeUpdate(CREATE_TABLE); - stmt.close(); - - connection.close(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testParameterMetaData() throws Exception { - Properties props = new Properties(); - props.putAll(this.getDefaultPropertiesForConnection()); - props.put("lc_ctype", "UNICODE_FSS"); - - Connection connection = DriverManager.getConnection(this.getUrl(), props); - - FirebirdPreparedStatement stmt = - (FirebirdPreparedStatement)connection.prepareStatement(TEST_QUERY); - - ParameterMetaData metaData = stmt.getParameterMetaData(); - - assertTrue("simple_field must have size 60", - metaData.getPrecision(1) == 60); - - assertTrue("two_byte_field must have size 60", - metaData.getPrecision(2) == 60); - - assertTrue("three_byte_field must have size 60", - metaData.getPrecision(3) == 60); - - assertTrue("long_field must have precision 19", - metaData.getPrecision(4) == 19); - - assertTrue("int_field must have precision 10", - metaData.getPrecision(5) == 10); - - assertTrue("short_field must have precision 5", - metaData.getPrecision(6) == 5); - - stmt.close(); - connection.close(); - } -} Deleted: client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBResultSet3_0.java =================================================================== --- client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBResultSet3_0.java 2012-08-05 18:59:13 UTC (rev 56998) +++ client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBResultSet3_0.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -1,84 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; - -/** - * Tests FBResultSets JDBC3.0 specific functionality. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - * @author <a href="mailto:sja...@us...">Steven Jardine </a> - */ -public class TestFBResultSet3_0 extends TestFBResultSet { - - public TestFBResultSet3_0(String name) { - super(name); - } - - public void testUpdatableHoldableResultSet() throws Exception { - - connection.setAutoCommit(true); - - int recordCount = 10; - PreparedStatement ps = connection.prepareStatement("INSERT INTO test_table(" - + "id, long_str) VALUES (?, ?)"); - - try { - for (int i = 0; i < recordCount; i++) { - ps.setInt(1, i); - ps.setString(2, "oldString" + i); - ps.executeUpdate(); - } - } finally { - ps.close(); - } - - connection.setAutoCommit(false); - - Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT); - - try { - ResultSet rs = stmt.executeQuery("SELECT id, long_str FROM test_table"); - - while (rs.next()) { - rs.updateString(2, rs.getString(2) + "a"); - rs.updateRow(); - connection.commit(); - } - - int counter = 0; - - rs = stmt.executeQuery("SELECT id, long_str FROM test_table"); - while (rs.next()) { - assertEquals("oldString" + counter + "a", rs.getString(2)); - counter++; - } - - } finally { - stmt.close(); - } - } - -} Deleted: client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBSavepoint.java =================================================================== --- client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBSavepoint.java 2012-08-05 18:59:13 UTC (rev 56998) +++ client-java/trunk/src/test_30/org/firebirdsql/jdbc/TestFBSavepoint.java 2012-08-06 08:00:47 UTC (rev 56999) @@ -1,239 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.*; - -import org.firebirdsql.common.FBTestBase; - -/** - * Tests for savepoint handling. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public class TestFBSavepoint extends FBTestBase { - - - private FirebirdConnection connection; - - public TestFBSavepoint(String name) { - super(name); - } - - protected void setUp() throws Exception { - super.setUp(); - - Class.forName(FBDriver.class.getName()); - - connection = (FirebirdConnection)getConnectionViaDriverManager(); - - Statement stmt = connection.createStatement(); - try { - stmt.execute("DROP TABLE test_svpt"); - } catch(SQLException ex) { - // do nothing - } - - try { - stmt.execute("CREATE TABLE test_svpt(id INTEGER)"); - } catch(SQLException ex) { - // ignore, most likely table exists - } finally { - stmt.close(); - } - } - - protected void tearDown() throws Exception { - - Statement stmt = connection.createStatement(); - - try { - stmt.execute("DROP TABLE test_svpt"); - } catch(SQLException ex) { - ex.printStackTrace(); - } finally { - stmt.close(); - } - - connection.close(); - - super.tearDown(); - } - - /** - * Test if basic savepoint handling works. - * - * @throws Exception if something went wrong. - */ - public void testBasicSavepoint() throws Exception { - - connection.setAutoCommit(true); - try { - connection.setSavepoint(); - assertTrue("Setting savepoint should not work in auto-commit mode", false); - } catch(SQLException e) { - // everything is fine - } - - connection.setAutoCommit(false); - - PreparedStatement stmt = connection.prepareStatement( - "INSERT INTO test_svpt VALUES(?)"); - - try { - stmt.setInt(1, 1); - stmt.execute(); - - Savepoint svpt1 = connection.setSavepoint(); - - try { - svpt1.getSavepointName(); - } catch(SQLException ex) { - // everything is fine - } - - stmt.clearParameters(); - - stmt.setInt(1, 2); - stmt.execute(); - - connection.rollback(svpt1); - connection.commit(); - - checkRowCount(1); - - } finally { - stmt.close(); - } - } - - /** - * Test if named savepoint handling works. - * - * @throws Exception if something went wrong. - */ - public void testNamedSavepoint() throws Exception { - - connection.setAutoCommit(false); - - PreparedStatement stmt = connection.prepareStatement( - "INSERT INTO test_svpt VALUES(?)"); - - try { - stmt.setInt(1, 1); - stmt.execute(); - - Savepoint svpt1 = connection.setSavepoint("test"); - - try { - svpt1.getSavepointId(); - } catch(SQLException ex) { - // everything is fine - } - - stmt.clearParameters(); - - stmt.setInt(1, 2); - stmt.execute(); - - Savepoint svpt2 = connection.setSavepoint("test"); - - assertTrue("Savepoints should be equal.", svpt1.equals(svpt2)); - - stmt.clearParameters(); - stmt.setInt(1, 3); - stmt.execute(); - - connection.rollback(svpt1); - connection.commit(); - - checkRowCount(2); - - } finally { - stmt.close(); - } - } - - /** - * Test if savepoints are released correctly. - * - * @throws Exception if something went wrong. - */ - public void testSavepointRelease() throws Exception { - connection.setAutoCommit(false); - - Savepoint svpt1 = connection.setSavepoint("test"); - - connection.releaseSavepoint(svpt1); - - checkInvalidSavepoint(svpt1); - - Savepoint svpt2 = connection.setSavepoint(); - - connection.releaseSavepoint(svpt2); - - checkInvalidSavepoint(svpt2); - - Savepoint svpt3 = connection.setSavepoint(); - - connection.commit(); - - checkInvalidSavepoint(svpt3); - } - - private void checkInvalidSavepoint(Savepoint savepoint) { - try { - connection.rollback(savepoint); - assertTrue("Released savepoint should not work.", false); - } catch(SQLException ex) { - // everything is fine - } - - try { - connection.releaseSavepoint(savepoint); - assertTrue("Released savepoint should not work.", false); - } catch(SQLException ex) { - // everything is fine - } - } - - /** - * Check if table contains correct number of rows. - * - * @param testRowCount expected number of rows. - * - * @throws SQLException if something went wrong when counting rows. - */ - private void checkRowCount(int testRowCount) throws SQLException { - Statement stmt = connection.createStatement(); - try { - ResultSet rs = stmt.executeQuery("SELECT * FROM test_svpt"); - - int counter = 0; - while(rs.next()) - counter++; - - assertTrue("Incorrect result set, expecting " + testRowCount + - " rows, obtained " + counter + ".", testRowCount == counter); - - } finally { - stmt.close(); - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-07 18:04:08
|
Revision: 57007 http://firebird.svn.sourceforge.net/firebird/?rev=57007&view=rev Author: mrotteveel Date: 2012-08-07 18:04:00 +0000 (Tue, 07 Aug 2012) Log Message: ----------- JDBC-212 Remove ClassFactory, GDSObjectFactory and FBStatementFactory Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledDataSourceFactory.java client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerConnectionPoolDataSource.java client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerXADataSource.java client-java/trunk/src/test/org/firebirdsql/pool/TestDriverConnectionPoolDataSource.java client-java/trunk/src/test/org/firebirdsql/pool/TestFBConnectionPoolDataSource.java Removed Paths: ------------- client-java/trunk/src/main/org/firebirdsql/gds/ClassFactory.java client-java/trunk/src/main/org/firebirdsql/gds/GDSObjectFactory.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatementFactory.java Deleted: client-java/trunk/src/main/org/firebirdsql/gds/ClassFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ClassFactory.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/ClassFactory.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,70 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds; - -import org.firebirdsql.logging.Logger; -import org.firebirdsql.logging.LoggerFactory; - -/** - * Returns classes either by the <code>Class.forName</code> method or by using - * an already cached instance. - * - * @author <a href="mailto:sja...@us...">Steven Jardine </a> - */ -public class ClassFactory { - - // Many commonly used class names. - public static final String DriverConnectionPoolDataSource = "org.firebirdsql.pool.DriverConnectionPoolDataSource"; - - public static final String FBCallableStatement = "org.firebirdsql.jdbc.FBCallableStatement"; - - public static final String FBConnection = "org.firebirdsql.jdbc.FBConnection"; - - public static final String FBConnectionPoolDataSource = "org.firebirdsql.pool.FBConnectionPoolDataSource"; - - public static final String FBPreparedStatement = "org.firebirdsql.jdbc.FBPreparedStatement"; - - public static final String FBStatement = "org.firebirdsql.jdbc.FBStatement"; - - public static final String JavaGDSImpl = "org.firebirdsql.gds.impl.wire.JavaGDSImpl"; - - private static Logger log = LoggerFactory.getLogger(ClassFactory.class, false); - - /** - * @param className the class name to return. - * @return the class corresponding to the string class name. - */ - public static Class get(String className) { - - try { - - return Class.forName(className); - - } catch (ClassNotFoundException e) { - - log.error(e.getMessage(), e); - - } - - return null; - - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/GDSObjectFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/GDSObjectFactory.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/GDSObjectFactory.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,55 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds; - -import org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl; -import org.firebirdsql.logging.Logger; -import org.firebirdsql.logging.LoggerFactory; - -/** - * Creates gds objects. - * - * @author <a href="mailto:sja...@us...">Steven Jardine </a> - */ -public class GDSObjectFactory { - - private static Logger log = LoggerFactory.getLogger(GDSObjectFactory.class, false); - - /** - * @return a new JavaGDSImpl object. - */ - public static AbstractJavaGDSImpl createJavaGDSImpl() { - - try { - - return (AbstractJavaGDSImpl) ClassFactory.get(ClassFactory.JavaGDSImpl).newInstance(); - - } catch (Exception e) { - - log.error(e.getMessage(), e); - - } - - return null; - - } - -} Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,9 +1,9 @@ package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.gds.GDS; import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.impl.GDSFactoryPlugin; +import org.firebirdsql.jdbc.FBConnection; public class EmbeddedGDSFactoryPlugin implements GDSFactoryPlugin { @@ -28,7 +28,7 @@ } public Class getConnectionClass() { - return ClassFactory.get(ClassFactory.FBConnection); + return FBConnection.class; } public String[] getSupportedProtocols() { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,9 +1,9 @@ package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.gds.GDS; import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.impl.GDSFactoryPlugin; +import org.firebirdsql.jdbc.FBConnection; public class LocalGDSFactoryPlugin implements GDSFactoryPlugin { @@ -27,7 +27,7 @@ } public Class getConnectionClass() { - return ClassFactory.get(ClassFactory.FBConnection); + return FBConnection.class; } public String[] getSupportedProtocols() { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,11 +1,10 @@ package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.gds.GDS; import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.impl.GDSFactoryPlugin; +import org.firebirdsql.jdbc.FBConnection; - public class NativeGDSFactoryPlugin implements GDSFactoryPlugin { private static final String[] TYPE_ALIASES = new String[]{"TYPE2"}; @@ -26,7 +25,7 @@ } public Class getConnectionClass() { - return ClassFactory.get(ClassFactory.FBConnection); + return FBConnection.class; } public String[] getSupportedProtocols() { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,10 +1,9 @@ package org.firebirdsql.gds.impl.wire; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.gds.GDS; import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.GDSObjectFactory; import org.firebirdsql.gds.impl.GDSFactoryPlugin; +import org.firebirdsql.jdbc.FBConnection; public class WireGDSFactoryPlugin implements GDSFactoryPlugin { @@ -26,7 +25,7 @@ } public Class getConnectionClass() { - return ClassFactory.get(ClassFactory.FBConnection); + return FBConnection.class; } public String[] getSupportedProtocols() { @@ -35,7 +34,7 @@ public GDS getGDS() { if (gdsImpl == null) - gdsImpl = GDSObjectFactory.createJavaGDSImpl(); + gdsImpl = new JavaGDSImpl(); return gdsImpl; } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -844,8 +844,8 @@ checkHoldability(resultSetType, resultSetHoldability); try { - Statement stmt = FBStatementFactory.createStatement(getGDSHelper(), resultSetType, - resultSetConcurrency, resultSetHoldability, txCoordinator); + Statement stmt = new FBStatement(getGDSHelper(), resultSetType, resultSetConcurrency, + resultSetHoldability, txCoordinator); activeStatements.add(stmt); return stmt; @@ -1185,7 +1185,7 @@ else blobCoordinator = txCoordinator; - stmt = FBStatementFactory.createPreparedStatement( + stmt = new FBPreparedStatement( getGDSHelper(), sql, resultSetType, resultSetConcurrency, resultSetHoldability, coordinator, blobCoordinator, metaData, false, generatedKeys); @@ -1231,8 +1231,7 @@ resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE; } - if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) - { + if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { addWarning(new FBSQLWarning("Scroll-sensitive result sets are not supported.")); resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE; } @@ -1250,7 +1249,7 @@ } try { - stmt = FBStatementFactory.createCallableStatement(getGDSHelper(), sql, resultSetType, + stmt = new FBCallableStatement(getGDSHelper(), sql, resultSetType, resultSetConcurrency, resultSetHoldability, storedProcedureMetaData, txCoordinator, txCoordinator); activeStatements.add(stmt); Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -6232,7 +6232,7 @@ InternalTransactionCoordinator.MetaDataTransactionCoordinator metaDataTransactionCoordinator = new InternalTransactionCoordinator.MetaDataTransactionCoordinator(); - s = FBStatementFactory.createPreparedStatement(gdsHelper, sql, + s = new FBPreparedStatement(gdsHelper, sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT, metaDataTransactionCoordinator, metaDataTransactionCoordinator, Deleted: client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatementFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatementFactory.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatementFactory.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -1,152 +0,0 @@ -/* - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.lang.reflect.*; - -import org.firebirdsql.gds.ClassFactory; -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.FBObjectListener.BlobListener; -import org.firebirdsql.jdbc.FBObjectListener.StatementListener; - -/** - * Creates statement objects. - * - * @author <a href="mailto:sja...@us...">Steven Jardine </a> - */ -public class FBStatementFactory { - - /** - * @return a new instance of FBCallableStatement. - */ - public static AbstractCallableStatement createCallableStatement(GDSHelper gdsHelper, - String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, - StoredProcedureMetaData storedProcMetaData, StatementListener statementListener, BlobListener blobListener) throws FBSQLException { - - try { - - Constructor constructor = ClassFactory.get(ClassFactory.FBCallableStatement) - .getConstructor( - new Class[] { GDSHelper.class, String.class, int.class, int.class, - int.class, StoredProcedureMetaData.class, StatementListener.class, BlobListener.class }); - - return (AbstractCallableStatement) constructor.newInstance(new Object[] { gdsHelper, - sql, new Integer(resultSetType), new Integer(resultSetConcurrency), - new Integer(resultSetHoldability), storedProcMetaData, statementListener, blobListener }); - - } catch(InvocationTargetException ex) { - - Throwable t = ex.getTargetException(); - if (t instanceof FBSQLException) - throw (FBSQLException)t; - else - throw new UndeclaredThrowableException(t); - - } catch (IllegalArgumentException e) { - throw new UndeclaredThrowableException(e); - } catch (InstantiationException e) { - throw new UndeclaredThrowableException(e); - } catch (IllegalAccessException e) { - throw new UndeclaredThrowableException(e); - } catch (NoSuchMethodException e) { - throw new UndeclaredThrowableException(e); - } - } - - /** - * @return a new instance of FBPreparedStatement - */ - public static AbstractPreparedStatement createPreparedStatement(GDSHelper gdsHelper, - String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, - StatementListener statementListener, BlobListener blobListener, boolean metadata, - boolean standaloneStatement, boolean generatedKeys) - throws FBSQLException { - - try { - - Constructor constructor = ClassFactory.get(ClassFactory.FBPreparedStatement) - .getConstructor( - new Class[] { GDSHelper.class, String.class, int.class, int.class, - int.class, StatementListener.class, BlobListener.class, - boolean.class, boolean.class, boolean.class }); - - return (AbstractPreparedStatement) constructor.newInstance(new Object[] { gdsHelper, - sql, new Integer(resultSetType), new Integer(resultSetConcurrency), - new Integer(resultSetHoldability), statementListener, blobListener, - Boolean.valueOf(metadata), Boolean.valueOf(standaloneStatement), - Boolean.valueOf(generatedKeys)}); - - } catch(InvocationTargetException ex) { - - Throwable t = ex.getTargetException(); - if (t instanceof FBSQLException) - throw (FBSQLException)t; - else - throw new UndeclaredThrowableException(t); - - } catch (IllegalArgumentException e) { - throw new UndeclaredThrowableException(e); - } catch (InstantiationException e) { - throw new UndeclaredThrowableException(e); - } catch (IllegalAccessException e) { - throw new UndeclaredThrowableException(e); - } catch (NoSuchMethodException e) { - throw new UndeclaredThrowableException(e); - } - - } - - /** - * @return a new instance FBStatement. - */ - public static AbstractStatement createStatement(GDSHelper gdsHelper, int resultSetType, - int resultSetConcurrency, int resultSetHoldability, StatementListener statementListener) - throws FBSQLException { - - try { - - Constructor constructor = ClassFactory.get(ClassFactory.FBStatement).getConstructor( - new Class[] { GDSHelper.class, int.class, int.class, int.class, - StatementListener.class }); - - return (AbstractStatement) constructor.newInstance(new Object[] { gdsHelper, - new Integer(resultSetType), new Integer(resultSetConcurrency), - new Integer(resultSetHoldability), statementListener }); - - } catch(InvocationTargetException ex) { - - Throwable t = ex.getTargetException(); - if (t instanceof FBSQLException) - throw (FBSQLException)t; - else - throw new UndeclaredThrowableException(t); - - } catch (IllegalArgumentException e) { - throw new UndeclaredThrowableException(e); - } catch (InstantiationException e) { - throw new UndeclaredThrowableException(e); - } catch (IllegalAccessException e) { - throw new UndeclaredThrowableException(e); - } catch (NoSuchMethodException e) { - throw new UndeclaredThrowableException(e); - } - - } - -} Modified: client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -3,6 +3,8 @@ import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.GDSFactoryPlugin; import org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl; +import org.firebirdsql.gds.impl.wire.JavaGDSImpl; +import org.firebirdsql.jdbc.oo.OOConnection; public class OOGDSFactoryPlugin implements GDSFactoryPlugin { @@ -28,7 +30,7 @@ } public Class getConnectionClass() { - return ClassFactory.get("org.firebirdsql.jdbc.oo.OOConnection"); + return OOConnection.class; } public String[] getSupportedProtocols() { @@ -36,7 +38,8 @@ } public GDS getGDS() { - if (gdsImpl == null) gdsImpl = GDSObjectFactory.createJavaGDSImpl(); + if (gdsImpl == null) + gdsImpl = new JavaGDSImpl(); return gdsImpl; } Modified: client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledDataSourceFactory.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledDataSourceFactory.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledDataSourceFactory.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -27,7 +27,6 @@ import javax.naming.Name; import javax.naming.Reference; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.jdbc.FBSQLException; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -48,8 +47,7 @@ try { - return (AbstractDriverConnectionPoolDataSource) ClassFactory.get( - ClassFactory.DriverConnectionPoolDataSource).newInstance(); + return new DriverConnectionPoolDataSource(); } catch (Exception e) { @@ -66,8 +64,7 @@ try { - return (AbstractFBConnectionPoolDataSource) ClassFactory.get( - ClassFactory.FBConnectionPoolDataSource).newInstance(); + return new FBConnectionPoolDataSource(); } catch (Exception e) { Modified: client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerConnectionPoolDataSource.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerConnectionPoolDataSource.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerConnectionPoolDataSource.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -30,8 +30,8 @@ import javax.sql.PooledConnection; import org.firebirdsql.ds.RootCommonDataSource; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.pool.AbstractFBConnectionPoolDataSource; +import org.firebirdsql.pool.FBConnectionPoolDataSource; import org.firebirdsql.pool.FBPooledDataSourceFactory; /** @@ -347,8 +347,8 @@ if (!getClass().getName().equals(passedRef.getClassName())) return null; - Reference ref = new Reference(ClassFactory.FBConnectionPoolDataSource, - ClassFactory.FBConnectionPoolDataSource, null); + Reference ref = new Reference(FBConnectionPoolDataSource.class.getName(), + FBConnectionPoolDataSource.class.getName(), null); convertReference(ref, passedRef); Modified: client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerXADataSource.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerXADataSource.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/pool/org/firebirdsql/pool/sun/AppServerXADataSource.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -29,8 +29,8 @@ import javax.sql.*; import org.firebirdsql.ds.RootCommonDataSource; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.pool.AbstractFBConnectionPoolDataSource; +import org.firebirdsql.pool.FBConnectionPoolDataSource; import org.firebirdsql.pool.FBPooledDataSourceFactory; /** @@ -337,8 +337,8 @@ return null; - Reference ref = new Reference(ClassFactory.FBConnectionPoolDataSource, - ClassFactory.FBConnectionPoolDataSource, null); + Reference ref = new Reference(FBConnectionPoolDataSource.class.getName(), + FBConnectionPoolDataSource.class.getName(), null); convertReference(ref, passedRef); Modified: client-java/trunk/src/test/org/firebirdsql/pool/TestDriverConnectionPoolDataSource.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/pool/TestDriverConnectionPoolDataSource.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/test/org/firebirdsql/pool/TestDriverConnectionPoolDataSource.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -22,7 +22,6 @@ import javax.naming.Context; -import org.firebirdsql.gds.ClassFactory; import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.jdbc.FBDriver; @@ -74,7 +73,7 @@ Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); - props.put(Context.OBJECT_FACTORIES, ClassFactory.get(ClassFactory.DriverConnectionPoolDataSource).getName()); + props.put(Context.OBJECT_FACTORIES, DriverConnectionPoolDataSource.class.getName()); checkJNDI(props); } Modified: client-java/trunk/src/test/org/firebirdsql/pool/TestFBConnectionPoolDataSource.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/pool/TestFBConnectionPoolDataSource.java 2012-08-06 13:51:12 UTC (rev 57006) +++ client-java/trunk/src/test/org/firebirdsql/pool/TestFBConnectionPoolDataSource.java 2012-08-07 18:04:00 UTC (rev 57007) @@ -109,7 +109,7 @@ Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); - props.put(Context.OBJECT_FACTORIES, ClassFactory.get(ClassFactory.FBConnectionPoolDataSource).getName()); + props.put(Context.OBJECT_FACTORIES, FBConnectionPoolDataSource.class.getName()); props.put(Context.PROVIDER_URL, "file:."); checkJNDI(props); @@ -185,7 +185,7 @@ } public void testReferenceSupport() throws Exception { - Reference ref = new Reference(ClassFactory.get(ClassFactory.FBConnectionPoolDataSource).getName()); + Reference ref = new Reference(FBConnectionPoolDataSource.class.getName()); fillReference(ref); @@ -193,7 +193,7 @@ Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); - props.put(Context.OBJECT_FACTORIES,ClassFactory.get(ClassFactory.FBConnectionPoolDataSource).getName()); + props.put(Context.OBJECT_FACTORIES, FBConnectionPoolDataSource.class.getName()); Context ctx = new InitialContext(props); try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-07 18:13:11
|
Revision: 57008 http://firebird.svn.sourceforge.net/firebird/?rev=57008&view=rev Author: mrotteveel Date: 2012-08-07 18:13:05 +0000 (Tue, 07 Aug 2012) Log Message: ----------- JDBC-263 / JDBC-195 : migrate src/wire_jdk1_4 into src/main Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java Removed Paths: ------------- client-java/trunk/src/wire_jdk1_4/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java (from rev 56999, client-java/trunk/src/wire_jdk1_4/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java 2012-08-07 18:13:05 UTC (rev 57008) @@ -0,0 +1,111 @@ +package org.firebirdsql.gds.impl.wire; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.ArrayList; + +/** + * Implements JDK1.4+ specific socket creation. + * + * This is necessary because of a bug found in the JDK1.4 and is / will not be + * fixed until JDK7.0. + * + * See bug details: <a + * href='http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063'> + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063 </a> + * + * @author <a href="mailto:sja...@us...">Steve Jardine </a> + */ +public class JavaGDSImpl extends AbstractJavaGDSImpl { + + /* + * (non-Javadoc) + * + * @see org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl#getSocket(java.lang.String, + * int) + */ + protected Socket getSocket(String server, int port) throws IOException, + UnknownHostException { + + // Check for a valid ip address. + byte[] address = parseRawAddress(server); + + // Create the socket using an instance of the InetAddress class if the + // ip address is a valid IPV4 or IPV6 address + if (address != null && address.length != 0) + return new Socket(InetAddress.getByAddress(address), port); + else + return new Socket(server, port); + + } + + /** + * Parses a string representation of a raw ip address. Only 4 byte (IPv4) or + * 16 byte (IPv6) are acceptable. + * + * @param server + * a string representation of the host server. + * @return a byte array representing the ip address + */ + public static byte[] parseRawAddress(String server) { + + ArrayList<Byte> result = new ArrayList<Byte>(); + String[] bytes = server.split("\\.|:"); + + try { + // Only 4 byte (IPv4) and 16 byte (IPv6) addresses are acceptable. + if (bytes.length == 4 ) { + // convert each string into a byte. If the string doesn't isn't in + // the range of 0 .. 255 return null. + for (int index = 0; index < bytes.length; index++) { + int value = Integer.parseInt(bytes[index]); + + if (value >= 0 && value <= 255) + result.add((byte) value); + else + return null; + + } + } else + if (bytes.length == 16 || bytes.length == 8) { + + // convert each string into a byte. If the string doesn't isn't in + // the range of 0 .. 255 return null. + for (int index = 0; index < bytes.length; index++) { + + bytes[index] = prependZeros(bytes[index], 4); + String hi = bytes[index].substring(0, 2); + String lo = bytes[index].substring(2); + + int hiValue = Integer.parseInt(hi, 16); + int loValue = Integer.parseInt(lo, 16); + + if (hiValue == -1 || loValue == -1) + return null; + + result.add((byte)hiValue); + result.add((byte)loValue); + + } + } else + return null; + } catch(NumberFormatException ex) { + return null; + } + + byte[] address = new byte[result.size()]; + for(int i = 0 ; i < result.size(); i++) + address[i] = result.get(i); + + return address; + + } + + private static String prependZeros(String s, int totalLength) { + s= "000000000000"+s; // twelve zeros prepended + return s.substring(s.length()-totalLength); // keep the rightmost 13 chars + } + +} Deleted: client-java/trunk/src/wire_jdk1_4/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java =================================================================== --- client-java/trunk/src/wire_jdk1_4/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java 2012-08-07 18:04:00 UTC (rev 57007) +++ client-java/trunk/src/wire_jdk1_4/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java 2012-08-07 18:13:05 UTC (rev 57008) @@ -1,111 +0,0 @@ -package org.firebirdsql.gds.impl.wire; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.ArrayList; - -/** - * Implements JDK1.4+ specific socket creation. - * - * This is necessary because of a bug found in the JDK1.4 and is / will not be - * fixed until JDK7.0. - * - * See bug details: <a - * href='http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063'> - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063 </a> - * - * @author <a href="mailto:sja...@us...">Steve Jardine </a> - */ -public class JavaGDSImpl extends AbstractJavaGDSImpl { - - /* - * (non-Javadoc) - * - * @see org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl#getSocket(java.lang.String, - * int) - */ - protected Socket getSocket(String server, int port) throws IOException, - UnknownHostException { - - // Check for a valid ip address. - byte[] address = parseRawAddress(server); - - // Create the socket using an instance of the InetAddress class if the - // ip address is a valid IPV4 or IPV6 address - if (address != null && address.length != 0) - return new Socket(InetAddress.getByAddress(address), port); - else - return new Socket(server, port); - - } - - /** - * Parses a string representation of a raw ip address. Only 4 byte (IPv4) or - * 16 byte (IPv6) are acceptable. - * - * @param server - * a string representation of the host server. - * @return a byte array representing the ip address - */ - public static byte[] parseRawAddress(String server) { - - ArrayList<Byte> result = new ArrayList<Byte>(); - String[] bytes = server.split("\\.|:"); - - try { - // Only 4 byte (IPv4) and 16 byte (IPv6) addresses are acceptable. - if (bytes.length == 4 ) { - // convert each string into a byte. If the string doesn't isn't in - // the range of 0 .. 255 return null. - for (int index = 0; index < bytes.length; index++) { - int value = Integer.parseInt(bytes[index]); - - if (value >= 0 && value <= 255) - result.add((byte) value); - else - return null; - - } - } else - if (bytes.length == 16 || bytes.length == 8) { - - // convert each string into a byte. If the string doesn't isn't in - // the range of 0 .. 255 return null. - for (int index = 0; index < bytes.length; index++) { - - bytes[index] = prependZeros(bytes[index], 4); - String hi = bytes[index].substring(0, 2); - String lo = bytes[index].substring(2); - - int hiValue = Integer.parseInt(hi, 16); - int loValue = Integer.parseInt(lo, 16); - - if (hiValue == -1 || loValue == -1) - return null; - - result.add((byte)hiValue); - result.add((byte)loValue); - - } - } else - return null; - } catch(NumberFormatException ex) { - return null; - } - - byte[] address = new byte[result.size()]; - for(int i = 0 ; i < result.size(); i++) - address[i] = result.get(i); - - return address; - - } - - private static String prependZeros(String s, int totalLength) { - s= "000000000000"+s; // twelve zeros prepended - return s.substring(s.length()-totalLength); // keep the rightmost 13 chars - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-08 19:30:17
|
Revision: 57017 http://firebird.svn.sourceforge.net/firebird/?rev=57017&view=rev Author: mrotteveel Date: 2012-08-08 19:30:10 +0000 (Wed, 08 Aug 2012) Log Message: ----------- Use <Number>.valueOf() instead of new <Number>() Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionHelper.java client-java/trunk/src/main/org/firebirdsql/management/FBManager.java client-java/trunk/src/pool/org/firebirdsql/pool/FBSimpleDataSource.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionQueue.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -176,7 +176,7 @@ if (internalExecute(!isSelectableProcedure())) throw new BatchUpdateException(toArray(results)); - results.add(new Integer(getUpdateCount())); + results.add(Integer.valueOf(getUpdateCount())); } catch (GDSException ex) { throw new BatchUpdateException(ex.getMessage(), "", ex.getFbErrorCode(), toArray(results)); @@ -1354,7 +1354,7 @@ } public void setByte(int parameterIndex, byte x) throws SQLException { - procedureCall.getInputParam(parameterIndex).setValue(new Byte(x)); + procedureCall.getInputParam(parameterIndex).setValue(Byte.valueOf(x)); } public void setBytes(int parameterIndex, byte[] x) throws SQLException { @@ -1387,11 +1387,11 @@ } public void setInt(int parameterIndex, int x) throws SQLException { - procedureCall.getInputParam(parameterIndex).setValue(new Integer(x)); + procedureCall.getInputParam(parameterIndex).setValue(Integer.valueOf(x)); } public void setLong(int parameterIndex, long x) throws SQLException { - procedureCall.getInputParam(parameterIndex).setValue(new Long(x)); + procedureCall.getInputParam(parameterIndex).setValue(Long.valueOf(x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { @@ -1420,7 +1420,7 @@ } public void setShort(int parameterIndex, short x) throws SQLException { - procedureCall.getInputParam(parameterIndex).setValue(new Short(x)); + procedureCall.getInputParam(parameterIndex).setValue(Short.valueOf(x)); } public void setString(int parameterIndex, String x) throws SQLException { Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -951,7 +951,7 @@ int updateCount = getUpdateCount(); - results.add(new Integer(updateCount)); + results.add(Integer.valueOf(updateCount)); } catch (SQLException ex) { throw new BatchUpdateException(ex.getMessage(), ex Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -673,7 +673,7 @@ // If it is the first time the columnName is used if (fieldNum == null){ int colNum = findColumn(columnName); - fieldNum = new Integer(colNum); + fieldNum = Integer.valueOf(colNum); colNames.put(columnName, fieldNum); } int colNum = fieldNum.intValue(); Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -1271,7 +1271,7 @@ throw new BatchUpdateException( toArray(responses)); else - responses.add(new Integer(getUpdateCount())); + responses.add(Integer.valueOf(getUpdateCount())); } catch (GDSException ge) { throw new BatchUpdateException(ge.getMessage(), Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionHelper.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionHelper.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionHelper.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -142,17 +142,17 @@ Integer type = (Integer)dpbParameterTypes.get(name); if (type == null) - type = new Integer(TYPE_UNKNOWN); + type = Integer.valueOf(TYPE_UNKNOWN); switch(type.intValue()) { case TYPE_BOOLEAN : return "".equals(value) ? Boolean.TRUE : Boolean.valueOf((String)value); case TYPE_BYTE : - return new Byte((String)value); + return Byte.valueOf((String)value); case TYPE_INT : - return new Integer((String)value); + return Integer.valueOf((String)value); case TYPE_STRING : return value; @@ -170,10 +170,10 @@ try { // try to deal with a value as a byte or int int intValue = Integer.parseInt((String)value); - if (intValue < 256) - return new Byte((byte) intValue); + if (intValue >= Byte.MIN_VALUE && intValue <= Byte.MAX_VALUE) + return Byte.valueOf((byte) intValue); else - return new Integer(intValue); + return Integer.valueOf(intValue); } catch (NumberFormatException nfex) { // all else fails: return as is (string) return value; @@ -291,23 +291,20 @@ String shortKey = key.substring(DPB_PREFIX.length()); String value = (String)entry.getValue(); + Integer typeValue; if ("boolean".equals(value)) { - dpbParameterTypes.put(key, new Integer(TYPE_BOOLEAN)); - dpbParameterTypes.put(shortKey, new Integer(TYPE_BOOLEAN)); - } else - if ("byte".equals(value)) { - dpbParameterTypes.put(key, new Integer(TYPE_BYTE)); - dpbParameterTypes.put(shortKey, new Integer(TYPE_BYTE)); - } else - if ("int".equals(value)) { - dpbParameterTypes.put(key, new Integer(TYPE_INT)); - dpbParameterTypes.put(shortKey, new Integer(TYPE_INT)); - } else - if ("string".equals(value)) { - dpbParameterTypes.put(key, new Integer(TYPE_STRING)); - dpbParameterTypes.put(shortKey, new Integer(TYPE_STRING)); - } else + typeValue = Integer.valueOf(TYPE_BOOLEAN); + } else if ("byte".equals(value)) { + typeValue = Integer.valueOf(TYPE_BYTE); + } else if ("int".equals(value)) { + typeValue = Integer.valueOf(TYPE_INT); + } else if ("string".equals(value)) { + typeValue = Integer.valueOf(TYPE_STRING); + } else { continue; + } + dpbParameterTypes.put(key, typeValue); + dpbParameterTypes.put(shortKey, typeValue); } } } Modified: client-java/trunk/src/main/org/firebirdsql/management/FBManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/management/FBManager.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/main/org/firebirdsql/management/FBManager.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -172,7 +172,7 @@ * @jmx.managed-attribute */ public void setPort(int port) { - this.port = new Integer(port); + this.port = Integer.valueOf(port); } /** Modified: client-java/trunk/src/pool/org/firebirdsql/pool/FBSimpleDataSource.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/FBSimpleDataSource.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/pool/org/firebirdsql/pool/FBSimpleDataSource.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -81,7 +81,7 @@ * @return length of BLOB buffer. */ public Integer getBlobBufferLength() { - return new Integer(mcf.getBlobBufferSize()); + return Integer.valueOf(mcf.getBlobBufferSize()); } /** Modified: client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionQueue.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionQueue.java 2012-08-08 14:41:07 UTC (rev 57016) +++ client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionQueue.java 2012-08-08 19:30:10 UTC (rev 57017) @@ -295,7 +295,7 @@ // save timestamp when connection was returned to queue connectionIdleTime.put( - connection, new Long(System.currentTimeMillis())); + connection, Long.valueOf(System.currentTimeMillis())); size++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-08-12 18:01:00
|
Revision: 57031 http://firebird.svn.sourceforge.net/firebird/?rev=57031&view=rev Author: mrotteveel Date: 2012-08-12 18:00:53 +0000 (Sun, 12 Aug 2012) Log Message: ----------- * Code cleanup of FBBigDecimalField * Add unit tests for FBBigDecimalField * Treat DECIMAL fields as DECIMAL instead of NUMERIC Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBBigDecimalField.java client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBBigDecimalField.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBBigDecimalField.java 2012-08-12 09:52:36 UTC (rev 57030) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBBigDecimalField.java 2012-08-12 18:00:53 UTC (rev 57031) @@ -19,6 +19,7 @@ package org.firebirdsql.jdbc.field; +import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.XSQLVAR; import java.sql.SQLException; @@ -42,13 +43,15 @@ private static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE); private static final BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE); - private int fieldType = 0; // 1.- Short, 2.- Integer, 3.- Long + private final FieldDataSize fieldDataSize; - FBBigDecimalField(XSQLVAR field, FieldDataProvider dataProvider, int fieldType, - int requiredType) throws SQLException + FBBigDecimalField(XSQLVAR field, FieldDataProvider dataProvider, int requiredType) throws SQLException { super(field, dataProvider, requiredType); - this.fieldType = fieldType; + fieldDataSize = FieldDataSize.getFieldDataSize(field); + if (fieldDataSize == null) { + throw new SQLException("FBBigDecimal, unsupported field sqltype: " + field.sqltype); + } } public boolean getBoolean() throws SQLException { @@ -71,8 +74,6 @@ } public double getDouble() throws SQLException { - if (getFieldData()==null) return DOUBLE_NULL_VALUE; - BigDecimal value = getBigDecimal(); if (value == BIGDECIMAL_NULL_VALUE) @@ -82,18 +83,12 @@ } public float getFloat() throws SQLException { - if (getFieldData()==null) return FLOAT_NULL_VALUE; - - double value = getDouble(); - - float cValue = (float) value; - // check if value is within bounds - if (cValue == Float.POSITIVE_INFINITY || - cValue == Float.NEGATIVE_INFINITY) - throw (SQLException)createException( - FLOAT_CONVERSION_ERROR + " " + value).fillInStackTrace(); - - return cValue; + BigDecimal value = getBigDecimal(); + + if (value == BIGDECIMAL_NULL_VALUE) + return FLOAT_NULL_VALUE; + + return value.floatValue(); } public int getInt() throws SQLException { @@ -140,8 +135,6 @@ } public String getString() throws SQLException { - if (getFieldData()==null) return STRING_NULL_VALUE; - BigDecimal value = getBigDecimal(); if (value == BIGDECIMAL_NULL_VALUE) @@ -153,21 +146,7 @@ public BigDecimal getBigDecimal() throws SQLException { if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE; - long longValue; - - if (fieldType==2) - longValue = field.decodeInt(getFieldData()); - else - if (fieldType==3) - longValue = field.decodeLong(getFieldData()); - else - if (fieldType==1) - longValue = field.decodeShort(getFieldData()); - else - throw (SQLException)createException( - BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); - - return BigDecimal.valueOf(longValue, -field.sqlscale); + return fieldDataSize.decode(field, getFieldData()); } //--- setXXX methods @@ -181,7 +160,7 @@ } public void setDouble(double value) throws SQLException { - setBigDecimal(new BigDecimal(Double.toString(value))); + setBigDecimal(BigDecimal.valueOf(value)); } public void setFloat(float value) throws SQLException { @@ -219,42 +198,113 @@ setNull(); return; } - - value = value.setScale(-field.sqlscale, BigDecimal.ROUND_HALF_UP); - if (fieldType == 1) { + setFieldData(fieldDataSize.encode(field, value)); + } + + /** + * Enum for handling the different fielddata sizes of NUMERIC/DECIMAL fields. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + */ + private enum FieldDataSize { + SHORT { + @Override + protected BigDecimal decode(final XSQLVAR field, final byte[] fieldData) { + long value = field.decodeShort(fieldData); + return BigDecimal.valueOf(value, -field.sqlscale); + } - // check if value is within bounds - if (value.unscaledValue().compareTo(MAX_SHORT) > 0 || - value.unscaledValue().compareTo(MIN_SHORT) < 0) - throw (SQLException)createException( - BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); + @Override + protected byte[] encode(final XSQLVAR field, final BigDecimal value) throws SQLException { + BigInteger unscaledValue = normalize(value, -field.sqlscale); + if (unscaledValue.compareTo(MAX_SHORT) > 0 || unscaledValue.compareTo(MIN_SHORT) < 0) { + throw (SQLException)createException(BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); + } + return field.encodeShort(unscaledValue.shortValue()); + } + }, + INTEGER { + @Override + protected BigDecimal decode(final XSQLVAR field, final byte[] fieldData) { + long value = field.decodeInt(fieldData); + return BigDecimal.valueOf(value, -field.sqlscale); + } - setFieldData(field.encodeShort(value.unscaledValue().shortValue())); - } else - if (fieldType == 2) { + @Override + protected byte[] encode(final XSQLVAR field, final BigDecimal value) throws SQLException { + BigInteger unscaledValue = normalize(value, -field.sqlscale); + if (unscaledValue.compareTo(MAX_INT) > 0 || unscaledValue.compareTo(MIN_INT) < 0) { + throw (SQLException)createException(BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); + } + return field.encodeInt(unscaledValue.intValue()); + } + }, + LONG { + @Override + protected BigDecimal decode(final XSQLVAR field, final byte[] fieldData) { + long value = field.decodeLong(fieldData); + return BigDecimal.valueOf(value, -field.sqlscale); + } - // check if value is within bounds - if (value.unscaledValue().compareTo(MAX_INT) > 0 || - value.unscaledValue().compareTo(MIN_INT) < 0) - throw (SQLException)createException( - BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); + @Override + protected byte[] encode(final XSQLVAR field, final BigDecimal value) throws SQLException { + BigInteger unscaledValue = normalize(value, -field.sqlscale); + if (unscaledValue.compareTo(MAX_LONG) > 0 || unscaledValue.compareTo(MIN_LONG) < 0) { + throw (SQLException)createException(BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); + } + return field.encodeLong(unscaledValue.longValue()); + } + }; + + /** + * Decodes the provided fieldData to a BigDecimal + * + * @param field XSQLVAR field instance + * @param fieldData encoded data + * @return BigDecimal instance + */ + protected abstract BigDecimal decode(final XSQLVAR field, final byte[] fieldData); - setFieldData(field.encodeInt(value.unscaledValue().intValue())); - } else - if (fieldType == 3) { - - // check if value is within bounds - if (value.unscaledValue().compareTo(MAX_LONG) > 0 || - value.unscaledValue().compareTo(MIN_LONG) < 0) - throw (SQLException)createException( - BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); - - setFieldData(field.encodeLong(value.unscaledValue().longValue())); - } else - throw (SQLException)createException( - BIGDECIMAL_CONVERSION_ERROR).fillInStackTrace(); - + /** + * Encodes the provided BigDecimal to fieldData + * @param field XSQLVAR field instance + * @param value BigDecimal instance + * @return encoded data + * @throws SQLException + */ + protected abstract byte[] encode(final XSQLVAR field, final BigDecimal value) throws SQLException; + + /** + * Helper method to rescale the BigDecimal to the provided scale and return the unscaled value of + * the resulting BigDecimal. + * + * @param value BigDecimal instance + * @param scale Required scale + * @return Unscaled value of the rescaled BigDecimal + */ + private static BigInteger normalize(final BigDecimal value, final int scale) { + BigDecimal valueToScale = value.setScale(scale, BigDecimal.ROUND_HALF_UP); + return valueToScale.unscaledValue(); + } + + /** + * Returns the FieldDataSize instance for the provided field. + * @param field XSQLVAR field instance + * @return FieldDataSize for the field, or null if none match + */ + protected static FieldDataSize getFieldDataSize(XSQLVAR field) { + switch (field.sqltype & ~1) { + case ISCConstants.SQL_SHORT: + return SHORT; + case ISCConstants.SQL_LONG: + return INTEGER; + case ISCConstants.SQL_INT64: + return LONG; + default: + return null; + } + } } } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBField.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBField.java 2012-08-12 09:52:36 UTC (rev 57030) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/field/FBField.java 2012-08-12 18:00:53 UTC (rev 57031) @@ -364,19 +364,19 @@ if (field.sqlscale == 0) return new FBShortField(field, dataProvider, Types.SMALLINT); else - return new FBBigDecimalField(field, dataProvider, 1, Types.NUMERIC); + return new FBBigDecimalField(field, dataProvider, field.sqlsubtype == 2 ? Types.DECIMAL : Types.NUMERIC); else if (isType(field, Types.INTEGER)) if (field.sqlscale == 0) return new FBIntegerField(field, dataProvider, Types.INTEGER); else - return new FBBigDecimalField(field, dataProvider,2, Types.NUMERIC); + return new FBBigDecimalField(field, dataProvider, field.sqlsubtype == 2 ? Types.DECIMAL : Types.NUMERIC); else if (isType(field, Types.BIGINT)) if (field.sqlscale == 0) return new FBLongField(field, dataProvider, Types.BIGINT); else - return new FBBigDecimalField(field, dataProvider,3, Types.NUMERIC); + return new FBBigDecimalField(field, dataProvider, field.sqlsubtype == 2 ? Types.DECIMAL : Types.NUMERIC); else if (isType(field, Types.FLOAT)) return new FBFloatField(field, dataProvider, Types.FLOAT); Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java 2012-08-12 09:52:36 UTC (rev 57030) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java 2012-08-12 18:00:53 UTC (rev 57031) @@ -18,66 +18,646 @@ */ package org.firebirdsql.jdbc.field; +import static org.junit.Assert.*; + +import java.math.BigDecimal; +import java.math.BigInteger; import java.sql.SQLException; +import java.sql.Types; import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.XSQLVAR; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.integration.junit4.JMock; +import org.jmock.integration.junit4.JUnit4Mockery; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; - -public class TestFBBigDecimalField extends BaseTestFBField { - - public TestFBBigDecimalField(String testName) { - super(testName); +/** + * Tests for {@link FBBigDecimalField} + */ +@RunWith(JMock.class) +public class TestFBBigDecimalField { + Mockery context = new JUnit4Mockery(); + + private FieldDataProvider fieldData; + + @Before + public void setUp() { + fieldData = context.mock(FieldDataProvider.class); } + + // TODO Add set<PrimitiveNumber> tests for out of range condition; in current implementation duplicates setBigDecimal out of range tests + // TODO Add tests for unsupported conversions + // TODO Add set/getObject test - protected void setUp() throws SQLException{ - final XSQLVAR[] xsqlvars = new XSQLVAR[1]; - xsqlvars[0] = createXSQLVAR(); - xsqlvars[0].sqltype = ISCConstants.SQL_INT64; + @Test + public void getBigDecimalNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); - field = FBField.createField(xsqlvars[0], createDataProvider(xsqlvars), null, false); + assertNull("Expected null result", field.getBigDecimal()); } - protected void tearDown() { + + @Test + public void getBigDecimalShort() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeShort((short) 231))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + BigDecimal expectedValue = new BigDecimal("23.1"); + assertEquals(expectedValue, field.getBigDecimal()); } - - public void testDouble() throws SQLException { + @Test + public void getBigDecimalInteger() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -4; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt(34))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + BigDecimal expectedValue = new BigDecimal("0.0034"); + assertEquals(expectedValue, field.getBigDecimal()); } - - public void testFloat() throws SQLException { + + @Test + public void getBigDecimalLong() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -8; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(51300000000L))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + BigDecimal expectedValue = new BigDecimal("513.00000000"); + assertEquals(expectedValue, field.getBigDecimal()); } - - public void testBigDecimal() throws SQLException { + + @Test + public void setBigDecimalShort() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeShort((short)4320)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + // TODO Might need to add separate test for the rescaling applied here + field.setBigDecimal(new BigDecimal("43.2")); } - - public void testObject() throws SQLException { + + @Test(expected = TypeConversionException.class) + public void setBigDecimalShortTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(BigDecimal.valueOf(Short.MAX_VALUE + 1, 2)); } - - public void testString() throws SQLException { + + @Test(expected = TypeConversionException.class) + public void setBigDecimalShortTooLow() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(BigDecimal.valueOf(Short.MIN_VALUE - 1, 2)); } - - public void testAsciiStream() throws SQLException { + + @Test + public void setBigDecimalShortNull() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -1; + setNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(null); } - - public void testBinaryStream() throws SQLException { + + @Test + public void setBigDecimalInteger() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -3; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeInt(1234567)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(new BigDecimal("1234.567")); } - - public void testBoolean() throws SQLException { + + @Test(expected = TypeConversionException.class) + public void setBigDecimalIntegerTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(BigDecimal.valueOf(Integer.MAX_VALUE + 1L, 2)); } - - public void testBytes() throws SQLException { + + @Test(expected = TypeConversionException.class) + public void setBigDecimalIntegerTooLow() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(BigDecimal.valueOf(Integer.MIN_VALUE - 1L, 2)); } - - public void testDate() throws SQLException { + + @Test + public void setBigDecimalIntegerNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + setNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(null); } - - public void testTime() throws SQLException { + + @Test + public void setBigDecimalLong() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -5; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeLong(1234567890123L)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(new BigDecimal("12345678.90123")); } - - public void testTimestamp() throws SQLException { + + @Test(expected = TypeConversionException.class) + public void setBigDecimalLongTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + BigInteger value = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + field.setBigDecimal(new BigDecimal(value, 2)); } + + @Test(expected = TypeConversionException.class) + public void setBigDecimalLongTooLow() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + BigInteger value = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE); + field.setBigDecimal(new BigDecimal(value, 2)); + } + + @Test + public void setBigDecimalLongNull() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -1; + setNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBigDecimal(null); + } + + @Test + public void getBooleanTrue() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + // NOTE: We could use 0 for the test, but in that case Jaybird would not have create a FBBigDecimalField + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeShort((short)10))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertTrue("Expected true from getBoolean", field.getBoolean()); + } + + @Test + public void getBooleanFalse() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + // NOTE: We could use 0 for the test, but in that case Jaybird would not have create a FBBigDecimalField + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + // NOTE Any value other than 10 would do + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeShort((short)0))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertFalse("Expected false from getBoolean", field.getBoolean()); + } + + @Test + public void setBooleanTrue() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + // NOTE: We could use 0 for the test, but in that case Jaybird would not have create a FBBigDecimalField + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeShort((short)10)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBoolean(true); + } + + @Test + public void setBooleanFalse() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + // NOTE: We could use 0 for the test, but in that case Jaybird would not have create a FBBigDecimalField + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeShort((short)0)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setBoolean(false); + } + + @Test + public void getByteNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -6; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getByte() to return 0 for NULL value", 0, field.getByte()); + } + + @Test + public void getByte() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt(Byte.MIN_VALUE * 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value for getByte()", Byte.MIN_VALUE, field.getByte()); + } + + @Test(expected = TypeConversionException.class) + public void getByteTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt((Byte.MAX_VALUE + 1)* 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getByte(); + } + + @Test(expected = TypeConversionException.class) + public void getByteTooLow() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt((Byte.MIN_VALUE - 1)* 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getByte(); + } + + @Test + public void setByte() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -7; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeLong(-340000000L)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setByte((byte) -34); + } + + @Test + public void getDoubleNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -6; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getDouble() to return 0.0 for NULL value", 0.0, field.getDouble(), 0.0); + } + + @Test + public void getDouble() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(Long.MIN_VALUE))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value for getDouble()", Long.MIN_VALUE / 100.0, field.getDouble(), 0.0); + } + + @Test + public void setDouble() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeShort((short)4691)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setDouble(469.1234567); + } + + @Test + public void getFloatNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -6; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getFloat() to return 0.0 for NULL value", 0.0, field.getFloat(), 0.0); + } + + @Test + public void getFloat() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(Long.MAX_VALUE))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value for getFloat()", Long.MAX_VALUE / 100.0f, field.getFloat(), 0.0); + } + + @Test + public void setFloat() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -5; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeLong(46912344L)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); - public void testUnicodeStream() throws SQLException { + field.setFloat(469.1234567f); } + @Test + public void getIntNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getInt() to return 0 for NULL value", 0, field.getInt()); + } + + @Test + public void getInt() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -6; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(987654321098765L))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value from getInt()", 987654321, field.getInt()); + } + + @Test(expected = TypeConversionException.class) + public void getIntTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong((Integer.MAX_VALUE + 1L) * 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getInt(); + } + + @Test(expected = TypeConversionException.class) + public void getIntTooLow() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong((Integer.MIN_VALUE - 1L) * 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getInt(); + } + + @Test + public void setInteger() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeInt(1234560)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setInteger(123456); + } + + @Test + public void getLongNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getLong() to return 0 for NULL value", 0, field.getLong()); + } + + @Test + public void getLong() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(Long.MAX_VALUE))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value from getLong()", Long.MAX_VALUE / 100, field.getLong()); + } + + @Test + public void setLong() throws SQLException { + final XSQLVAR xsqlvar = createShortXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeShort((short)3500)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setLong(35); + } + + @Test + public void setNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + setNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setNull(); + } + + @Test + public void getShortNull() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -1; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Expected getShort() to return 0 for NULL value", 0, field.getShort()); + } + + @Test + public void getShort() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -4; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt(123456789))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value from getShort()", 12345, field.getShort()); + } + + @Test(expected = TypeConversionException.class) + public void getShortTooHigh() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt((Short.MAX_VALUE + 1) * 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getShort(); + } + + @Test(expected = TypeConversionException.class) + public void getShortTooLow() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeInt((Short.MIN_VALUE - 1) * 100))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.getShort(); + } + + @Test + public void setShort() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -3; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeLong(Short.MIN_VALUE * 1000L)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setShort(Short.MIN_VALUE); + } + + @Test + public void getStringNull() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -1; + toReturnNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertNull(field.getString()); + } + + @Test + public void getString() throws SQLException { + final XSQLVAR xsqlvar = createLongXSQLVAR(); + xsqlvar.sqlscale = -2; + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(xsqlvar.encodeLong(456789123))); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + assertEquals("Unexpected value from getString()", "4567891.23", field.getString()); + } + + @Test + public void setString() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + context.checking(new Expectations() {{ + oneOf(fieldData).setFieldData(xsqlvar.encodeInt(789123)); + }}); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setString("78912.3456"); + } + + @Test + public void setStringNull() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + setNullExpectations(); + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setString(null); + } + + @Test(expected = TypeConversionException.class) + public void setStringNonNumber() throws SQLException { + final XSQLVAR xsqlvar = createIntegerXSQLVAR(); + xsqlvar.sqlscale = -1; + FBBigDecimalField field = new FBBigDecimalField(xsqlvar, fieldData, Types.NUMERIC); + + field.setString("NotANumber"); + } + + @Test(expected = SQLException.class) + public void constructWithUnsupportedSqlType() throws SQLException { + final XSQLVAR xsqlvar = new XSQLVAR(); + xsqlvar.sqltype = ISCConstants.SQL_VARYING; + + new FBBigDecimalField(xsqlvar, fieldData, Types.VARCHAR); + } + + /** + * Expectations to return null from fieldData. + */ + private void toReturnNullExpectations() { + context.checking(new Expectations() {{ + atLeast(1).of(fieldData).getFieldData(); will(returnValue(null)); + }}); + } + + /** + * Expectations for setting field to null + */ + private void setNullExpectations() { + context.checking(new Expectations() {{ + one(fieldData).setFieldData(null); + }}); + } + + private static XSQLVAR createShortXSQLVAR() { + XSQLVAR xsqlvar = new XSQLVAR(); + xsqlvar.sqltype = ISCConstants.SQL_SHORT; + return xsqlvar; + } + + private static XSQLVAR createIntegerXSQLVAR() { + XSQLVAR xsqlvar = new XSQLVAR(); + xsqlvar.sqltype = ISCConstants.SQL_LONG; + return xsqlvar; + } + + private static XSQLVAR createLongXSQLVAR() { + XSQLVAR xsqlvar = new XSQLVAR(); + xsqlvar.sqltype = ISCConstants.SQL_INT64; + return xsqlvar; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-09-02 11:03:13
|
Revision: 57096 http://firebird.svn.sourceforge.net/firebird/?rev=57096&view=rev Author: mrotteveel Date: 2012-09-02 11:03:04 +0000 (Sun, 02 Sep 2012) Log Message: ----------- JDBC-86 / JDBC-144 : Eliminate deprecated datasources and related classes and tests Removed Paths: ------------- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractConnectionPool.java client-java/trunk/src/pool/org/firebirdsql/pool/AbstractDriverConnectionPoolDataSource.java client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java client-java/trunk/src/pool/org/firebirdsql/pool/BasicAbstractConnectionPool.java client-java/trunk/src/pool/org/firebirdsql/pool/BlockingStack.java client-java/trunk/src/pool/org/firebirdsql/pool/ConnectionPoolConfiguration.java client-java/trunk/src/pool/org/firebirdsql/pool/DriverConnectionPoolDataSource.java client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledConnection.java client-java/trunk/src/pool/org/firebirdsql/pool/FBPooledDataSourceFactory.java client-java/trunk/src/pool/org/firebirdsql/pool/FBPoolingDefaults.java client-java/trunk/src/pool/org/firebirdsql/pool/FirebirdPool.java client-java/trunk/src/pool/org/firebirdsql/pool/ObjectCloseTraceException.java client-java/trunk/src/pool/org/firebirdsql/pool/PoolDebugConfiguration.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionEventListener.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionHandler.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionManager.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledConnectionQueue.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledObject.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledObjectEvent.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledObjectListener.java client-java/trunk/src/pool/org/firebirdsql/pool/PooledPreparedStatementHandler.java client-java/trunk/src/pool/org/firebirdsql/pool/ResultSetHandler.java client-java/trunk/src/pool/org/firebirdsql/pool/SimpleDataSource.java client-java/trunk/src/pool/org/firebirdsql/pool/StatementHandler.java client-java/trunk/src/pool/org/firebirdsql/pool/UnknownDriverTypeException.java client-java/trunk/src/pool/org/firebirdsql/pool/XCachablePreparedStatement.java client-java/trunk/src/pool/org/firebirdsql/pool/XConnectionManager.java client-java/trunk/src/pool/org/firebirdsql/pool/XConnectionUtil.java client-java/trunk/src/pool/org/firebirdsql/pool/XPingableConnection.java client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementCache.java client-java/trunk/src/pool/org/firebirdsql/pool/XPreparedStatementModel.java client-java/trunk/src/pool/org/firebirdsql/pool/XStatementManager.java client-java/trunk/src/pool_jdk1_5/org/firebirdsql/pool/PingablePooledConnection.java client-java/trunk/src/pool_jdk1_6/org/firebirdsql/pool/PingablePooledConnection.java client-java/trunk/src/test/org/firebirdsql/pool/TestBlockingStack.java Deleted: client-java/trunk/src/pool/org/firebirdsql/pool/AbstractConnectionPool.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractConnectionPool.java 2012-09-02 10:37:13 UTC (rev 57095) +++ client-java/trunk/src/pool/org/firebirdsql/pool/AbstractConnectionPool.java 2012-09-02 11:03:04 UTC (rev 57096) @@ -1,377 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ - -package org.firebirdsql.pool; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.firebirdsql.ds.RootCommonDataSource; -import org.firebirdsql.logging.Logger; - -/** - * Abstract class for creating connection pools. Subclasses must implement - * factory method to produce physical connections to the database (method - * {@link #getConnectionManager()} and few utility methods ({@link #getLogger()} - * and {@link #getPoolName}). - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public abstract class AbstractConnectionPool extends RootCommonDataSource implements PooledObjectListener { - - /** - * Structure class to store user name and password. - */ - protected static class UserPasswordPair { - private String userName; - private String password; - - public UserPasswordPair() { - this(null, null); - } - - public String getUserName() { - return userName; - } - - public String getPassword() { - return password; - } - - public UserPasswordPair(String userName, String password) { - this.userName = userName; - this.password = password; - } - - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null) return false; - if (!(obj instanceof UserPasswordPair)) return false; - - UserPasswordPair that = (UserPasswordPair)obj; - - boolean equal = true; - - equal &= userName != null ? - userName.equals(that.userName) : that.userName == null; - - equal &= password != null ? - password.equals(that.password) : that.password == null; - - return equal; - } - - public int hashCode() { - int result = 3; - - result ^= userName != null ? userName.hashCode() : 0; - result ^= password != null ? password.hashCode() : 0; - - return result; - } - } - - /** - * This constant controls behavior of this class in case of - * severe error situation. Usually, if value of this constant - * is <code>true</code>, such error condition will result in - * raising either runtime exception or error. - */ - private static final boolean PARANOID_MODE = true; - - /** - * This map contains mapping between key and pooled connection queue. - */ - private HashMap connectionQueues = new HashMap(); - - /** - * This map contains mapping between connection and queue, so we - * easily know to which queue connection should be returned to. - */ - private HashMap connectionToQueueMap = new HashMap(); - - /** - * Get logger for this instance. By default all log messages belong to - * this class. Subclasses can override this behavior. - * - * @return instance of {@link Logger}. - */ - protected abstract Logger getLogger(); - - /** - * Create instance of this class. - */ - protected AbstractConnectionPool(){ - // empty - } - - /** - * Shutdown pool if object is garbage collected. - * - * @throws Throwable if something bad happened. - */ - protected void finalize() throws Throwable { - shutdown(); - } - - /** - * Restart this JDBC pool. This method restarts all JDBC connections. - */ - public void restart() - { - Iterator iter = connectionQueues.entrySet().iterator(); - while(iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); - - PooledConnectionQueue queue = - (PooledConnectionQueue)entry.getValue(); - - queue.restart(); - } - - if (getLogger() != null) - getLogger().info( - "Pool restarted. Pool name was " - + getPoolName() - + "."); - } - - /** - * Shutdown this JDBC pool. This method closes all JDBC connections - * and marks pool as shut down. - */ - public void shutdown() { - - Iterator iter = connectionQueues.entrySet().iterator(); - while(iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); - - PooledConnectionQueue queue = - (PooledConnectionQueue)entry.getValue(); - - queue.shutdown(); - } - - if (getLogger() != null) - getLogger().info( - "Pool shutted down. Pool name was " - + getPoolName() - + "."); - - } - - /** - * Get queue for the specified user name and password. - * - * @param key key identifying pool. - * - * @return instance of {@link PooledConnectionQueue}. - * - * @throws SQLException if something went wrong. - */ - public PooledConnectionQueue getQueue(Object key) - throws SQLException - { - synchronized(connectionQueues) { - PooledConnectionQueue queue = - (PooledConnectionQueue)connectionQueues.get(key); - - if (queue == null) { - queue = new PooledConnectionQueue( - getConnectionManager(), - getLogger(), - getConfiguration(), - getPoolName(), - key); - - queue.start(); - - connectionQueues.put(key, queue); - } - - return queue; - } - } - - /** - * Get pooled connection. This method will block until there will be - * free connection to return. - * - * @param queue instance of {@link PooledConnectionQueue} where connection - * will be obtained. - * - * @return instance of {@link PooledObject}. - * - * @throws SQLException if pooled connection cannot be obtained. - */ - protected synchronized PooledObject getPooledConnection( - PooledConnectionQueue queue) throws SQLException - { - - PooledObject result; - - result = queue.take(); - - if (result instanceof XPingableConnection) { - - boolean isValid = false; - - while (!isValid) { - - XPingableConnection pingableConnection = (XPingableConnection)result; - - long lastPingTime = pingableConnection.getLastPingTime(); - long pingInterval = System.currentTimeMillis() - lastPingTime; - - isValid = true; - if (getConfiguration().getPingInterval() > 0) - isValid &= pingInterval < getConfiguration().getPingInterval(); - - if (!isValid && !pingableConnection.ping()) { - if (getLogger() != null) - getLogger().warn( - "Connection " + result - + " was not valid, trying to get another one."); - - // notify queue that invalid connection was destroyed - queue.destroyConnection(result); - - // take another one - result = (PooledObject)queue.take(); - } - } - } - - // save the queue to which this connection belongs to - connectionToQueueMap.put(result, queue); - - return result; - } - - /** - * Notify about new available connection. This method is called by - * {@link javax.sql.PooledConnection} when its wrapped connection being closed. - * - * @param event instance of {@link PooledObjectEvent} containing - * information about closed connection. - */ - public void pooledObjectReleased(PooledObjectEvent event) { - try { - PooledObject connection = - (PooledObject) event.getSource(); - - PooledConnectionQueue queue = - (PooledConnectionQueue)connectionToQueueMap.get(connection); - - if (queue == null) { - if (getLogger() != null) - getLogger().warn("Connection " + connection + - " does not have corresponding queue"); - - connectionToQueueMap.remove(connection); - - if (PARANOID_MODE) - throw new IllegalStateException( - "Connection " + connection + - " does not have corresponding queue"); - else - connection.deallocate(); - } else { - - if (event.isDeallocated()) { - connectionToQueueMap.remove(connection); - queue.physicalConnectionDeallocated(connection); - } else - queue.put(connection); - } - - } catch (SQLException ex) { - - if (getLogger() != null) - getLogger().warn("Error releasing connection.", ex); - } - } - - /** - * Notify about the deallocation of the physical connection (for example, - * when connection is removed by the idle remover thread). - * - * @param event instance of {@link PooledObjectEvent}. - */ - protected void physicalConnectionDeallocated(PooledObjectEvent event) { - PooledObject connection = (PooledObject) event.getSource(); - connectionToQueueMap.remove(connection); - } - - /** - * Get configuration of this data source. - * - * @return instance of {@link ConnectionPoolConfiguration} describing - * this data source. - */ - public abstract ConnectionPoolConfiguration getConfiguration(); - - /** - * Get instance of {@link PooledConnectionManager} responsible for - * instantiating pooled connections. - * - * @return instance of {@link PooledConnectionManager} - * - * @throws SQLException if connection manager cannot be obtained. - */ - protected abstract PooledConnectionManager getConnectionManager() - throws SQLException; - - /** - * Get name of the pool. This name will be displayed in log when pool - * is started. - * - * @return name of the connection queue. - */ - protected abstract String getPoolName(); - - /** - * Get number of free connections in this pool. This method returns the - * number of free open connections to the specified database. It might - * return 0, but this does not mean that next request will block. This - * will happen only if - * <code>getMaxSize() != 0 && getMaxSize() == getWorkingSize()</code>, - * meaning that we have allocated maximum number of connections and all - * of them are in use. - * - * @return number of free connections left. - */ - public abstract int getFreeSize() throws SQLException; - - /** - * Get total size of physical connections opened to the database. - * - * @return total number of opened connections to the database. - */ - public abstract int getTotalSize() throws SQLException; - - /** - * Get number of connections that are in use. - * - * @return number of working connections. - */ - public abstract int getWorkingSize() throws SQLException ; -} \ No newline at end of file Deleted: client-java/trunk/src/pool/org/firebirdsql/pool/AbstractDriverConnectionPoolDataSource.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractDriverConnectionPoolDataSource.java 2012-09-02 10:37:13 UTC (rev 57095) +++ client-java/trunk/src/pool/org/firebirdsql/pool/AbstractDriverConnectionPoolDataSource.java 2012-09-02 11:03:04 UTC (rev 57096) @@ -1,435 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.pool; - -import java.io.PrintWriter; -import java.sql.*; -import java.util.Properties; - -import javax.naming.*; -import javax.sql.*; - -import org.firebirdsql.jdbc.FBConnectionHelper; -import org.firebirdsql.jdbc.FBSQLException; -import org.firebirdsql.logging.Logger; -import org.firebirdsql.logging.LoggerFactory; - -/** - * Generic implementation of {@link javax.sql.ConnectionPoolDataSource} that - * uses {@link java.sql.DriverManager} to open physical connections to the - * database. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -abstract public class AbstractDriverConnectionPoolDataSource extends BasicAbstractConnectionPool - implements ConnectionPoolDataSource, PooledConnectionEventListener -{ - - private static final Logger logger = LoggerFactory.getLogger( - AbstractDriverConnectionPoolDataSource.class, false); - - public static final UserPasswordPair EMPTY_USER_PASSWORD = new UserPasswordPair(); - - private PrintWriter logWriter; - - private String jdbcUrl; - private String driverClassName; - private int transactionIsolation = FBPoolingDefaults.DEFAULT_ISOLATION; - - - private Properties props = new Properties(); - - private DriverPooledConnectionManager connectionManager = - new DriverPooledConnectionManager(); - - public String getJdbcUrl() { - return jdbcUrl; - } - - public void setJdbcUrl(String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - public String getDriverClassName() { - return driverClassName; - } - - public void setDriverClassName(String driverClassName) { - this.driverClassName = driverClassName; - } - - public String getProperty(String name) { - return props.getProperty(name); - } - - public void setProperty(String name, String value) { - props.setProperty(name, value); - } - - public Properties getProperties() { - return props; - } - - /** - * Set JDBC properties that will be passed when opening a connection. - * - * @param properties instance of {@link Properties} containing properties - * of a connection to open. - * - * @see #getProperties() - */ - public void setProperties(Properties properties) { - if (properties == null) - throw new NullPointerException("Specified properties are null."); - - props.putAll(properties); - } - - protected Logger getLogger() { - return logger; - } - - public PrintWriter getLogWriter() { - return logWriter; - } - - public void setLogWriter(PrintWriter out) { - logWriter = out; - } - - /** - * Get login timeout. - * - * @return value set in {@link #setLoginTimeout(int)} method or 0. - */ - public int getLoginTimeout() { - return getBlockingTimeout() / 1000; - } - - /** - * Set login timeout for new connection. Currently ignored. - * - * @param seconds how long pool should wait until new connection is - * granted. - */ - public void setLoginTimeout(int seconds) { - setBlockingTimeout(seconds * 1000); - } - - public int getTransactionIsolationLevel() { - return transactionIsolation; - } - - public void setTransactionIsolationLevel(int transactionIsolation) { - this.transactionIsolation = transactionIsolation; - } - - public String getIsolation() { - switch (getTransactionIsolationLevel()) { - - case Connection.TRANSACTION_READ_COMMITTED: - return FBConnectionHelper.TRANSACTION_READ_COMMITTED; - - case Connection.TRANSACTION_REPEATABLE_READ: - return FBConnectionHelper.TRANSACTION_REPEATABLE_READ; - - case Connection.TRANSACTION_SERIALIZABLE: - return FBConnectionHelper.TRANSACTION_SERIALIZABLE; - - default: - throw new IllegalStateException( - "Unknown transaction isolation level"); - } - } - - public void setIsolation(String isolation) throws SQLException { - if (FBConnectionHelper.TRANSACTION_READ_COMMITTED - .equalsIgnoreCase(isolation)) - setTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED); - else if (FBConnectionHelper.TRANSACTION_REPEATABLE_READ - .equalsIgnoreCase(isolation)) - setTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ); - else if (FBConnectionHelper.TRANSACTION_SERIALIZABLE - .equalsIgnoreCase(isolation)) - setTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE); - else - throw new FBSQLException("Unknown transaction isolation.", - FBSQLException.SQL_STATE_INVALID_ARG_VALUE); - } - - - /** - * Get connection manager that will allocate physical connections to the - * database. - * - * @return instance of {@link PooledConnectionManager} class. - */ - protected PooledConnectionManager getConnectionManager() throws SQLException { - return connectionManager; - } - - /** - * Get name of this connection pool. - * - * @return name of the pool, equal to the JDBC URL value. - */ - protected String getPoolName() { - return getJdbcUrl(); - } - - /** - * Get pooled connection from the pooled queue. - */ - protected synchronized PooledObject getPooledConnection( - PooledConnectionQueue queue) throws SQLException - { - PingablePooledConnection connection = - (PingablePooledConnection)super.getPooledConnection(queue); - - connection.addConnectionEventListener(this); - - return connection; - } - - /** - * Get pooled connection. This method will block until there will be - * free connection to return. - * - * @return instance of {@link PooledConnection}. - * - * @throws SQLException if pooled connection cannot be obtained. - */ - public synchronized PooledConnection getPooledConnection() - throws SQLException - { - return (PooledConnection)getPooledConnection( - getQueue(EMPTY_USER_PASSWORD)); - } - - /** - * Get pooled connection for the specified user name and password. - * - * @param user user name. - * @param password password corresponding to specified user name. - * - * @return instance of {@link PooledConnection} for the specified - * credentials. - * - * @throws SQLException always, this method is not yet implemented. - */ - public PooledConnection getPooledConnection(String user, String password) - throws SQLException - { - return (PooledConnection)getPooledConnection( - getQueue(new UserPasswordPair(user, password))); - } - - /** - * Notify about connection being closed. - * - * @param connectionEvent instance of {@link ConnectionEvent}. - */ - public void connectionClosed(ConnectionEvent connectionEvent) { - PooledObjectEvent event = - new PooledObjectEvent(connectionEvent.getSource()); - - pooledObjectReleased(event); - } - - /** - * Notify about physical connection being closed. - * - * @param connectionEvent instance of {@link ConnectionEvent}. - */ - public void physicalConnectionClosed(ConnectionEvent connectionEvent) { - PooledObjectEvent event = - new PooledObjectEvent(connectionEvent.getSource(), true); - - pooledObjectReleased(event); - } - - /** - * Notify about the deallocation of the physical connection. - * - * @param connectionEvent instance of {@link ConnectionEvent}. - */ - public void physicalConnectionDeallocated(ConnectionEvent connectionEvent) { - PooledObjectEvent event = - new PooledObjectEvent(connectionEvent.getSource(), true); - - physicalConnectionDeallocated(event); - } - - /** - * Notify about serious error when using the connection. Currently - * these events are ignored. - * - * @param event instance of {@link ConnectionEvent} containing - * information about an error. - */ - public void connectionErrorOccurred(ConnectionEvent event) { - if (getLogger() != null) - getLogger().error("Error occured in connection.", - event.getSQLException()); - } - - public int getFreeSize() throws SQLException { - return getQueue(EMPTY_USER_PASSWORD).size(); - } - - public int getTotalSize() throws SQLException { - return getQueue(EMPTY_USER_PASSWORD).totalSize(); - } - - public int getWorkingSize() throws SQLException { - return getQueue(EMPTY_USER_PASSWORD).workingSize(); - } - - /* - * JNDI-related stuff - */ - protected static final String PROPERTIES = "properties"; - protected static final String DRIVER_CLASS_NAME = "driverClassName"; - protected static final String JDBC_URL = "jdbcUrl"; - - /** - * Create instance of this data source. - */ - protected BasicAbstractConnectionPool createObjectInstance() { - return FBPooledDataSourceFactory.createDriverConnectionPoolDataSource(); - } - - /** - * Get object instance for the specified name in the specified context. - */ - /** - * Get default JNDI reference for this instance. - */ - public Reference getDefaultReference() { - Reference ref = super.getDefaultReference(); - - if (getDriverClassName() != null) - ref.add(new StringRefAddr(DRIVER_CLASS_NAME, getDriverClassName())); - - if (getJdbcUrl() != null) - ref.add(new StringRefAddr(JDBC_URL, getJdbcUrl())); - - byte[] data = serialize(getProperties()); - ref.add(new BinaryRefAddr(PROPERTIES, data)); - - return ref; - } - - protected Object processObjectInstance(AbstractDriverConnectionPoolDataSource ds, Object obj) throws Exception - { - if (ds == null) - return null; - - Reference ref = (Reference) obj; - - String addr; - - addr = getRefAddr(ref, DRIVER_CLASS_NAME); - if (addr != null) - ds.setDriverClassName(addr); - - addr = getRefAddr(ref, JDBC_URL); - if (addr != null) - ds.setJdbcUrl(addr); - - RefAddr binAddr = ref.get(PROPERTIES); - if (binAddr != null) { - byte[] data = (byte[]) binAddr.getContent(); - Properties props = (Properties) deserialize(data); - if (props != null) - ds.setProperties(props); - } - - return ds; - } - - /** - * Pooled connection manager that uses {@link java.sql.DriverManager} - * to allocate physical connections. - */ - private class DriverPooledConnectionManager implements PooledConnectionManager { - - private static final String USER_NAME_PROPERTY = "user"; - private static final String PASSWORD_PROPERTY = "password"; - - private boolean driverInitialized; - - /** - * Allocate physical connection to the database. - */ - public PooledObject allocateConnection(Object key) throws SQLException { - if (!driverInitialized) { - try { - Class.forName(getDriverClassName()); - driverInitialized = true; - - } catch(ClassNotFoundException ex) { - throw new FBSQLException( - "Class " + getDriverClassName() + " not found."); - } - } - - if (!(key instanceof UserPasswordPair)) - throw new FBSQLException("Incorrect key."); - - UserPasswordPair pair = (UserPasswordPair)key; - - String userName = pair.getUserName(); - String password = pair.getPassword(); - - // set all properties - Properties props = new Properties(); - props.putAll( - AbstractDriverConnectionPoolDataSource.this.getProperties()); - - if (userName != null) - props.setProperty(USER_NAME_PROPERTY, userName); - - if (password != null) - props.setProperty(PASSWORD_PROPERTY, password); - - // open JDBC connection to the database - Connection connection = DriverManager.getConnection( - getJdbcUrl(), props); - - // wrap connection into PooledObject implementation - PingablePooledConnection pooledConnection = null; - - if (isPingable()) - pooledConnection = new PingablePooledConnection( - connection, getPingStatement(), getPingInterval(), - isStatementPooling(), - getMaxStatements(), isKeepStatements()); - else - pooledConnection = new PingablePooledConnection( - connection, isStatementPooling(), - getMaxStatements(), isKeepStatements()); - - pooledConnection.setDefaultTransactionIsolation(getTransactionIsolationLevel()); - - return pooledConnection; - } - } - - } Deleted: client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-09-02 10:37:13 UTC (rev 57095) +++ client-java/trunk/src/pool/org/firebirdsql/pool/AbstractPingablePooledConnection.java 2012-09-02 11:03:04 UTC (rev 57096) @@ -1,753 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ - -package org.firebirdsql.pool; - -import static org.firebirdsql.ds.ReflectionHelper.getAllInterfaces; - -import java.lang.reflect.Proxy; -import java.sql.*; - -import javax.sql.*; - -import org.firebirdsql.jdbc.*; -import org.firebirdsql.logging.Logger; -import org.firebirdsql.logging.LoggerFactory; -import org.firebirdsql.util.SQLExceptionChainBuilder; - -import java.util.*; - -/** - * This class implements {@link javax.sql.PooledConnection} interface. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public abstract class AbstractPingablePooledConnection implements PooledConnection, - PooledObject, XConnectionManager, - XPingableConnection, XStatementManager { - - private static final boolean LOG_PREPARE_STATEMENT = PoolDebugConfiguration.DEBUG_STMT_POOL; - private static final boolean LOG_POOL_CLEANING = PoolDebugConfiguration.DEBUG_STMT_POOL; - - private static final boolean LOG_META_DATA = PoolDebugConfiguration.LOG_DEBUG_INFO; - - private static Logger log = - LoggerFactory.getLogger(PingablePooledConnection.class, false); - - protected Connection jdbcConnection; - private HashSet eventListeners = new HashSet(); - - private boolean invalid; - private boolean inPool; - - private PooledConnectionHandler currentConnection; - - private String pingStatement; - private long lastPingTime = System.currentTimeMillis(); - private int pingInterval = 0; - - private int maxStatements; - private boolean keepStatements; - - private boolean supportsStatementsAccrossCommit; - private boolean supportsStatementsAccrossRollback; - private boolean statementPooling; - - private int transactionIsolation = -1; - - private HashMap statements = new HashMap(); - - protected Logger getLogChannel() { - return log; - } - - protected AbstractPingablePooledConnection(Connection connection, - boolean statementPooling, - /*int transactionIsolation,*/ - int maxStatements, boolean keepStatements) - throws SQLException - { - this.jdbcConnection = connection; - this.statementPooling = statementPooling; - //this.transactionIsolation = transactionIsolation; - this.maxStatements = maxStatements; - this.keepStatements = keepStatements; - - this.supportsStatementsAccrossCommit = - connection.getMetaData().supportsOpenStatementsAcrossCommit(); - - if (LOG_META_DATA && getLogChannel() != null) { - getLogChannel().info( - "Pool supports open statements across commit : " + - supportsStatementsAccrossCommit); - - } - this.supportsStatementsAccrossRollback = - connection.getMetaData().supportsOpenStatementsAcrossRollback(); - - if (LOG_META_DATA && getLogChannel() != null) { - getLogChannel().info( - "Pool supports open statements across rollback : " + - supportsStatementsAccrossRollback); - - } - } - - protected AbstractPingablePooledConnection(Connection connection, - String pingStatement, int pingInterval, boolean statementPooling, - int maxStatements, boolean keepStatements) - throws SQLException - { - this(connection, statementPooling, /*transactionIsolation,*/ maxStatements, keepStatements); - this.pingStatement = pingStatement; - this.pingInterval = pingInterval; - } - - public void setDefaultTransactionIsolation(int isolation) { - this.transactionIsolation = isolation; - } - - public long getLastPingTime() { - return lastPingTime; - } - - public boolean isStatementPooling() { - return statementPooling; - } - - public boolean isKeepStatements() { - return keepStatements; - } - - /** - * Ping connection by executing a ping statement. - */ - public synchronized boolean ping() { - if (pingStatement == null) { - return false; - } - - try { - Statement stmt = null; - try { - stmt = jdbcConnection.createStatement(); - ResultSet rs = stmt.executeQuery(pingStatement); - return rs.next(); - } finally { - if (stmt != null) { - stmt.close(); - - } - lastPingTime = System.currentTimeMillis(); - } - } catch (SQLException sqlex) { - return false; - } - } - - /** - * Invalidate this instance. After invalidating, no operation can be - * executed on this instance. - */ - private void invalidate() { - invalid = true; - } - - /** - * Check if instance has correct state. - * - * @throws IllegalStateException if instance has illegal state. - */ - private void checkValidity() { - if (invalid) { - throw new IllegalStateException( - "Cannot execute desired operation " + - "because pooled connection has invalid state."); - } - } - - /** - * Check if this pooled connection is still valid. - * - * @return <code>true</code> if this pooled connection is still valid. - */ - public boolean isValid() { - - if (invalid) { - return false; - } - - if (pingInterval > 0 && - (System.currentTimeMillis() - lastPingTime) > pingInterval && - pingStatement != null) { - return ping(); - } else { - return true; - } - } - - /** - * Check whether this object is currently in pool or had been released - * to the application. - * - * @return <code>true</code> if the object is currently in pool. - */ - public boolean isInPool() { - return inPool; - } - - /** - * Set the "inPool" flag to this object. This method should be called only - * by the pool implementation. - * - * @param inPool <code>true</code> if object is in pool, otherwise - * <code>false</code>. - */ - public void setInPool(boolean inPool) { - this.inPool = inPool; - } - - private void checkInPool() throws SQLException { - if (inPool) - throw new FBSQLException( - "Physical connection is currently in pool, " + - "you cannot allocate logical connections now."); - } - - /** - * Add connection listener to be notified about connection events. - * - * @param listener listener to add. - */ - public synchronized - void addConnectionEventListener(ConnectionEventListener listener) { - eventListeners.add(listener); - } - - /** - * Remove connection listener from this pooled connection. - * - * @param listener listener to remove. - */ - public synchronized - void removeConnectionEventListener(ConnectionEventListener listener) { - eventListeners.remove(listener); - } - - /** - * Close this pooled connection. This operation closes physical - * connection to the database. Should not be called by applications - * directly. - * - * @throws SQLException - */ - public void close() throws SQLException { - internalClose(); - - ConnectionEvent event = new ConnectionEvent(this); - - List tempListeners = new ArrayList(eventListeners); - - Iterator iter = tempListeners.iterator(); - while (iter.hasNext()) { - ConnectionEventListener listener = - (ConnectionEventListener)iter.next(); - - if (!(listener instanceof PooledConnectionEventListener)) - continue; - - PooledConnectionEventListener pooledEventListener = - (PooledConnectionEventListener)listener; - - pooledEventListener.physicalConnectionClosed(event); - } - } - - /** - * Close this connection. - * - * @throws SQLException if something went wrong. - */ - protected void internalClose() throws SQLException { - checkValidity(); - - if (currentConnection != null) - currentConnection.deallocate(); - - jdbcConnection.close(); - - statements.clear(); - - invalidate(); - } - - /** - * Deallocate this object. - */ - public void deallocate() { - try { - internalClose(); - } catch(SQLException ex) { - if (log != null) - log.warn("Could not cleanly deallocate connection.", ex); - - } finally { - // and finally notify about the event - ConnectionEvent event = new ConnectionEvent(this); - - List tempListeners = new ArrayList(eventListeners); - - Iterator iter = tempListeners.iterator(); - while (iter.hasNext()) { - ConnectionEventListener listener = - (ConnectionEventListener)iter.next(); - - if (!(listener instanceof PooledConnectionEventListener)) - continue; - - PooledConnectionEventListener pooledEventListener = - (PooledConnectionEventListener)listener; - - pooledEventListener.physicalConnectionDeallocated(event); - } - } - } - - /** - * Get JDBC connection corresponding to this pooled connection instance. - * - * @return instance of {@link Connection} - * - * @throws SQLException if some error happened. - */ - public - Connection getConnection() throws SQLException { - - checkValidity(); - - checkInPool(); - - if (currentConnection != null) { - - throw new IllegalStateException( - "Cannot provide new connection while old one is still in use."); - - //currentConnection.close(); - } - - currentConnection = new PooledConnectionHandler(jdbcConnection, this); - - Connection result = currentConnection.getProxy(); - - configureConnectionDefaults(result); - - return result; - } - - /** - * Configure default values for this connection. - * - * @param connection instance of {@link Connection} to configure. - * - * @throws SQLException if something went wrong. - */ - protected void configureConnectionDefaults(Connection connection) throws SQLException { - connection.setAutoCommit(true); - connection.setReadOnly(false); - - if (transactionIsolation != -1) - connection.setTransactionIsolation(transactionIsolation); - } - - /** - * Handle {@link Connection#prepareStatement(String)} method call. This - * method check internal cache first and returns prepared statement if found. - * Otherwise, it prepares statement and caches it. - * - * @param statement statement to prepare. - * @param resultSetType result set type. - * @param resultSetConcurrency result set concurrency. - * @param resultSetHoldability result set holdability. - * - * @return instance of {@link PreparedStatement} corresponding to the - * <code>statement</code>. - * - * @throws SQLException if there was problem preparing statement. - */ - public PreparedStatement getPreparedStatement(String statement, - int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - - if (!isStatementPooling()) - return jdbcConnection.prepareStatement( - statement, resultSetType, resultSetConcurrency, resultSetHoldability); - - synchronized (statements) { - XPreparedStatementModel key = new XPreparedStatementModel(statement, - resultSetType, resultSetConcurrency, resultSetHoldability); - - XPreparedStatementCache stmtCache = - (XPreparedStatementCache)statements.get(key); - - if (stmtCache == null) { - stmtCache = new XPreparedStatementCache(this, key, maxStatements); - - statements.put(key, stmtCache); - } - - PreparedStatement stmt = stmtCache.take(currentConnection.getProxy()); - - return stmt; - } - } - - public PreparedStatement getPreparedStatement(String sql, - int resultSetType, int resultSetConcurrency) throws SQLException { - return getPreparedStatement(sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT); - } - - public PreparedStatement getPreparedStatement(String statement, int[] keyIndexes, - String[] keyColumns) throws SQLException { - - if (!isStatementPooling()) { - if (keyIndexes == null && keyColumns == null) - return jdbcConnection.prepareStatement( - statement, Statement.RETURN_GENERATED_KEYS); - else - if (keyIndexes != null) - return jdbcConnection.prepareStatement(statement, keyIndexes); - else - if (keyColumns != null) - return jdbcConnection.prepareStatement(statement, keyColumns); - else - throw new IllegalStateException(); - } - - synchronized (statements) { - XPreparedStatementModel key; - - if (keyIndexes == null && keyColumns == null) - key = new XPreparedStatementModel(statement, Statement.RETURN_GENERATED_KEYS); - else - if (keyIndexes != null) - key = new XPreparedStatementModel(statement, keyIndexes); - else - if (keyColumns != null) - key = new XPreparedStatementModel(statement, keyColumns); - else - throw new IllegalStateException(); - - XPreparedStatementCache stmtCache = - (XPreparedStatementCache)statements.get(key); - - if (stmtCache == null) { - stmtCache = new XPreparedStatementCache(this, key, maxStatements); - - statements.put(key, stmtCache); - } - - PreparedStatement stmt = stmtCache.take(currentConnection.getProxy()); - - return stmt; - } } - - /** - * Prepare the specified statement and wrap it with cache notification - * wrapper. - * - * @param key Statement model of the statement to prepare - * - * @param cached <code>true</code> if prepared statement will be cached - * - * @return prepared and wrapped statement. - * - * @throws SQLException if underlying connection threw this exception. - */ - public XCachablePreparedStatement prepareStatement( - XPreparedStatementModel key, boolean cached) throws SQLException { - if (LOG_PREPARE_STATEMENT && getLogChannel() != null) { - getLogChannel().info("Prepared statement for SQL '" + key.getSql() + - "'"); - - } - - if (!key.isGeneratedKeys()) - return prepareStatementNoGeneratedKeys(key, cached); - else - return prepareStatementGeneratedKeys(key, cached); - } - - /** - * Prepare specified SQL statement. This method should call - * {@link java.sql.Connection#prepareStatement(String)} method on physical JDBC - * connection. - * - * @param sql SQL statement to prepare. - * - * @param resultSetType type of result set - * - * @param resultSetConcurrency result set concurrency - * - * @param cached <code>true</code> if prepared statement will be cached. - * - * @return instance of {@link java.sql.PreparedStatement} corresponding to the - * specified SQL statement. - * - * @throws SQLException if something went wrong. - * - * @see java.sql.Connection#prepareStatement(java.lang.String, int, int) - * - * @deprecated use {@link #prepareStatement(XPreparedStatementModel, boolean)} - * instead. - */ - public XCachablePreparedStatement prepareStatement(String sql, - int resultSetType, int resultSetConcurrency, - boolean cached) throws SQLException { - - return prepareStatement( - new XPreparedStatementModel(sql, resultSetType, resultSetConcurrency, - ResultSet.CLOSE_CURSORS_AT_COMMIT), cached); - } - - private XCachablePreparedStatement prepareStatementNoGeneratedKeys( - XPreparedStatementModel key, boolean cached) throws SQLException { - PreparedStatement stmt = jdbcConnection.prepareStatement(key.getSql(), - key.getResultSetType(), key.getResultSetConcurrency(), key - .getResultSetHoldability()); - - return wrapPreparedStatement(key, cached, stmt); - } - - private XCachablePreparedStatement prepareStatementGeneratedKeys( - XPreparedStatementModel key, boolean cached) - throws SQLException { - - PreparedStatement stmt; - if (key.getKeyIndexes() == null && key.getKeyColumns() == null) - stmt = jdbcConnection.prepareStatement( - key.getSql(), Statement.RETURN_GENERATED_KEYS); - else - if (key.getKeyIndexes() != null) - stmt = jdbcConnection.prepareStatement(key.getSql(), key.getKeyIndexes()); - else - if (key.getKeyColumns() != null) - stmt = jdbcConnection.prepareStatement(key.getSql(), key.getKeyColumns()); - else - throw new IllegalArgumentException(); - - return wrapPreparedStatement(key, cached, stmt); - } - - private XCachablePreparedStatement wrapPreparedStatement( - XPreparedStatementModel key, boolean cached, PreparedStatement stmt) { - - Class[] implementedInterfaces = - getAllInterfaces(stmt.getClass()); - - PooledPreparedStatementHandler handler = - new PooledPreparedStatementHandler(key, stmt, this, cached); - - // copy all implemented interfaces from the original prepared statement - // and add XCachablePreparedStatement interface - Class[] interfacesToImplement = - new Class[implementedInterfaces.length + 1]; - - System.arraycopy( - implementedInterfaces, 0, - interfacesToImplement, 0, - implementedInterfaces.length); - - interfacesToImplement[implementedInterfaces.length] = - XCachablePreparedStatement.class; - - // create a dynamic proxy for the specified handler - return (XCachablePreparedStatement)Proxy.newProxyInstance( - getClass().getClassLoader(), - interfacesToImplement, - handler); - } - - - public void statementClosed(String sql, Object proxy) - throws SQLException { - throw new UnsupportedOperationException(); - } - - - /** - * Clean the cache. - * - * @throws SQLException if at least one of the cached statement could not - * be closed. - */ - private void cleanCache() throws SQLException { - - if (LOG_POOL_CLEANING && getLogChannel() != null) { - getLogChannel().info("Prepared statement cache cleaned."); - - } - - SQLExceptionChainBuilder chain = new SQLExceptionChainBuilder(); - - synchronized (statements) { - Iterator iter = statements.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry item = (Map.Entry)iter.next(); - - XPreparedStatementCache stmtCache = - (XPreparedStatementCache)item.getValue(); - - iter.remove(); - - try { - stmtCache.invalidate(); - } catch(SQLException ex) { - chain.append(ex); - } - } - } - - if (chain.hasException()) - throw chain.getException(); - } - - /** - * Handle {@link java.sql.PreparedStatement#close()} method. This implementation - * dereferences proxy in cache. - * - * @param key Statement model of the statement to prepare - * @param proxy proxy wrapping the connection. - * - * @throws SQLException if prepared statement cannot be added to the pool. - */ - public void statementClosed(XPreparedStatementModel key, Object proxy) - throws SQLException - { - synchronized (statements) { - XPreparedStatementCache stmtCache = - (XPreparedStatementCache)statements.get(key); - - if (stmtCache == null) { - if (getLogChannel() != null) { - getLogChannel().error( - "Cannot find statement cache for SQL \"" + key.getSql() + - "\". Trying to close statement to release resources." - ); - - } - if (proxy instanceof XCachablePreparedStatement) { - ((XCachablePreparedStatement)proxy).forceClose(); - } - } else { - stmtCache.put(proxy); - } - } - } - - public void connectionClosed(PooledConnectionHandler connection) throws SQLException { - - if (connection != currentConnection) { - throw new IllegalArgumentException( - "Notified about a connection that is not under my control."); - } - - if (!keepStatements) - cleanCache(); - - try { - if (!jdbcConnection.getAutoCommit() && !connection.isClosed()) - jdbcConnection.rollback(); - } catch(SQLException ex) { - if (log != null && log.isWarnEnabled()) - log.warn("Exception while trying to rollback transaction " + - "before returning connection to pool.", ex); - - close(); - - throw ex; - } - - currentConnection = null; - - ConnectionEvent event = new ConnectionEvent(this); - - List tempListeners = new ArrayList(eventListeners); - - Iterator iter = tempListeners.iterator(); - while (iter.hasNext()) { - ((ConnectionEventListener)iter.next()).connectionClosed(event); - } - } - - public void connectionErrorOccured(PooledConnectionHandler connection, SQLException ex) { - ConnectionEvent event = new ConnectionEvent(this, ex); - - List tempListeners = new ArrayList(eventListeners); - - Iterator iter = tempListeners.iterator(); - while (iter.hasNext()) { - ((ConnectionEventListener)iter.next()).connectionErrorOccurred( - event); - } - } - - public boolean isValid(PooledConnectionHandler connection) { - return connection == currentConnection; - } - - /** - * Notify this class that transaction was committed. - * - * @param connection connection that was commited. - * - * @see XConnectionManager#connectionCommitted(PooledConnectionHandler) - */ - public void connectionCommitted(PooledConnectionHandler connection) throws SQLException { - - if (connection != currentConnection) { - throw new IllegalArgumentException( - "Specified connection does not correspond " + - "current physical connection"); - } - - if (!supportsStatementsAccrossCommit) { - cleanCache(); - } - } - - /** - * Notify this class that transaction was rolled back. - * - * @param connection connection that was commited. - * - * @see XConnectionManager#connectionRolledBack(PooledConnectionHandler) - */ - public void connectionRolledBack(PooledConnectionHandler connection) throws - SQLException { - if (connection != currentConnection) { - throw new IllegalArgumentException( - "Specified connection does not correspond " + - "current physical connection"); - } - - if (!supportsStatementsAccrossRollback) { - cleanCache(); - } - } - -} \ No newline at end of file Deleted: client-java/trunk/src/pool/org/firebirdsql/pool/BasicAbstractConnectionPool.java =================================================================== --- client-java/trunk/src/pool/org/firebirdsql/pool/BasicAbstractConnectionPool.java 2012-09-02 10:37:13 UTC (rev 57095) +++ client-java/trunk/src/pool/org/firebirdsql/pool/BasicAbstractConnectionPool.java 2012-09-02 11:03:04 UTC (rev 57096) @@ -1,449 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.pool; - -import java.io.*; -import java.sql.SQLException; - -import javax.naming.*; -import javax.sql.ConnectionPoolDataSource; -import javax.sql.PooledConnection; - -/** - * Base class for connection pool implementations. Main feature of this class is - * that it implements {@link org.firebirdsql.pool.ConnectionPoolConfiguration} - * interface and releives developers from creating getters and setters for - * pool configuration parameters. Additionally this class provides basic - * functionality for JNDI-enabled connection pools. - * - * No other functionality is available. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public abstract class BasicAbstractConnectionPool - extends AbstractConnectionPool - implements ConnectionPoolConfiguration, ConnectionPoolDataSource, - Serializable, Referenceable -{ - - /* - * Following fields contain information about the pool characteristics. - */ - private int minPoolSize = FBPoolingDefaults.DEFAULT_MIN_SIZE; - private int maxPoolSize = FBPoolingDefaults.DEFAULT_MAX_SIZE; - - private int blockingTimeout = FBPoolingDefaults.DEFAULT_BLOCKING_TIMEOUT; - private int retryInterval = FBPoolingDefaults.DEFAULT_RETRY_INTERVAL; - private int maxIdleTime = FBPoolingDefaults.DEFAULT_IDLE_TIMEOUT; - - private int pingInterval = FBPoolingDefaults.DEFAULT_PING_INTERVAL; - private String pingStatement; - - private boolean pooling = true; - private boolean statementPooling = true; - private boolean keepStatements = true; - private int maxStatements = FBPoolingDefaults.DEFAULT_MAX_STATEMENTS; - - private Reference reference; - - /** - * Create instance of this class. Default constructor introduced to make - * it available to subclasses. - */ - protected BasicAbstractConnectionPool() { - super(); - } - - public abstract int getLoginTimeout() throws SQLException; - public abstract void setLoginTimeout(int seconds) throws SQLException; - - public abstract PrintWriter getLogWriter() throws SQLException; - public abstract void setLogWriter(PrintWriter printWriter) throws SQLException; - - public abstract PooledConnection getPooledConnection() throws SQLException; - public abstract PooledConnection getPooledConnection( - String user, String password) throws SQLException; - - public ConnectionPoolConfiguration getConfiguration() { - return this; - } - - public int getBlockingTimeout() { - return blockingTimeout; - } - - public void setBlockingTimeout(int blockingTimeout) { - this.blockingTimeout = b... [truncated message content] |
From: <mro...@us...> - 2012-09-02 14:13:17
|
Revision: 57100 http://firebird.svn.sourceforge.net/firebird/?rev=57100&view=rev Author: mrotteveel Date: 2012-09-02 14:13:10 +0000 (Sun, 02 Sep 2012) Log Message: ----------- Remove deprecated FBXADataSource and related classes (related to JDBC-86 and JDBC-144) Removed Paths: ------------- client-java/trunk/src/jca_jdk1_4/org/firebirdsql/jca/FBXAConnection.java client-java/trunk/src/jca_jdk1_6/org/firebirdsql/jca/FBXAConnection.java client-java/trunk/src/main/org/firebirdsql/jca/AbstractXAConnection.java client-java/trunk/src/main/org/firebirdsql/jca/FBXAConnectionHandle.java client-java/trunk/src/main/org/firebirdsql/jca/FBXADataSource.java Deleted: client-java/trunk/src/jca_jdk1_4/org/firebirdsql/jca/FBXAConnection.java =================================================================== --- client-java/trunk/src/jca_jdk1_4/org/firebirdsql/jca/FBXAConnection.java 2012-09-02 12:24:55 UTC (rev 57099) +++ client-java/trunk/src/jca_jdk1_4/org/firebirdsql/jca/FBXAConnection.java 2012-09-02 14:13:10 UTC (rev 57100) @@ -1,29 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jca; - -import org.firebirdsql.jdbc.AbstractConnection; - -public class FBXAConnection extends AbstractXAConnection { - - protected FBXAConnection(AbstractConnection connection) { - super(connection); - } - -} Deleted: client-java/trunk/src/jca_jdk1_6/org/firebirdsql/jca/FBXAConnection.java =================================================================== --- client-java/trunk/src/jca_jdk1_6/org/firebirdsql/jca/FBXAConnection.java 2012-09-02 12:24:55 UTC (rev 57099) +++ client-java/trunk/src/jca_jdk1_6/org/firebirdsql/jca/FBXAConnection.java 2012-09-02 14:13:10 UTC (rev 57100) @@ -1,39 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jca; - -import javax.sql.StatementEventListener; - -import org.firebirdsql.jdbc.AbstractConnection; - -public class FBXAConnection extends AbstractXAConnection { - - protected FBXAConnection(AbstractConnection connection) { - super(connection); - } - - public void addStatementEventListener(StatementEventListener listener) { - - } - - public void removeStatementEventListener(StatementEventListener listener) { - - } - -} Deleted: client-java/trunk/src/main/org/firebirdsql/jca/AbstractXAConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/AbstractXAConnection.java 2012-09-02 12:24:55 UTC (rev 57099) +++ client-java/trunk/src/main/org/firebirdsql/jca/AbstractXAConnection.java 2012-09-02 14:13:10 UTC (rev 57100) @@ -1,64 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jca; - -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.ConnectionEventListener; -import javax.sql.XAConnection; -import javax.transaction.xa.XAResource; - -import org.firebirdsql.jdbc.AbstractConnection; - -/** - * Simple non-pooled XAConnection implementation. - * - * @author <a href="mailto:lo...@bi...">Ludovic Orban</a> - * @deprecated - */ -public abstract class AbstractXAConnection implements XAConnection { - - private AbstractConnection connection; - - protected AbstractXAConnection(AbstractConnection connection) { - this.connection = connection; - } - - public XAResource getXAResource() throws SQLException { - return connection.getManagedConnection(); - } - - public void close() throws SQLException { - connection.close(); - } - - public Connection getConnection() throws SQLException { - return new FBXAConnectionHandle(connection, this).getProxy(); - } - - public void addConnectionEventListener(ConnectionEventListener listener) { - //TODO: do something ! - } - - public void removeConnectionEventListener(ConnectionEventListener listener) { - //TODO: do something ! - } - -} Deleted: client-java/trunk/src/main/org/firebirdsql/jca/FBXAConnectionHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBXAConnectionHandle.java 2012-09-02 12:24:55 UTC (rev 57099) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBXAConnectionHandle.java 2012-09-02 14:13:10 UTC (rev 57100) @@ -1,159 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jca; - -import static org.firebirdsql.ds.ReflectionHelper.findMethod; -import static org.firebirdsql.ds.ReflectionHelper.getAllInterfaces; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.XAConnection; - -import org.firebirdsql.jdbc.AbstractConnection; -import org.firebirdsql.jdbc.FBSQLException; -import org.firebirdsql.jdbc.FirebirdConnection; - -/** - * Simple Connection wrapper returned by FBXAConnection. - * - * @author <a href="mailto:lo...@bi...">Ludovic Orban</a> - * @deprecated - */ -public class FBXAConnectionHandle implements InvocationHandler { - - private final static Method CONNECTION_CLOSE = findMethod( - Connection.class, "close", new Class[0]); - - private final static Method CONNECTION_IS_CLOSED = findMethod( - Connection.class, "isClosed", new Class[0]); - - - private AbstractConnection connection; - private XAConnection owner; - - private Connection proxy; - - private SQLException closeStackTrace; - - /** - * Construct instance of this class. This method constructs new proxy - * that implements {@link Connection} interface and uses newly constructed - * object as invocation handler. - * - * @param connection connection to wrap. - * - * @param owner instance of {@link XAConnection} that owns this - * connection instance. - * - * @throws SQLException if something went wrong during initialization. - */ - public - FBXAConnectionHandle(AbstractConnection connection, XAConnection owner) - throws SQLException - { - - this.connection = connection; - this.owner = owner; - - Class[] implementedInterfaces = - getAllInterfaces(connection.getClass()); - - proxy = (Connection)Proxy.newProxyInstance( - FirebirdConnection.class.getClassLoader(), - implementedInterfaces, - this); - } - - /** - * Get proxy implementing {@link Connection} interface and using this - * instance as invocation handler. - * - * @return instance of {@link Connection}. - */ - public Connection getProxy() { - return proxy; - } - - /** - * Get manager of this connection wrapper. - * - * @return instance of {@link XAConnection}. - */ - public XAConnection getXAConnection() { - return owner; - } - - // Connection overridings - - public void handleConnectionClose() throws SQLException { - connection = null; - closeStackTrace = new SQLException("Close trace."); - } - - /** - * Invoke method on a specified proxy. Here we check if <code>method</code> - * is a method {@link Connection#prepareStatement(String)}. If yes, we check - * if there is already a prepared statement for the wrapped connection or - * wrap a newly created one. - * - * @param proxy proxy on which method is invoked. - * @param method instance of {@link Method} describing method being invoked. - * @param args array with arguments. - * - * @return result of method invokation. - * - * @throws Throwable if invoked method threw an exception. - */ - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable - { - try { - - // if object is closed, throw an exception - if (connection == null) { - - // check whether Connection.isClose() method is called first - if (CONNECTION_IS_CLOSED.equals(method)) - return Boolean.TRUE; - - FBSQLException ex = new FBSQLException( - "Connection " + this + " was closed. " + - "See the attached exception to find the place " + - "where it was closed"); - ex.setNextException(closeStackTrace); - throw ex; - } - - if (method.equals(CONNECTION_CLOSE)) { - handleConnectionClose(); - return Void.TYPE; - } else - return method.invoke(connection, args); - } catch(InvocationTargetException ex) { - throw ex.getTargetException(); - } catch(SQLException ex) { - throw ex; - } - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/jca/FBXADataSource.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBXADataSource.java 2012-09-02 12:24:55 UTC (rev 57099) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBXADataSource.java 2012-09-02 14:13:10 UTC (rev 57100) @@ -1,160 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jca; - -import java.sql.SQLException; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; - -import javax.resource.ResourceException; -import javax.sql.XAConnection; -import javax.sql.XADataSource; - -import org.firebirdsql.ds.RootCommonDataSource; -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSFactory; -import org.firebirdsql.gds.impl.GDSType; -import org.firebirdsql.jdbc.AbstractConnection; -import org.firebirdsql.jdbc.FBConnectionHelper; -import org.firebirdsql.jdbc.FBDriverPropertyManager; -import org.firebirdsql.jdbc.FBSQLException; - -/** - * A simple non-pooling XADataSource implementation. - * - * @author <a href="mailto:lo...@bi...">Ludovic Orban</a> - * @version 1.0 - * @deprecated Use {@link org.firebirdsql.ds.FBXADataSource} - */ -public class FBXADataSource extends RootCommonDataSource implements XADataSource { - - private String user; - private String password; - private String database; - - public FBXADataSource() { - } - - public String getPassword() { - return password; - } - public void setPassword(String password) { - this.password = password; - } - - public String getDatabase() { - return database; - } - public void setDatabase(String database) { - this.database = database; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - private String getUrl() { - return "jdbc:firebirdsql:" + database; - } - - private static AbstractConnection createConnection(String url, String user, String password) throws ResourceException, SQLException, GDSException { - FBManagedConnectionFactory mcf = createMcf(url, user, password); - - FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo(); - subjectCri.setUserName(user); - subjectCri.setPassword(password); - - FBManagedConnection mc = (FBManagedConnection)((FBManagedConnectionFactory)mcf).createManagedConnection(null, subjectCri); - mc.setManagedEnvironment(false); - mc.setConnectionSharing(false); - return (AbstractConnection) mc.getConnection(null, subjectCri); - } - - private static FBManagedConnectionFactory createMcf(String url, String user, String password) throws SQLException, ResourceException, GDSException, FBResourceException { - GDSType type = GDSFactory.getTypeForProtocol(url); - - Properties originalInfo = new Properties(); - originalInfo.setProperty("user", user); - originalInfo.setProperty("password", password); - - Map normalizedInfo = FBDriverPropertyManager.normalize(url, originalInfo); - int qMarkIndex = url.indexOf('?'); - if (qMarkIndex != -1) - url = url.substring(0, qMarkIndex); - - FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type); - - FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo(); - subjectCri.setUserName(user); - subjectCri.setPassword(password); - - String databaseURL = GDSFactory.getDatabasePath(type, url); - - mcf.setDatabase(databaseURL); - for (Iterator iter = normalizedInfo.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - - mcf.setNonStandardProperty((String)entry.getKey(), (String)entry.getValue()); - } - - FBConnectionHelper.processTpbMapping(mcf.getGDS(), mcf, originalInfo); - - mcf = mcf.canonicalize(); - return mcf; - } - - public XAConnection getXAConnection() throws SQLException { - return getXAConnection(user, password); - } - - public XAConnection getXAConnection(String user, String password) throws SQLException { - if (database == null) - throw new SQLException("database cannot be null"); - if (user == null) - throw new SQLException("user cannot be null"); - if (password == null) - throw new SQLException("password cannot be null"); - - try { - AbstractConnection c = createConnection(getUrl(), user, password); - return new FBXAConnection(c); - } catch (ResourceException ex) { - throw new FBSQLException(ex); - } catch (GDSException ex) { - throw new FBSQLException(ex); - } - } - - public int getLoginTimeout() throws SQLException { - return 0; - } - public void setLoginTimeout(int timeout) throws SQLException { - } - -} - - - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-10-10 17:48:03
|
Revision: 57231 http://firebird.svn.sourceforge.net/firebird/?rev=57231&view=rev Author: mrotteveel Date: 2012-10-10 17:47:51 +0000 (Wed, 10 Oct 2012) Log Message: ----------- JDBC-254 : Perform system property retrieval always as a privileged action + some refactoring of GDSFactoryPlugin implementations Modified Paths: -------------- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/GDSSynchronizationPolicy.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java client-java/trunk/src/main/org/firebirdsql/logging/LoggerFactory.java client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/impl/BaseGDSFactoryPlugin.java Modified: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -66,11 +66,7 @@ public int getJDBCMinorVersion() { try { - String javaImplementation = AccessController.doPrivileged(new PrivilegedAction<String>() { - public String run() { - return System.getProperty("java.implementation.version"); - } - }); + String javaImplementation = getSystemPropertyPrivileged("java.implementation.version"); if (javaImplementation != null && "1.7".compareTo(javaImplementation) <= 0) { // JDK 1.7 or higher: JDBC 4.1 return 1; @@ -83,4 +79,12 @@ return 0; } } + + private static String getSystemPropertyPrivileged(final String propertyName) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(propertyName); + } + }); + } } Added: client-java/trunk/src/main/org/firebirdsql/gds/impl/BaseGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/BaseGDSFactoryPlugin.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/BaseGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.jdbc.FBConnection; + +/** + * Base class for {@link GDSFactoryPlugin} implementations. + * <p> + * Handles commonalities across existing implementations. + * </p> + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.3 + */ +public abstract class BaseGDSFactoryPlugin implements GDSFactoryPlugin { + + public Class<?> getConnectionClass() { + return FBConnection.class; + } + + public String getDefaultProtocol() { + return getSupportedProtocols()[0]; + } + + public String getDatabasePath(String jdbcUrl) throws GDSException { + String[] protocols = getSupportedProtocols(); + for (String protocol : protocols) { + if (jdbcUrl.startsWith(protocol)) + return jdbcUrl.substring(protocol.length()); + } + + throw new IllegalArgumentException("Incorrect JDBC protocol handling: " + + jdbcUrl); + } + + public int hashCode() { + return getTypeName().hashCode(); + } + + public boolean equals(Object obj) { + if (obj == null) + return false; + if (obj == this) + return true; + + return getClass().equals(obj.getClass()); + } +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/impl/BaseGDSFactoryPlugin.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.gds.impl.jni; import org.firebirdsql.gds.GDS; @@ -2,6 +22,5 @@ import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSFactoryPlugin; -import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; -public class EmbeddedGDSFactoryPlugin implements GDSFactoryPlugin { +public class EmbeddedGDSFactoryPlugin extends BaseGDSFactoryPlugin { @@ -13,8 +32,6 @@ "jdbc:firebirdsql:embedded:" }; - private static GDS gds; - public String getPluginName() { return "GDS implementation for embedded server."; } @@ -27,70 +44,23 @@ return TYPE_ALIASES; } - public Class<?> getConnectionClass() { - return FBConnection.class; - } - public String[] getSupportedProtocols() { return JDBC_PROTOCOLS; } - - public synchronized GDS getGDS() { - if (gds == null) - gds = applySyncPolicy(new EmbeddedGDSImpl()); - - return gds; - } - - /** - * Apply the synchronization policy if the current platform is not Windows. - * @param tempGds instance if {@link GDS} to which policy should be applied. - */ - public static GDS applySyncPolicy(GDS tempGds) { - GDSSynchronizationPolicy.AbstractSynchronizationPolicy syncPolicy = null; - - String osName = System.getProperty("os.name"); - if (osName != null && osName.indexOf("Windows") == -1) - syncPolicy = new GDSSynchronizationPolicy.ClientLibrarySyncPolicy(tempGds); - - if (syncPolicy != null) - return GDSSynchronizationPolicy.applySyncronizationPolicy(tempGds, syncPolicy); - else - return tempGds; - } - public String getDatabasePath(String server, Integer port, String path) throws GDSException { return path; } - - public String getDatabasePath(String jdbcUrl) throws GDSException { - String[] protocols = getSupportedProtocols(); - for (int i = 0; i < protocols.length; i++) { - if (jdbcUrl.startsWith(protocols[i])) - return jdbcUrl.substring(protocols[i].length()); - } - - throw new IllegalArgumentException("Incorrect JDBC protocol handling: " - + jdbcUrl); + + /** + * Initialization-on-demand depending on classloading behavior specified in JLS 12.4 + */ + private static final class GDSHolder { + private static final GDS gds = GDSSynchronizationPolicy.applyClientSyncPolicyNonWindows(new EmbeddedGDSImpl()); } - public String getDefaultProtocol() { - return getSupportedProtocols()[0]; + public GDS getGDS() { + return GDSHolder.gds; } - - public int hashCode() { - return getTypeName().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof EmbeddedGDSFactoryPlugin)) - return false; - - return true; - } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSImpl.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EmbeddedGDSImpl.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -30,7 +30,7 @@ attemptToLoadAClientLibraryFromList(EMBEDDED_LIBRARIES_TO_TRY); - if (logging) log.info("Initilized native library OK."); + if (logging) log.info("Initialized native library OK."); } protected String getServerUrl(String file_name) throws GDSException { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/GDSSynchronizationPolicy.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/GDSSynchronizationPolicy.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/GDSSynchronizationPolicy.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -23,6 +23,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.security.AccessController; +import java.security.PrivilegedAction; import org.firebirdsql.gds.GDS; import org.firebirdsql.util.ReflectionHelper; @@ -35,6 +37,24 @@ public class GDSSynchronizationPolicy { /** + * Apply the synchronization policy if the current platform is not Windows. + * + * @param tempGds instance if {@link GDS} to which policy should be applied. + */ + static GDS applyClientSyncPolicyNonWindows(GDS tempGds) { + GDSSynchronizationPolicy.AbstractSynchronizationPolicy syncPolicy = null; + + String osName = getSystemPropertyPrivileged("os.name"); + if (osName != null && osName.indexOf("Windows") == -1) + syncPolicy = new GDSSynchronizationPolicy.ClientLibrarySyncPolicy(tempGds); + + if (syncPolicy != null) + return GDSSynchronizationPolicy.applySyncronizationPolicy(tempGds, syncPolicy); + else + return tempGds; + } + + /** * Apply synchronization policy on the specfied instance of {@link GDS}. * * @param gds instance of {@link GDS} to wrap. @@ -123,5 +143,13 @@ return SYNC_OBJECT; } } + + private static String getSystemPropertyPrivileged(final String propertyName) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(propertyName); + } + }); + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,5 +1,8 @@ package org.firebirdsql.gds.impl.jni; +import java.security.AccessController; +import java.security.PrivilegedAction; + import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.logging.Logger; @@ -52,14 +55,14 @@ protected static void initJNIBridge() throws UnsatisfiedLinkError { final boolean logging = log != null; - boolean amd64Architecture = "amd64".equals(System.getProperty("os.arch")); - - String jaybirdJniLibrary = amd64Architecture ? JAYBIRD_JNI_LIBRARY_X64 : JAYBIRD_JNI_LIBRARY; + try { + boolean amd64Architecture = "amd64".equals(getSystemPropertyPrivileged("os.arch")); + + String jaybirdJniLibrary = amd64Architecture ? JAYBIRD_JNI_LIBRARY_X64 : JAYBIRD_JNI_LIBRARY; + + if (logging) + log.info("Attempting to load JNI library : [" + jaybirdJniLibrary + "]"); - if (logging) - log.info("Attempting to load JNI library : [" + jaybirdJniLibrary + "]"); - - try { System.loadLibrary(jaybirdJniLibrary); } catch (SecurityException ex) { if (logging) @@ -279,4 +282,12 @@ protected void finalize() throws Throwable { native_isc_finalize(isc_api_handle); } + + private static String getSystemPropertyPrivileged(final String propertyName) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(propertyName); + } + }); + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.gds.impl.jni; import org.firebirdsql.gds.GDS; @@ -2,14 +22,10 @@ import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSFactoryPlugin; -import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; +public class LocalGDSFactoryPlugin extends BaseGDSFactoryPlugin { -public class LocalGDSFactoryPlugin implements GDSFactoryPlugin { - private static final String[] TYPE_ALIASES = new String[0]; private static final String[] JDBC_PROTOCOLS = new String[] { "jdbc:firebirdsql:local:"}; - private static GDS gds; - public String getPluginName() { @@ -26,70 +42,22 @@ return TYPE_ALIASES; } - public Class<?> getConnectionClass() { - return FBConnection.class; - } - public String[] getSupportedProtocols() { return JDBC_PROTOCOLS; } - - public GDS getGDS() { - - if (gds == null) - gds = applySyncPolicy(new LocalGDSImpl()); - - - return gds; + + public String getDatabasePath(String server, Integer port, String path) throws GDSException{ + return path; } /** - * Apply the synchronization policy if the current platform is not Windows. - * @param tempGds instance if {@link GDS} to which policy should be applied. + * Initialization-on-demand depending on classloading behavior specified in JLS 12.4 */ - public static GDS applySyncPolicy(GDS tempGds) { - GDSSynchronizationPolicy.AbstractSynchronizationPolicy syncPolicy = null; - - String osName = System.getProperty("os.name"); - if (osName != null && osName.indexOf("Windows") == -1) - syncPolicy = new GDSSynchronizationPolicy.ClientLibrarySyncPolicy(tempGds); - - if (syncPolicy != null) - return GDSSynchronizationPolicy.applySyncronizationPolicy(tempGds, syncPolicy); - else - return tempGds; + private static final class GDSHolder { + private static final GDS gds = GDSSynchronizationPolicy.applyClientSyncPolicyNonWindows(new LocalGDSImpl()); } - public String getDatabasePath(String server, Integer port, String path) throws GDSException{ - return path; + public GDS getGDS() { + return GDSHolder.gds; } - - public String getDatabasePath(String jdbcUrl) throws GDSException { - String[] protocols = getSupportedProtocols(); - for (int i = 0; i < protocols.length; i++) { - if (jdbcUrl.startsWith(protocols[i])) - return jdbcUrl.substring(protocols[i].length()); - } - - throw new IllegalArgumentException("Incorrect JDBC protocol handling: " - + jdbcUrl); - } - - public String getDefaultProtocol() { - return getSupportedProtocols()[0]; - } - - public int hashCode() { - return getTypeName().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof LocalGDSFactoryPlugin)) - return false; - - return true; - } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.gds.impl.jni; import org.firebirdsql.gds.GDS; @@ -2,12 +22,9 @@ import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSFactoryPlugin; -import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; -public class NativeGDSFactoryPlugin implements GDSFactoryPlugin { +public class NativeGDSFactoryPlugin extends BaseGDSFactoryPlugin { private static final String[] TYPE_ALIASES = new String[]{"TYPE2"}; private static final String[] JDBC_PROTOCOLS = new String[]{"jdbc:firebirdsql:native:"}; - private static GDS gds; - public String getPluginName() { @@ -24,21 +41,10 @@ return TYPE_ALIASES; } - public Class<?> getConnectionClass() { - return FBConnection.class; - } - public String[] getSupportedProtocols() { return JDBC_PROTOCOLS; } - public GDS getGDS() { - if (gds == null) - gds = new NativeGDSImpl(); - - return gds; - } - public String getDatabasePath(String server, Integer port, String path) throws GDSException{ if (server == null) throw new GDSException("Server name/address is required " + @@ -58,32 +64,14 @@ return sb.toString(); } - public String getDatabasePath(String jdbcUrl) throws GDSException { - String[] protocols = getSupportedProtocols(); - for (int i = 0; i < protocols.length; i++) { - if (jdbcUrl.startsWith(protocols[i])) - return jdbcUrl.substring(protocols[i].length()); - } - - throw new IllegalArgumentException("Incorrect JDBC protocol handling: " - + jdbcUrl); + /** + * Initialization-on-demand depending on classloading behavior specified in JLS 12.4 + */ + private static final class GDSHolder { + private static final GDS gds = new NativeGDSImpl(); } - public String getDefaultProtocol() { - return getSupportedProtocols()[0]; - } - - public int hashCode() { - return getTypeName().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof NativeGDSFactoryPlugin)) - return false; - - return true; + public GDS getGDS() { + return GDSHolder.gds; } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -499,7 +499,7 @@ } } - private String getSystemPropertyPrivileged(final String propertyName) { + private static String getSystemPropertyPrivileged(final String propertyName) { return AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { return System.getProperty(propertyName); @@ -1994,7 +1994,15 @@ // Here we identify the user to the engine. This may or may not be // used as login info to a database. - String user = System.getProperty("user.name"); + String user; + try { + user = getSystemPropertyPrivileged("user.name"); + } catch (SecurityException ex) { + if (debug) + log.debug("Unable to retrieve user.name property", ex); + // TODO Find out if using empty string is sufficient + user = ""; + } if (debug) log.debug("user.name: " + user); Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/WireGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.gds.impl.wire; import org.firebirdsql.gds.GDS; @@ -2,12 +22,9 @@ import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSFactoryPlugin; -import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; -public class WireGDSFactoryPlugin implements GDSFactoryPlugin { +public class WireGDSFactoryPlugin extends BaseGDSFactoryPlugin { private static final String[] TYPE_ALIASES = new String[]{"TYPE4"}; private static final String[] JDBC_PROTOCOLS = new String[]{"jdbc:firebirdsql:java:", "jdbc:firebirdsql:"}; - private static AbstractJavaGDSImpl gdsImpl; - public String getPluginName() { @@ -24,21 +41,10 @@ return TYPE_ALIASES; } - public Class<?> getConnectionClass() { - return FBConnection.class; - } - public String[] getSupportedProtocols() { return JDBC_PROTOCOLS; } - public GDS getGDS() { - if (gdsImpl == null) - gdsImpl = new JavaGDSImpl(); - - return gdsImpl; - } - public String getDatabasePath(String server, Integer port, String path) throws GDSException{ if (server == null) throw new GDSException("Server name/address is required " + @@ -57,34 +63,15 @@ return sb.toString(); } - - public String getDatabasePath(String jdbcUrl) throws GDSException { - - String[] protocols = getSupportedProtocols(); - for (int i = 0; i < protocols.length; i++) { - if (jdbcUrl.startsWith(protocols[i])) - return jdbcUrl.substring(protocols[i].length()); - } - - throw new IllegalArgumentException("Incorrect JDBC protocol handling: " - + jdbcUrl); + + /** + * Initialization-on-demand depending on classloading behavior specified in JLS 12.4 + */ + private static final class GDSHolder { + private static final GDS gds = new JavaGDSImpl(); } - public String getDefaultProtocol() { - return getSupportedProtocols()[0]; - } - - public int hashCode() { - return getTypeName().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof WireGDSFactoryPlugin)) - return false; - - return true; + public GDS getGDS() { + return GDSHolder.gds; } } Modified: client-java/trunk/src/main/org/firebirdsql/logging/LoggerFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/logging/LoggerFactory.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/main/org/firebirdsql/logging/LoggerFactory.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,4 +1,4 @@ - /* +/* * Firebird Open Source J2ee connector - jdbc driver * * Distributable under LGPL license. @@ -18,57 +18,65 @@ */ package org.firebirdsql.logging; +import java.security.AccessController; +import java.security.PrivilegedAction; + /** * Describe class <code>LoggerFactory</code> here. - * + * * @author <a href="mailto:br...@us...">Blas Rodriguez Somoza</a> * @version 1.0 */ -public class LoggerFactory{ - +public class LoggerFactory { + private static final boolean forceConsoleLogger = false; - + private static boolean checked = false; private static boolean log4j = false; + + public static Logger getLogger(String name, boolean def) { + if (!checked) { + try { + String sLog4j = getSystemPropertyPrivileged("FBLog4j"); + log4j = sLog4j != null && sLog4j.equals("true"); + // TODO: Code smell: logging initialization logic decided by first to call getLogger + if (!def) { + log4j = sLog4j != null && sLog4j.equals("true"); + } else { + log4j = !(sLog4j != null && sLog4j.equals("false")); + } - public static Logger getLogger(String name,boolean def) { - if (!checked){ - String sLog4j = System.getProperty("FBLog4j"); - if (!def){ - if (sLog4j != null && sLog4j.equals("true")) - log4j = true; - else - log4j = false; - } - else{ - if (sLog4j != null && sLog4j.equals("false")) - log4j = false; - else - log4j = true; - } - - if (log4j){ - try { - Class.forName("org.apache.log4j.Category"); - log4j = true; - } - catch (ClassNotFoundException cnfe){ - log4j = false; - } - + if (log4j) { + try { + Class.forName("org.apache.log4j.Category"); + log4j = true; + } catch (ClassNotFoundException cnfe) { + log4j = false; + } + } + } catch (RuntimeException ex) { + log4j = false; + } finally { + checked = true; } - checked = true; } if (log4j) return new Log4jLogger(name); - else - if (forceConsoleLogger) + else if (forceConsoleLogger) return new ConsoleLogger(name); else return null; } - + public static Logger getLogger(Class<?> clazz, boolean def) { return getLogger(clazz.getName(), def); } + + private static String getSystemPropertyPrivileged(final String propertyName) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(propertyName); + } + }); + } } Modified: client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2012-10-10 14:09:54 UTC (rev 57230) +++ client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2012-10-10 17:47:51 UTC (rev 57231) @@ -1,12 +1,31 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.gds.impl.oo; import org.firebirdsql.gds.*; -import org.firebirdsql.gds.impl.GDSFactoryPlugin; -import org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl; +import org.firebirdsql.gds.impl.BaseGDSFactoryPlugin; import org.firebirdsql.gds.impl.wire.JavaGDSImpl; import org.firebirdsql.jdbc.oo.OOConnection; -public class OOGDSFactoryPlugin implements GDSFactoryPlugin { +public class OOGDSFactoryPlugin extends BaseGDSFactoryPlugin { private static final String TYPE_NAME = "OOREMOTE"; @@ -15,8 +34,6 @@ private static final String[] JDBC_PROTOCOLS = new String[] { "jdbc:firebird:oo:", "jdbc:firebirdsql:oo:"}; - private static AbstractJavaGDSImpl gdsImpl; - public String getPluginName() { return "GDS implementation for OpenOffice."; } @@ -29,6 +46,7 @@ return TYPE_ALIASES; } + @Override public Class<?> getConnectionClass() { return OOConnection.class; } @@ -37,13 +55,6 @@ return JDBC_PROTOCOLS; } - public GDS getGDS() { - if (gdsImpl == null) - gdsImpl = new JavaGDSImpl(); - - return gdsImpl; - } - public String getDatabasePath(String server, Integer port, String path) throws GDSException { if (server == null) @@ -63,31 +74,14 @@ return sb.toString(); } - public String getDatabasePath(String jdbcUrl) throws GDSException { - - String[] protocols = getSupportedProtocols(); - for (int i = 0; i < protocols.length; i++) { - if (jdbcUrl.startsWith(protocols[i])) - return jdbcUrl.substring(protocols[i].length()); - } - - throw new IllegalArgumentException("Incorrect JDBC protocol handling: " - + jdbcUrl); + /** + * Initialization-on-demand depending on classloading behavior specified in JLS 12.4 + */ + private static final class GDSHolder { + private static final GDS gds = new JavaGDSImpl(); } - public String getDefaultProtocol() { - return getSupportedProtocols()[0]; + public GDS getGDS() { + return GDSHolder.gds; } - - public int hashCode() { - return getTypeName().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) return true; - - if (!(obj instanceof OOGDSFactoryPlugin)) return false; - - return true; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-10-13 08:23:24
|
Revision: 57240 http://firebird.svn.sourceforge.net/firebird/?rev=57240&view=rev Author: mrotteveel Date: 2012-10-13 08:23:16 +0000 (Sat, 13 Oct 2012) Log Message: ----------- Move JDBC 40 classes into main Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java client-java/trunk/src/main/org/firebirdsql/ds/RootCommonDataSource.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriverNotCapableException.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java client-java/trunk/src/test/org/firebirdsql/ds/TestStatementHandlerMock4_0.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection4_0.java Removed Paths: ------------- client-java/trunk/src/jdbc_40/org/firebirdsql/ds/FBPooledConnection.java client-java/trunk/src/jdbc_40/org/firebirdsql/ds/RootCommonDataSource.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBCallableStatement.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBConnection.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriver.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriverNotCapableException.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBPreparedStatement.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBResultSet.java client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBStatement.java client-java/trunk/src/test_40/org/firebirdsql/ds/TestStatementHandlerMock4_0.java client-java/trunk/src/test_40/org/firebirdsql/jdbc/TestFBConnection4_0.java Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/ds/FBPooledConnection.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,46 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.ds; - -import java.sql.Connection; - -import javax.sql.StatementEventListener; - -/** - * JDBC 4.0 implementation of PooledConnection. - * - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - * @since 2.2 - */ -public class FBPooledConnection extends AbstractPooledConnection { - - protected FBPooledConnection(Connection connection) { - super(connection); - } - - public void addStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException("Not yet implemented"); - } - - public void removeStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException("Not yet implemented"); - } -} \ No newline at end of file Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/ds/RootCommonDataSource.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/ds/RootCommonDataSource.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/ds/RootCommonDataSource.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,56 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.ds; - -import java.io.PrintWriter; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Logger; - -import javax.sql.CommonDataSource; - -import org.firebirdsql.jdbc.FBDriverNotCapableException; - -/** - * Root superclass for the datasources in Firebird. - * <p> - * Used to workaround incompatibilities introduced for JDBC 3.0 and earlier by JDBC 4.1 (getParentLogger). - * </p> - * - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - * @since 2.2 - */ -public abstract class RootCommonDataSource implements CommonDataSource { - - public PrintWriter getLogWriter() throws SQLException { - // Unused by Jaybird - return null; - } - - public void setLogWriter(PrintWriter out) throws SQLException { - // Unused by Jaybird - } - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new FBDriverNotCapableException(); - } - -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBCallableStatement.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBCallableStatement.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBCallableStatement.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,91 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. You may obtain a copy of the License at - * http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the LGPL License for more details. - * - * This file was created by members of the firebird development team. All - * individual contributions remain the Copyright (C) of those individuals. - * Contributors to this file are either listed here or can be obtained from a - * CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.*; - -import org.firebirdsql.gds.impl.GDSHelper; - -/** - * JDBC 4.x compliant implementation of {@link java.sql.CallableStatement}. - */ -public class FBCallableStatement extends AbstractCallableStatement { - - /** - * Create instance of this class. - * - * @param c - * instance of {@link AbstractConnection} - * @param sql - * SQL statement containing procedure call. - * - * @throws SQLException - * if SQL error occured. - */ - public FBCallableStatement(GDSHelper c, String sql, int rsType, int rsConcurrency, - int rsHoldability, StoredProcedureMetaData storedProcedureMetaData, - FBObjectListener.StatementListener statementListener, - FBObjectListener.BlobListener blobListener) throws SQLException { - super(c, sql, rsType, rsConcurrency, rsHoldability, storedProcedureMetaData, - statementListener, blobListener); - } - - public NClob getNClob(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getNClob(parameterIndex); - } - - public NClob getNClob(String parameterName) throws SQLException { - return getNClob(findOutParameter(parameterName)); - } - - public RowId getRowId(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getRowId(parameterIndex); - } - - public RowId getRowId(String parameterName) throws SQLException { - return getRowId(findOutParameter(parameterName)); - } - - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getSQLXML(parameterIndex); - } - - public SQLXML getSQLXML(String parameterName) throws SQLException { - return getSQLXML(findOutParameter(parameterName)); - } - - public void setNClob(String parameterName, NClob value) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void setRowId(String parameterName, RowId x) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { - throw new FBDriverNotCapableException(); - } -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBConnection.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBConnection.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBConnection.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,205 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.*; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.Executor; - -import org.firebirdsql.jca.FBManagedConnection; -import org.firebirdsql.util.SQLExceptionChainBuilder; - -/** - * Firebird connection class implementing JDBC 3.0 methods. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public class FBConnection extends AbstractConnection { - - // TODO Nothing is ever put into this set - private Set<String> clientInfoPropNames = new HashSet<String>(); - - /** - * Create instance of this class for the specified managed connection. - * - * @param mc - * managed connection. - */ - public FBConnection(FBManagedConnection mc) { - super(mc); - } - - // ------------------------------------------------------------------------- - // JDBC 4.0 - // ------------------------------------------------------------------------- - - public NClob createNClob() throws SQLException { - throw new FBDriverNotCapableException(); - } - - public SQLXML createSQLXML() throws SQLException { - throw new FBDriverNotCapableException(); - } - - private static final String GET_CLIENT_INFO_SQL = - "SELECT " - + " rdb$get_context('USER_SESSION', ?) session_context " - + " , rdb$get_context('USER_TRANSACTION', ?) tx_context " - + "FROM rdb$database"; - - private static final String SET_CLIENT_INFO_SQL = - "SELECT " - + " rdb$set_context('USER_SESSION', ?, ?) session_context " - + "FROM rdb$database"; - - public Properties getClientInfo() throws SQLException { - Properties result = new Properties(); - - PreparedStatement stmt = prepareStatement(GET_CLIENT_INFO_SQL); - try { - for (String propName : clientInfoPropNames) { - result.put(propName, getClientInfo(stmt, propName)); - } - } finally { - stmt.close(); - } - - return result; - } - - public String getClientInfo(String name) throws SQLException { - PreparedStatement stmt = prepareStatement(GET_CLIENT_INFO_SQL); - try { - return getClientInfo(stmt, name); - } finally { - stmt.close(); - } - } - - protected String getClientInfo(PreparedStatement stmt, String name) throws SQLException { - stmt.clearParameters(); - - stmt.setString(1, name); - stmt.setString(2, name); - - ResultSet rs = stmt.executeQuery(); - try { - if (!rs.next()) - return null; - - String sessionContext = rs.getString(1); - String transactionContext = rs.getString(2); - - if (transactionContext != null) - return transactionContext; - else if (sessionContext != null) - return sessionContext; - else - return null; - - } finally { - rs.close(); - } - - } - - public void setClientInfo(Properties properties) throws SQLClientInfoException { - SQLExceptionChainBuilder<SQLClientInfoException> chain = new SQLExceptionChainBuilder<SQLClientInfoException>(); - - try { - PreparedStatement stmt = prepareStatement(SET_CLIENT_INFO_SQL); - try { - - for (String propName : properties.stringPropertyNames()) { - String propValue = properties.getProperty(propName); - - try { - setClientInfo(stmt, propName, propValue); - } catch (SQLClientInfoException ex) { - chain.append(ex); - } - } - } finally { - stmt.close(); - } - - } catch (SQLException ex) { - throw new SQLClientInfoException(ex.getMessage(), ex.getSQLState(), null, ex); - } - - if (chain.hasException()) - throw chain.getException(); - } - - public void setClientInfo(String name, String value) throws SQLClientInfoException { - try { - PreparedStatement stmt = prepareStatement(SET_CLIENT_INFO_SQL); - try { - setClientInfo(stmt, name, value); - } finally { - stmt.close(); - } - - } catch (SQLException ex) { - throw new SQLClientInfoException(ex.getMessage(), ex.getSQLState(), null, ex); - } - } - - protected void setClientInfo(PreparedStatement stmt, String name, String value) - throws SQLException { - try { - stmt.clearParameters(); - stmt.setString(1, name); - stmt.setString(2, value); - - ResultSet rs = stmt.executeQuery(); - if (!rs.next()) - throw new FBDriverConsistencyCheckException( - "Expected result from RDB$SET_CONTEXT call"); - - // needed, since the value is set on fetch!!! - rs.getInt(1); - - } catch (SQLException ex) { - throw new SQLClientInfoException(null, ex); - } - } - - public void abort(Executor executor) throws SQLException { - // TODO Write implementation - checkValidity(); - throw new FBDriverNotCapableException(); - } - - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - // TODO Write implementation - checkValidity(); - throw new FBDriverNotCapableException(); - } - - public int getNetworkTimeout() throws SQLException { - // TODO Write implementation - checkValidity(); - return 0; - } -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,90 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.sql.RowIdLifetime; -import java.sql.SQLException; - -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.GDSHelper; - -public class FBDatabaseMetaData extends AbstractDatabaseMetaData { - - public FBDatabaseMetaData(AbstractConnection c) throws GDSException { - super(c); - } - - public FBDatabaseMetaData(GDSHelper gdsHelper) { - super(gdsHelper); - } - - /** - * Indicates whether or not this data source supports the SQL <code>ROWID</code> type, - * and if so the lifetime for which a <code>RowId</code> object remains valid. - * <p> - * The returned int values have the following relationship: - * <pre> - * ROWID_UNSUPPORTED < ROWID_VALID_OTHER < ROWID_VALID_TRANSACTION - * < ROWID_VALID_SESSION < ROWID_VALID_FOREVER - * </pre> - * so conditional logic such as - * <pre> - * if (metadata.getRowIdLifetime() > DatabaseMetaData.ROWID_VALID_TRANSACTION) - * </pre> - * can be used. Valid Forever means valid across all Sessions, and valid for - * a Session means valid across all its contained Transactions. - * - * @return the status indicating the lifetime of a <code>RowId</code> - * @throws SQLException if a database access error occurs - * @since 1.6 - */ - public RowIdLifetime getRowIdLifetime() throws SQLException { - return RowIdLifetime.ROWID_UNSUPPORTED; - } - - public int getJDBCMajorVersion() { - return 4; - } - - public int getJDBCMinorVersion() { - try { - String javaImplementation = getSystemPropertyPrivileged("java.implementation.version"); - if (javaImplementation != null && "1.7".compareTo(javaImplementation) <= 0) { - // JDK 1.7 or higher: JDBC 4.1 - return 1; - } else { - // JDK 1.6 (or lower): JDBC 4.0 - return 0; - } - } catch (RuntimeException ex) { - // default to 0 (JDBC 4.0) when privileged call fails - return 0; - } - } - - private static String getSystemPropertyPrivileged(final String propertyName) { - return AccessController.doPrivileged(new PrivilegedAction<String>() { - public String run() { - return System.getProperty(propertyName); - } - }); - } -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriver.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriver.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriver.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,40 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - - -import java.sql.*; -import java.util.logging.Logger; - -/** - * The Jaybird JDBC Driver implementation for the Firebird database. - * - * @author <a href="mailto:d_j...@us...">David Jencks</a> - * @version 1.0 - */ -public class FBDriver extends AbstractDriver implements FirebirdDriver { - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new FBDriverNotCapableException(); - } - -} - Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriverNotCapableException.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriverNotCapableException.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriverNotCapableException.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,48 +0,0 @@ -/* - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.SQLFeatureNotSupportedException; - - -/** - * Tell that driver is not able to serve the request due to missing capabilities. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public class FBDriverNotCapableException extends SQLFeatureNotSupportedException { - public static final String SQL_STATE_FEATURE_NOT_SUPPORTED = "0A000"; - - /** - * Create instance of this class for the specified reason. - * - * @param reason reason that will be displayed. - */ - public FBDriverNotCapableException(String reason) { - super(reason, SQL_STATE_FEATURE_NOT_SUPPORTED); - } - - /** - * Create instance of this class. - */ - public FBDriverNotCapableException() { - super("Not yet implemented.", SQL_STATE_FEATURE_NOT_SUPPORTED); - } - -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBPreparedStatement.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBPreparedStatement.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBPreparedStatement.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,60 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.sql.*; - -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.FBObjectListener.BlobListener; -import org.firebirdsql.jdbc.FBObjectListener.StatementListener; - -/** - * JDBC-4.x implementation of {@link java.sql.PreparedStatement}. - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public class FBPreparedStatement extends AbstractPreparedStatement { - - public FBPreparedStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, - StatementListener statementListener, BlobListener blobListener) throws SQLException { - super(c, rsType, rsConcurrency, rsHoldability, statementListener, blobListener); - } - - public FBPreparedStatement(GDSHelper gdsHelper, String sql, int rsType, int rsConcurrency, - int rsHoldability, FBObjectListener.StatementListener statementListener, - FBObjectListener.BlobListener blobListener, boolean metaDataQuery, - boolean standaloneStatement, boolean generatedKeys) throws SQLException { - super(gdsHelper, sql, rsType, rsConcurrency, rsHoldability, statementListener, - blobListener, metaDataQuery, standaloneStatement, generatedKeys); - } - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { - throw new FBDriverNotCapableException(); - } -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBResultSet.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBResultSet.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBResultSet.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,122 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.io.Reader; -import java.sql.*; -import java.util.List; - -import org.firebirdsql.gds.XSQLVAR; -import org.firebirdsql.gds.impl.AbstractIscStmtHandle; -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.FBObjectListener.ResultSetListener; - -/** - * Implementation of {@link java.sql.ResultSet} interface. - * - * @author <a href="mailto:d_j...@us...">David Jencks</a> - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - */ -public class FBResultSet extends AbstractResultSet { - - public FBResultSet(GDSHelper gdsHelper, AbstractStatement fbStatement, - AbstractIscStmtHandle stmt, ResultSetListener listener, - boolean metaDataQuery, int rsType, int rsConcurrency, - int rsHoldability, boolean cached) throws SQLException { - - super(gdsHelper, fbStatement, stmt, listener, metaDataQuery, rsType, - rsConcurrency, rsHoldability, cached); - } - - public FBResultSet(XSQLVAR[] xsqlvars, List<byte[][]> rows) throws SQLException { - super(xsqlvars, rows); - } - - public NClob getNClob(int columnIndex) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public NClob getNClob(String columnLabel) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public RowId getRowId(int columnIndex) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public RowId getRowId(String columnLabel) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(int columnIndex, NClob clob) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(int columnIndex, Reader reader, long length) - throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(String columnLabel, NClob clob) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(String columnLabel, Reader reader, long length) - throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateNClob(String columnLabel, Reader reader) - throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) - throws SQLException { - throw new FBDriverNotCapableException(); - } - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) - throws SQLException { - throw new FBDriverNotCapableException(); - } -} Deleted: client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBStatement.java =================================================================== --- client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBStatement.java 2012-10-13 08:17:34 UTC (rev 57239) +++ client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBStatement.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -1,22 +0,0 @@ -package org.firebirdsql.jdbc; - -import java.sql.*; -import java.util.logging.Logger; - -import org.firebirdsql.gds.impl.GDSHelper; - -/** - * - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - */ -public class FBStatement extends AbstractStatement { - - public FBStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, - FBObjectListener.StatementListener statementListener) throws SQLException { - super(c, rsType, rsConcurrency, rsHoldability, statementListener); - } - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new FBDriverNotCapableException(); - } -} Copied: client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/ds/FBPooledConnection.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Firebird Open Source J2EE Connector - JDBC Driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.ds; + +import java.sql.Connection; + +import javax.sql.StatementEventListener; + +/** + * JDBC 4.0 implementation of PooledConnection. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.2 + */ +public class FBPooledConnection extends AbstractPooledConnection { + + protected FBPooledConnection(Connection connection) { + super(connection); + } + + public void addStatementEventListener(StatementEventListener listener) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public void removeStatementEventListener(StatementEventListener listener) { + throw new UnsupportedOperationException("Not yet implemented"); + } +} \ No newline at end of file Copied: client-java/trunk/src/main/org/firebirdsql/ds/RootCommonDataSource.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/ds/RootCommonDataSource.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/RootCommonDataSource.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/ds/RootCommonDataSource.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,56 @@ +/* + * $Id$ + * + * Firebird Open Source J2EE Connector - JDBC Driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.ds; + +import java.io.PrintWriter; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.logging.Logger; + +import javax.sql.CommonDataSource; + +import org.firebirdsql.jdbc.FBDriverNotCapableException; + +/** + * Root superclass for the datasources in Firebird. + * <p> + * Used to workaround incompatibilities introduced for JDBC 3.0 and earlier by JDBC 4.1 (getParentLogger). + * </p> + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.2 + */ +public abstract class RootCommonDataSource implements CommonDataSource { + + public PrintWriter getLogWriter() throws SQLException { + // Unused by Jaybird + return null; + } + + public void setLogWriter(PrintWriter out) throws SQLException { + // Unused by Jaybird + } + + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new FBDriverNotCapableException(); + } + +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBCallableStatement.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,91 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. You may obtain a copy of the License at + * http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the LGPL License for more details. + * + * This file was created by members of the firebird development team. All + * individual contributions remain the Copyright (C) of those individuals. + * Contributors to this file are either listed here or can be obtained from a + * CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.sql.*; + +import org.firebirdsql.gds.impl.GDSHelper; + +/** + * JDBC 4.x compliant implementation of {@link java.sql.CallableStatement}. + */ +public class FBCallableStatement extends AbstractCallableStatement { + + /** + * Create instance of this class. + * + * @param c + * instance of {@link AbstractConnection} + * @param sql + * SQL statement containing procedure call. + * + * @throws SQLException + * if SQL error occured. + */ + public FBCallableStatement(GDSHelper c, String sql, int rsType, int rsConcurrency, + int rsHoldability, StoredProcedureMetaData storedProcedureMetaData, + FBObjectListener.StatementListener statementListener, + FBObjectListener.BlobListener blobListener) throws SQLException { + super(c, sql, rsType, rsConcurrency, rsHoldability, storedProcedureMetaData, + statementListener, blobListener); + } + + public NClob getNClob(int parameterIndex) throws SQLException { + assertHasData(getCurrentResultSet()); + parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); + return getCurrentResultSet().getNClob(parameterIndex); + } + + public NClob getNClob(String parameterName) throws SQLException { + return getNClob(findOutParameter(parameterName)); + } + + public RowId getRowId(int parameterIndex) throws SQLException { + assertHasData(getCurrentResultSet()); + parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); + return getCurrentResultSet().getRowId(parameterIndex); + } + + public RowId getRowId(String parameterName) throws SQLException { + return getRowId(findOutParameter(parameterName)); + } + + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + assertHasData(getCurrentResultSet()); + parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); + return getCurrentResultSet().getSQLXML(parameterIndex); + } + + public SQLXML getSQLXML(String parameterName) throws SQLException { + return getSQLXML(findOutParameter(parameterName)); + } + + public void setNClob(String parameterName, NClob value) throws SQLException { + throw new FBDriverNotCapableException(); + } + + public void setRowId(String parameterName, RowId x) throws SQLException { + throw new FBDriverNotCapableException(); + } + + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { + throw new FBDriverNotCapableException(); + } +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBConnection.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,205 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.sql.*; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.Executor; + +import org.firebirdsql.jca.FBManagedConnection; +import org.firebirdsql.util.SQLExceptionChainBuilder; + +/** + * Firebird connection class implementing JDBC 3.0 methods. + * + * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> + */ +public class FBConnection extends AbstractConnection { + + // TODO Nothing is ever put into this set + private Set<String> clientInfoPropNames = new HashSet<String>(); + + /** + * Create instance of this class for the specified managed connection. + * + * @param mc + * managed connection. + */ + public FBConnection(FBManagedConnection mc) { + super(mc); + } + + // ------------------------------------------------------------------------- + // JDBC 4.0 + // ------------------------------------------------------------------------- + + public NClob createNClob() throws SQLException { + throw new FBDriverNotCapableException(); + } + + public SQLXML createSQLXML() throws SQLException { + throw new FBDriverNotCapableException(); + } + + private static final String GET_CLIENT_INFO_SQL = + "SELECT " + + " rdb$get_context('USER_SESSION', ?) session_context " + + " , rdb$get_context('USER_TRANSACTION', ?) tx_context " + + "FROM rdb$database"; + + private static final String SET_CLIENT_INFO_SQL = + "SELECT " + + " rdb$set_context('USER_SESSION', ?, ?) session_context " + + "FROM rdb$database"; + + public Properties getClientInfo() throws SQLException { + Properties result = new Properties(); + + PreparedStatement stmt = prepareStatement(GET_CLIENT_INFO_SQL); + try { + for (String propName : clientInfoPropNames) { + result.put(propName, getClientInfo(stmt, propName)); + } + } finally { + stmt.close(); + } + + return result; + } + + public String getClientInfo(String name) throws SQLException { + PreparedStatement stmt = prepareStatement(GET_CLIENT_INFO_SQL); + try { + return getClientInfo(stmt, name); + } finally { + stmt.close(); + } + } + + protected String getClientInfo(PreparedStatement stmt, String name) throws SQLException { + stmt.clearParameters(); + + stmt.setString(1, name); + stmt.setString(2, name); + + ResultSet rs = stmt.executeQuery(); + try { + if (!rs.next()) + return null; + + String sessionContext = rs.getString(1); + String transactionContext = rs.getString(2); + + if (transactionContext != null) + return transactionContext; + else if (sessionContext != null) + return sessionContext; + else + return null; + + } finally { + rs.close(); + } + + } + + public void setClientInfo(Properties properties) throws SQLClientInfoException { + SQLExceptionChainBuilder<SQLClientInfoException> chain = new SQLExceptionChainBuilder<SQLClientInfoException>(); + + try { + PreparedStatement stmt = prepareStatement(SET_CLIENT_INFO_SQL); + try { + + for (String propName : properties.stringPropertyNames()) { + String propValue = properties.getProperty(propName); + + try { + setClientInfo(stmt, propName, propValue); + } catch (SQLClientInfoException ex) { + chain.append(ex); + } + } + } finally { + stmt.close(); + } + + } catch (SQLException ex) { + throw new SQLClientInfoException(ex.getMessage(), ex.getSQLState(), null, ex); + } + + if (chain.hasException()) + throw chain.getException(); + } + + public void setClientInfo(String name, String value) throws SQLClientInfoException { + try { + PreparedStatement stmt = prepareStatement(SET_CLIENT_INFO_SQL); + try { + setClientInfo(stmt, name, value); + } finally { + stmt.close(); + } + + } catch (SQLException ex) { + throw new SQLClientInfoException(ex.getMessage(), ex.getSQLState(), null, ex); + } + } + + protected void setClientInfo(PreparedStatement stmt, String name, String value) + throws SQLException { + try { + stmt.clearParameters(); + stmt.setString(1, name); + stmt.setString(2, value); + + ResultSet rs = stmt.executeQuery(); + if (!rs.next()) + throw new FBDriverConsistencyCheckException( + "Expected result from RDB$SET_CONTEXT call"); + + // needed, since the value is set on fetch!!! + rs.getInt(1); + + } catch (SQLException ex) { + throw new SQLClientInfoException(null, ex); + } + } + + public void abort(Executor executor) throws SQLException { + // TODO Write implementation + checkValidity(); + throw new FBDriverNotCapableException(); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + // TODO Write implementation + checkValidity(); + throw new FBDriverNotCapableException(); + } + + public int getNetworkTimeout() throws SQLException { + // TODO Write implementation + checkValidity(); + return 0; + } +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java (from rev 57231, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDatabaseMetaData.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,90 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.sql.RowIdLifetime; +import java.sql.SQLException; + +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.impl.GDSHelper; + +public class FBDatabaseMetaData extends AbstractDatabaseMetaData { + + public FBDatabaseMetaData(AbstractConnection c) throws GDSException { + super(c); + } + + public FBDatabaseMetaData(GDSHelper gdsHelper) { + super(gdsHelper); + } + + /** + * Indicates whether or not this data source supports the SQL <code>ROWID</code> type, + * and if so the lifetime for which a <code>RowId</code> object remains valid. + * <p> + * The returned int values have the following relationship: + * <pre> + * ROWID_UNSUPPORTED < ROWID_VALID_OTHER < ROWID_VALID_TRANSACTION + * < ROWID_VALID_SESSION < ROWID_VALID_FOREVER + * </pre> + * so conditional logic such as + * <pre> + * if (metadata.getRowIdLifetime() > DatabaseMetaData.ROWID_VALID_TRANSACTION) + * </pre> + * can be used. Valid Forever means valid across all Sessions, and valid for + * a Session means valid across all its contained Transactions. + * + * @return the status indicating the lifetime of a <code>RowId</code> + * @throws SQLException if a database access error occurs + * @since 1.6 + */ + public RowIdLifetime getRowIdLifetime() throws SQLException { + return RowIdLifetime.ROWID_UNSUPPORTED; + } + + public int getJDBCMajorVersion() { + return 4; + } + + public int getJDBCMinorVersion() { + try { + String javaImplementation = getSystemPropertyPrivileged("java.implementation.version"); + if (javaImplementation != null && "1.7".compareTo(javaImplementation) <= 0) { + // JDK 1.7 or higher: JDBC 4.1 + return 1; + } else { + // JDK 1.6 (or lower): JDBC 4.0 + return 0; + } + } catch (RuntimeException ex) { + // default to 0 (JDBC 4.0) when privileged call fails + return 0; + } + } + + private static String getSystemPropertyPrivileged(final String propertyName) { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(propertyName); + } + }); + } +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriver.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,40 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + + +import java.sql.*; +import java.util.logging.Logger; + +/** + * The Jaybird JDBC Driver implementation for the Firebird database. + * + * @author <a href="mailto:d_j...@us...">David Jencks</a> + * @version 1.0 + */ +public class FBDriver extends AbstractDriver implements FirebirdDriver { + + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new FBDriverNotCapableException(); + } + +} + Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriverNotCapableException.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBDriverNotCapableException.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriverNotCapableException.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriverNotCapableException.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,48 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.sql.SQLFeatureNotSupportedException; + + +/** + * Tell that driver is not able to serve the request due to missing capabilities. + * + * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> + */ +public class FBDriverNotCapableException extends SQLFeatureNotSupportedException { + public static final String SQL_STATE_FEATURE_NOT_SUPPORTED = "0A000"; + + /** + * Create instance of this class for the specified reason. + * + * @param reason reason that will be displayed. + */ + public FBDriverNotCapableException(String reason) { + super(reason, SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + /** + * Create instance of this class. + */ + public FBDriverNotCapableException() { + super("Not yet implemented.", SQL_STATE_FEATURE_NOT_SUPPORTED); + } + +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBPreparedStatement.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,60 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.sql.*; + +import org.firebirdsql.gds.impl.GDSHelper; +import org.firebirdsql.jdbc.FBObjectListener.BlobListener; +import org.firebirdsql.jdbc.FBObjectListener.StatementListener; + +/** + * JDBC-4.x implementation of {@link java.sql.PreparedStatement}. + * + * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> + */ +public class FBPreparedStatement extends AbstractPreparedStatement { + + public FBPreparedStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, + StatementListener statementListener, BlobListener blobListener) throws SQLException { + super(c, rsType, rsConcurrency, rsHoldability, statementListener, blobListener); + } + + public FBPreparedStatement(GDSHelper gdsHelper, String sql, int rsType, int rsConcurrency, + int rsHoldability, FBObjectListener.StatementListener statementListener, + FBObjectListener.BlobListener blobListener, boolean metaDataQuery, + boolean standaloneStatement, boolean generatedKeys) throws SQLException { + super(gdsHelper, sql, rsType, rsConcurrency, rsHoldability, statementListener, + blobListener, metaDataQuery, standaloneStatement, generatedKeys); + } + + public void setNClob(int parameterIndex, NClob value) throws SQLException { + throw new FBDriverNotCapableException(); + } + + public void setRowId(int parameterIndex, RowId x) throws SQLException { + throw new FBDriverNotCapableException(); + } + + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + throw new FBDriverNotCapableException(); + } +} Copied: client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java (from rev 57181, client-java/trunk/src/jdbc_40/org/firebirdsql/jdbc/FBResultSet.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java 2012-10-13 08:23:16 UTC (rev 57240) @@ -0,0 +1,122 @@ +/* + * $Id$ + * + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import java.io.Reader; +import java.sql.*; +import java.util.List; + +import org.firebirdsql.gds.XSQLVAR; +import org.firebirdsql.gds.impl.AbstractIscStmtHandle; +import org.firebirdsql.gds.impl.GDSHelper; +import org.firebirdsql.jdbc.FBObjectListener.ResultSetListener; + +/** + * Implementation of {@link java.sql.ResultSet} interface. + * + * @author <a href="mailto:d_j...@us...">David Jencks</a> + * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + */ +public class FBResultSet extends AbstractResultSet { + + public FBResultSet(GDSHelper gdsHelper, AbstractStatement fbStatement, + AbstractIscStmtHandle stmt, ResultSetListener listener, + boolean metaDataQuery, int rsType, int rsConcurrency, + int rsHoldability, boolean cached) throws SQLException { + + super(gdsHelper, fbStatement, stmt, listener, metaDataQuery, rsType, + rsConcurrency, rsHoldability, cached); + } + + public FBResultSet(XSQLVAR[] xsqlvars, List<byte[][]> rows) throws SQLException { + super(xsqlvars, rows); + } + + public NClob getNClob(int columnIndex) throws SQLException { + t... [truncated message content] |
From: <mro...@us...> - 2012-10-13 09:32:40
|
Revision: 57242 http://firebird.svn.sourceforge.net/firebird/?rev=57242&view=rev Author: mrotteveel Date: 2012-10-13 09:32:31 +0000 (Sat, 13 Oct 2012) Log Message: ----------- JDBC-263 eliminate abstract classes from hierarchy Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/ds/FBXAConnection.java client-java/trunk/src/main/org/firebirdsql/ds/FBXADataSource.java client-java/trunk/src/main/org/firebirdsql/ds/PooledConnectionHandler.java client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java client-java/trunk/src/main/org/firebirdsql/jca/FBLocalTransaction.java client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBObjectListener.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBProcedureCall.java client-java/trunk/src/main/org/firebirdsql/jdbc/InternalTransactionCoordinator.java client-java/trunk/src/main/org/firebirdsql/jdbc/StoredProcedureMetaDataFactory.java client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OODatabaseMetaData.java client-java/trunk/src/test/org/firebirdsql/ds/TestStatementHandlerMock.java client-java/trunk/src/test/org/firebirdsql/jca/TestFBBlob.java client-java/trunk/src/test/org/firebirdsql/jca/TestFBDatabaseMetaData.java client-java/trunk/src/test/org/firebirdsql/jca/TestFBResultSet.java client-java/trunk/src/test/org/firebirdsql/jca/TestFBStandAloneConnectionManager.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java Removed Paths: ------------- client-java/trunk/src/main/org/firebirdsql/ds/AbstractPooledConnection.java client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractDriver.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDriver.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBResultSet.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java client-java/trunk/src/test/org/firebirdsql/ds/TestStatementHandlerMock4_0.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection4_0.java Deleted: client-java/trunk/src/main/org/firebirdsql/ds/AbstractPooledConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/AbstractPooledConnection.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/ds/AbstractPooledConnection.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -1,228 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.ds; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import javax.sql.ConnectionEvent; -import javax.sql.ConnectionEventListener; -import javax.sql.PooledConnection; - -import org.firebirdsql.jdbc.FBSQLException; - -/** - * PooledConnection implementation for {@link FBConnectionPoolDataSource} - * <p> - * This class is abstract to account for both a JDBC 3.0 and JDBC 4.0 compliant implementation. - * </p> - * - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - * @since 2.2 - */ -public abstract class AbstractPooledConnection implements PooledConnection { - - private final List<ConnectionEventListener> connectionEventListeners = - Collections.synchronizedList(new LinkedList<ConnectionEventListener>()); - - protected Connection connection; - protected volatile PooledConnectionHandler handler; - - protected AbstractPooledConnection(Connection connection) { - this.connection = connection; - } - - public synchronized Connection getConnection() throws SQLException { - if (connection == null) { - FBSQLException ex = new FBSQLException("The PooledConnection has been closed", - FBSQLException.SQL_STATE_CONNECTION_CLOSED); - fireFatalConnectionError(ex); - throw ex; - } - try { - if (handler != null) { - handler.close(); - } - resetConnection(); - } catch (SQLException ex) { - fireFatalConnectionError(ex); - throw ex; - } - handler = createConnectionHandler(); - - return handler.getProxy(); - } - - protected void resetConnection() throws SQLException { - connection.setAutoCommit(true); - } - - /** - * Creates the PooledConnectionHandler for the connection. - * <p> - * Subclasses may override this method to return their own subclass of PooledConnectionHandler. - * </p> - * - * @return PooledConnectionHandler - */ - protected PooledConnectionHandler createConnectionHandler() { - return new PooledConnectionHandler(connection, this); - } - - public synchronized void close() throws SQLException { - SQLException receivedException = null; - if (handler != null) { - try { - handler.close(); - } catch (SQLException se) { - receivedException = se; - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException se) { - // We want the exception of closing the physical connection to be the first - if (receivedException != null) { - se.setNextException(receivedException); - } - receivedException = se; - } finally { - connection = null; - } - } - if (receivedException != null) { - throw receivedException; - } - } - - /** - * Helper method to fire the connectionErrorOccurred event. To be used with - * fatal (connection) errors only. - * - * @param ex - * The exception - */ - protected void fireFatalConnectionError(SQLException ex) { - ConnectionEvent evt = new ConnectionEvent(this, ex); - // Make a copy to prevent errors when listeners remove themselves - List<ConnectionEventListener> listeners; - synchronized (connectionEventListeners) { - listeners = new ArrayList<ConnectionEventListener>(connectionEventListeners); - } - for (ConnectionEventListener listener : listeners) { - listener.connectionErrorOccurred(evt); - } - } - - /** - * Helper method to fire the connectionErrorOccurred event. - * <p> - * This method will decide which errors warrant a connectionErrorOccurred - * event to be reported or not. - * </p> - * - * @param ex - * The exception - */ - protected void fireConnectionError(SQLException ex) { - // TODO Do we need to walk over Exception chain to check if it wraps a fatal SQLException? - String sqlState = ex.getSQLState(); - if (isFatalState(sqlState)) { - fireFatalConnectionError(ex); - } - } - - /** - * Decides if the given SQL state is a fatal connection error. - * - * @param sqlState - * SQL State value - * @return <code>true</code> if the SQL state is considered fatal - */ - private boolean isFatalState(String sqlState) { - if (sqlState == null || sqlState.length() < 2) { - // No SQL State or no class specified, assume it's fatal - return true; - } - for (int idx = 0; idx < FATAL_SQL_STATE_CLASSES.length; idx++) { - if (sqlState.startsWith(FATAL_SQL_STATE_CLASSES[idx])) { - return true; - } - } - return false; - } - - private static final String[] FATAL_SQL_STATE_CLASSES = { - // TODO double check firebird and Jaybird implementation for other states - "08", // Connection errors - "XX", // Internal errors - "01002", // Disconnect error - "01S00", // Invalid connection string attribute - "2D000", // Invalid transaction termination - "2E000", // Invalid connection name - "HY000", // General error (TODO: maybe too general?) - "HY001", // Memory allocation error - "HYT00", // Timeout expired - "HYT01", // Connection timeout expired - }; - - /** - * Helper method to fire the connectionClosed event. - */ - protected void fireConnectionClosed() { - ConnectionEvent evt = new ConnectionEvent(this); - // Make a copy to prevent errors when listeners remove themselves - List<ConnectionEventListener> listeners; - synchronized (connectionEventListeners) { - listeners = new ArrayList<ConnectionEventListener>(connectionEventListeners); - } - for (ConnectionEventListener listener : listeners) { - listener.connectionClosed(evt); - } - } - - /** - * Releases the current handler if it is equal to the handler passed in <code>pch</code>. - * <p> - * To be called by the PooledConnectionHandler when it has been closed. - * </p> - * - * @param pch PooledConnectionHandler to release. - */ - protected synchronized void releaseConnectionHandler(PooledConnectionHandler pch) { - if (handler == pch) { - handler = null; - } - } - - public void addConnectionEventListener(ConnectionEventListener listener) { - connectionEventListeners.add(listener); - } - - public void removeConnectionEventListener(ConnectionEventListener listener) { - connectionEventListeners.remove(listener); - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -1,46 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2EE Connector - JDBC Driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.ds; - -import java.sql.Connection; - -import javax.sql.StatementEventListener; - -/** - * JDBC 4.0 implementation of PooledConnection. - * - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - * @since 2.2 - */ -public class FBPooledConnection extends AbstractPooledConnection { - - protected FBPooledConnection(Connection connection) { - super(connection); - } - - public void addStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException("Not yet implemented"); - } - - public void removeStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException("Not yet implemented"); - } -} \ No newline at end of file Copied: client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java (from rev 57240, client-java/trunk/src/main/org/firebirdsql/ds/AbstractPooledConnection.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBPooledConnection.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -0,0 +1,234 @@ +/* + * $Id$ + * + * Firebird Open Source J2EE Connector - JDBC Driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.ds; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import javax.sql.ConnectionEvent; +import javax.sql.ConnectionEventListener; +import javax.sql.PooledConnection; +import javax.sql.StatementEventListener; + +import org.firebirdsql.jdbc.FBSQLException; + +/** + * PooledConnection implementation for {@link FBConnectionPoolDataSource} + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.2 + */ +public class FBPooledConnection implements PooledConnection { + + private final List<ConnectionEventListener> connectionEventListeners = + Collections.synchronizedList(new LinkedList<ConnectionEventListener>()); + + protected Connection connection; + protected volatile PooledConnectionHandler handler; + + protected FBPooledConnection(Connection connection) { + this.connection = connection; + } + + public synchronized Connection getConnection() throws SQLException { + if (connection == null) { + FBSQLException ex = new FBSQLException("The PooledConnection has been closed", + FBSQLException.SQL_STATE_CONNECTION_CLOSED); + fireFatalConnectionError(ex); + throw ex; + } + try { + if (handler != null) { + handler.close(); + } + resetConnection(); + } catch (SQLException ex) { + fireFatalConnectionError(ex); + throw ex; + } + handler = createConnectionHandler(); + + return handler.getProxy(); + } + + protected void resetConnection() throws SQLException { + connection.setAutoCommit(true); + } + + /** + * Creates the PooledConnectionHandler for the connection. + * <p> + * Subclasses may override this method to return their own subclass of PooledConnectionHandler. + * </p> + * + * @return PooledConnectionHandler + */ + protected PooledConnectionHandler createConnectionHandler() { + return new PooledConnectionHandler(connection, this); + } + + public synchronized void close() throws SQLException { + SQLException receivedException = null; + if (handler != null) { + try { + handler.close(); + } catch (SQLException se) { + receivedException = se; + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException se) { + // We want the exception of closing the physical connection to be the first + if (receivedException != null) { + se.setNextException(receivedException); + } + receivedException = se; + } finally { + connection = null; + } + } + if (receivedException != null) { + throw receivedException; + } + } + + /** + * Helper method to fire the connectionErrorOccurred event. To be used with + * fatal (connection) errors only. + * + * @param ex + * The exception + */ + protected void fireFatalConnectionError(SQLException ex) { + ConnectionEvent evt = new ConnectionEvent(this, ex); + // Make a copy to prevent errors when listeners remove themselves + List<ConnectionEventListener> listeners; + synchronized (connectionEventListeners) { + listeners = new ArrayList<ConnectionEventListener>(connectionEventListeners); + } + for (ConnectionEventListener listener : listeners) { + listener.connectionErrorOccurred(evt); + } + } + + /** + * Helper method to fire the connectionErrorOccurred event. + * <p> + * This method will decide which errors warrant a connectionErrorOccurred + * event to be reported or not. + * </p> + * + * @param ex + * The exception + */ + protected void fireConnectionError(SQLException ex) { + // TODO Do we need to walk over Exception chain to check if it wraps a fatal SQLException? + String sqlState = ex.getSQLState(); + if (isFatalState(sqlState)) { + fireFatalConnectionError(ex); + } + } + + /** + * Decides if the given SQL state is a fatal connection error. + * + * @param sqlState + * SQL State value + * @return <code>true</code> if the SQL state is considered fatal + */ + private boolean isFatalState(String sqlState) { + if (sqlState == null || sqlState.length() < 2) { + // No SQL State or no class specified, assume it's fatal + return true; + } + for (int idx = 0; idx < FATAL_SQL_STATE_CLASSES.length; idx++) { + if (sqlState.startsWith(FATAL_SQL_STATE_CLASSES[idx])) { + return true; + } + } + return false; + } + + private static final String[] FATAL_SQL_STATE_CLASSES = { + // TODO double check firebird and Jaybird implementation for other states + "08", // Connection errors + "XX", // Internal errors + "01002", // Disconnect error + "01S00", // Invalid connection string attribute + "2D000", // Invalid transaction termination + "2E000", // Invalid connection name + "HY000", // General error (TODO: maybe too general?) + "HY001", // Memory allocation error + "HYT00", // Timeout expired + "HYT01", // Connection timeout expired + }; + + /** + * Helper method to fire the connectionClosed event. + */ + protected void fireConnectionClosed() { + ConnectionEvent evt = new ConnectionEvent(this); + // Make a copy to prevent errors when listeners remove themselves + List<ConnectionEventListener> listeners; + synchronized (connectionEventListeners) { + listeners = new ArrayList<ConnectionEventListener>(connectionEventListeners); + } + for (ConnectionEventListener listener : listeners) { + listener.connectionClosed(evt); + } + } + + /** + * Releases the current handler if it is equal to the handler passed in <code>pch</code>. + * <p> + * To be called by the PooledConnectionHandler when it has been closed. + * </p> + * + * @param pch PooledConnectionHandler to release. + */ + protected synchronized void releaseConnectionHandler(PooledConnectionHandler pch) { + if (handler == pch) { + handler = null; + } + } + + public void addConnectionEventListener(ConnectionEventListener listener) { + connectionEventListeners.add(listener); + } + + public void removeConnectionEventListener(ConnectionEventListener listener) { + connectionEventListeners.remove(listener); + } + + public void addStatementEventListener(StatementEventListener listener) { + throw new UnsupportedOperationException("Not yet implemented"); + } + + public void removeStatementEventListener(StatementEventListener listener) { + throw new UnsupportedOperationException("Not yet implemented"); + } +} Modified: client-java/trunk/src/main/org/firebirdsql/ds/FBXAConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBXAConnection.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBXAConnection.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -27,7 +27,7 @@ import javax.transaction.xa.XAResource; import org.firebirdsql.jca.FBManagedConnection; -import org.firebirdsql.jdbc.AbstractConnection; +import org.firebirdsql.jdbc.FBConnection; import org.firebirdsql.jdbc.FBSQLException; /** @@ -40,7 +40,7 @@ private WeakReference<FBManagedConnection> mc; - public FBXAConnection(AbstractConnection connection) { + public FBXAConnection(FBConnection connection) { super(connection); mc = new WeakReference<FBManagedConnection>(connection.getManagedConnection()); } Modified: client-java/trunk/src/main/org/firebirdsql/ds/FBXADataSource.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBXADataSource.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBXADataSource.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -39,7 +39,7 @@ import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.jca.FBManagedConnection; import org.firebirdsql.jca.FBManagedConnectionFactory; -import org.firebirdsql.jdbc.AbstractConnection; +import org.firebirdsql.jdbc.FBConnection; import org.firebirdsql.jdbc.FBDataSource; import org.firebirdsql.jdbc.FBSQLException; @@ -61,7 +61,7 @@ if (internalDs == null) { initialize(); } - AbstractConnection connection = (AbstractConnection) internalDs.getConnection(user, + FBConnection connection = (FBConnection) internalDs.getConnection(user, password); return new FBXAConnection(connection); } Modified: client-java/trunk/src/main/org/firebirdsql/ds/PooledConnectionHandler.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/PooledConnectionHandler.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/ds/PooledConnectionHandler.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -54,14 +54,14 @@ protected static final String CLOSED_MESSAGE = "Logical connection already closed"; protected static final String FORCIBLY_CLOSED_MESSAGE = "Logical connection was forcibly closed by the connection pool"; - protected final AbstractPooledConnection owner; + protected final FBPooledConnection owner; protected volatile Connection connection; protected volatile Connection proxy; protected volatile boolean forcedClose; private final List<StatementHandler> openStatements = Collections.synchronizedList(new LinkedList<StatementHandler>()); - protected PooledConnectionHandler(Connection connection, AbstractPooledConnection owner) { + protected PooledConnectionHandler(Connection connection, FBPooledConnection owner) { this.connection = connection; this.owner = owner; proxy = (Connection) Proxy.newProxyInstance(getClass().getClassLoader(), Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -313,7 +313,7 @@ } /** - * Get class extending the {@link org.firebirdsql.jdbc.AbstractConnection} + * Get class extending the {@link org.firebirdsql.jdbc.FBConnection} * that will be instantiated when new connection is created. This method * finds the plugin for the specified type and delegates the call to it. * Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBLocalTransaction.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBLocalTransaction.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBLocalTransaction.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -24,7 +24,7 @@ import javax.transaction.xa.*; import org.firebirdsql.gds.GDSException; -import org.firebirdsql.jdbc.AbstractConnection; +import org.firebirdsql.jdbc.FBConnection; /** * The class <code>FBLocalTransaction</code> implements LocalTransaction both @@ -53,7 +53,7 @@ protected final ConnectionEvent rollbackEvent; // should be package!!! perhaps reorganize and eliminate jdbc!!! - public FBLocalTransaction(FBManagedConnection mc, AbstractConnection c) { + public FBLocalTransaction(FBManagedConnection mc, FBConnection c) { this.mc = mc; if (c == null) { beginEvent = null; Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -60,7 +60,7 @@ private final List<ConnectionEventListener> connectionEventListeners = new CopyOnWriteArrayList<ConnectionEventListener>(); // TODO Review synchronization of connectionHandles (especially in blocks like in disassociateConnections, setConnectionSharing etc) - private final List<AbstractConnection> connectionHandles = Collections.synchronizedList(new ArrayList<AbstractConnection>()); + private final List<FBConnection> connectionHandles = Collections.synchronizedList(new ArrayList<FBConnection>()); private int timeout = 0; @@ -202,7 +202,7 @@ "connection in non-sharing mode."); // there will be at most one connection. - for (AbstractConnection connection : connectionHandles) { + for (FBConnection connection : connectionHandles) { try { connection.setManagedEnvironment(managedEnvironment); } catch(SQLException ex) { @@ -214,7 +214,7 @@ /** * Check if connection sharing is enabled. When connection sharing is - * enabled, multiple connection handles ({@link AbstractConnection} instances) + * enabled, multiple connection handles ({@link FBConnection} instances) * can access this managed connection in thread-safe manner (they synchronize * on this instance). This feature can be enabled only in JCA environment, * any other environment must not use connection sharing. @@ -370,7 +370,7 @@ disassociateConnections(); try { - final AbstractConnection abstractConnection = (AbstractConnection) connection; + final FBConnection abstractConnection = (FBConnection) connection; abstractConnection.setManagedConnection(this); connectionHandles.add(abstractConnection); } catch (ClassCastException cce) { @@ -431,8 +431,8 @@ SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<SQLException>(); // Iterate over copy of list as connection.close() will remove connection - List<AbstractConnection> connectionHandleCopy = new ArrayList<AbstractConnection>(connectionHandles); - for (AbstractConnection connection : connectionHandleCopy) { + List<FBConnection> connectionHandleCopy = new ArrayList<FBConnection>(connectionHandles); + for (FBConnection connection : connectionHandleCopy) { try { connection.close(); } catch(SQLException sqlex) { @@ -489,7 +489,7 @@ if (!connectionSharing) disassociateConnections(); - AbstractConnection c = mcf.newConnection(this); + FBConnection c = mcf.newConnection(this); try { c.setManagedEnvironment(isManagedEnvironment()); connectionHandles.add(c); @@ -1149,7 +1149,7 @@ * @param c * The <code>AbstractConnection</code> that is being closed */ - public void close(AbstractConnection c) { + public void close(FBConnection c) { c.setManagedConnection(null); connectionHandles.remove(c); ConnectionEvent ce = new ConnectionEvent(this, Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -777,20 +777,20 @@ } } - AbstractConnection newConnection(FBManagedConnection mc) + FBConnection newConnection(FBManagedConnection mc) throws ResourceException { Class<?> connectionClass = GDSFactory.getConnectionClass(getGDSType()); - if (!AbstractConnection.class.isAssignableFrom(connectionClass)) + if (!FBConnection.class.isAssignableFrom(connectionClass)) throw new IllegalArgumentException("Specified connection class" - + " does not extend " + AbstractConnection.class.getName() + + " does not extend " + FBConnection.class.getName() + " class"); try { Constructor<?> constructor = connectionClass .getConstructor(new Class[] { FBManagedConnection.class}); - return (AbstractConnection) constructor + return (FBConnection) constructor .newInstance(new Object[] { mc}); } catch (NoSuchMethodException ex) { Deleted: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java 2012-10-13 08:49:06 UTC (rev 57241) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java 2012-10-13 09:32:31 UTC (rev 57242) @@ -1,1498 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver - * - * Distributable under LGPL license. - * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * LGPL License for more details. - * - * This file was created by members of the firebird development team. - * All individual contributions remain the Copyright (C) of those - * individuals. Contributors to this file are either listed here or - * can be obtained from a CVS history command. - * - * All rights reserved. - */ -package org.firebirdsql.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.*; -import java.sql.Date; -import java.util.*; - -import org.firebirdsql.gds.DatabaseParameterBuffer; -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.field.FBField; -import org.firebirdsql.jdbc.field.TypeConversionException; - -/** - * The interface used to execute SQL - * stored procedures. JDBC provides a stored procedure - * SQL escape syntax that allows stored procedures to be called in a standard - * way for all RDBMSs. This escape syntax has one form that includes - * a result parameter and one that does not. If used, the result - * parameter must be registered as an OUT parameter. The other parameters - * can be used for input, output or both. Parameters are referred to - * sequentially, by number, with the first parameter being 1. - * <P> - * <blockquote><pre> - * {?= call <procedure-name>[<arg1>,<arg2>, ...]} - * {call <procedure-name>[<arg1>,<arg2>, ...]} - * </pre></blockquote> - * <P> - * IN parameter values are set using the set methods inherited from - * {@link PreparedStatement}. The type of all OUT parameters must be - * registered prior to executing the stored procedure; their values - * are retrieved after execution via the <code>get</code> methods provided here. - * <P> - * A <code>CallableStatement</code> can return one {@link ResultSet} or - * multiple <code>ResultSet</code> objects. Multiple - * <code>ResultSet</code> objects are handled using operations - * inherited from {@link Statement}. - * <P> - * For maximum portability, a call's <code>ResultSet</code> objects and - * update counts should be processed prior to getting the values of output - * parameters. - * <P> - * Methods that are new in the JDBC 2.0 API are marked "Since 1.2." - * - * Note: Escape syntax currently is not supported. Please use native - * Firebird procedure call syntax: - * <pre> - * EXECUTE PROCEDURE <proc_name>(param1, ...); - * </pre> - * - * @see Connection#prepareCall - * @see ResultSet - * - * @author <a href="mailto:d_j...@us...">David Jencks</a> - * @author <a href="mailto:rro...@us...">Roman Rokytskyy</a> - * @author <a href="mailto:sja...@us...">Steven Jardine</a> - * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - */ -public abstract class AbstractCallableStatement extends FBPreparedStatement implements CallableStatement, FirebirdCallableStatement { - - static final String NATIVE_CALL_COMMAND = "EXECUTE PROCEDURE"; - static final String NATIVE_SELECT_COMMAND = "SELECT * FROM"; - - private ResultSet currentRs; - - protected boolean selectableProcedure; - - protected FBProcedureCall procedureCall; - - protected AbstractCallableStatement(GDSHelper c, String sql, int rsType, - int rsConcurrency, int rsHoldability, - StoredProcedureMetaData storedProcMetaData, - FBObjectListener.StatementListener statementListener, - FBObjectListener.BlobListener blobListener) - throws SQLException { - super(c, rsType, rsConcurrency, rsHoldability, statementListener, blobListener); - - DatabaseParameterBuffer dpb = c.getDatabaseParameterBuffer(); - - int mode = FBEscapedParser.USE_BUILT_IN; - - if (dpb.hasArgument(DatabaseParameterBufferExtension.USE_STANDARD_UDF)) - mode = FBEscapedParser.USE_STANDARD_UDF; - - FBEscapedCallParser parser = new FBEscapedCallParser(mode); - - // here statement is parsed twice, once in c.nativeSQL(...) - // and second time in parser.parseCall(...)... not nice, maybe - // in the future should be fixed by calling FBEscapedParser for - // each parameter in FBEscapedCallParser class - procedureCall = parser.parseCall(nativeSQL(sql)); - - if (storedProcMetaData.canGetSelectableInformation()) { - setSelectabilityAutomatically(storedProcMetaData); - } - } - - public ParameterMetaData getParameterMetaData() throws SQLException { - statementListener.executionStarted(this); - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - try { - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - } catch (GDSException ge) { - throw new FBSQLException(ge); - } - } - - return new FBParameterMetaData(fixedStmt.getInSqlda().sqlvar, gdsHelper); - } - - public void addBatch() throws SQLException { - batchList.add(procedureCall.clone()); - } - - public int[] executeBatch() throws SQLException { - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - boolean success = false; - try { - notifyStatementStarted(); - - List<Integer> results = new ArrayList<Integer>(batchList.size()); - Iterator<Object> iterator = batchList.iterator(); - - try { - while (iterator.hasNext()) { - procedureCall = (FBProcedureCall) iterator.next(); - executeSingleForBatch(results); - } - - success = true; - return toArray(results); - } finally { - clearBatch(); - } - } finally { - notifyStatementCompleted(success); - } - } - } - - private void executeSingleForBatch(List<Integer> results) throws SQLException { - /* - * TODO: array given to BatchUpdateException might not be JDBC-compliant - * (should set Statement.EXECUTE_FAILED and throwing it right away - * instead of continuing may fail intention) - */ - try { - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - - if (internalExecute(!isSelectableProcedure())) - throw new BatchUpdateException(toArray(results)); - - results.add(Integer.valueOf(getUpdateCount())); - } catch (GDSException ex) { - throw new BatchUpdateException(ex.getMessage(), "", ex.getFbErrorCode(), - toArray(results)); - } - } - - /* (non-Javadoc) - * @see org.firebirdsql.jdbc.FirebirdCallableStatement#setSelectableProcedure(boolean) - */ - public void setSelectableProcedure(boolean selectableProcedure) { - this.selectableProcedure = selectableProcedure; - } - - public boolean isSelectableProcedure() { - return selectableProcedure; - } - - /** - * Set required types for output parameters. - * - * @throws SQLException if something went wrong. - */ - protected void setRequiredTypes() throws SQLException { - FBResultSet resultSet = (FBResultSet) getCurrentResultSet(); - - for (FBProcedureParam param : procedureCall.getOutputParams()) { - if (param == null) - continue; - - FBField field = resultSet.getField( - procedureCall.mapOutParamIndexToPosition(param.getIndex()), - false); - - field.setRequiredType(param.getType()); - } - } - - /** - * We allow multiple calls to this method without re-preparing the statement. - * This is an workaround to the issue that the statement is actually prepared - * only after all OUT parameters are registered. - */ - protected void prepareFixedStatement(String sql, boolean describeBind) - throws GDSException, SQLException { - - if (fixedStmt != null) - return; - - super.prepareFixedStatement(sql, describeBind); - } - - /** - * Since we deferred the statement preparation until all OUT params are - * registered, we ensure that the statement is prepared before the meta - * data for the callable statement is obtained. - */ - public ResultSetMetaData getMetaData() throws SQLException { - - statementListener.executionStarted(this); - - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - try { - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - } catch (GDSException ge) { - throw new FBSQLException(ge); - } - } - - return super.getMetaData(); - } - - /** - * Executes an execute stored procedure. - * Some prepared statements return multiple results; the <code>execute</code> - * method handles these complex statements as well as the simpler - * form of statements handled by the methods <code>executeQuery</code> - * and <code>executeUpdate</code>. - * - * @exception SQLException if a database access error occurs - * @see Statement#execute - */ - public boolean execute() throws SQLException { - boolean hasResultSet = false; - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - notifyStatementStarted(); - - try { - currentRs = null; - - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - hasResultSet = internalExecute(!isSelectableProcedure()); - - if (hasResultSet) - setRequiredTypes(); - }catch (GDSException ge) { - throw new FBSQLException(ge); - } finally { - if (!hasResultSet) notifyStatementCompleted(); - } - - return hasResultSet; - } - - } - - /** - * Execute query. This method prepares statement before execution. Rest of - * the processing is done by superclass. - */ - public ResultSet executeQuery() throws SQLException { - - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - notifyStatementStarted(); - - try { - currentRs = null; - - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - - if (!internalExecute(!isSelectableProcedure())) - throw new FBSQLException( - "No resultset for sql", - FBSQLException.SQL_STATE_NO_RESULT_SET); - - getResultSet(); - - setRequiredTypes(); - - return getCurrentResultSet(); - - } catch (GDSException ex) { - throw new FBSQLException(ex); - } - } - } - - /** - * Execute query. This method prepares statement before execution. Rest of - * the processing is done by superclass. - */ - public int executeUpdate() throws SQLException { - Object syncObject = getSynchronizationObject(); - synchronized (syncObject) { - try { - notifyStatementStarted(); - - currentRs = null; - - prepareFixedStatement(procedureCall.getSQL(isSelectableProcedure()), true); - - /* - * // R.Rokytskyy: JDBC CTS suite uses executeUpdate() // - * together with output parameters, therefore we cannot // - * throw exception if we want to pass the test suite - * - * if (internalExecute(true)) throw new FBSQLException( - * "Update statement returned results."); - */ - - boolean hasResults = internalExecute(!isSelectableProcedure()); - - if (hasResults) { - setRequiredTypes(); - } - - return getUpdateCount(); - } catch (GDSException ex) { - throw new FBSQLException(ex); - } finally { - notifyStatementCompleted(); - } - } - } - - /** - * Execute statement internally. This method sets cached parameters. Rest of - * the processing is done by superclass. - */ - protected boolean internalExecute(boolean sendOutParams) throws SQLException { - - int counter = 0; - - for (FBProcedureParam param : procedureCall.getInputParams()) { - if (param != null && param.isParam()) { - - counter++; - - Object value = param.getValue(); - FBField field = getField(counter); - - if (value == null) - field.setNull(); - else if (value instanceof WrapperWithCalendar) { - setField(field, (WrapperWithCalendar)value); - } else if (value instanceof WrapperWithInt) { - setField(field, (WrapperWithInt)value); - } else - field.setObject(value); - - isParamSet[counter - 1] = true; - } - } - - return super.internalExecute(sendOutParams); - } - - private void setField(FBField field, WrapperWithInt value) throws SQLException { - Object obj = value.getValue(); - - if (obj == null) { - field.setNull(); - } else { - int intValue = value.getIntValue(); - - if (obj instanceof InputStream) - field.setBinaryStream((InputStream) obj, intValue); - else if (obj instanceof Reader) - field.setCharacterStream((Reader) obj, intValue); - else - throw new TypeConversionException("Cannot convert type " + obj.getClass().getName()); - } - } - - private void setField(FBField field, WrapperWithCalendar value) throws SQLException { - Object obj = value.getValue(); - - if (obj == null) { - field.setNull(); - } else { - Calendar cal = value.getCalendar(); - - if (obj instanceof Timestamp) - field.setTimestamp((Timestamp) obj, cal); - else if (obj instanceof java.sql.Date) - field.setDate((java.sql.Date) obj, cal); - else if (obj instanceof Time) - field.setTime((Time) obj, cal); - else - throw new TypeConversionException("Cannot convert type " + obj.getClass().getName()); - } - } - - /** - * Registers the OUT parameter in ordinal position - * <code>parameterIndex</code> to the JDBC type - * <code>sqlType</code>. All OUT parameters must be registered - * before a stored procedure is executed. - * <p> - * The JDBC type specified by <code>sqlType</code> for an OUT - * parameter determines the Java type that must be used - * in the <code>get</code> method to read the value of that parameter. - * <p> - * If the JDBC type expected to be returned to this output parameter - * is specific to this particular database, <code>sqlType</code> - * should be <code>java.sql.Types.OTHER</code>. The method - * {@link #getObject} retrieves the value. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>. - * If the parameter is of JDBC type <code>NUMERIC</code> - * or <code>DECIMAL</code>, the version of - * <code>registerOutParameter</code> that accepts a scale value - * should be used. - * @exception SQLException if a database access error occurs - * @see Types - */ - public void registerOutParameter(int parameterIndex, int sqlType) - throws SQLException - { - procedureCall.registerOutParam(parameterIndex, sqlType); - } - - /** - * Registers the parameter in ordinal position - * <code>parameterIndex</code> to be of JDBC type - * <code>sqlType</code>. This method must be called - * before a stored procedure is executed. - * <p> - * The JDBC type specified by <code>sqlType</code> for an OUT - * parameter determines the Java type that must be used - * in the <code>get</code> method to read the value of that parameter. - * <p> - * This version of <code>registerOutParameter</code> should be - * used when the parameter is of JDBC type <code>NUMERIC</code> - * or <code>DECIMAL</code>. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @param sqlType SQL type code defined by <code>java.sql.Types</code>. - * @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 - * @see Types - */ - public void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException - { - procedureCall.registerOutParam(parameterIndex, sqlType); - } - - /** - * Indicates whether or not the last OUT parameter read had the value of - * SQL <code>NULL</code>. Note that this method should be called only after - * calling a <code>getXXX</code> method; otherwise, there is no value to use in - * determining whether it is <code>null</code> or not. - * @return <code>true</code> if the last parameter read was SQL - * <code>NULL</code>; <code>false</code> otherwise - * @exception SQLException if a database access error occurs - */ - public boolean wasNull() throws SQLException { - assertHasData(getCurrentResultSet()); - return getCurrentResultSet().wasNull(); - } - - /** - * Retrieves the value of a JDBC <code>CHAR</code>, <code>VARCHAR</code>, - * or <code>LONGVARCHAR</code> parameter as a <code>String</code> in - * the Java programming language. - * <p> - * For the fixed-length type JDBC <code>CHAR</code>, - * the <code>String</code> object - * returned has exactly the same value the JDBC - * <code>CHAR</code> value had in the - * database, including any padding added by the database. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is <code>null</code>. - * @exception SQLException if a database access error occurs - */ - public String getString(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getString(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>BIT</code> parameter as a <code>boolean</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is <code>false</code>. - * @exception SQLException if a database access error occurs - */ - public boolean getBoolean(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getBoolean(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>TINYINT</code> parameter as a <code>byte</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public byte getByte(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getByte(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>SMALLINT</code> parameter as a <code>short</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public short getShort(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getShort(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>INTEGER</code> parameter as an <code>int</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public int getInt(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getInt(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>BIGINT</code> parameter as a <code>long</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public long getLong(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getLong(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>FLOAT</code> parameter as a <code>float</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public float getFloat(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getFloat(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>DOUBLE</code> parameter as a <code>double</code> - * in the Java programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is 0. - * @exception SQLException if a database access error occurs - */ - public double getDouble(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getDouble(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>NUMERIC</code> parameter as a - * <code>java.math.BigDecimal</code> object with scale digits to - * the right of the decimal point. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @param scale the number of digits to the right of the decimal point - * @return the parameter value. If the value is SQL <code>NULL</code>, the result is - * <code>null</code>. - * @exception SQLException if a database access error occurs - * @deprecated - */ - @Deprecated - public BigDecimal getBigDecimal(int parameterIndex, int scale) - throws SQLException - { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getBigDecimal(parameterIndex, scale); - } - - /** - * Gets the value of a JDBC <code>BINARY</code> or <code>VARBINARY</code> - * parameter as an array of <code>byte</code> values in the Java - * programming language. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result is - * <code>null</code>. - * @exception SQLException if a database access error occurs - */ - public byte[] getBytes(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getBytes(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>DATE</code> parameter as a - * <code>java.sql.Date</code> object. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is <code>null</code>. - * @exception SQLException if a database access error occurs - */ - public java.sql.Date getDate(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getDate(parameterIndex); - } - - /** - * Get the value of a JDBC <code>TIME</code> parameter as a - * <code>java.sql.Time</code> object. - * @param parameterIndex the first parameter is 1, the second is 2, - * and so on - * @return the parameter value. If the value is SQL <code>NULL</code>, the result - * is <code>null</code>. - * @exception SQLException if a database access error occurs - */ - public Time getTime(int parameterIndex) throws SQLException { - assertHasData(getCurrentResultSet()); - parameterIndex = procedureCall.mapOutParamIndexToPosition(parameterIndex); - return getCurrentResultSet().getTime(parameterIndex); - } - - /** - * Gets the value of a JDBC <code>TIMESTAMP</code> parameter as a - * <code>java.... [truncated message content] |
From: <mro...@us...> - 2012-11-03 16:42:40
|
Revision: 57299 http://firebird.svn.sourceforge.net/firebird/?rev=57299&view=rev Author: mrotteveel Date: 2012-11-03 16:42:32 +0000 (Sat, 03 Nov 2012) Log Message: ----------- JDBC-281: Fix for Exception when setting foreign Clob or Reader + other improvements / formatting fixes Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/FBBlob.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBClob.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBClob.java Added Paths: ----------- client-java/trunk/src/test/org/firebirdsql/jdbc/StringClob.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBBlob.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBBlob.java 2012-11-03 14:11:26 UTC (rev 57298) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBBlob.java 2012-11-03 16:42:32 UTC (rev 57299) @@ -16,7 +16,6 @@ * * All rights reserved. */ - package org.firebirdsql.jdbc; import java.io.*; @@ -52,7 +51,6 @@ * This class is new in the JDBC 2.0 API. * @since 1.2 */ - public class FBBlob implements FirebirdBlob, Synchronizable { public static final boolean SEGMENTED = true; @@ -421,7 +419,6 @@ throw new FBDriverNotCapableException(); } - /** * Determines the byte position in the <code>BLOB</code> value * designated by this <code>Blob</code> object at which @@ -441,7 +438,6 @@ throw new FBDriverNotCapableException(); } - //jdbc 3.0 additions /** @@ -510,7 +506,7 @@ "You can't start before the beginning of the blob", FBSQLException.SQL_STATE_INVALID_ARG_VALUE); - if ((isNew) && (pos > 1)) + if (isNew && pos > 1) throw new FBSQLException( "Previous value was null, you must start at position 1", FBSQLException.SQL_STATE_INVALID_ARG_VALUE); @@ -571,8 +567,8 @@ byte[] buffer = new byte[Math.min(bufferlength, length)]; int chunk; try { - while (length >0) { - chunk =inputStream.read(buffer, 0, ((length<bufferlength) ? length:bufferlength)); + while (length > 0) { + chunk = inputStream.read(buffer, 0, ((length < bufferlength) ? length : bufferlength)); if (chunk == -1) break; os.write(buffer, 0, chunk); @@ -621,7 +617,6 @@ public void copyCharacterStream(Reader inputStream, int length, String encoding) throws SQLException { OutputStream os = setBinaryStream(1); try { - OutputStreamWriter osw; if (encoding != null) osw = new OutputStreamWriter(os, encoding); @@ -631,10 +626,7 @@ char[] buffer = new char[Math.min(bufferlength, length)]; int chunk; try { - while (length >0) { - chunk =inputStream.read(buffer, 0, ((length<bufferlength) ? length:bufferlength)); - if (chunk == -1) - break; + while (length > 0 && (chunk = inputStream.read(buffer, 0, Math.min(buffer.length, length))) != -1) { osw.write(buffer, 0, chunk); length -= chunk; } @@ -652,8 +644,6 @@ ); } } - - } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBClob.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBClob.java 2012-11-03 14:11:26 UTC (rev 57298) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBClob.java 2012-11-03 16:42:32 UTC (rev 57299) @@ -16,7 +16,6 @@ * * All rights reserved. */ - package org.firebirdsql.jdbc; import java.io.IOException; @@ -110,12 +109,12 @@ } int n; char[] buffer = new char[1024]; - StringBuffer stringBuffer = new StringBuffer(); + StringBuilder sb = new StringBuilder(length); while (length > 0 && (n = reader.read(buffer, 0, Math.min(length, buffer.length))) != -1) { - stringBuffer.append(buffer, 0, Math.min(n, length)); + sb.append(buffer, 0, n); length -= n; } - return stringBuffer.toString(); + return sb.toString(); } catch (IOException e) { throw new FBSQLException(e); } finally { @@ -145,8 +144,7 @@ return new InputStreamReader(inputStream); } else { try { - return new InputStreamReader(wrappedBlob.getBinaryStream(), - encoding); + return new InputStreamReader(wrappedBlob.getBinaryStream(), encoding); } catch (IOException ioe) { throw new FBSQLException(ioe); } @@ -236,25 +234,12 @@ } - /** - * <b>This operation is not supported</b> - * - * @param param1 - * <description> - * @param param2 - * <description> - * @param param3 - * <description> - * @param param4 - * <description> - * @return <description> - * @exception java.sql.SQLException - * <description> + /* + * This operation is not supported */ public int setString(long param1, String param2, int param3, int param4) throws SQLException { throw new FBDriverNotCapableException(); - } /** @@ -280,8 +265,8 @@ * <description> */ public Writer setCharacterStream(long position) throws SQLException { - String encoding = wrappedBlob.gdsHelper.getJavaEncoding(); + // FIXME: This is wrong for multibyte charactersets; doesn't matter right now as setBinaryStream isn't implemented for position > 1 OutputStream outputStream = wrappedBlob.setBinaryStream(position); if (encoding == null) { return new OutputStreamWriter(outputStream); @@ -295,10 +280,11 @@ } public void free() throws SQLException { - this.wrappedBlob.free(); + wrappedBlob.free(); } public Reader getCharacterStream(long pos, long length) throws SQLException { + // FIXME: This is wrong for multibyte charactersets; doesn't matter right now as getBinaryStream isn't implemented InputStream inputStream = wrappedBlob.getBinaryStream(pos, length); String encoding = getWrappedBlob().gdsHelper.getJavaEncoding(); if (encoding == null) { @@ -313,8 +299,7 @@ } public void copyCharacterStream(Reader characterStream) throws SQLException { - - Writer writer = setCharacterStream(0); + Writer writer = setCharacterStream(1); try { int chunk = 0; char[] buffer = new char[1024]; @@ -327,13 +312,15 @@ } catch (IOException ioe) { throw new FBSQLException(ioe); } - } - - + /** + * Retrieves the FBBlob wrapped by this FBClob. + * + * @return FBBlob instance + * @throws SQLException + */ public FBBlob getWrappedBlob() throws SQLException { return wrappedBlob; } - } Added: client-java/trunk/src/test/org/firebirdsql/jdbc/StringClob.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/StringClob.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/StringClob.java 2012-11-03 16:42:32 UTC (rev 57299) @@ -0,0 +1,99 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.firebirdsql.jdbc; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.Writer; +import java.sql.Clob; +import java.sql.SQLException; + +/** + * Copied from Hibernate sources for testing purposes. + * + * @author Steve Ebersole + */ +public class StringClob implements Clob { + private final String value; + + public StringClob(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public long length() throws SQLException { + return value.length(); + } + + public String getSubString(long pos, int length) throws SQLException { + return value.substring( (int)pos, (int)(pos+length) ); + } + + public Reader getCharacterStream() throws SQLException { + return new StringReader( value ); + } + + public Reader getCharacterStream(long pos, long length) throws SQLException { + return new StringReader( getSubString( pos, (int)length ) ); + } + + public InputStream getAsciiStream() throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public long position(String searchstr, long start) throws SQLException { + return value.indexOf( searchstr, (int)start ); + } + + public long position(Clob searchstr, long start) throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public int setString(long pos, String str) throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public int setString(long pos, String str, int offset, int len) throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public OutputStream setAsciiStream(long pos) throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public Writer setCharacterStream(long pos) throws SQLException { + throw new UnsupportedOperationException( "not supported" ); + } + + public void truncate(long len) throws SQLException { + } + + public void free() throws SQLException { + } +} Property changes on: client-java/trunk/src/test/org/firebirdsql/jdbc/StringClob.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBClob.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBClob.java 2012-11-03 14:11:26 UTC (rev 57298) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBClob.java 2012-11-03 16:42:32 UTC (rev 57299) @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.sql.Clob; @@ -33,441 +34,410 @@ import java.sql.Statement; import java.util.Properties; +import org.firebirdsql.common.DdlHelper; import org.firebirdsql.common.FBTestBase; +import org.firebirdsql.common.JdbcResourceHelper; import static org.firebirdsql.common.FBTestProperties.*; public class TestFBClob extends FBTestBase { - private static final String PLAIN_BLOB = "plain_blob"; + private static final String PLAIN_BLOB = "plain_blob"; - private static final String TEXT_BLOB = "text_blob"; + private static final String TEXT_BLOB = "text_blob"; - private Connection connection; + public static final String CREATE_TABLE = + "CREATE TABLE test_clob(" + + " id INTEGER, " + + TEXT_BLOB + " BLOB SUB_TYPE TEXT, " + + PLAIN_BLOB + " BLOB )"; - public static final String CREATE_TABLE = "" + "CREATE TABLE test_clob(" - + " id INTEGER, " + TEXT_BLOB + " BLOB SUB_TYPE TEXT, " - + PLAIN_BLOB + " BLOB )"; + public static final String DROP_TABLE = "DROP TABLE test_clob"; - public static final String DROP_TABLE = "DROP TABLE test_clob"; + public static final byte[] LATIN1_BYTES = new byte[] { (byte) 0xC8, + (byte) 0xC9, (byte) 0xCA, (byte) 0xCB }; - public static final byte[] LATIN1_BYTES = new byte[] { (byte) 0xC8, - (byte) 0xC9, (byte) 0xCA, (byte) 0xCB }; + public static final byte[] CP1251_BYTES = new byte[] { (byte) 0xf2, + (byte) 0xe5, (byte) 0xf1, (byte) 0xf2, (byte) 0xee, (byte) 0xe2, + (byte) 0xe0, (byte) 0x20, (byte) 0xf1, (byte) 0xf2, (byte) 0xf0, + (byte) 0xb3, (byte) 0xf7, (byte) 0xea, (byte) 0xe0 }; - public static final byte[] CP1251_BYTES = new byte[] { (byte) 0xf2, - (byte) 0xe5, (byte) 0xf1, (byte) 0xf2, (byte) 0xee, (byte) 0xe2, - (byte) 0xe0, (byte) 0x20, (byte) 0xf1, (byte) 0xf2, (byte) 0xf0, - (byte) 0xb3, (byte) 0xf7, (byte) 0xea, (byte) 0xe0 }; + public static final String LATIN1_TEST_STRING; + public static final String CP1251_TEST_STRING; - public static final String LATIN1_TEST_STRING; - public static final String CP1251_TEST_STRING; + static { + try { + LATIN1_TEST_STRING = new String(LATIN1_BYTES, "ISO-8859-1"); + CP1251_TEST_STRING = new String(CP1251_BYTES, "Cp1251"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } - static { - try { - LATIN1_TEST_STRING = new String(LATIN1_BYTES, "ISO-8859-1"); - CP1251_TEST_STRING = new String(CP1251_BYTES, "Cp1251"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } + public TestFBClob(String name) { + super(name); + } - public TestFBClob(String name) { - super(name); - } + protected void setUp() throws Exception { + super.setUp(); + Connection con = getConnectionViaDriverManager(); + try { + DdlHelper.executeDropTable(con, DROP_TABLE); + DdlHelper.executeCreateTable(con, CREATE_TABLE); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - protected void setUp() throws Exception { - super.setUp(); - Class.forName(FBDriver.class.getName()); - connection = getConnectionViaDriverManager(); + public void testSimpleGetAsciiStream() throws SQLException { + Connection con = getConnectionViaDriverManager(); + try { + final String TEST_VALUE = "TEST_VALUE"; + addTestValues(con, 1, TEST_VALUE, PLAIN_BLOB); + String clobValue = null; + Statement stmt = con.createStatement(); - Statement stmt = connection.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB + " FROM test_clob"); + resultSet.next(); + Clob clob = resultSet.getClob(1); + InputStream inputStream = clob.getAsciiStream(); + clobValue = slurpString(inputStream); - try { - stmt.execute(DROP_TABLE); - } catch (SQLException sqle) { - // Ignore - } + assertEquals(TEST_VALUE, clobValue); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - stmt.execute(CREATE_TABLE); + public void testNullClob() throws SQLException { + Connection con = getConnectionViaDriverManager(); + try { + addTestValues(con, 1, null, PLAIN_BLOB); + Statement stmt = con.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB + " FROM test_clob"); + resultSet.next(); + Clob clob = resultSet.getClob(1); - stmt.close(); - } + assertNull(clob); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - protected void tearDown() throws Exception { + public void testCachedNullClob() throws SQLException { + Connection con = getConnectionViaDriverManager(); + try { + addTestValues(con, 1, null, PLAIN_BLOB); + PreparedStatement stmt = con.prepareStatement("SELECT " + PLAIN_BLOB + " FROM test_clob", + ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + ResultSet resultSet = stmt.executeQuery(); + resultSet.next(); + Clob clob = resultSet.getClob(1); + assertNull(clob); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - Statement stmt = connection.createStatement(); + public void testSimpleGetCharacterStream() throws Exception { + Connection con = getConnectionViaDriverManager(); + try { + final String TEST_VALUE = "TEST_STRING"; + addTestValues(con, 1, TEST_VALUE, PLAIN_BLOB); + Statement stmt = con.createStatement(); + String clobValue = null; + ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB + " FROM test_clob"); + resultSet.next(); + Clob clob = resultSet.getClob(1); + clobValue = slurpString(clob.getCharacterStream()); - try { - stmt.execute(DROP_TABLE); - } catch (SQLException sqle) { - // Ignore - } + assertEquals(TEST_VALUE, clobValue); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - connection.close(); - super.tearDown(); - } + public void testGetSubString() throws SQLException { + Connection con = getConnectionViaDriverManager(); + try { + final String TEST_VALUE = "TEST_STRING"; + addTestValues(con, 1, TEST_VALUE, PLAIN_BLOB); + Statement stmt = con.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB + " FROM test_clob"); + resultSet.next(); + Clob clob = resultSet.getClob(1); - public void testSimpleGetAsciiStream() throws SQLException { - final String TEST_VALUE = "TEST_VALUE"; - addTestValues(1, TEST_VALUE, PLAIN_BLOB); - String clobValue = null; - Statement stmt = connection.createStatement(); - try { - ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB - + " FROM test_clob"); - try { - resultSet.next(); - Clob clob = resultSet.getClob(1); - InputStream inputStream = clob.getAsciiStream(); - clobValue = slurpString(inputStream); - } finally { - resultSet.close(); - } - } finally { - stmt.close(); - } - assertEquals(TEST_VALUE, clobValue); - } + for (int start = 1; start <= TEST_VALUE.length(); start++) { + for (int length = 0; length <= TEST_VALUE.length() - (start - 1); length++) { + String clobValue = clob.getSubString(start, length); + assertEquals(TEST_VALUE.substring(start - 1, start - 1 + length), clobValue); + } + } + assertEquals(TEST_VALUE, clob.getSubString(1, TEST_VALUE.length() * 2)); + assertEquals("", clob.getSubString(1, 0)); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - public void testNullClob() throws SQLException { - addTestValues(1, null, PLAIN_BLOB); - Statement stmt = connection.createStatement(); - try { - ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB - + " FROM test_clob"); - try { - resultSet.next(); - Clob clob = resultSet.getClob(1); - assertNull(clob); - } finally { - resultSet.close(); - } - } finally { - stmt.close(); - } - } + public void testReadMultiByteCharacterClobUtfLatin1() throws Exception { + runMultibyteReadTest(LATIN1_TEST_STRING, "UNICODE_FSS", TEXT_BLOB, "UTF-8"); + } - public void testCachedNullClob() throws SQLException { - addTestValues(1, null, PLAIN_BLOB); - PreparedStatement stmt = connection.prepareStatement( - "SELECT " + PLAIN_BLOB + " FROM test_clob", - ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); - try { - ResultSet resultSet = stmt.executeQuery(); - try { - resultSet.next(); - Clob clob = resultSet.getClob(1); - assertNull(clob); - } finally { - resultSet.close(); - } - } finally { - stmt.close(); - } - } + public void testReadMultiByteCharacterClobUtfCp1251() throws Exception { + runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); + } - public void testSimpleGetCharacterStream() throws Exception { + public void testReadMultiByteCharacterClobNoSubtypeUtfLatin1() throws Exception { + runMultibyteReadTest(LATIN1_TEST_STRING, "UNICODE_FSS", PLAIN_BLOB, "UTF-8"); + } - final String TEST_VALUE = "TEST_STRING"; - addTestValues(1, TEST_VALUE, PLAIN_BLOB); - Statement stmt = connection.createStatement(); - String clobValue = null; - try { - ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB - + " FROM test_clob"); - try { - resultSet.next(); - Clob clob = resultSet.getClob(1); - clobValue = slurpString(clob.getCharacterStream()); - } finally { - resultSet.close(); - } - } finally { - stmt.close(); - } - assertEquals(TEST_VALUE, clobValue); - } + public void testReadMultiByteCharacterClobNoSubtypeUtfCp1251() throws Exception { + runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, "Cp1251"); + } - public void testGetSubString() throws SQLException { - final String TEST_VALUE = "TEST_STRING"; - addTestValues(1, TEST_VALUE, PLAIN_BLOB); - Statement stmt = connection.createStatement(); - try { - ResultSet resultSet = stmt.executeQuery("SELECT " + PLAIN_BLOB - + " FROM test_clob"); - try { - resultSet.next(); - Clob clob = resultSet.getClob(1); + public void testReadMultiByteCharacterClobLatin1() throws Exception { + runMultibyteReadTest(LATIN1_TEST_STRING, "ISO8859_1", TEXT_BLOB, "ISO-8859-1"); + } - for (int start = 1; start <= TEST_VALUE.length(); start++) { - for (int length = 0; length <= TEST_VALUE.length() - - (start - 1); length++) { - String clobValue = clob.getSubString(start, length); - assertEquals(TEST_VALUE.substring(start - 1, start - 1 - + length), clobValue); - } - } - assertEquals(TEST_VALUE, clob.getSubString(1, TEST_VALUE - .length() * 2)); - assertEquals("", clob.getSubString(1, 0)); - } finally { - resultSet.close(); - } - } finally { - stmt.close(); - } - } + public void testReadMultiByteCharacterClobCp1251() throws Exception { + runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); + } - public void testReadMultiByteCharacterClobUtfLatin1() throws Exception { - runMultibyteReadTest(LATIN1_TEST_STRING, "UNICODE_FSS", TEXT_BLOB, - "UTF-8"); - } + public void testReadMultiByteCharacterClobNoSubtypeLatin1() throws Exception { + runMultibyteReadTest(LATIN1_TEST_STRING, "ISO8859_1", PLAIN_BLOB, "ISO-8859-1"); + } - public void testReadMultiByteCharacterClobUtfCp1251() throws Exception { - runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); - } + public void testReadMultiByteCharacterClobNoSubtypeCp1251() throws Exception { + runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, "Cp1251"); + } - public void testReadMultiByteCharacterClobNoSubtypeUtfLatin1() - throws Exception { - runMultibyteReadTest(LATIN1_TEST_STRING, "UNICODE_FSS", PLAIN_BLOB, - "UTF-8"); - } + private void runMultibyteReadTest(String testString, String fbEncoding, String colName, String javaEncoding) + throws Exception, SQLException, IOException { - public void testReadMultiByteCharacterClobNoSubtypeUtfCp1251() - throws Exception { - runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, - "Cp1251"); - } + Connection con = getEncodedConnection(fbEncoding); + try { + insertStringBytesViaBlobWithEncoding(con, testString, colName, javaEncoding); + char[] buffer = readClobViaCharacterStream(con, colName, testString.length()); + String outputString = new String(buffer); - public void testReadMultiByteCharacterClobLatin1() throws Exception { - runMultibyteReadTest(LATIN1_TEST_STRING, "ISO8859_1", TEXT_BLOB, - "ISO-8859-1"); - } + assertEquals(testString, outputString); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - public void testReadMultiByteCharacterClobCp1251() throws Exception { - runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); - } + public void testWriteMultiByteCharacterClobUtfLatin1() throws Exception { + runMultibyteWriteTest(LATIN1_TEST_STRING, "UNICODE_FSS", TEXT_BLOB, "UTF-8"); + } - public void testReadMultiByteCharacterClobNoSubtypeLatin1() - throws Exception { - runMultibyteReadTest(LATIN1_TEST_STRING, "ISO8859_1", PLAIN_BLOB, - "ISO-8859-1"); - } + public void testWriteMultiByteCharacterClobUtfCp1251() throws Exception { + runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); + } - public void testReadMultiByteCharacterClobNoSubtypeCp1251() - throws Exception { - runMultibyteReadTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, - "Cp1251"); - } + public void testWriteMultiByteCharacterClobPlainBlobUtfLatin1() throws Exception { + runMultibyteWriteTest(LATIN1_TEST_STRING, "UNICODE_FSS", PLAIN_BLOB, "UTF-8"); + } - private void runMultibyteReadTest(String testString, String fbEncoding, - String colName, String javaEncoding) throws Exception, - SQLException, IOException { + public void testWriteMultiByteCharacterClobPlainBlobUtfCp1251() throws Exception { + runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, "Cp1251"); + } - insertStringBytesViaBlobWithEncoding(testString, colName, javaEncoding, - fbEncoding); - char[] buffer = readClobViaCharacterStream(fbEncoding, colName, - testString.length()); - String outputString = new String(buffer); + public void testWriteMultiByteCharacterClobLatin1() throws Exception { + runMultibyteWriteTest(LATIN1_TEST_STRING, "ISO8859_1", TEXT_BLOB, "ISO-8859-1"); + } - assertEquals(testString, outputString); - } + public void testWriteMultiByteCharacterClobCp1251() throws Exception { + runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, "Cp1251"); + } - public void testWriteMultiByteCharacterClobUtfLatin1() throws Exception { - runMultibyteWriteTest(LATIN1_TEST_STRING, "UNICODE_FSS", TEXT_BLOB, - "UTF-8"); - } + public void testWriteMultiByteCharacterClobPlainBlobLatin1() throws Exception { + runMultibyteWriteTest(LATIN1_TEST_STRING, "ISO8859_1", PLAIN_BLOB, "ISO-8859-1"); + } - public void testWriteMultiByteCharacterClobUtfCp1251() throws Exception { - runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, - "Cp1251"); - } + public void testWriteMultiByteCharacterClobPlainBlobCp1251() throws Exception { + runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, "Cp1251"); + } - public void testWriteMultiByteCharacterClobPlainBlobUtfLatin1() - throws Exception { - runMultibyteWriteTest(LATIN1_TEST_STRING, "UNICODE_FSS", PLAIN_BLOB, - "UTF-8"); - } + public void testHoldableClobFromPlainBlob() throws Exception { + runHoldableClobTest(PLAIN_BLOB, LATIN1_TEST_STRING, "UTF-8", "UNICODE_FSS"); + } - public void testWriteMultiByteCharacterClobPlainBlobUtfCp1251() - throws Exception { - runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, - "Cp1251"); - } + public void testHoldableClobFromBlobSubtypeText() throws Exception { + runHoldableClobTest(TEXT_BLOB, LATIN1_TEST_STRING, "ISO-8859-1", "ISO8859_1"); + } - public void testWriteMultiByteCharacterClobLatin1() throws Exception { - runMultibyteWriteTest(LATIN1_TEST_STRING, "ISO8859_1", TEXT_BLOB, - "ISO-8859-1"); - } + public void testWriteClobUsingReader() throws Exception { + Connection con = getEncodedConnection("ISO8859_1"); + try { + PreparedStatement insertStmt = con.prepareStatement("INSERT INTO test_clob (" + TEXT_BLOB + ") VALUES (?)"); - public void testWriteMultiByteCharacterClobCp1251() throws Exception { - runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", TEXT_BLOB, - "Cp1251"); - } + insertStmt.setClob(1, new StringReader(LATIN1_TEST_STRING)); + insertStmt.execute(); + insertStmt.close(); - public void testWriteMultiByteCharacterClobPlainBlobLatin1() - throws Exception { - runMultibyteWriteTest(LATIN1_TEST_STRING, "ISO8859_1", PLAIN_BLOB, - "ISO-8859-1"); - } + PreparedStatement selStatement = con.prepareStatement("SELECT " + TEXT_BLOB + " FROM test_clob"); + ResultSet rs = selStatement.executeQuery(); - public void testWriteMultiByteCharacterClobPlainBlobCp1251() - throws Exception { - runMultibyteWriteTest(CP1251_TEST_STRING, "WIN1251", PLAIN_BLOB, - "Cp1251"); - } + if (rs.next()) { + String result = rs.getString(1); + assertEquals("Unexpected value for clob roundtrip", LATIN1_TEST_STRING, result); + } else { + fail("Expected a row"); + } + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } + + public void testWriteClobUsingNonFBClob() throws Exception { + Connection con = getEncodedConnection("ISO8859_1"); + try { + PreparedStatement insertStmt = con.prepareStatement("INSERT INTO test_clob (" + TEXT_BLOB + ") VALUES (?)"); - public void testHoldableClobFromPlainBlob() throws Exception { - runHoldableClobTest(PLAIN_BLOB, LATIN1_TEST_STRING, "UTF-8", - "UNICODE_FSS"); - } + insertStmt.setClob(1, new StringClob(LATIN1_TEST_STRING)); + insertStmt.execute(); + insertStmt.close(); - public void testHoldableClobFromBlobSubtypeText() throws Exception { - runHoldableClobTest(TEXT_BLOB, LATIN1_TEST_STRING, "ISO-8859-1", - "ISO8859_1"); - } + PreparedStatement selStatement = con.prepareStatement("SELECT " + TEXT_BLOB + " FROM test_clob"); + ResultSet rs = selStatement.executeQuery(); - private void runHoldableClobTest(String colName, String testString, - String javaEncoding, String fbEncoding) throws Exception, - SQLException, IOException { - insertStringBytesViaBlobWithEncoding(testString, colName, javaEncoding, - fbEncoding); + if (rs.next()) { + String result = rs.getString(1); + assertEquals("Unexpected value for clob roundtrip", LATIN1_TEST_STRING, result); + } else { + fail("Expected a row"); + } + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - Connection unicodeConnection = getEncodedConnection(fbEncoding); - PreparedStatement stmt = unicodeConnection.prepareStatement("SELECT " - + colName + " FROM test_clob", ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); - ResultSet resultSet = stmt.executeQuery(); - resultSet.next(); - Clob clob = resultSet.getClob(1); - resultSet.close(); - stmt.close(); - unicodeConnection.close(); + private void runHoldableClobTest(String colName, String testString, String javaEncoding, String fbEncoding) + throws Exception, SQLException, IOException { - Reader reader = clob.getCharacterStream(); - char[] buffer = new char[testString.length()]; - reader.read(buffer); - reader.close(); + Connection con = getEncodedConnection(fbEncoding); + try { + insertStringBytesViaBlobWithEncoding(con, testString, colName, javaEncoding); + PreparedStatement stmt = con.prepareStatement("SELECT " + colName + " FROM test_clob", + ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + ResultSet resultSet = stmt.executeQuery(); + resultSet.next(); + Clob clob = resultSet.getClob(1); + resultSet.close(); + stmt.close(); + con.close(); - assertEquals(testString, new String(buffer)); - } + Reader reader = clob.getCharacterStream(); + char[] buffer = new char[testString.length()]; + reader.read(buffer); + reader.close(); - private void runMultibyteWriteTest(String testString, String fbEncoding, - String colName, String javaEncoding) throws SQLException, - IOException, UnsupportedEncodingException { + assertEquals(testString, new String(buffer)); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - insertStringViaClobCharacterStream(testString, fbEncoding, colName); + private void runMultibyteWriteTest(String testString, String fbEncoding, String colName, String javaEncoding) + throws SQLException, IOException, UnsupportedEncodingException { - String selectString = readStringViaGetBytes(colName, javaEncoding); + Connection con = getEncodedConnection(fbEncoding); + try { + insertStringViaClobCharacterStream(con, testString, colName); - assertEquals(testString, selectString); - } + String selectString = readStringViaGetBytes(con, colName, javaEncoding); - private String readStringViaGetBytes(String colName, String javaEncoding) - throws SQLException, UnsupportedEncodingException { - PreparedStatement selectStmt = connection.prepareStatement("SELECT " - + colName + " FROM test_clob"); - ResultSet resultSet = selectStmt.executeQuery(); - resultSet.next(); - byte[] byteBuffer = resultSet.getBytes(1); - String selectString = new String(byteBuffer, javaEncoding); - resultSet.close(); - selectStmt.close(); - return selectString; - } + assertEquals(testString, selectString); + } finally { + JdbcResourceHelper.closeQuietly(con); + } + } - private void insertStringViaClobCharacterStream(String testString, - String fbEncoding, String colName) throws SQLException, IOException { - FBConnection unicodeConnection = getEncodedConnection(fbEncoding); - PreparedStatement insertStmt = unicodeConnection - .prepareStatement("INSERT INTO test_clob (" + colName - + ") VALUES (?)"); - Clob insertClob = unicodeConnection.createClob(); - Writer writer = insertClob.setCharacterStream(1); - writer.write(testString.toCharArray()); - writer.close(); - insertStmt.setClob(1, insertClob); - insertStmt.execute(); - unicodeConnection.close(); - } + private String readStringViaGetBytes(Connection con, String colName, String javaEncoding) throws SQLException, + UnsupportedEncodingException { + PreparedStatement selectStmt = con.prepareStatement("SELECT " + colName + " FROM test_clob"); + ResultSet resultSet = selectStmt.executeQuery(); + resultSet.next(); + byte[] byteBuffer = resultSet.getBytes(1); + String selectString = new String(byteBuffer, javaEncoding); + resultSet.close(); + selectStmt.close(); + return selectString; + } - private char[] readClobViaCharacterStream(String fbEncoding, - String colName, int expectedLength) throws SQLException, - IOException { - Connection unicodeConnection = getEncodedConnection(fbEncoding); - PreparedStatement selectStmt = unicodeConnection - .prepareStatement("SELECT " + colName + " FROM test_clob"); - ResultSet resultSet = selectStmt.executeQuery(); - resultSet.next(); + private void insertStringViaClobCharacterStream(Connection con, String testString, String colName) + throws SQLException, IOException { + PreparedStatement insertStmt = con.prepareStatement("INSERT INTO test_clob (" + colName + ") VALUES (?)"); + Clob insertClob = con.createClob(); + Writer writer = insertClob.setCharacterStream(1); + writer.write(testString.toCharArray()); + writer.close(); + insertStmt.setClob(1, insertClob); + insertStmt.execute(); + } - Clob clob = resultSet.getClob(1); - Reader reader = clob.getCharacterStream(); - char[] buffer = new char[expectedLength]; - reader.read(buffer); - reader.close(); - selectStmt.close(); - unicodeConnection.close(); - return buffer; - } + private char[] readClobViaCharacterStream(Connection con, String colName, int expectedLength) throws SQLException, + IOException { + PreparedStatement selectStmt = con.prepareStatement("SELECT " + colName + " FROM test_clob"); + ResultSet resultSet = selectStmt.executeQuery(); + resultSet.next(); - private void insertStringBytesViaBlobWithEncoding(String insertString, - String colName, String javaEncoding, String connEncoding) - throws Exception { - Connection localConnection = getEncodedConnection(connEncoding); + Clob clob = resultSet.getClob(1); + Reader reader = clob.getCharacterStream(); + char[] buffer = new char[expectedLength]; + reader.read(buffer); + reader.close(); + selectStmt.close(); + return buffer; + } - PreparedStatement insertStmt = localConnection - .prepareStatement("INSERT INTO test_clob (" + colName - + ") VALUES (?)"); + private void insertStringBytesViaBlobWithEncoding(Connection con, String insertString, String colName, + String javaEncoding) throws Exception { + PreparedStatement insertStmt = con.prepareStatement("INSERT INTO test_clob (" + colName + ") VALUES (?)"); - byte[] bytes = insertString.getBytes(javaEncoding); - insertStmt.setBytes(1, bytes); + byte[] bytes = insertString.getBytes(javaEncoding); + insertStmt.setBytes(1, bytes); - insertStmt.execute(); - insertStmt.close(); - localConnection.close(); - } + insertStmt.execute(); + insertStmt.close(); + } - private FBConnection getEncodedConnection(String encoding) - throws SQLException { - Properties props = new Properties(); - props.putAll(getDefaultPropertiesForConnection()); - props.put("lc_ctype", encoding); - Connection connection = DriverManager.getConnection(getUrl(), props); - return (FBConnection) connection; - } + private FBConnection getEncodedConnection(String encoding) throws SQLException { + Properties props = new Properties(); + props.putAll(getDefaultPropertiesForConnection()); + props.put("lc_ctype", encoding); + Connection connection = DriverManager.getConnection(getUrl(), props); + return (FBConnection) connection; + } - private String slurpString(InputStream inputStream) { - return slurpString(new InputStreamReader(inputStream)); - } + private String slurpString(InputStream inputStream) { + return slurpString(new InputStreamReader(inputStream)); + } - private String slurpString(Reader reader) { - StringBuffer stringBuffer = new StringBuffer(); - char[] buffer = new char[1028]; - int n = 0; - try { - while ((n = reader.read(buffer)) != -1) { - stringBuffer.append(new String(buffer, 0, n)); - } - reader.close(); - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - return stringBuffer.toString(); - } + private String slurpString(Reader reader) { + StringBuilder sb = new StringBuilder(); + char[] buffer = new char[1024]; + int n = 0; + try { + while ((n = reader.read(buffer)) != -1) { + sb.append(buffer, 0, n); + } + reader.close(); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + return sb.toString(); + } - private void addTestValues(int id, String value, String colName) - throws SQLException { - PreparedStatement stmt = connection - .prepareStatement("INSERT INTO test_clob (id, " + colName - + ") VALUES (?, ?)"); - try { - stmt.setInt(1, id); - stmt.setString(2, value); - stmt.execute(); - } finally { - stmt.close(); - } - } - + private void addTestValues(Connection con, int id, String value, String colName) throws SQLException { + PreparedStatement stmt = con.prepareStatement("INSERT INTO test_clob (id, " + colName + ") VALUES (?, ?)"); + try { + stmt.setInt(1, id); + stmt.setString(2, value); + stmt.execute(); + } finally { + stmt.close(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-04 13:23:17
|
Revision: 57308 http://firebird.svn.sourceforge.net/firebird/?rev=57308&view=rev Author: mrotteveel Date: 2012-11-04 13:23:09 +0000 (Sun, 04 Nov 2012) Log Message: ----------- Cleanup IscDbHandle implementations and usage (step towards using interfaces wherever possible) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/GDSException.java client-java/trunk/src/main/org/firebirdsql/gds/IscDbHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscDbHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_db_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_db_handle_impl.java client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/GDSException.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/GDSException.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/GDSException.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -25,6 +25,8 @@ package org.firebirdsql.gds; +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; + /** * A GDS-specific exception * @@ -35,6 +37,9 @@ private static final long serialVersionUID = -2993273656432230359L; + private static final AtomicReferenceFieldUpdater<GDSException,GDSException> nextUpdater = + AtomicReferenceFieldUpdater.newUpdater(GDSException.class, GDSException.class, "next"); + private final int type; private final int intParam; private final String strParam; @@ -53,7 +58,7 @@ /** * My child */ - private GDSException next; + private volatile GDSException next; /** * Factory method to create a new instance with a given <code>XA</code> @@ -206,7 +211,19 @@ * @param e The next chained exception */ public void setNext(GDSException e) { - next = e; + GDSException current = this; + for(;;) { + GDSException next = current.next; + if (next != null) { + current = next; + continue; + } + + if (nextUpdater.compareAndSet(current, null, e)) { + return; + } + current = current.next; + } } /** Modified: client-java/trunk/src/main/org/firebirdsql/gds/IscDbHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/IscDbHandle.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/IscDbHandle.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -145,5 +145,7 @@ * <code>false</code> otherwise */ boolean isValid(); + + void invalidate() throws Exception; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscDbHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscDbHandle.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscDbHandle.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -37,6 +37,7 @@ import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.IscDbHandle; +import org.firebirdsql.gds.IscTrHandle; /** @@ -57,18 +58,12 @@ private GDSServerVersion serverVersion; private int ODSMajorVersion; private int ODSMinorVersion; - private int resp_object; - private byte[] resp_data; - protected final Collection<AbstractIscTrHandle> rdb_transactions = Collections.synchronizedList(new ArrayList<AbstractIscTrHandle>()); + protected final Collection<IscTrHandle> rdb_transactions = Collections.synchronizedList(new ArrayList<IscTrHandle>()); private long resp_blob_id; protected AbstractIscDbHandle() { } - protected AbstractIscDbHandle(byte[] defaultResp_data) { - resp_data = defaultResp_data; - } - public int getDatabaseProductMajorVersion() { return serverVersion.getMajorVersion(); } @@ -169,30 +164,14 @@ rdb_warnings.clear(); } - public void setResp_object(int value) { - resp_object = value; - } - - public int getResp_object() { - return resp_object; - } - - public void setResp_data(byte[] value) { - resp_data = value; - } - - public byte[] getResp_data() { - return resp_data; - } - public boolean hasTransactions() { checkValidity(); return !rdb_transactions.isEmpty(); } - public Collection<AbstractIscTrHandle> getTransactions() { + public Collection<IscTrHandle> getTransactions() { synchronized (rdb_transactions) { - return new ArrayList<AbstractIscTrHandle>(rdb_transactions); + return new ArrayList<IscTrHandle>(rdb_transactions); } } @@ -212,5 +191,15 @@ protected final synchronized void invalidateHandle() { invalid = true; } + + public void addTransaction(IscTrHandle tr) { + checkValidity(); + rdb_transactions.add(tr); + } + + public void removeTransaction(IscTrHandle tr) { + checkValidity(); + rdb_transactions.remove(tr); + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -25,6 +25,7 @@ import org.firebirdsql.encodings.EncodingFactory; import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.AbstractGDS; +import org.firebirdsql.gds.impl.AbstractIscDbHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; import org.firebirdsql.gds.impl.GDSType; @@ -32,6 +33,9 @@ import org.firebirdsql.logging.LoggerFactory; public abstract class BaseGDSImpl extends AbstractGDS { + + // TODO Synchronization seems to be inconsistent: sometimes on dbhandle, sometimes on this (and soemtimes on blobhandle) + // TODO Checking for validity of dbhandle is inconsistent (sometimes only null check, sometimes also .isValid()) private static Logger log = LoggerFactory.getLogger(BaseGDSImpl.class, false); @@ -161,13 +165,13 @@ // --------------------------------------------------------------------------------------------- public void iscCloseBlob(IscBlobHandle blob_handle) throws GDSException { isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - isc_db_handle_impl db = blob.getDb(); + IscDbHandle db = blob.getDb(); if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } isc_tr_handle_impl tr = blob.getTr(); if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - synchronized (((isc_blob_handle_impl) blob_handle).getDb()) { + synchronized (db) { native_isc_close_blob(blob_handle); } @@ -180,7 +184,7 @@ isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -205,7 +209,7 @@ throw new GDSException(ISCConstants.isc_bad_trans_handle); } isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -229,7 +233,7 @@ public void iscCreateBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; + AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; @@ -306,15 +310,16 @@ // isc_detach_database // --------------------------------------------------------------------------------------------- public void iscDetachDatabase(IscDbHandle db_handle) throws GDSException { - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } + if (db_handle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } synchronized (this) { -// if (db.hasTransactions()) { throw new GDSException( -// ISCConstants.isc_open_trans, db.getOpenTransactionCount()); } - native_isc_detach_database(db_handle); - ((isc_db_handle_impl) db_handle).invalidate(); + try { + db_handle.invalidate(); + } catch (Exception e) { + // Actual implementation does not throw exception + throw new GDSException(ISCConstants.isc_network_error); + } } } @@ -333,7 +338,6 @@ // --------------------------------------------------------------------------------------------- public void iscDsqlAllocateStatement(IscDbHandle db_handle, IscStmtHandle stmt_handle) throws GDSException { - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; if (db_handle == null) { throw new GDSException( @@ -342,10 +346,10 @@ if (stmt_handle == null) { throw new GDSException( ISCConstants.isc_bad_req_handle); } - synchronized (db) { + synchronized (db_handle) { native_isc_dsql_allocate_statement(db_handle, stmt_handle); - stmt.setRsr_rdb((isc_db_handle_impl) db_handle); + stmt.setRsr_rdb((AbstractIscDbHandle) db_handle); stmt.setAllRowsFetched(false); } } @@ -500,7 +504,7 @@ } isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - isc_db_handle_impl db = stmt.getRsr_rdb(); + IscDbHandle db = stmt.getRsr_rdb(); synchronized (db) { // Apply fetchSize @@ -532,7 +536,7 @@ throw new GDSException(ISCConstants.isc_bad_req_handle); } isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - isc_db_handle_impl db = stmt.getRsr_rdb(); + IscDbHandle db = stmt.getRsr_rdb(); synchronized (db) { // Does not seem to be possible or necessary to close @@ -572,7 +576,7 @@ throw new GDSException(ISCConstants.isc_bad_req_handle); } isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - isc_db_handle_impl db = stmt.getRsr_rdb(); + IscDbHandle db = stmt.getRsr_rdb(); synchronized (db) { stmt.setInSqlda(null); @@ -658,7 +662,7 @@ } isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - isc_db_handle_impl db = stmt.getRsr_rdb(); + IscDbHandle db = stmt.getRsr_rdb(); synchronized (db) { native_isc_dsql_set_cursor_name(stmt_handle, cursor_name, type); @@ -695,7 +699,7 @@ public void iscOpenBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; + AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; @@ -725,7 +729,7 @@ isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + AbstractIscDbHandle db = (AbstractIscDbHandle) tr.getDbHandle(); synchronized (db) { if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( @@ -745,7 +749,7 @@ isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + IscDbHandle db = tr.getDbHandle(); synchronized (db) { if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( @@ -787,7 +791,7 @@ tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); native_isc_reconnect_transaction(db_handle, tr_handle, buffer); - tr.setDbHandle((isc_db_handle_impl) db_handle); + tr.setDbHandle((AbstractIscDbHandle) db_handle); tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); } @@ -799,7 +803,7 @@ isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -822,7 +826,7 @@ isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; if (tr == null) { throw new GDSException( ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -924,7 +928,7 @@ IscDbHandle db_handle, TransactionParameterBuffer tpb) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; + IscDbHandle db = db_handle; TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; if (tr == null) { throw new GDSException( @@ -945,7 +949,7 @@ byte[] arg = tpbImpl.getBytesForNativeCode(); native_isc_start_transaction(tr_handle, db_handle, arg); - tr.setDbHandle((isc_db_handle_impl) db_handle); + tr.setDbHandle((AbstractIscDbHandle) db_handle); tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); } @@ -1134,7 +1138,7 @@ int value = 0; int len = 0; int i = 0; - isc_db_handle_impl db = (isc_db_handle_impl) handle; + IscDbHandle db = handle; while (info[i] != ISCConstants.isc_info_end) { switch (info[i++]) { case ISCConstants.isc_info_db_sql_dialect: @@ -1359,8 +1363,7 @@ public void fbCancelOperation(IscDbHandle dbHandle, int kind) throws GDSException { - isc_db_handle_impl db = (isc_db_handle_impl) dbHandle; - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } + if (dbHandle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } synchronized (this) { native_fb_cancel_operation(dbHandle, kind); Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -20,6 +20,7 @@ package org.firebirdsql.gds.impl.jni; import org.firebirdsql.gds.*; +import org.firebirdsql.gds.impl.AbstractIscDbHandle; /** * Describe class <code>isc_blob_handle_impl</code> here. @@ -29,7 +30,7 @@ */ public final class isc_blob_handle_impl implements IscBlobHandle { - private isc_db_handle_impl db; + private AbstractIscDbHandle db; private isc_tr_handle_impl tr; @@ -54,11 +55,11 @@ tr = value; } - public isc_db_handle_impl getDb() { + public AbstractIscDbHandle getDb() { return db; } - public void setDb(isc_db_handle_impl value) { + public void setDb(AbstractIscDbHandle value) { db = value; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_db_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_db_handle_impl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_db_handle_impl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -37,29 +37,8 @@ * @version 1.0 */ public final class isc_db_handle_impl extends AbstractIscDbHandle { - - private int rdb_id_ptr; - - protected void invalidate() { + + public void invalidate() throws Exception { invalidateHandle(); } - - void setRdb_id_ptr(int rdb_id_ptr, int value) { - setRdbId(value); - this.rdb_id_ptr = rdb_id_ptr; - } - - public int getRdb_id_ptr() { - return rdb_id_ptr; - } - - void addTransaction(isc_tr_handle_impl tr) { - checkValidity(); - rdb_transactions.add(tr); - } - - void removeTransaction(isc_tr_handle_impl tr) { - checkValidity(); - rdb_transactions.remove(tr); - } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -28,6 +28,7 @@ import org.firebirdsql.gds.XSQLDA; import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.impl.AbstractIscDbHandle; import org.firebirdsql.gds.impl.AbstractIscStmtHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; @@ -42,7 +43,7 @@ private int rsr_id; private int rsr_id_ptr = 0; - private isc_db_handle_impl rsr_rdb; + private AbstractIscDbHandle rsr_rdb; private XSQLDA in_sqlda = null; private XSQLDA out_sqlda = null; private byte[][][] rows; @@ -169,11 +170,11 @@ this.rsr_id_ptr = rsr_id_ptr; } - public isc_db_handle_impl getRsr_rdb() { + public AbstractIscDbHandle getRsr_rdb() { return rsr_rdb; } - public void setRsr_rdb(isc_db_handle_impl value) { + public void setRsr_rdb(AbstractIscDbHandle value) { rsr_rdb = value; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -27,6 +27,7 @@ import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.impl.AbstractIscDbHandle; import org.firebirdsql.gds.impl.AbstractIscStmtHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; @@ -48,7 +49,7 @@ private int rtr_id; private int rtr_id_ptr = 0; - private isc_db_handle_impl rtr_rdb; + private AbstractIscDbHandle rtr_rdb; private List<isc_blob_handle_impl> blobs = Collections.synchronizedList(new LinkedList<isc_blob_handle_impl>()); private Set<AbstractIscStmtHandle> stmts = Collections.synchronizedSet(new HashSet<AbstractIscStmtHandle>()); @@ -91,7 +92,7 @@ return rtr_id_ptr; } - void setDbHandle(final isc_db_handle_impl db) { + void setDbHandle(final AbstractIscDbHandle db) { this.rtr_rdb = db; rtr_rdb.addTransaction(this); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -109,7 +109,7 @@ static final int op_write_page = 14; /* write page and optionally release lock */ - static final int op_lock = 15; /* sieze lock */ + static final int op_lock = 15; /* seize lock */ static final int op_convert_lock = 16; /* convert existing lock */ @@ -177,7 +177,7 @@ static final int op_mgr_report = 47; /* Report on server */ - static final int op_que_events = 48; /* Que event notification request */ + static final int op_que_events = 48; /* Queue event notification request */ static final int op_cancel_events = 49; /* Cancel event notification request */ @@ -187,10 +187,7 @@ static final int op_event = 52; /* Completed event request (asynchronous) */ - static final int op_connect_request = 53; /* - * Request to establish - * connection - */ + static final int op_connect_request = 53; /* Request to establish connection */ static final int op_aux_connect = 54; /* Establish auxiliary connection */ @@ -204,10 +201,7 @@ static final int op_put_slice = 59; - static final int op_slice = 60; /* - * Successful response to static final int - * op_get_slice - */ + static final int op_slice = 60; /* Successful response to static final int op_get_slice */ static final int op_seek_blob = 61; /* Blob seek operation */ @@ -390,19 +384,6 @@ internalAttachDatabase(dbai, db_handle, databaseParameterBuffer, true); } - /** - * @deprecated This method will be removed in Jaybird 2.3 - */ - @Deprecated - public void internalAttachDatabase(String host, Integer port, - String file_name, IscDbHandle db_handle, - DatabaseParameterBuffer databaseParameterBuffer) - throws GDSException { - // TODO: Unused, remove? - DbAttachInfo dbai = new DbAttachInfo(host, port, file_name); - internalAttachDatabase(dbai, db_handle, databaseParameterBuffer, false); - } - public void iscAttachDatabase(String connectString, IscDbHandle db_handle, DatabaseParameterBuffer databaseParameterBuffer) throws GDSException { @@ -1609,7 +1590,6 @@ isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; isc_db_handle_impl db = stmt.getRsr_rdb(); - synchronized (db) { try { if (debug) @@ -1843,6 +1823,8 @@ int len = 0; int srcpos = 0; int destpos = 0; + // TODO It looks like this might cause IndexOutOfBounds if srcpos = bufferLength - 1 and bufferLength = buffer.length + // TODO Or might read garbage if bufferLength is smaller than buffer.length while (srcpos < bufferLength) { len = iscVaxInteger(buffer, srcpos, 2); srcpos += 2; @@ -2225,9 +2207,7 @@ case ISCConstants.isc_arg_gds: int er = db.in.readInt(); if (debug) - log - .debug("readStatusVector arg:isc_arg_gds int: " - + er); + log.debug("readStatusVector arg:isc_arg_gds int: " + er); if (er != 0) { GDSException td = new GDSException(arg, er); if (head == null) { @@ -2279,9 +2259,7 @@ default: int e = db.in.readInt(); if (debug) - log - .debug("readStatusVector arg: " + arg - + " int: " + e); + log.debug("readStatusVector arg: " + arg + " int: " + e); if (e != 0) { GDSException td = new GDSException(arg, e); if (head == null) { @@ -2296,8 +2274,7 @@ } } } catch (IOException ioe) { - // ioe.getMessage() makes little sense here, it will not be - // displayed + // ioe.getMessage() makes little sense here, it will not be displayed // because error message for isc_net_read_err does not accept params throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_net_read_err, ioe.getMessage()); Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_db_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_db_handle_impl.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_db_handle_impl.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -39,21 +39,24 @@ * @author <a href="mailto:d_j...@us...">David Jencks</a> * @version 1.0 */ -public class isc_db_handle_impl extends AbstractIscDbHandle { +public final class isc_db_handle_impl extends AbstractIscDbHandle { private static final int DEFAULT_RESP_DATA = 65536; Socket socket; public XdrOutputStream out; public WireXdrInputStream in; + EventCoordinator eventCoordinator; + private int resp_object; + private byte[] resp_data; private int resp_data_len; - EventCoordinator eventCoordinator; - public isc_db_handle_impl() { - super(new byte[DEFAULT_RESP_DATA]); + isc_db_handle_impl() { + resp_data = new byte[DEFAULT_RESP_DATA]; } - protected void invalidate() throws IOException { + // TODO Consider throwing GDSException instead? + public void invalidate() throws IOException { if (!isValid()) return; @@ -91,28 +94,36 @@ } } } + + // TODO merge getResp_data_truncated() and getResp_data() ? - void addTransaction(isc_tr_handle_impl tr) { - checkValidity(); - rdb_transactions.add(tr); - } - - void removeTransaction(isc_tr_handle_impl tr) { - checkValidity(); - rdb_transactions.remove(tr); - } - - public byte[] getResp_data_truncated() { + byte[] getResp_data_truncated() { byte[] dest = new byte[getResp_data_len()]; System.arraycopy(getResp_data(), 0, dest, 0, dest.length); return dest; } + + byte[] getResp_data() { + return resp_data; + } - public void setResp_data_len(int len) { + void setResp_data_len(int len) { this.resp_data_len = len; } - public int getResp_data_len() { + int getResp_data_len() { return this.resp_data_len; } + + void setResp_object(int value) { + resp_object = value; + } + + int getResp_object() { + return resp_object; + } + + void setResp_data(byte[] value) { + resp_data = value; + } } Modified: client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java 2012-11-04 11:52:25 UTC (rev 57307) +++ client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java 2012-11-04 13:23:09 UTC (rev 57308) @@ -33,6 +33,7 @@ import org.firebirdsql.gds.IscTrHandle; import org.firebirdsql.gds.XSQLDA; import org.firebirdsql.gds.XSQLVAR; +import org.firebirdsql.gds.impl.AbstractIscDbHandle; import org.firebirdsql.gds.impl.GDSFactory; import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.jca.FBTpb; @@ -177,8 +178,8 @@ db2 = gds.createIscDbHandle(); gds.iscAttachDatabase(getdbpath(dbName), db2, c); - if (log != null) log.info("test- rdb_id1: " + ((isc_db_handle_impl)db1).getRdbId()); - if (log != null) log.info("test- rdb_id2: " + ((isc_db_handle_impl)db2).getRdbId()); + if (log != null) log.info("test- rdb_id1: " + ((AbstractIscDbHandle)db1).getRdbId()); + if (log != null) log.info("test- rdb_id2: " + ((AbstractIscDbHandle)db2).getRdbId()); if (log != null) log.info("test- isc_detach_database"); gds.iscDetachDatabase(db1); @@ -197,8 +198,8 @@ db1 = createDatabase(dbName); db2 = createDatabase(dbName2); - if (log != null) log.info("test- rdb_id1: " + ((isc_db_handle_impl)db1).getRdbId()); - if (log != null) log.info("test- rdb_id2: " + ((isc_db_handle_impl)db2).getRdbId()); + if (log != null) log.info("test- rdb_id1: " + ((AbstractIscDbHandle)db1).getRdbId()); + if (log != null) log.info("test- rdb_id2: " + ((AbstractIscDbHandle)db2).getRdbId()); t1 = startTransaction(db1); doSQLImmed(db1, t1, "create table r1 (col1 smallint not null primary key)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-05 15:58:06
|
Revision: 57313 http://firebird.svn.sourceforge.net/firebird/?rev=57313&view=rev Author: mrotteveel Date: 2012-11-05 15:57:56 +0000 (Mon, 05 Nov 2012) Log Message: ----------- Cleanup IscStmtHandle implementations and usage (step towards using interfaces wherever possible) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/IscStmtHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscStmtHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_blob_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_stmt_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_tr_handle_impl.java client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/IscStmtHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/IscStmtHandle.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/IscStmtHandle.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -29,7 +29,6 @@ * Portions created by Alejandro Alberola are Copyright (C) 2001 * Boix i Oltra, S.L. All Rights Reserved. */ - package org.firebirdsql.gds; /** @@ -55,14 +54,52 @@ int TYPE_ROLLBACK = ISCConstants.isc_info_sql_stmt_rollback; int TYPE_SELECT_FOR_UPDATE = ISCConstants.isc_info_sql_stmt_select_for_upd; int TYPE_SET_GENERATOR = ISCConstants.isc_info_sql_stmt_set_generator; + + /** + * Get the {@link IscDbHandle} associated with this statement + * + * @return Instance of {@link IscDbHandle} + */ + IscDbHandle getRsr_rdb(); + + /** + * Sets the {@link IscDbHandle} associated with this statement + * @param value Instance of {@link IscDbHandle} + */ + void setRsr_rdb(IscDbHandle value); + + /** + * Add warning to this statement + * + * @param warning Warning to add + */ + void addWarning(GDSException warning); /** + * @return The statement text + */ + String getStatementText(); + + /** + * @param statement The statement text + */ + void setStatementText(String statement); + + /** * Get the input data structure that contains data that is put into * the statement. * * @return The input data structure */ XSQLDA getInSqlda(); + + /** + * Sets the input data structure that contains data that is put into + * the statement. + * + * @param xsqlda The input data structure + */ + void setInSqlda(XSQLDA xsqlda); /** * Get the output data structure that contains data that is retrieved @@ -71,16 +108,15 @@ * @return The output data structure */ XSQLDA getOutSqlda(); - + /** - * Retrieve whether all rows have been fetched of the rows selected - * by executing this statement. + * Sets the output data structure that contains data that is retrieved + * from the statement. * - * @return <code>true</code> if all rows have been fetched, - * <code>false</code> otherwise + * @param xsqlda The output data structure */ - boolean isAllRowsFetched(); - + void setOutSqlda(XSQLDA xsqlda); + /** * Get the execution plan from the statement. * @@ -90,6 +126,24 @@ String getExecutionPlan(); /** + * Sets the execution plan from the statement. + * + * @param plan execution plan or <code>null</code> if the execution plan was + * not fetched from the server. + */ + void setExecutionPlan(String plan); + + /** + * @return The Firebird server id for this statement + */ + int getRsrId(); + + /** + * @param value The Firebird server id for this statement + */ + void setRsrId(int value); + + /** * Get the statement type. * * @return one of the constants defined in this interface or {@link #TYPE_UNKNOWN} @@ -97,4 +151,189 @@ */ int getStatementType(); + /** + * Sets the statement type + * @param statementType one of the constants defined in this interface or {@link #TYPE_UNKNOWN} + * when no statement type was received from the server. + */ + void setStatementType(int statementType); + + // TODO: Move rows / size related methods to separate interface + + /** + * Retrieve whether all rows have been fetched of the rows selected + * by executing this statement. + * + * @return <code>true</code> if all rows have been fetched, + * <code>false</code> otherwise + */ + boolean isAllRowsFetched(); + + /** + * Set whether all rows have been fetched. + * + * @param value <code>true</code> if all rows have been fetched, <code>false</code> otherwise + */ + void setAllRowsFetched(boolean value); + + /** + * Get the number of rows contained in this statement. + * + * @return The rowcount for this statement + */ + int size(); + + /** + * Ensure capacity for specified number of rows. + * + * @param maxSize Capacity for rows to be created/reserved + */ + void ensureCapacity(int maxSize); + + /** + * Remove all rows contained by this statement. This method differs from + * {@link #clearRows} in that it effectively clears all rows from this + * statement. + * + * @see #clearRows + */ + void removeRows(); + + /** + * Clear all rows that have been fetched for this statement. This + * method differs from {@link #removeRows} in that it only affects rows + * that have already been fetched. + * + * @see #removeRows + */ + void clearRows(); + + /** + * Get the rows retrieved by executing this statement. + * + * @return Array of rows retrieved + */ + byte[][][] getRows(); + + /** + * Adds row to collection of fetched rows + * + * @param row Row to add + */ + void addRow(byte[][] row); + + // TODO Consider moving count methods to separate interface + + /** + * Get the number of rows that were deleted by executing this statement. + * + * @return The number of deleted rows + */ + int getDeleteCount(); + + /** + * Sets the number of rows that were deleted by executing this statement. + * + * @param deleteCount The number of deleted rows + */ + void setDeleteCount(int deleteCount); + + /** + * Get the number of rows that were inserted by executing this statement. + * + * @return The number of inserted rows + */ + int getInsertCount(); + + /** + * Sets the number of rows that were inserted by executing this statement. + * + * @param insertCount The number of inserted rows + */ + void setInsertCount(int insertCount); + + /** + * Get the number of rows that were updated by executing this statement. + * + * @return The number of updated rows + */ + int getUpdateCount(); + + /** + * Sets the number of rows that were updated by executing this statement. + * + * @param updateCount The number of updated rows + */ + void setUpdateCount(int updateCount); + + /** + * Get the number of rows that were selected by executing this statement. + * + * @return The number of selected rows + */ + int getSelectCount(); + + /** + * Get the number of rows that were selected by executing this statement. + * + * @param selectCount The number of selected rows + */ + void setSelectCount(int selectCount); + + /** + * Register statement for the transaction. This method is used within + * the <code>GDS.iscDsqlExecXXX</code> methods to keep a reference on + * current transaction in which statement is executed. + * + * @param trHandle instance of {@link IscTrHandle}. + */ + void registerTransaction(IscTrHandle trHandle); + + /** + * Get current transaction in which statement is currently executed. + * + * @return instance of {@link IscTrHandle} or <code>null</code> + * if statement is not assigned to a transaction. + */ + IscTrHandle getTransaction(); + + /** + * Unregister statement from the transaction. + */ + void unregisterTransaction(); + + /** + * Retrieve whether this statement has an open <code>ResultSet</code>. + * + * @return <code>true</code> if this statement has an open + * <code>ResultSet</code>, false otherwise + */ + boolean hasOpenResultSet(); + + /** + * Notifies this statement that there are open resultsets. + */ + void notifyOpenResultSet(); + + /** + * Retrieve whether this statement has singleton result set. + * + * @return <code>true</code> if result set has singleton result set. + */ + boolean isSingletonResult(); + + /** + * Sets whether this statement has singleton result set. + * + * @param value <code>true</code> if result set has singleton result set. + */ + void setSingletonResult(boolean value); + + /** + * Retrieve whether or not this statement is valid. + * + * @return <code>true</code> if this is a valid statement, + * <code>false</code> otherwise + */ + boolean isValid(); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscStmtHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscStmtHandle.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscStmtHandle.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -1,141 +1,72 @@ /* - * Public Firebird Java API. + * Firebird Open Source J2ee connector - jdbc driver * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 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 of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 THE AUTHOR 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. + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. */ +/* + * The Original Code is the Firebird Java GDS implementation. + * + * The Initial Developer of the Original Code is Alejandro Alberola. + * Portions created by Alejandro Alberola are Copyright (C) 2001 + * Boix i Oltra, S.L. All Rights Reserved. + */ package org.firebirdsql.gds.impl; -import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.IscStmtHandle; +import org.firebirdsql.gds.IscTrHandle; +import org.firebirdsql.gds.XSQLDA; +import org.firebirdsql.logging.Logger; +import org.firebirdsql.logging.LoggerFactory; - /** * Abstract implementation of the {@link org.firebirdsql.gds.IscStmtHandle} * interface. */ public abstract class AbstractIscStmtHandle implements IscStmtHandle { + private static final Logger log = LoggerFactory.getLogger(AbstractIscStmtHandle.class, false); + private String executionPlan; - private int statementType = TYPE_UNKNOWN; - public String statement; - - /** - * Clear all rows that have been fetched for this statement. This - * method differs from {@link #removeRows} in that it only affects rows - * that have already been fetched. - * - * @see #removeRows - */ - public abstract void clearRows(); - - /** - * Get the number of rows that were deleted by executing this statement. - * - * @return The number of deleted rows - */ - public abstract int getDeleteCount(); - - /** - * Get the number of rows that were inserted by executing this statement. - * - * @return The number of inserted rows - */ - public abstract int getInsertCount(); - - /** - * Get the rows retrieved by executing this statement. - * - * @return Array of rows retrieved - */ - public abstract byte[][][] getRows(); - - /** - * Get the number of rows that were updated by executing this statement. - * - * @return The number of updated rows - */ - public abstract int getUpdateCount(); + private int statementType = IscStmtHandle.TYPE_UNKNOWN; + private String statement; + private int insertCount; + private int updateCount; + private int deleteCount; + private int selectCount; + private XSQLDA in_sqlda = null; + private XSQLDA out_sqlda = null; + private int rsr_id; + private byte[][][] rows; + private int size; + private boolean allRowsFetched = false; + private boolean isSingletonResult = false; + private boolean hasOpenResultSet = false; + private IscTrHandle trHandle; + private IscDbHandle rsr_rdb; - /** - * Retrieve whether this statement has an open <code>ResultSet</code>. - * - * @return <code>true</code> if this statement has an open - * <code>ResultSet</code>, false otherwise - */ - public abstract boolean hasOpenResultSet(); + public String getStatementText() { + return statement; + } - /** - * Retrieve whether this statement has singleton result set. - * - * @return <code>true</code> if result set has singleton result set. - */ - public abstract boolean isSingletonResult(); + public void setStatementText(String statement) { + this.statement = statement; + } - /** - * Retrieve whether or not this statement is valid. - * - * @return <code>true</code> if this is a valid statement, - * <code>false</code> otherwise - */ - public abstract boolean isValid(); - - /** - * Get the number of rows contained in this statement. - * - * @return The rowcount for this statement - */ - public abstract int size(); - - /** - * Remove all rows contained by this statement. This method differs from - * {@link #clearRows} in that it effectively clears all rows from this - * statement. - * - * @see #clearRows - */ - public abstract void removeRows(); - - /** - * Register statement for the transaction. This method is used within - * the <code>GDS.iscDsqlExecXXX</code> methods to keep a reference on - * current transaction in which statement is executed. - * - * @param trHandle instance of {@link AbstractIscTrHandle}. - */ - public abstract void registerTransaction(AbstractIscTrHandle trHandle); - - /** - * Get current transaction in which statement is currently executed. - * - * @return instance of {@link AbstractIscTrHandle} or <code>null</code> - * if statement is not assigned to a transaction. - */ - public abstract AbstractIscTrHandle getTransaction(); - - /** - * Unregister statement from the transaction. - */ - public abstract void unregisterTransaction(); - public String getExecutionPlan() { return executionPlan; } @@ -144,11 +75,6 @@ this.executionPlan = plan; } - /** - * Get type of the statement. - * - * @return value from the {@link ISCConstants} class. - */ public int getStatementType() { return statementType; } @@ -157,4 +83,180 @@ this.statementType = statementType; } + public void setInsertCount(int value) { + insertCount = value; + } + + public int getInsertCount() { + return insertCount; + } + + public void setUpdateCount(int value) { + updateCount = value; + } + + public int getUpdateCount() { + return updateCount; + } + + public void setDeleteCount(int value) { + deleteCount = value; + } + + public int getDeleteCount() { + return deleteCount; + } + + public void setSelectCount(int value) { + selectCount = value; + } + + public int getSelectCount() { + return selectCount; + } + + public XSQLDA getInSqlda() { + return in_sqlda; + } + + public XSQLDA getOutSqlda() { + return out_sqlda; + } + + public void setInSqlda(XSQLDA xsqlda) { + in_sqlda = xsqlda; + } + + public void setOutSqlda(XSQLDA xsqlda) { + out_sqlda = xsqlda; + } + + public void ensureCapacity(int maxSize) { + if (rows == null || rows.length < maxSize) + rows = new byte[maxSize][][]; + size = 0; + } + + public void clearRows() { + size = 0; + if (rows != null) + rows = null; + allRowsFetched = false; + hasOpenResultSet = false; + } + + public boolean isAllRowsFetched() { + return allRowsFetched; + } + + public void setAllRowsFetched(boolean value) { + allRowsFetched = value; + } + + public boolean isSingletonResult() { + return isSingletonResult; + } + + public void setSingletonResult(boolean value) { + isSingletonResult = value; + } + + public int getRsrId() { + return rsr_id; + } + + public void setRsrId(int value) { + rsr_id = value; + } + + public boolean hasOpenResultSet() { + return hasOpenResultSet; + } + + public void notifyOpenResultSet() { + hasOpenResultSet = true; + } + + public int size() { + return size; + } + + public byte[][][] getRows() { + // TODO Return rows up to size? + return rows; + } + + public void removeRows() { + rows = null; + size = 0; + } + + public void addRow(byte[][] row) { + rows[size++] = row; + } + + public IscTrHandle getTransaction() { + return trHandle; + } + + public void registerTransaction(IscTrHandle trHandle) { + this.trHandle = trHandle; + } + + public void unregisterTransaction() { + this.trHandle = null; + } + + public void addWarning(GDSException warning) { + // TODO: Store warnings on statement level? (currently only used from JNI-code) + rsr_rdb.addWarning(warning); + } + + public IscDbHandle getRsr_rdb() { + return rsr_rdb; + } + + public void setRsr_rdb(IscDbHandle value) { + rsr_rdb = value; + } + + public boolean isValid() { + return rsr_rdb != null && rsr_rdb.isValid(); + } + + /** + * Helper method to print the bytes of a row using hex representation. + * @param row Row to print + */ + public static void printRow(byte[][] row) { + StringBuilder sb = new StringBuilder(); + sb.append('\t'); + + if (row == null) + sb.append("null"); + else { + for (int i = 0; i < row.length; i++) { + + if (row[i] == null) + sb.append("null"); + else { + for (int j = 0; j < row[i].length; j++) { + String hexValue = Integer.toHexString(row[i][j] & 0xff); + if (hexValue.length() == 1) + sb.append(0); + + sb.append(hexValue); + if (j < row[i].length - 1) + sb.append(' '); + } + } + + if (i < row.length - 1) + sb.append(", "); + } + } + + if (log != null) + log.debug(sb.toString()); + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -24,9 +24,17 @@ */ package org.firebirdsql.gds.impl; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.firebirdsql.gds.IscBlobHandle; +import org.firebirdsql.gds.IscStmtHandle; import org.firebirdsql.gds.IscTrHandle; - /** * Abstract implementation of the {@link org.firebirdsql.gds.IscTrHandle} * interface. @@ -40,12 +48,24 @@ public final static int TRANSACTIONROLLINGBACK = 6; public final static int TRANSACTIONSTARTED = 2; public final static int TRANSACTIONSTARTING = 1; + + private final List<IscBlobHandle> blobs = Collections.synchronizedList(new LinkedList<IscBlobHandle>()); + private final Set<IscStmtHandle> stmts = Collections.synchronizedSet(new HashSet<IscStmtHandle>()); /** * Clear all the saved result sets from this handle. */ - public abstract void forgetResultSets(); - + public void forgetResultSets() { + synchronized(stmts) { + for (Iterator<IscStmtHandle> iter = stmts.iterator(); iter.hasNext();) { + AbstractIscStmtHandle stmt = (AbstractIscStmtHandle) iter.next(); + stmt.clearRows(); + } + + stmts.clear(); + } + } + /** * Get the current state of the transaction to which this handle is * pointing. The state is equal to one of the <code>TRANSACTION*</code> @@ -56,6 +76,14 @@ */ public abstract int getState(); + public void addBlob(IscBlobHandle blob) { + blobs.add(blob); + } + + public void removeBlob(IscBlobHandle blob) { + blobs.remove(blob); + } + /** * Register a statement within the transaction to which this handle points. * This method allows automated cleanup of the rows fetched within a @@ -63,12 +91,16 @@ * * @param fbStatement Handle to the statement to be registered. */ - public abstract void registerStatementWithTransaction(AbstractIscStmtHandle fbStatement); + public void registerStatementWithTransaction(IscStmtHandle stmt) { + stmts.add(stmt); + } /** * Unregister a statement from the transaction in which it was registered. * * @param fbStatement Handle to the statement to be unregistered. */ - public abstract void unregisterStatementFromTransaction(AbstractIscStmtHandle fbStatement); + public void unregisterStatementFromTransaction(IscStmtHandle stmt) { + stmts.remove(stmt); + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -196,7 +196,7 @@ if (describeBind) gds.iscDsqlDescribeBind(stmt, ISCConstants.SQLDA_VERSION1); - stmt.statement = sql; + stmt.setStatementText(sql); } catch(GDSException ex) { notifyListeners(ex); @@ -220,7 +220,7 @@ try { if (log != null && log.isDebugEnabled()) - log.debug("Executing " + stmt.statement); + log.debug("Executing " + stmt.getStatementText()); // System.out.println("Executing " + stmt.statement); Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -26,6 +26,7 @@ import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.AbstractGDS; import org.firebirdsql.gds.impl.AbstractIscDbHandle; +import org.firebirdsql.gds.impl.AbstractIscStmtHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; import org.firebirdsql.gds.impl.GDSType; @@ -34,7 +35,7 @@ public abstract class BaseGDSImpl extends AbstractGDS { - // TODO Synchronization seems to be inconsistent: sometimes on dbhandle, sometimes on this (and soemtimes on blobhandle) + // TODO Synchronization seems to be inconsistent: sometimes on dbhandle, sometimes on this (and sometimes on blobhandle) // TODO Checking for validity of dbhandle is inconsistent (sometimes only null check, sometimes also .isValid()) private static Logger log = LoggerFactory.getLogger(BaseGDSImpl.class, @@ -50,12 +51,11 @@ ISCConstants.isc_info_base_level, ISCConstants.isc_info_end }; - private static byte[] stmtInfo = new byte[] { ISCConstants.isc_info_sql_records, ISCConstants.isc_info_sql_stmt_type, ISCConstants.isc_info_end}; - private static int INFO_SIZE = 128; + private static final int INFO_SIZE = 128; public int isc_api_handle; @@ -115,8 +115,9 @@ public void iscAttachDatabase(String file_name, IscDbHandle db_handle, DatabaseParameterBuffer databaseParameterBuffer) throws GDSException { - if (db_handle == null) { throw new GDSException( - ISCConstants.isc_bad_db_handle); } + if (db_handle == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } final byte[] dpbBytes; final String filenameCharset; @@ -166,10 +167,13 @@ public void iscCloseBlob(IscBlobHandle blob_handle) throws GDSException { isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; IscDbHandle db = blob.getDb(); - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - isc_tr_handle_impl tr = blob.getTr(); - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } + if (db == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } + AbstractIscTrHandle tr = blob.getTr(); + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } synchronized (db) { native_isc_close_blob(blob_handle); @@ -182,8 +186,9 @@ // --------------------------------------------------------------------------------------------- public void iscCommitRetaining(IscTrHandle tr_handle) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) @@ -191,8 +196,9 @@ synchronized (db) { if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { throw new GDSException( - ISCConstants.isc_tra_state); } + && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + throw new GDSException(ISCConstants.isc_tra_state); + } tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); @@ -215,8 +221,9 @@ synchronized (db) { if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { throw new GDSException( - ISCConstants.isc_tra_state); } + && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + throw new GDSException(ISCConstants.isc_tra_state); + } tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); @@ -234,14 +241,18 @@ IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; + AbstractIscTrHandle tr = (AbstractIscTrHandle) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } - if (blob == null) { throw new GDSException( - ISCConstants.isc_bad_segstr_handle); } + if (db == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } + if (blob == null) { + throw new GDSException(ISCConstants.isc_bad_segstr_handle); + } final byte[] bpb = blobParameterBuffer == null ? null : ((BlobParameterBufferImp) blobParameterBuffer) @@ -288,8 +299,7 @@ throw new GDSException(ISCConstants.isc_bad_dpb_content); } - native_isc_create_database(urlData, db_handle, - dpbBytes); + native_isc_create_database(urlData, db_handle, dpbBytes); } } @@ -326,8 +336,9 @@ // isc_drop_database // --------------------------------------------------------------------------------------------- public void iscDropDatabase(IscDbHandle db_handle) throws GDSException { - if (db_handle == null) { throw new GDSException( - ISCConstants.isc_bad_db_handle); } + if (db_handle == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } synchronized (this) { native_isc_drop_database(db_handle); @@ -338,39 +349,35 @@ // --------------------------------------------------------------------------------------------- public void iscDsqlAllocateStatement(IscDbHandle db_handle, IscStmtHandle stmt_handle) throws GDSException { - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - if (db_handle == null) { throw new GDSException( - ISCConstants.isc_bad_db_handle); } + if (db_handle == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } - if (stmt_handle == null) { throw new GDSException( - ISCConstants.isc_bad_req_handle); } + if (stmt_handle == null) { + throw new GDSException(ISCConstants.isc_bad_req_handle); + } synchronized (db_handle) { native_isc_dsql_allocate_statement(db_handle, stmt_handle); - stmt.setRsr_rdb((AbstractIscDbHandle) db_handle); - stmt.setAllRowsFetched(false); + stmt_handle.setRsr_rdb(db_handle); + stmt_handle.setAllRowsFetched(false); } } // isc_dsql_describe // --------------------------------------------------------------------------------------------- - public XSQLDA iscDsqlDescribe(IscStmtHandle stmt_handle, int da_version) - throws GDSException { - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; + public XSQLDA iscDsqlDescribe(IscStmtHandle stmt_handle, int da_version) throws GDSException { - if (stmt == null) { throw new GDSException( - ISCConstants.isc_bad_req_handle); } + if (stmt_handle == null) { + throw new GDSException(ISCConstants.isc_bad_req_handle); + } - synchronized (stmt.getRsr_rdb()) { + synchronized (stmt_handle.getRsr_rdb()) { + stmt_handle.setInSqlda(native_isc_dsql_describe(stmt_handle, da_version)); + // TODO setInSqlda here ?? - stmt.setInSqlda(native_isc_dsql_describe(stmt_handle, da_version)); /* - * @todo - * setInSqlda - * here ?? - */ - return stmt_handle.getInSqlda(); } } @@ -379,11 +386,9 @@ // --------------------------------------------------------------------------------------------- public XSQLDA iscDsqlDescribeBind(IscStmtHandle stmt_handle, int da_version) throws GDSException { - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - synchronized (stmt.getRsr_rdb()) { - stmt.setInSqlda(native_isc_dsql_describe_bind(stmt_handle, - da_version)); + synchronized (stmt_handle.getRsr_rdb()) { + stmt_handle.setInSqlda(native_isc_dsql_describe_bind(stmt_handle, da_version)); return stmt_handle.getInSqlda(); } @@ -403,6 +408,7 @@ public void iscDsqlExecImmed2(IscDbHandle db_handle, IscTrHandle tr_handle, String statement, int dialect, XSQLDA in_xsqlda, XSQLDA out_xsqlda) throws GDSException { + // TODO Suspicious use of NONE here iscDsqlExecImmed2(db_handle, tr_handle, statement, "NONE", dialect, in_xsqlda, out_xsqlda); } @@ -438,26 +444,25 @@ public void iscDsqlExecute2(IscTrHandle tr_handle, IscStmtHandle stmt_handle, int da_version, XSQLDA in_xsqlda, XSQLDA out_xsqlda) throws GDSException { - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - synchronized (stmt.getRsr_rdb()) { + synchronized (stmt_handle.getRsr_rdb()) { native_isc_dsql_execute2(tr_handle, stmt_handle, da_version, - in_xsqlda, out_xsqlda); /* @todo Fetch Statements */ + in_xsqlda, out_xsqlda); /* TODO Fetch Statements */ - if (stmt.getOutSqlda() != null) stmt.notifyOpenResultSet(); + if (stmt_handle.getOutSqlda() != null) stmt_handle.notifyOpenResultSet(); if (out_xsqlda != null) { // this would be an Execute procedure - stmt.ensureCapacity(1); - readSQLData(out_xsqlda, stmt); - stmt.setAllRowsFetched(true); - stmt.setSingletonResult(true); + stmt_handle.ensureCapacity(1); + readSQLData(out_xsqlda, stmt_handle); + stmt_handle.setAllRowsFetched(true); + stmt_handle.setSingletonResult(true); } else { - stmt.setAllRowsFetched(false); - stmt.setSingletonResult(false); + stmt_handle.setAllRowsFetched(false); + stmt_handle.setSingletonResult(false); } - stmt.registerTransaction((AbstractIscTrHandle)tr_handle); + stmt_handle.registerTransaction(tr_handle); } } @@ -503,26 +508,26 @@ throw new GDSException(ISCConstants.isc_dsql_sqlda_err); } - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - IscDbHandle db = stmt.getRsr_rdb(); + IscDbHandle db = stmt_handle.getRsr_rdb(); synchronized (db) { // Apply fetchSize // Fetch next batch of rows - stmt.ensureCapacity(fetchSize); + stmt_handle.ensureCapacity(fetchSize); for (int i = 0; i < fetchSize; i++) { + // TODO Repeating fetchSize times, but also passing fetchSize into fetch call? try { boolean isRowPresent = native_isc_dsql_fetch(stmt_handle, da_version, xsqlda, fetchSize); if (isRowPresent) { - readSQLData(xsqlda, stmt); + readSQLData(xsqlda, stmt_handle); } else { - stmt.setAllRowsFetched(true); + stmt_handle.setAllRowsFetched(true); return; } } finally { - stmt.notifyOpenResultSet(); + stmt_handle.notifyOpenResultSet(); } } } @@ -535,29 +540,28 @@ if (stmt_handle == null) { throw new GDSException(ISCConstants.isc_bad_req_handle); } - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - IscDbHandle db = stmt.getRsr_rdb(); + IscDbHandle db = stmt_handle.getRsr_rdb(); synchronized (db) { // Does not seem to be possible or necessary to close // an execute procedure statement. - if (stmt.isSingletonResult() && option == ISCConstants.DSQL_close) { return; } + if (stmt_handle.isSingletonResult() && option == ISCConstants.DSQL_close) { return; } if (option == ISCConstants.DSQL_drop) { - stmt.setInSqlda(null); - stmt.setOutSqlda(null); - stmt.setRsr_rdb(null); + stmt_handle.setInSqlda(null); + stmt_handle.setOutSqlda(null); + stmt_handle.setRsr_rdb(null); } native_isc_dsql_free_statement(stmt_handle, option); // clear association with transaction try { - AbstractIscTrHandle tr = stmt.getTransaction(); + AbstractIscTrHandle tr = (AbstractIscTrHandle)stmt_handle.getTransaction(); if (tr != null) - tr.unregisterStatementFromTransaction(stmt); + tr.unregisterStatementFromTransaction(stmt_handle); } finally { - stmt.unregisterTransaction(); + stmt_handle.unregisterTransaction(); } } @@ -575,17 +579,15 @@ if (stmt_handle == null) { throw new GDSException(ISCConstants.isc_bad_req_handle); } - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - IscDbHandle db = stmt.getRsr_rdb(); + + synchronized (stmt_handle.getRsr_rdb()) { + stmt_handle.setInSqlda(null); + stmt_handle.setOutSqlda(null); - synchronized (db) { - stmt.setInSqlda(null); - stmt.setOutSqlda(null); - - stmt.setOutSqlda(native_isc_dsql_prepare(tr_handle, stmt_handle, + stmt_handle.setOutSqlda(native_isc_dsql_prepare(tr_handle, stmt_handle, getZeroTerminatedArray(statement), dialect)); - getStatementType(stmt); + getStatementType(stmt_handle); return stmt_handle.getOutSqlda(); } @@ -598,7 +600,7 @@ * * @throws GDSException if error occured. */ - private void getStatementType(isc_stmt_handle_impl stmt) throws GDSException { + private void getStatementType(IscStmtHandle stmt) throws GDSException { final byte [] REQUEST = new byte [] { ISCConstants.isc_info_sql_stmt_type, ISCConstants.isc_info_end }; @@ -661,8 +663,7 @@ throw new GDSException(ISCConstants.isc_bad_req_handle); } - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - IscDbHandle db = stmt.getRsr_rdb(); + IscDbHandle db = stmt_handle.getRsr_rdb(); synchronized (db) { native_isc_dsql_set_cursor_name(stmt_handle, cursor_name, type); @@ -673,18 +674,11 @@ // --------------------------------------------------------------------------------------------- public byte[] iscDsqlSqlInfo(IscStmtHandle stmt_handle, byte[] items, int buffer_length) throws GDSException { - synchronized (((isc_stmt_handle_impl) stmt_handle).getRsr_rdb()) { + synchronized (((AbstractIscStmtHandle) stmt_handle).getRsr_rdb()) { return native_isc_dsql_sql_info(stmt_handle, items, buffer_length); } } - // isc_expand_dpb - // --------------------------------------------------------------------------------------------- - public byte[] iscExpandDpb(byte[] dpb, int dpb_length, int param, - Object[] params) throws GDSException { - return dpb; - } - // isc_get_segment // --------------------------------------------------------------------------------------------- public byte[] iscGetSegment(IscBlobHandle blob, int maxread) @@ -700,14 +694,18 @@ IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; + AbstractIscTrHandle tr = (AbstractIscTrHandle) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } - if (blob == null) { throw new GDSException( - ISCConstants.isc_bad_segstr_handle); } + if (db == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } + if (blob == null) { + throw new GDSException(ISCConstants.isc_bad_segstr_handle); + } final byte[] bpb = blobParameterBuffer == null ? null : ((BlobParameterBufferImp) blobParameterBuffer) @@ -727,11 +725,11 @@ public void iscPrepareTransaction(IscTrHandle tr_handle) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } - AbstractIscDbHandle db = (AbstractIscDbHandle) tr.getDbHandle(); - - synchronized (db) { + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } + + synchronized (tr.getDbHandle()) { if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( ISCConstants.isc_tra_state); } tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); @@ -747,13 +745,15 @@ public void iscPrepareTransaction2(IscTrHandle tr_handle, byte[] bytes) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } - IscDbHandle db = tr.getDbHandle(); - - synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( - ISCConstants.isc_tra_state); } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } + + synchronized (tr.getDbHandle()) { + if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { + throw new GDSException(ISCConstants.isc_tra_state); + } + tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); native_isc_prepare_transaction2(tr_handle, bytes); @@ -791,7 +791,7 @@ tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); native_isc_reconnect_transaction(db_handle, tr_handle, buffer); - tr.setDbHandle((AbstractIscDbHandle) db_handle); + tr.setDbHandle(db_handle); tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); } @@ -801,8 +801,9 @@ // --------------------------------------------------------------------------------------------- public void iscRollbackRetaining(IscTrHandle tr_handle) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -824,8 +825,9 @@ public void iscRollbackTransaction(IscTrHandle tr_handle) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } IscDbHandle db = tr.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); @@ -843,7 +845,6 @@ } } - public byte [] iscTransactionInformation(IscTrHandle trHandle, byte [] requestBuffer, int bufferLen) throws GDSException { synchronized (trHandle) { @@ -876,8 +877,7 @@ } } - public void iscServiceDetach(IscSvcHandle serviceHandle) - throws GDSException { + public void iscServiceDetach(IscSvcHandle serviceHandle) throws GDSException { synchronized (serviceHandle) { if (serviceHandle.isNotValid()) throw new GDSException("serviceHandle is not attached."); @@ -928,13 +928,15 @@ IscDbHandle db_handle, TransactionParameterBuffer tpb) throws GDSException { isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - IscDbHandle db = db_handle; TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; - if (tr == null) { throw new GDSException( - ISCConstants.isc_bad_trans_handle); } + if (tr == null) { + throw new GDSException(ISCConstants.isc_bad_trans_handle); + } - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } + if (db_handle == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } synchronized (db_handle) { if (tr.getState() != AbstractIscTrHandle.NOTRANSACTION) @@ -942,14 +944,10 @@ tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); - // final byte[] arg = new byte[tpb.length + 1]; - // arg[0] = 3; - // System.arraycopy(tpb, 0, arg, 1, tpb.length); - byte[] arg = tpbImpl.getBytesForNativeCode(); native_isc_start_transaction(tr_handle, db_handle, arg); - tr.setDbHandle((AbstractIscDbHandle) db_handle); + tr.setDbHandle(db_handle); tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); } @@ -1130,6 +1128,7 @@ */ private void parseAttachDatabaseInfo(byte[] info, IscDbHandle handle) throws GDSException { + // TODO Duplicate of method in wire.AbstractJavaGDSImpl? boolean debug = log != null && log.isDebugEnabled(); if (debug) log.debug("parseDatabaseInfo: first 2 bytes are " @@ -1207,7 +1206,7 @@ } } - public void readSQLData(XSQLDA xsqlda, isc_stmt_handle_impl stmt) { + public void readSQLData(XSQLDA xsqlda, IscStmtHandle stmt) { // This only works if not (port->port_flags & PORT_symmetric) int numCols = xsqlda.sqld; byte[][] row = new byte[numCols][]; @@ -1245,13 +1244,13 @@ } public void getSqlCounts(IscStmtHandle stmt_handle) throws GDSException { - isc_stmt_handle_impl stmt = (isc_stmt_handle_impl) stmt_handle; - byte[] buffer = iscDsqlSqlInfo(stmt, /* stmtInfo.length, */stmtInfo, INFO_SIZE); + // TODO duplicate of method in wire.AbstractJavaGDSImpl? + byte[] buffer = iscDsqlSqlInfo(stmt_handle, stmtInfo, INFO_SIZE); - stmt.setInsertCount(0); - stmt.setUpdateCount(0); - stmt.setDeleteCount(0); - stmt.setSelectCount(0); + stmt_handle.setInsertCount(0); + stmt_handle.setUpdateCount(0); + stmt_handle.setDeleteCount(0); + stmt_handle.setSelectCount(0); int pos = 0; int length; @@ -1268,19 +1267,19 @@ pos += 2; switch (t) { case ISCConstants.isc_info_req_insert_count: - stmt.setInsertCount(iscVaxInteger(buffer, pos, + stmt_handle.setInsertCount(iscVaxInteger(buffer, pos, l)); break; case ISCConstants.isc_info_req_update_count: - stmt.setUpdateCount(iscVaxInteger(buffer, pos, + stmt_handle.setUpdateCount(iscVaxInteger(buffer, pos, l)); break; case ISCConstants.isc_info_req_delete_count: - stmt.setDeleteCount(iscVaxInteger(buffer, pos, + stmt_handle.setDeleteCount(iscVaxInteger(buffer, pos, l)); break; case ISCConstants.isc_info_req_select_count: - stmt.setSelectCount(iscVaxInteger(buffer, pos, + stmt_handle.setSelectCount(iscVaxInteger(buffer, pos, l)); break; default: @@ -1290,7 +1289,7 @@ } break; case ISCConstants.isc_info_sql_stmt_type: - stmt.setStatementType(iscVaxInteger(buffer, pos, length)); + stmt_handle.setStatementType(iscVaxInteger(buffer, pos, length)); pos += length; break; default: @@ -1363,7 +1362,9 @@ public void fbCancelOperation(IscDbHandle dbHandle, int kind) throws GDSException { - if (dbHandle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } + if (dbHandle == null) { + throw new GDSException(ISCConstants.isc_bad_db_handle); + } synchronized (this) { native_fb_cancel_operation(dbHandle, kind); Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -21,6 +21,7 @@ import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.AbstractIscDbHandle; +import org.firebirdsql.gds.impl.AbstractIscTrHandle; /** * Describe class <code>isc_blob_handle_impl</code> here. @@ -32,7 +33,7 @@ private AbstractIscDbHandle db; - private isc_tr_handle_impl tr; + private AbstractIscTrHandle tr; private int rbl_id; @@ -47,11 +48,11 @@ db.addWarning(warning); } - public isc_tr_handle_impl getTr() { + public AbstractIscTrHandle getTr() { return tr; } - public void setTr(isc_tr_handle_impl value) { + public void setTr(AbstractIscTrHandle value) { tr = value; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_stmt_handle_impl.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -16,21 +16,9 @@ * * All rights reserved. */ -/* - * The Original Code is the Firebird Java GDS implementation. - * - * The Initial Developer of the Original Code is Alejandro Alberola. - * Portions created by Alejandro Alberola are Copyright (C) 2001 - * Boix i Oltra, S.L. All Rights Reserved. - */ - package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.XSQLDA; -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.AbstractIscDbHandle; import org.firebirdsql.gds.impl.AbstractIscStmtHandle; -import org.firebirdsql.gds.impl.AbstractIscTrHandle; /** * Describe class <code>isc_stmt_handle_impl</code> here. @@ -40,182 +28,4 @@ * @version 1.0 */ public final class isc_stmt_handle_impl extends AbstractIscStmtHandle { - private int rsr_id; - private int rsr_id_ptr = 0; - - private AbstractIscDbHandle rsr_rdb; - private XSQLDA in_sqlda = null; - private XSQLDA out_sqlda = null; - private byte[][][] rows; - private int size; - private boolean allRowsFetched = false; - private boolean isSingletonResult = false; - private boolean hasOpenResultSet = false; - - private int statementType; - private int insertCount; - private int updateCount; - private int deleteCount; - private int selectCount; //???? - - private AbstractIscTrHandle trHandle; - - public void addWarning(GDSException warning) { - rsr_rdb.addWarning(warning); - } - - public isc_stmt_handle_impl() { - } - - public XSQLDA getInSqlda() { - return in_sqlda; - } - - public XSQLDA getOutSqlda() { - return out_sqlda; - } - - public void setInSqlda(XSQLDA xsqlda) { - in_sqlda = xsqlda; - } - - public void setOutSqlda(XSQLDA xsqlda) { - out_sqlda = xsqlda; - } - - public void ensureCapacity(int maxSize) { - if (rows== null || rows.length<maxSize) - rows = new byte[maxSize][][]; - size=0; - } - - public void clearRows() { - size = 0; - if (rows != null) - rows = null; - allRowsFetched = false; - hasOpenResultSet = false; - } - - public void setStatementType(int value) { - statementType = value; - } - - public int getStatementType() { - return statementType; - } - - public void setInsertCount(int value) { - insertCount = value; - } - - public int getInsertCount() { - return insertCount; - } - - public void setUpdateCount(int value) { - updateCount = value; - } - - public int getUpdateCount() { - return updateCount; - } - - public void setDeleteCount(int value) { - deleteCount = value; - } - - public int getDeleteCount() { - return deleteCount; - } - - public void setSelectCount(int value) { - selectCount = value; - } - - public int getSelectCount() { - return selectCount; - } - - public boolean isAllRowsFetched() { - return allRowsFetched; - } - - public void setAllRowsFetched(boolean value) { - allRowsFetched = value; - } - - public boolean isSingletonResult() { - return isSingletonResult; - } - - public void setSingletonResult(boolean value) { - isSingletonResult = value; - } - - public int getRsrId() { - return rsr_id; - } - - public void setRsrId(int value) { - rsr_id = value; - } - - public int getRsr_id_ptr() { - return rsr_id_ptr; - } - - public void setRsr_id_ptr(int rsr_id_ptr,int value) { - setRsrId(value); - this.rsr_id_ptr = rsr_id_ptr; - } - - public AbstractIscDbHandle getRsr_rdb() { - return rsr_rdb; - } - - public void setRsr_rdb(AbstractIscDbHandle value) { - rsr_rdb = value; - } - - public boolean isValid() { - return rsr_rdb != null && rsr_rdb.isValid(); - } - - public boolean hasOpenResultSet() { - return hasOpenResultSet; - } - - void notifyOpenResultSet() { - hasOpenResultSet = true; - } - - public int size() { - return size; - } - - public byte[][][] getRows() { - return rows; - } - - public void removeRows() { - rows = null; - size = 0; - } - - public void addRow(byte[][] row) { - rows[size++] = row; - } - - public AbstractIscTrHandle getTransaction() { - return trHandle; - } - - public void registerTransaction(AbstractIscTrHandle trHandle) { - this.trHandle = trHandle; - } - - public void unregisterTransaction() { - this.trHandle = null; - } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-05 08:20:57 UTC (rev 57312) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-05 15:57:56 UTC (rev 57313) @@ -27,16 +27,8 @@ import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.impl.AbstractIscDbHandle; -import org.firebirdsql.gds.impl.AbstractIscStmtHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; /** * Describe class <code>is... [truncated message content] |
From: <mro...@us...> - 2012-11-05 17:29:45
|
Revision: 57314 http://firebird.svn.sourceforge.net/firebird/?rev=57314&view=rev Author: mrotteveel Date: 2012-11-05 17:29:36 +0000 (Mon, 05 Nov 2012) Log Message: ----------- Cleanup IscTrHandle implementations and usage (step towards using interfaces wherever possible) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/XdrInputStream.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_tr_handle_impl.java client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -44,10 +44,79 @@ */ public interface IscTrHandle { + // TODO Replace with enum + public static final int NOTRANSACTION = 0; + public static final int TRANSACTIONSTARTING = 1; + public static final int TRANSACTIONSTARTED = 2; + public static final int TRANSACTIONPREPARING = 3; + public static final int TRANSACTIONPREPARED = 4; + public static final int TRANSACTIONCOMMITTING = 5; + public static final int TRANSACTIONROLLINGBACK = 6; + + int getTransactionId(); + + void setTransactionId(final int rtr_id); + /** * Retrieve a handle to the database to which this transaction is linked. * * @return Handle to the database */ IscDbHandle getDbHandle(); + + /** + * Sets a handle to the database to which this transaction is linked. + * + * @return Handle to the database + */ + void setDbHandle(IscDbHandle db); + + /** + * Clears the database handle associated with this transaction + */ + public void unsetDbHandle(); + + /** + * Add a warning to the connection associated with this transaction. + * + * @param warning Warning to add + */ + void addWarning(GDSException warning); + + /** + * Get the current state of the transaction to which this handle is + * pointing. The state is equal to one of the <code>TRANSACTION*</code> + * constants of this interface, or the <code>NOTRANSACTION</code> constant, + * also of this interface. + * + * @return The corresponding value for the current state + */ + int getState(); + + void setState(int state); + + void addBlob(IscBlobHandle blob); + + void removeBlob(IscBlobHandle blob); + + /** + * Register a statement within the transaction to which this handle points. + * This method allows automated cleanup of the rows fetched within a + * transaction on commit or rollback point. + * + * @param stmt Handle to the statement to be registered. + */ + void registerStatementWithTransaction(IscStmtHandle stmt); + + /** + * Unregister a statement from the transaction in which it was registered. + * + * @param stmt Handle to the statement to be unregistered. + */ + void unregisterStatementFromTransaction(IscStmtHandle stmt); + + /** + * Clear all the saved result sets from this handle. + */ + void forgetResultSets(); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscTrHandle.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -1,27 +1,28 @@ /* - * Public Firebird Java API. + * Firebird Open Source J2ee connector - jdbc driver * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 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 of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 THE AUTHOR 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. + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. */ +/* + * The Original Code is the Firebird Java GDS implementation. + * + * The Initial Developer of the Original Code is Alejandro Alberola. + * Portions created by Alejandro Alberola are Copyright (C) 2001 + * Boix i Oltra, S.L. All Rights Reserved. + */ package org.firebirdsql.gds.impl; import java.util.Collections; @@ -31,30 +32,27 @@ import java.util.List; import java.util.Set; +import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.IscBlobHandle; +import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.IscStmtHandle; import org.firebirdsql.gds.IscTrHandle; /** * Abstract implementation of the {@link org.firebirdsql.gds.IscTrHandle} * interface. + * + * @author <a href="mailto:alb...@us...">Alejandro Alberola</a> + * @author <a href="mailto:d_j...@us...">David Jencks</a> */ public abstract class AbstractIscTrHandle implements IscTrHandle { - public final static int NOTRANSACTION = 0; - public final static int TRANSACTIONCOMMITTING = 5; - public final static int TRANSACTIONPREPARED = 4; - public final static int TRANSACTIONPREPARING = 3; - public final static int TRANSACTIONROLLINGBACK = 6; - public final static int TRANSACTIONSTARTED = 2; - public final static int TRANSACTIONSTARTING = 1; - private final List<IscBlobHandle> blobs = Collections.synchronizedList(new LinkedList<IscBlobHandle>()); private final Set<IscStmtHandle> stmts = Collections.synchronizedSet(new HashSet<IscStmtHandle>()); + private IscDbHandle rtr_rdb; + private int state = NOTRANSACTION; + private int rtr_id; - /** - * Clear all the saved result sets from this handle. - */ public void forgetResultSets() { synchronized(stmts) { for (Iterator<IscStmtHandle> iter = stmts.iterator(); iter.hasNext();) { @@ -65,16 +63,6 @@ stmts.clear(); } } - - /** - * Get the current state of the transaction to which this handle is - * pointing. The state is equal to one of the <code>TRANSACTION*</code> - * constants of this interface, or the <code>NOTRANSACTION</code> constant, - * also of this interface. - * - * @return The corresponding value for the current state - */ - public abstract int getState(); public void addBlob(IscBlobHandle blob) { blobs.add(blob); @@ -84,23 +72,60 @@ blobs.remove(blob); } - /** - * Register a statement within the transaction to which this handle points. - * This method allows automated cleanup of the rows fetched within a - * transaction on commit or rollback point. - * - * @param fbStatement Handle to the statement to be registered. - */ public void registerStatementWithTransaction(IscStmtHandle stmt) { stmts.add(stmt); } - /** - * Unregister a statement from the transaction in which it was registered. - * - * @param fbStatement Handle to the statement to be unregistered. - */ public void unregisterStatementFromTransaction(IscStmtHandle stmt) { stmts.remove(stmt); } + + public void addWarning(GDSException warning) { + rtr_rdb.addWarning(warning); + } + + public IscDbHandle getDbHandle() { + return rtr_rdb; + } + + public void setDbHandle(final IscDbHandle db) { + this.rtr_rdb = db; + rtr_rdb.addTransaction(this); + } + + public void unsetDbHandle() { + rtr_rdb.removeTransaction(this); + rtr_rdb = null; + } + + public void setState(int state) { + this.state = state; + } + + public int getState() { + return state; + } + + public void setTransactionId(final int rtr_id) { + this.rtr_id = rtr_id; + } + + public int getTransactionId() { + return rtr_id; + } + + @Override + public int hashCode() { + return rtr_id; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof AbstractIscTrHandle)) + return false; + AbstractIscTrHandle that = (AbstractIscTrHandle) obj; + return this.rtr_id == that.rtr_id; + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSHelper.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -90,7 +90,7 @@ listener.errorOccured(ex); } - public synchronized AbstractIscTrHandle getCurrentTrHandle() { + public synchronized IscTrHandle getCurrentTrHandle() { return currentTr; } @@ -592,7 +592,7 @@ } } - public void prepareTransaction(AbstractIscTrHandle trHandle, byte[] message) throws GDSException { + public void prepareTransaction(IscTrHandle trHandle, byte[] message) throws GDSException { try { gds.iscPrepareTransaction2(trHandle, message); } catch(GDSException ex) { @@ -601,7 +601,7 @@ } } - public void commitTransaction(AbstractIscTrHandle trHandle) throws GDSException { + public void commitTransaction(IscTrHandle trHandle) throws GDSException { try { gds.iscCommitTransaction(trHandle); } catch(GDSException ex) { @@ -610,7 +610,7 @@ } } - public void rollbackTransaction(AbstractIscTrHandle trHandle) throws GDSException { + public void rollbackTransaction(IscTrHandle trHandle) throws GDSException { try { gds.iscRollbackTransaction(trHandle); } catch(GDSException ex) { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -185,26 +185,25 @@ // isc_commit_retaining // --------------------------------------------------------------------------------------------- public void iscCommitRetaining(IscTrHandle tr_handle) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - IscDbHandle db = tr.getDbHandle(); + IscDbHandle db = tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); + tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); native_isc_commit_retaining(tr_handle); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } @@ -214,24 +213,23 @@ if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - IscDbHandle db = tr.getDbHandle(); + IscDbHandle db = tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); + tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); native_isc_commit_transaction(tr_handle); - tr.setState(AbstractIscTrHandle.NOTRANSACTION); + tr_handle.setState(IscTrHandle.NOTRANSACTION); - tr.unsetDbHandle(); + tr_handle.unsetDbHandle(); } } @@ -241,13 +239,12 @@ IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; - AbstractIscTrHandle tr = (AbstractIscTrHandle) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } if (blob == null) { @@ -262,8 +259,8 @@ native_isc_create_blob2(db_handle, tr_handle, blob_handle, bpb); blob.setDb(db); - blob.setTr(tr); - tr.addBlob(blob); + blob.setTr((AbstractIscTrHandle) tr_handle); + tr_handle.addBlob(blob); } } @@ -540,9 +537,7 @@ if (stmt_handle == null) { throw new GDSException(ISCConstants.isc_bad_req_handle); } - IscDbHandle db = stmt_handle.getRsr_rdb(); - - synchronized (db) { + synchronized (stmt_handle.getRsr_rdb()) { // Does not seem to be possible or necessary to close // an execute procedure statement. if (stmt_handle.isSingletonResult() && option == ISCConstants.DSQL_close) { return; } @@ -674,7 +669,7 @@ // --------------------------------------------------------------------------------------------- public byte[] iscDsqlSqlInfo(IscStmtHandle stmt_handle, byte[] items, int buffer_length) throws GDSException { - synchronized (((AbstractIscStmtHandle) stmt_handle).getRsr_rdb()) { + synchronized (stmt_handle.getRsr_rdb()) { return native_isc_dsql_sql_info(stmt_handle, items, buffer_length); } } @@ -693,14 +688,12 @@ public void iscOpenBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { - AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; - AbstractIscTrHandle tr = (AbstractIscTrHandle) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - if (db == null) { + if (db_handle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } if (blob == null) { @@ -711,12 +704,12 @@ : ((BlobParameterBufferImp) blobParameterBuffer) .getBytesForNativeCode(); - synchronized (db) { + synchronized (db_handle) { native_isc_open_blob2(db_handle, tr_handle, blob_handle, bpb); - blob.setDb(db); - blob.setTr(tr); - tr.addBlob(blob); + blob.setDb((AbstractIscDbHandle) db_handle); + blob.setTr((AbstractIscTrHandle) tr_handle); + tr_handle.addBlob(blob); } } @@ -724,19 +717,18 @@ // --------------------------------------------------------------------------------------------- public void iscPrepareTransaction(IscTrHandle tr_handle) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - synchronized (tr.getDbHandle()) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( + synchronized (tr_handle.getDbHandle()) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); native_isc_prepare_transaction(tr_handle); - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARED); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); } } @@ -744,21 +736,20 @@ // --------------------------------------------------------------------------------------------- public void iscPrepareTransaction2(IscTrHandle tr_handle, byte[] bytes) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - synchronized (tr.getDbHandle()) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { + synchronized (tr_handle.getDbHandle()) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); native_isc_prepare_transaction2(tr_handle, bytes); - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARED); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); } } @@ -780,43 +771,40 @@ public void iscReconnectTransaction(IscTrHandle tr_handle, IscDbHandle db_handle, long transactionId) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - byte[] buffer = new byte[4]; for (int i = 0; i < 4; i++){ buffer[i] = (byte)(transactionId >>> (i * 8)); } synchronized (db_handle) { - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); native_isc_reconnect_transaction(db_handle, tr_handle, buffer); - tr.setDbHandle(db_handle); + tr_handle.setDbHandle(db_handle); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } // isc_rollback_retaining // --------------------------------------------------------------------------------------------- public void iscRollbackRetaining(IscTrHandle tr_handle) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - IscDbHandle db = tr.getDbHandle(); + IscDbHandle db = tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { throw new GDSException( + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException( ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONROLLINGBACK); + tr_handle.setState(IscTrHandle.TRANSACTIONROLLINGBACK); native_isc_rollback_retaining(tr_handle); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } @@ -824,24 +812,23 @@ // --------------------------------------------------------------------------------------------- public void iscRollbackTransaction(IscTrHandle tr_handle) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - IscDbHandle db = tr.getDbHandle(); + IscDbHandle db = tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() == AbstractIscTrHandle.NOTRANSACTION) { throw new GDSException( + if (tr_handle.getState() == IscTrHandle.NOTRANSACTION) { throw new GDSException( ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONROLLINGBACK); + tr_handle.setState(IscTrHandle.TRANSACTIONROLLINGBACK); native_isc_rollback_transaction(tr_handle); - tr.setState(AbstractIscTrHandle.NOTRANSACTION); - tr.unsetDbHandle(); + tr_handle.setState(IscTrHandle.NOTRANSACTION); + tr_handle.unsetDbHandle(); } } @@ -927,10 +914,9 @@ public void iscStartTransaction(IscTrHandle tr_handle, IscDbHandle db_handle, TransactionParameterBuffer tpb) throws GDSException { - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -939,17 +925,17 @@ } synchronized (db_handle) { - if (tr.getState() != AbstractIscTrHandle.NOTRANSACTION) + if (tr_handle.getState() != IscTrHandle.NOTRANSACTION) throw new GDSException(ISCConstants.isc_tra_state); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); byte[] arg = tpbImpl.getBytesForNativeCode(); native_isc_start_transaction(tr_handle, db_handle, arg); - tr.setDbHandle(db_handle); + tr_handle.setDbHandle(db_handle); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_tr_handle_impl.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -16,20 +16,10 @@ * * All rights reserved. */ -/* - * The Original Code is the Firebird Java GDS implementation. - * - * The Initial Developer of the Original Code is Alejandro Alberola. - * Portions created by Alejandro Alberola are Copyright (C) 2001 - * Boix i Oltra, S.L. All Rights Reserved. - */ package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.IscDbHandle; -import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.impl.AbstractIscTrHandle; - /** * Describe class <code>isc_tr_handle_impl</code> here. * @@ -38,46 +28,4 @@ * @version 1.0 */ public final class isc_tr_handle_impl extends AbstractIscTrHandle { - private int rtr_id; - - private IscDbHandle rtr_rdb; - private int state = NOTRANSACTION; - - public isc_tr_handle_impl() { - } - - public void addWarning(GDSException warning) { - rtr_rdb.addWarning(warning); - } - - public IscDbHandle getDbHandle() { - return rtr_rdb; - } - - void setState(int state) { - this.state = state; - } - - public int getState() { - return state; - } - - void setTransactionId(final int rtr_id) - { - this.rtr_id = rtr_id; - } - - int getTransactionId() { - return rtr_id; - } - - void setDbHandle(final IscDbHandle db) { - this.rtr_rdb = db; - rtr_rdb.addTransaction(this); - } - - void unsetDbHandle() { - rtr_rdb.removeTransaction(this); - rtr_rdb = null; - } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -72,8 +72,9 @@ public static final String PURE_JAVA_TYPE_NAME = "PURE_JAVA"; - private static Logger log = LoggerFactory.getLogger( - AbstractJavaGDSImpl.class, false); + private static Logger log = LoggerFactory.getLogger(AbstractJavaGDSImpl.class, false); + + // TODO Move operation constants to separate class/interface /* Operation (packet) types */ @@ -734,7 +735,6 @@ TransactionParameterBuffer tpb) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_db_handle_impl db = (isc_db_handle_impl) db_handle; TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; @@ -742,15 +742,15 @@ if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - - if (db_handle == null) { + if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } + synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.NOTRANSACTION) { + if (tr_handle.getState() != IscTrHandle.NOTRANSACTION) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); try { if (debug) @@ -765,10 +765,10 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_network_error); } - tr.setTransactionId(db.getResp_object()); + tr_handle.setTransactionId(db.getResp_object()); - tr.setDbHandle(db); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setDbHandle(db); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } @@ -777,20 +777,19 @@ IscDbHandle db_handle, long transactionId) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_db_handle_impl db = (isc_db_handle_impl) db_handle; if (tr_handle == null) throw new GDSException(ISCConstants.isc_bad_trans_handle); - if (db_handle == null) + if (db == null) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.NOTRANSACTION) + if (tr_handle.getState() != IscTrHandle.NOTRANSACTION) throw new GDSException(ISCConstants.isc_tra_state); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTING); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); try { if (debug) @@ -812,11 +811,10 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_network_error); } - tr.setTransactionId(db.getResp_object()); + tr_handle.setTransactionId(db.getResp_object()); - // tr.rtr_rdb = db; - tr.setDbHandle(db); - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setDbHandle(db); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); // db.rdb_transactions.addElement(tr); } } @@ -827,27 +825,26 @@ throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); + tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); try { if (debug) { log.debug("op_commit "); - log.debug("tr.rtr_id: " + tr.getTransactionId()); + log.debug("tr.rtr_id: " + tr_handle.getTransactionId()); } db.out.writeInt(op_commit); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.flush(); if (debug) log.debug("sent"); @@ -856,34 +853,33 @@ throw new GDSException(ISCConstants.isc_net_read_err); } - tr.setState(AbstractIscTrHandle.NOTRANSACTION); - tr.unsetDbHandle(); + tr_handle.setState(IscTrHandle.NOTRANSACTION); + tr_handle.unsetDbHandle(); } } public void iscCommitRetaining(IscTrHandle tr_handle) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONCOMMITTING); + tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); try { if (debug) log.debug("op_commit_retaining "); db.out.writeInt(op_commit_retaining); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.flush(); if (debug) log.debug("sent"); @@ -891,7 +887,7 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); } - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } @@ -899,22 +895,21 @@ public void iscPrepareTransaction(IscTrHandle tr_handle) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); try { if (debug) log.debug("op_prepare "); db.out.writeInt(op_prepare); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.flush(); if (debug) log.debug("sent"); @@ -922,29 +917,28 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARED); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); } } public void iscPrepareTransaction2(IscTrHandle tr_handle, byte[] bytes) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARING); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); try { if (debug) log.debug("op_prepare2 "); db.out.writeInt(op_prepare2); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.writeBuffer(bytes); db.out.flush(); if (debug) @@ -954,7 +948,7 @@ throw new GDSException(ISCConstants.isc_net_read_err); } - tr.setState(AbstractIscTrHandle.TRANSACTIONPREPARED); + tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); } } @@ -962,26 +956,25 @@ throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() == AbstractIscTrHandle.NOTRANSACTION) { + if (tr_handle.getState() == IscTrHandle.NOTRANSACTION) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONROLLINGBACK); + tr_handle.setState(IscTrHandle.TRANSACTIONROLLINGBACK); try { if (debug) log.debug("op_rollback "); db.out.writeInt(op_rollback); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.flush(); if (debug) log.debug("sent"); @@ -989,34 +982,33 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); } finally { - tr.setState(AbstractIscTrHandle.NOTRANSACTION); - tr.unsetDbHandle(); + tr_handle.setState(IscTrHandle.NOTRANSACTION); + tr_handle.unsetDbHandle(); } } } public void iscRollbackRetaining(IscTrHandle tr_handle) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); if (db == null || !db.isValid()) throw new GDSException(ISCConstants.isc_bad_db_handle); synchronized (db) { - if (tr.getState() != AbstractIscTrHandle.TRANSACTIONSTARTED - && tr.getState() != AbstractIscTrHandle.TRANSACTIONPREPARED) { + if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED + && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { throw new GDSException(ISCConstants.isc_tra_state); } - tr.setState(AbstractIscTrHandle.TRANSACTIONROLLINGBACK); + tr_handle.setState(IscTrHandle.TRANSACTIONROLLINGBACK); try { if (debug) log.debug("op_rollback_retaining "); db.out.writeInt(op_rollback_retaining); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.flush(); if (debug) log.debug("sent"); @@ -1024,7 +1016,7 @@ } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); } - tr.setState(AbstractIscTrHandle.TRANSACTIONSTARTED); + tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); } } @@ -1032,18 +1024,17 @@ byte[] requestBuffer, int bufferLen) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - isc_db_handle_impl db = (isc_db_handle_impl) tr.getDbHandle(); + isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); synchronized (db) { try { if (debug) log.debug("op_info_transaction "); db.out.writeInt(op_info_transaction); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.writeInt(0); db.out.writeBuffer(requestBuffer); db.out.writeInt(bufferLen); @@ -1102,7 +1093,6 @@ throw new GDSException(ISCConstants.isc_wish_list); } - public XSQLDA iscDsqlDescribe(IscStmtHandle stmt_handle, int da_version) throws GDSException { byte[] describeSelectInfo = getDescribeSelectInfo(stmt_handle); byte[] buffer = iscDsqlSqlInfo(stmt_handle, describeSelectInfo, MAX_BUFFER_SIZE); @@ -1129,7 +1119,6 @@ XSQLDA out_xsqlda) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_db_handle_impl db = (isc_db_handle_impl) stmt_handle.getRsr_rdb(); // Test Handles needed here @@ -1142,7 +1131,7 @@ out.writeInt((out_xsqlda == null) ? op_execute : op_execute2); out.writeInt(stmt_handle.getRsrId()); - out.writeInt(tr.getTransactionId()); + out.writeInt(tr_handle.getTransactionId()); if (in_xsqlda != null) { out.writeBuffer(in_xsqlda.blr); @@ -1180,7 +1169,7 @@ } // end of else receiveResponse(db, op); - stmt_handle.registerTransaction(tr); + stmt_handle.registerTransaction(tr_handle); } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); @@ -1234,7 +1223,6 @@ throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_db_handle_impl db = (isc_db_handle_impl) db_handle; // Test Handles @@ -1269,7 +1257,7 @@ out.writeInt(0); } - out.writeInt(tr.getTransactionId()); + out.writeInt(tr_handle.getTransactionId()); out.writeInt(0); out.writeInt(dialect); out.writeBuffer(statement); @@ -1342,7 +1330,8 @@ sqldata_messages = in.readInt(); if (sqldata_messages > 0 && sqldata_status == 0) { - in.readSQLData(xsqlda.ioLength, (isc_stmt_handle_impl) stmt_handle); + in.readSQLData(xsqlda.ioLength, stmt_handle); + // TODO Replace with while do { op = nextOperation(db.in); if (op == op_response) { @@ -1444,14 +1433,14 @@ stmt_handle.clearRows(); try { - AbstractIscTrHandle tr = (AbstractIscTrHandle)stmt_handle.getTransaction(); + IscTrHandle tr = stmt_handle.getTransaction(); if (tr != null) tr.unregisterStatementFromTransaction(stmt_handle); } finally { stmt_handle.unregisterTransaction(); } - /** @todo implement statement handle tracking correctly */ + // TODO implement statement handle tracking correctly // db.rdb_sql_requests.remove(stmt); } catch (IOException ex) { throw new GDSException(ISCConstants.isc_net_read_err); @@ -1488,7 +1477,6 @@ } boolean debug = log != null && log.isDebugEnabled(); - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_db_handle_impl db = (isc_db_handle_impl) stmt_handle.getRsr_rdb(); // reinitialize stmt SQLDA members. @@ -1500,7 +1488,7 @@ if (debug) log.debug("op_prepare_statement "); db.out.writeInt(op_prepare_statement); - db.out.writeInt(tr.getTransactionId()); + db.out.writeInt(tr_handle.getTransactionId()); db.out.writeInt(stmt_handle.getRsrId()); db.out.writeInt(dialect); db.out.writeBuffer(statement); @@ -1703,13 +1691,12 @@ throws GDSException { boolean debug = log != null && log.isDebugEnabled(); isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle; isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - if (tr == null) { + if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } if (blob == null) { @@ -1729,7 +1716,7 @@ db.out.writeTyped(ISCConstants.isc_bpb_version1, (Xdrable) blobParameterBuffer); } - db.out.writeInt(tr.getTransactionId()); // ??really a short? + db.out.writeInt(tr_handle.getTransactionId()); // ??really a short? if (debug) log.debug("sending blob_id: " + blob.getBlobId()); db.out.writeLong(blob.getBlobId()); @@ -1739,10 +1726,10 @@ log.debug("sent"); receiveResponse(db, -1); blob.setDb(db); - blob.setTr(tr); + blob.setTr((AbstractIscTrHandle) tr_handle); blob.setRbl_id(db.getResp_object()); blob.setBlobId(db.getResp_blob_id()); - tr.addBlob(blob); + tr_handle.addBlob(blob); } catch (IOException ioe) { throw new GDSException(ISCConstants.isc_net_read_err); } @@ -1757,7 +1744,7 @@ if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - AbstractIscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -1827,7 +1814,7 @@ if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - AbstractIscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -1859,7 +1846,7 @@ if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - AbstractIscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -2164,11 +2151,9 @@ int op = 0; do { op = in.readInt(); - if (debug) { - if (op == op_dummy) { - log.debug("op_dummy received"); - } - } + if (debug && op == op_dummy) { + log.debug("op_dummy received"); + } } while (op == op_dummy); return op; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/XdrInputStream.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/XdrInputStream.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/XdrInputStream.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -25,15 +25,14 @@ * Boix i Oltra, S.L. All Rights Reserved. * */ - package org.firebirdsql.gds.impl.wire; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import org.firebirdsql.gds.IscStmtHandle; - /** * <code>XdrInputStream</code> is an input stream for reading in data that * is in the XDR format. An <code>XdrInputStream</code> instance is wrapped @@ -127,7 +126,7 @@ * @throws IOException if an error occurs while reading from the * underlying input stream */ - public void readSQLData(int[] ioLength, isc_stmt_handle_impl stmt) throws IOException { + public void readSQLData(int[] ioLength, IscStmtHandle stmt) throws IOException { // This only works if not (port->port_flags & PORT_symmetric) int numCols = ioLength.length; byte[][] row = new byte[numCols][]; Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_tr_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_tr_handle_impl.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_tr_handle_impl.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -16,77 +16,16 @@ * * All rights reserved. */ -/* - * The Original Code is the Firebird Java GDS implementation. - * - * The Initial Developer of the Original Code is Alejandro Alberola. - * Portions created by Alejandro Alberola are Copyright (C) 2001 - * Boix i Oltra, S.L. All Rights Reserved. - */ - package org.firebirdsql.gds.impl.wire; -import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.impl.AbstractIscTrHandle; - /** * Describe class <code>isc_tr_handle_impl</code> here. - * + * * @author <a href="mailto:alb...@us...">Alejandro Alberola</a> * @author <a href="mailto:d_j...@us...">David Jencks</a> * @version 1.0 */ public final class isc_tr_handle_impl extends AbstractIscTrHandle { - private int rtr_id; - private IscDbHandle rtr_rdb; - private int state = NOTRANSACTION; - - public isc_tr_handle_impl() { - } - - public IscDbHandle getDbHandle() { - return rtr_rdb; - } - - void setState(int state) { - this.state = state; - } - - public int getState() { - return state; - } - - void setTransactionId(final int rtr_id) - { - this.rtr_id = rtr_id; - } - - int getTransactionId() - { - return rtr_id; - } - - void setDbHandle(final IscDbHandle db) - { - this.rtr_rdb = db; - rtr_rdb.addTransaction(this); - } - - void unsetDbHandle() - { - rtr_rdb.removeTransaction(this); - rtr_rdb = null; - } - - public int hashCode() { - return rtr_id; - } - - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof isc_tr_handle_impl)) return false; - isc_tr_handle_impl that = (isc_tr_handle_impl)obj; - return this.rtr_id == that.rtr_id; - } } Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -860,7 +860,7 @@ int internalPrepare(Xid xid) throws FBXAException, GDSException { if (log != null) log.trace("prepare called: " + xid); - AbstractIscTrHandle committingTr = xidMap.get(xid); + IscTrHandle committingTr = xidMap.get(xid); if (committingTr == null) throw new FBXAException("Prepare called with unknown transaction", XAException.XAER_NOTA); Modified: client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java 2012-11-05 15:57:56 UTC (rev 57313) +++ client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java 2012-11-05 17:29:36 UTC (rev 57314) @@ -86,7 +86,7 @@ GDSHelper gdsHelper1 = new GDSHelper(gds, dpb, dbHandle1, null); - AbstractIscTrHandle trHandle1 = (AbstractIscTrHandle)gds.createIscTrHandle(); + IscTrHandle trHandle1 = gds.createIscTrHandle(); gds.iscStartTransaction(trHandle1, dbHandle1, tpb.getTransactionParameterBuffer()); gdsHelper1.getTransactionId(trHandle1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-11 12:56:52
|
Revision: 57342 http://firebird.svn.sourceforge.net/firebird/?rev=57342&view=rev Author: mrotteveel Date: 2012-11-11 12:56:44 +0000 (Sun, 11 Nov 2012) Log Message: ----------- Cleanup IscBlobHandle implementations and usage (step towards using interfaces wherever possible) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/IscBlobHandle.java client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_svc_handle_impl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_blob_handle_impl.java client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscBlobHandle.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/IscBlobHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/IscBlobHandle.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/IscBlobHandle.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -48,7 +48,44 @@ */ void setBlobId(long blobId); - // only used in the tests + /** + * Get the database handle for this blob + * + * @return Database handle for this blob + */ + IscDbHandle getDb(); + + /** + * Set the database handle for this blob + * + * @param value Database handle for this blob + */ + void setDb(IscDbHandle value); + + /** + * Get the transaction handle for this blob + * + * @return Transaction handle for this blob + */ + IscTrHandle getTr(); + + /** + * Set the transaction handle for this blob + * + * @param value Transaction handle for this blob + */ + void setTr(IscTrHandle value); + + /** + * Add a warning to the connection associated with this blob. + * + * @param warning Warning to add + */ + void addWarning(GDSException warning); + + int getRblId(); + + void setRblId(int value); /** * Retrieve whether the <code>EOF</code> has been reached with this blob. @@ -57,5 +94,9 @@ * <code>false</code> otherwise */ boolean isEof(); - + + /** + * Sets this blob handle as being eof + */ + void setEof(); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/IscTrHandle.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -53,9 +53,19 @@ public static final int TRANSACTIONCOMMITTING = 5; public static final int TRANSACTIONROLLINGBACK = 6; + /** + * Get the Firebird id for this transaction. + * + * @return Firebird transaction id + */ int getTransactionId(); - void setTransactionId(final int rtr_id); + /** + * Sets the Firebird id for this transaction. + * + * param rtr_id Firebird transaction id + */ + void setTransactionId(int rtr_id); /** * Retrieve a handle to the database to which this transaction is linked. @@ -67,7 +77,7 @@ /** * Sets a handle to the database to which this transaction is linked. * - * @return Handle to the database + * @param db Handle to the database */ void setDbHandle(IscDbHandle db); @@ -93,10 +103,25 @@ */ int getState(); + /** + * Sets the current transaction state. + * + * @param state The value for the current state + */ void setState(int state); + /** + * Register blob created under this transaction. + * + * @param blob Blob to be registered + */ void addBlob(IscBlobHandle blob); + /** + * Remove blob as registered under this transaction. + * + * @param blob Blob to removed + */ void removeBlob(IscBlobHandle blob); /** Added: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscBlobHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscBlobHandle.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscBlobHandle.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -0,0 +1,81 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.IscBlobHandle; +import org.firebirdsql.gds.IscDbHandle; +import org.firebirdsql.gds.IscTrHandle; + +/** + * Abstract implementation of the {@link org.firebirdsql.gds.IscBlobHandle} + * interface. + */ +public abstract class AbstractIscBlobHandle implements IscBlobHandle { + + private IscDbHandle db; + private IscTrHandle tr; + private int rbl_id; + private long blob_id; + private boolean isEndOfFile = false; + + public void addWarning(GDSException warning) { + db.addWarning(warning); + } + + public IscTrHandle getTr() { + return tr; + } + + public void setTr(IscTrHandle value) { + tr = value; + } + + public IscDbHandle getDb() { + return db; + } + + public void setDb(IscDbHandle value) { + db = value; + } + + public long getBlobId() { + return blob_id; + } + + public void setBlobId(long value) { + blob_id = value; + } + + public int getRblId() { + return rbl_id; + } + + public void setRblId(int value) { + rbl_id = value; + } + + public boolean isEof() { + return isEndOfFile; + } + + public void setEof() { + isEndOfFile = true; + } +} \ No newline at end of file Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/impl/AbstractIscBlobHandle.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -25,9 +25,6 @@ import org.firebirdsql.encodings.EncodingFactory; import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.AbstractGDS; -import org.firebirdsql.gds.impl.AbstractIscDbHandle; -import org.firebirdsql.gds.impl.AbstractIscStmtHandle; -import org.firebirdsql.gds.impl.AbstractIscTrHandle; import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.logging.Logger; @@ -38,8 +35,7 @@ // TODO Synchronization seems to be inconsistent: sometimes on dbhandle, sometimes on this (and sometimes on blobhandle) // TODO Checking for validity of dbhandle is inconsistent (sometimes only null check, sometimes also .isValid()) - private static Logger log = LoggerFactory.getLogger(BaseGDSImpl.class, - false); + private static Logger log = LoggerFactory.getLogger(BaseGDSImpl.class, false); protected static final byte[] DESCRIBE_DATABASE_INFO_BLOCK = new byte[] { ISCConstants.isc_info_db_sql_dialect, @@ -67,8 +63,7 @@ super(gdsType); } - protected abstract String getServerUrl(String file_name) - throws GDSException; + protected abstract String getServerUrl(String file_name) throws GDSException; public BlobParameterBuffer createBlobParameterBuffer() { return new BlobParameterBufferImp(); @@ -156,21 +151,20 @@ public byte[] iscBlobInfo(IscBlobHandle handle, byte[] items, int buffer_length) throws GDSException { - isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; - synchronized (blob) { - return native_isc_blob_info(blob, items, buffer_length); + synchronized (handle) { + // TODO Change native method to accept IscBlobHandle + return native_isc_blob_info((isc_blob_handle_impl) handle, items, buffer_length); } } // isc_close_blob // --------------------------------------------------------------------------------------------- public void iscCloseBlob(IscBlobHandle blob_handle) throws GDSException { - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - IscDbHandle db = blob.getDb(); + IscDbHandle db = blob_handle.getDb(); if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - AbstractIscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob_handle.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -179,7 +173,7 @@ native_isc_close_blob(blob_handle); } - tr.removeBlob(blob); + tr.removeBlob(blob_handle); } // isc_commit_retaining @@ -238,16 +232,13 @@ public void iscCreateBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { - AbstractIscDbHandle db = (AbstractIscDbHandle) db_handle; - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - - if (db == null) { + if (db_handle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - if (blob == null) { + if (blob_handle == null) { throw new GDSException(ISCConstants.isc_bad_segstr_handle); } @@ -255,12 +246,12 @@ : ((BlobParameterBufferImp) blobParameterBuffer) .getBytesForNativeCode(); - synchronized (db) { + synchronized (db_handle) { native_isc_create_blob2(db_handle, tr_handle, blob_handle, bpb); - blob.setDb(db); - blob.setTr((AbstractIscTrHandle) tr_handle); - tr_handle.addBlob(blob); + blob_handle.setDb(db_handle); + blob_handle.setTr(tr_handle); + tr_handle.addBlob(blob_handle); } } @@ -325,6 +316,7 @@ db_handle.invalidate(); } catch (Exception e) { // Actual implementation does not throw exception + // TODO : Invalidate should throw GDSException? throw new GDSException(ISCConstants.isc_network_error); } } @@ -552,7 +544,7 @@ // clear association with transaction try { - AbstractIscTrHandle tr = (AbstractIscTrHandle)stmt_handle.getTransaction(); + IscTrHandle tr = stmt_handle.getTransaction(); if (tr != null) tr.unregisterStatementFromTransaction(stmt_handle); } finally { @@ -678,7 +670,7 @@ // --------------------------------------------------------------------------------------------- public byte[] iscGetSegment(IscBlobHandle blob, int maxread) throws GDSException { - synchronized (((isc_blob_handle_impl) blob).getDb()) { + synchronized (blob.getDb()) { return native_isc_get_segment(blob, maxread); } } @@ -688,15 +680,13 @@ public void iscOpenBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, IscBlobHandle blob_handle, BlobParameterBuffer blobParameterBuffer) throws GDSException { - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - if (db_handle == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - if (blob == null) { + if (blob_handle == null) { throw new GDSException(ISCConstants.isc_bad_segstr_handle); } @@ -707,9 +697,9 @@ synchronized (db_handle) { native_isc_open_blob2(db_handle, tr_handle, blob_handle, bpb); - blob.setDb((AbstractIscDbHandle) db_handle); - blob.setTr((AbstractIscTrHandle) tr_handle); - tr_handle.addBlob(blob); + blob_handle.setDb(db_handle); + blob_handle.setTr(tr_handle); + tr_handle.addBlob(blob_handle); } } @@ -757,7 +747,7 @@ // --------------------------------------------------------------------------------------------- public void iscPutSegment(IscBlobHandle blob_handle, byte[] buffer) throws GDSException { - synchronized (((isc_blob_handle_impl) blob_handle).getDb()) { + synchronized (blob_handle.getDb()) { native_isc_put_segment(blob_handle, buffer); } } @@ -843,6 +833,7 @@ throws GDSException { isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; synchronized (handle) { + // TODO Change native method to accept IscBlobHandle native_isc_seek_blob(blob, position, mode); } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_blob_handle_impl.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -16,12 +16,9 @@ * * All rights reserved. */ - package org.firebirdsql.gds.impl.jni; -import org.firebirdsql.gds.*; -import org.firebirdsql.gds.impl.AbstractIscDbHandle; -import org.firebirdsql.gds.impl.AbstractIscTrHandle; +import org.firebirdsql.gds.impl.AbstractIscBlobHandle; /** * Describe class <code>isc_blob_handle_impl</code> here. @@ -29,58 +26,5 @@ * @author <a href="mailto:d_j...@us...">David Jencks</a> * @version 1.0 */ -public final class isc_blob_handle_impl implements IscBlobHandle { - - private AbstractIscDbHandle db; - - private AbstractIscTrHandle tr; - - private int rbl_id; - - private long blob_id; - - boolean isEndOfFile = false; - - public isc_blob_handle_impl() { - }; - - public void addWarning(GDSException warning) { - db.addWarning(warning); - } - - public AbstractIscTrHandle getTr() { - return tr; - } - - public void setTr(AbstractIscTrHandle value) { - tr = value; - } - - public AbstractIscDbHandle getDb() { - return db; - } - - public void setDb(AbstractIscDbHandle value) { - db = value; - } - - public long getBlobId() { - return blob_id; - } - - public void setBlobId(long value) { - blob_id = value; - } - - public int getRblId() { - return rbl_id; - } - - public void setRblId(int value) { - rbl_id = value; - } - - public boolean isEof() { - return isEndOfFile; - } +public final class isc_blob_handle_impl extends AbstractIscBlobHandle { } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_svc_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_svc_handle_impl.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/isc_svc_handle_impl.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -30,7 +30,7 @@ /** * ngds implementation for isc_svc_handle. */ -class isc_svc_handle_impl implements IscSvcHandle { +public final class isc_svc_handle_impl implements IscSvcHandle { private List<GDSException> warnings = Collections.synchronizedList(new LinkedList<GDSException>()); private int handle = 0; Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -519,14 +519,13 @@ public byte[] iscBlobInfo(IscBlobHandle handle, byte[] items, int buffer_length) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; - isc_db_handle_impl db = blob.getDb(); - synchronized (blob) { + isc_db_handle_impl db = (isc_db_handle_impl) handle.getDb(); + synchronized (handle) { try { if (debug) log.debug("op_info_blob "); db.out.writeInt(op_info_blob); - db.out.writeInt(blob.getRbl_id()); + db.out.writeInt(handle.getRblId()); db.out.writeInt(0); db.out.writeBuffer(items); db.out.writeInt(buffer_length); @@ -547,21 +546,19 @@ public void iscSeekBlob(IscBlobHandle handle, int position, int seekMode) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; - isc_db_handle_impl db = blob.getDb(); - synchronized (blob) { + isc_db_handle_impl db = (isc_db_handle_impl) handle.getDb(); + synchronized (handle) { try { if (debug) log.debug("op_info_blob "); db.out.writeInt(op_seek_blob); - db.out.writeInt(blob.getRbl_id()); + db.out.writeInt(handle.getRblId()); db.out.writeInt(seekMode); db.out.writeInt(position); db.out.flush(); if (debug) log.debug("sent"); receiveResponse(db, -1); - blob.setPosition(db.getResp_object()); } catch (IOException ex) { throw new GDSException(ISCConstants.isc_network_error); } @@ -1672,8 +1669,6 @@ blobParameterBuffer, (blobParameterBuffer == null) ? op_create_blob : op_create_blob2); - ((isc_blob_handle_impl) blob_handle) - .rbl_flagsAdd(ISCConstants.RBL_create); } public void iscOpenBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, @@ -1691,15 +1686,13 @@ throws GDSException { boolean debug = log != null && log.isDebugEnabled(); isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } if (tr_handle == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - if (blob == null) { + if (blob_handle == null) { throw new GDSException(ISCConstants.isc_bad_segstr_handle); } synchronized (db) { @@ -1718,18 +1711,18 @@ } db.out.writeInt(tr_handle.getTransactionId()); // ??really a short? if (debug) - log.debug("sending blob_id: " + blob.getBlobId()); - db.out.writeLong(blob.getBlobId()); + log.debug("sending blob_id: " + blob_handle.getBlobId()); + db.out.writeLong(blob_handle.getBlobId()); db.out.flush(); if (debug) log.debug("sent"); receiveResponse(db, -1); - blob.setDb(db); - blob.setTr((AbstractIscTrHandle) tr_handle); - blob.setRbl_id(db.getResp_object()); - blob.setBlobId(db.getResp_blob_id()); - tr_handle.addBlob(blob); + blob_handle.setDb(db); + blob_handle.setTr(tr_handle); + blob_handle.setRblId(db.getResp_object()); + blob_handle.setBlobId(db.getResp_blob_id()); + tr_handle.addBlob(blob_handle); } catch (IOException ioe) { throw new GDSException(ISCConstants.isc_net_read_err); } @@ -1739,12 +1732,11 @@ public byte[] iscGetSegment(IscBlobHandle blob_handle, int requested) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - isc_db_handle_impl db = blob.getDb(); + isc_db_handle_impl db = (isc_db_handle_impl) blob_handle.getDb(); if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - IscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob_handle.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -1754,7 +1746,7 @@ if (debug) log.debug("op_get_segment "); db.out.writeInt(op_get_segment); - db.out.writeInt(blob.getRbl_id()); // short??? + db.out.writeInt(blob_handle.getRblId()); // short??? if (debug) log .debug("trying to read bytes: " @@ -1768,11 +1760,8 @@ if (debug) log.debug("sent"); receiveResponse(db, -1); - blob.rbl_flagsRemove(ISCConstants.RBL_segment); - if (db.getResp_object() == 1) { - blob.rbl_flagsAdd(ISCConstants.RBL_segment); - } else if (db.getResp_object() == 2) { - blob.rbl_flagsAdd(ISCConstants.RBL_eof_pending); + if (db.getResp_object() == 2) { + blob_handle.setEof(); } if (db.getResp_data_len() == 0) @@ -1809,12 +1798,11 @@ public void iscPutSegment(IscBlobHandle blob_handle, byte[] buffer) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - isc_db_handle_impl db = blob.getDb(); + isc_db_handle_impl db = (isc_db_handle_impl) blob_handle.getDb(); if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - IscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob_handle.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } @@ -1825,8 +1813,8 @@ log.debug("op_batch_segments "); db.out.writeInt(op_batch_segments); if (debug) - log.debug("blob.rbl_id: " + blob.getRbl_id()); - db.out.writeInt(blob.getRbl_id()); // short??? + log.debug("blob.rbl_id: " + blob_handle.getRblId()); + db.out.writeInt(blob_handle.getRblId()); // short??? if (debug) log.debug("buffer.length " + buffer.length); db.out.writeBlobBuffer(buffer); @@ -1841,17 +1829,16 @@ } public void iscCloseBlob(IscBlobHandle blob_handle) throws GDSException { - isc_blob_handle_impl blob = (isc_blob_handle_impl) blob_handle; - isc_db_handle_impl db = blob.getDb(); + isc_db_handle_impl db = (isc_db_handle_impl) blob_handle.getDb(); if (db == null) { throw new GDSException(ISCConstants.isc_bad_db_handle); } - IscTrHandle tr = blob.getTr(); + IscTrHandle tr = blob_handle.getTr(); if (tr == null) { throw new GDSException(ISCConstants.isc_bad_trans_handle); } - releaseObject(db, op_close_blob, blob.getRbl_id()); - tr.removeBlob(blob); + releaseObject(db, op_close_blob, blob_handle.getRblId()); + tr.removeBlob(blob_handle); } private byte[] getByteArrayForString(String statement, String encoding) Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_blob_handle_impl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_blob_handle_impl.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/isc_blob_handle_impl.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -16,12 +16,10 @@ * * All rights reserved. */ - package org.firebirdsql.gds.impl.wire; -import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.IscBlobHandle; -import org.firebirdsql.gds.impl.AbstractIscTrHandle; +import org.firebirdsql.gds.impl.AbstractIscBlobHandle; /** * Describe class <code>isc_blob_handle_impl</code> here. @@ -29,71 +27,5 @@ * @author <a href="mailto:d_j...@us...">David Jencks</a> * @version 1.0 */ -public final class isc_blob_handle_impl implements IscBlobHandle { - - private isc_db_handle_impl db; - private AbstractIscTrHandle tr; - private int rbl_id; - private long blob_id; - private int rbl_flags; - private int position; - - isc_blob_handle_impl() {}; - - public AbstractIscTrHandle getTr() { - return tr; - } - - public void setTr(AbstractIscTrHandle value) { - tr = value; - } - - public isc_db_handle_impl getDb() { - return db; - } - - public void setDb(isc_db_handle_impl value) { - db = value; - } - - public long getBlobId() { - return blob_id; - } - - public void setBlobId(long value) { - blob_id = value; - } - - public int getRbl_id() { - return rbl_id; - } - - public void setRbl_id(int value) { - rbl_id = value; - } -/* not used - public int getRbl_flags() { - return rbl_flags; - } -*/ - public void rbl_flagsAdd(int value) { - rbl_flags |= value; - } - - public void rbl_flagsRemove(int value) { - rbl_flags &= ~value; - } - - public int getPosition() { - return position; - } - - public void setPosition(int position) { - this.position = position; - } - - // only used in the tests - public boolean isEof() { - return (rbl_flags & ISCConstants.RBL_eof_pending) != 0; - } +public final class isc_blob_handle_impl extends AbstractIscBlobHandle implements IscBlobHandle { } Modified: client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/test/org/firebirdsql/gds/TestReconnectTransaction.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -4,7 +4,6 @@ import org.firebirdsql.common.FBTestBase; import org.firebirdsql.gds.impl.*; -import org.firebirdsql.gds.impl.wire.isc_db_handle_impl; import org.firebirdsql.jca.FBTpb; import org.firebirdsql.jdbc.FBTpbMapper; import org.firebirdsql.jdbc.field.FBField; @@ -96,8 +95,7 @@ //gds.isc_commit_transaction(trHandle1); //gds.isc_detach_database(dbHandle1); - if (dbHandle1 instanceof isc_db_handle_impl) - ((isc_db_handle_impl)dbHandle1).out.close(); + dbHandle1.invalidate(); IscDbHandle dbHandle2 = gds.createIscDbHandle(); gds.iscAttachDatabase(getdbpath(DB_NAME), dbHandle2, dpb); @@ -155,8 +153,6 @@ row++; } - - gdsHelper2.closeStatement(stmtHandle2, true); gds.iscCommitTransaction(trHandle2); Modified: client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -29,6 +29,7 @@ import org.firebirdsql.gds.DatabaseParameterBuffer; import org.firebirdsql.gds.GDS; import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.IscBlobHandle; import org.firebirdsql.gds.IscDbHandle; import org.firebirdsql.gds.IscStmtHandle; import org.firebirdsql.gds.IscTrHandle; @@ -377,7 +378,7 @@ db1 = createDatabase(dbName); t1 = startTransaction(db1); - isc_blob_handle_impl blob = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob = gds.createIscBlobHandle(); gds.iscCreateBlob2(db1, t1, blob, null); gds.iscCloseBlob(blob); commit(t1); @@ -391,7 +392,7 @@ db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds.createBlobParameterBuffer(); blobParameterBuffer.addArgument(ISCConstants.isc_bpb_type, ISCConstants.isc_bpb_type_segmented); gds.iscCreateBlob2(db1, t1, blob1, blobParameterBuffer); @@ -433,7 +434,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -479,7 +480,7 @@ db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds.createBlobParameterBuffer(); blobParameterBuffer.addArgument(ISCConstants.isc_bpb_type, ISCConstants.isc_bpb_type_segmented); gds.iscCreateBlob2(db1, t1, blob1, blobParameterBuffer); @@ -524,7 +525,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -577,7 +578,7 @@ db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds.createBlobParameterBuffer(); blobParameterBuffer.addArgument(ISCConstants.isc_bpb_type, ISCConstants.isc_bpb_type_segmented); gds.iscCreateBlob2(db1, t1, blob1, blobParameterBuffer); @@ -623,7 +624,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -678,7 +679,7 @@ db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds.createBlobParameterBuffer(); blobParameterBuffer.addArgument(ISCConstants.isc_bpb_type, ISCConstants.isc_bpb_type_stream); gds.iscCreateBlob2(db1, t1, blob1, blobParameterBuffer); @@ -724,7 +725,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds.createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); Modified: client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java 2012-11-11 12:53:07 UTC (rev 57341) +++ client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java 2012-11-11 12:56:44 UTC (rev 57342) @@ -16,7 +16,6 @@ * * All rights reserved. */ - package org.firebirdsql.gds.impl.wire; import java.util.Arrays; @@ -27,7 +26,6 @@ import org.firebirdsql.logging.LoggerFactory; import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.GDSFactory; -import org.firebirdsql.gds.impl.wire.isc_blob_handle_impl; import org.firebirdsql.gds.impl.wire.isc_db_handle_impl; import org.firebirdsql.gds.impl.wire.isc_stmt_handle_impl; import org.firebirdsql.jca.FBTpb; @@ -460,8 +458,7 @@ if (log != null) log.info("test- testCreateBlob"); db1 = createDatabase(dbName); t1 = startTransaction(db1); - isc_blob_handle_impl blob = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob = gds.createIscBlobHandle(); gds.iscCreateBlob2(db1, t1, blob, null); gds.iscCloseBlob(blob); commit(t1); @@ -479,8 +476,7 @@ if (log != null) log.info("test- test- testCreateAndWriteBlob"); db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds .createBlobParameterBuffer(); @@ -521,8 +517,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -563,8 +558,7 @@ if (log != null) log.info("test- testCreateAndWriteBlobStream"); db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds .createBlobParameterBuffer(); @@ -610,8 +604,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -659,8 +652,7 @@ log.info("test- testCreateAndWriteBlobStreamInSegmentedPieces"); db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); // Clumplet bpb = GDSFactory.newClumplet(ISCConstants.isc_bpb_type, // ISCConstants.isc_bpb_type_stream); @@ -706,8 +698,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); @@ -752,8 +743,7 @@ log.info("test- testCreateAndWriteBlobInStreamPieces"); db1 = setupTable2(); t1 = startTransaction(db1); - isc_blob_handle_impl blob1 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob1 = gds.createIscBlobHandle(); final BlobParameterBuffer blobParameterBuffer = gds .createBlobParameterBuffer(); @@ -798,8 +788,7 @@ if (log != null) log.info("test- isc_dsql_execute2"); gds.iscDsqlExecute2(t1, stmt1, 1, null, null); - isc_blob_handle_impl blob2 = (isc_blob_handle_impl) gds - .createIscBlobHandle(); + IscBlobHandle blob2 = gds.createIscBlobHandle(); byte[][] row = null; gds.iscDsqlFetch(stmt1, 1, out_xsqlda, 200); Object[] rows = stmt1.getRows(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-17 10:42:34
|
Revision: 57358 http://firebird.svn.sourceforge.net/firebird/?rev=57358&view=rev Author: mrotteveel Date: 2012-11-17 10:42:26 +0000 (Sat, 17 Nov 2012) Log Message: ----------- Update errors and sqlstate (from currentFB 3 trunk) + changes to MessageDump utility Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/ISCConstants.java client-java/trunk/src/messages/org/firebirdsql/util/MessageDump.java client-java/trunk/src/resources/isc_error_msg.properties client-java/trunk/src/resources/isc_error_sqlstates.properties Modified: client-java/trunk/src/main/org/firebirdsql/gds/ISCConstants.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ISCConstants.java 2012-11-17 03:40:35 UTC (rev 57357) +++ client-java/trunk/src/main/org/firebirdsql/gds/ISCConstants.java 2012-11-17 10:42:26 UTC (rev 57358) @@ -752,6 +752,7 @@ public final static int isc_arg_netware = 16; /* NetWare error code */ public final static int isc_arg_win32 = 17; /* Win32 error code */ public final static int isc_arg_warning = 18; /* warning argument */ + public final static int isc_arg_sql_state = 19; /* SQLSTATE */ public final static int isc_arith_except = 335544321; public final static int isc_bad_dbkey = 335544322; @@ -1131,10 +1132,10 @@ public final static int isc_log_length_spec = 335544696; public final static int isc_precision_err = 335544697; public final static int isc_scale_nogt = 335544698; - public final static int isc_expec_int = 335544699; + public final static int isc_expec_short = 335544699; public final static int isc_expec_long = 335544700; - public final static int isc_expec_uint = 335544701; - public final static int isc_like_escape_invalid = 335544702; + public final static int isc_expec_ushort = 335544701; + public final static int isc_escape_invalid = 335544702; public final static int isc_svcnoexe = 335544703; public final static int isc_net_lookup_err = 335544704; public final static int isc_service_unknown = 335544705; @@ -1264,6 +1265,221 @@ public final static int isc_exec_sql_invalid_var = 335544829; public final static int isc_exec_sql_max_call_exceeded = 335544830; public final static int isc_conf_access_denied = 335544831; + public final static int isc_wrong_backup_state = 335544832; + public final static int isc_wal_backup_err = 335544833; + public final static int isc_cursor_not_open = 335544834; + public final static int isc_bad_shutdown_mode = 335544835; + public final static int isc_concat_overflow = 335544836; + public final static int isc_bad_substring_offset = 335544837; + public final static int isc_foreign_key_target_doesnt_exist = 335544838; + public final static int isc_foreign_key_references_present = 335544839; + public final static int isc_no_update = 335544840; + public final static int isc_cursor_already_open = 335544841; + public final static int isc_stack_trace = 335544842; + public final static int isc_ctx_var_not_found = 335544843; + public final static int isc_ctx_namespace_invalid = 335544844; + public final static int isc_ctx_too_big = 335544845; + public final static int isc_ctx_bad_argument = 335544846; + public final static int isc_identifier_too_long = 335544847; + public final static int isc_except2 = 335544848; + public final static int isc_malformed_string = 335544849; + public final static int isc_prc_out_param_mismatch = 335544850; + public final static int isc_command_end_err2 = 335544851; + public final static int isc_partner_idx_incompat_type = 335544852; + public final static int isc_bad_substring_length = 335544853; + public final static int isc_charset_not_installed = 335544854; + public final static int isc_collation_not_installed = 335544855; + public final static int isc_att_shutdown = 335544856; + public final static int isc_blobtoobig = 335544857; + public final static int isc_must_have_phys_field = 335544858; + public final static int isc_invalid_time_precision = 335544859; + public final static int isc_blob_convert_error = 335544860; + public final static int isc_array_convert_error = 335544861; + public final static int isc_record_lock_not_supp = 335544862; + public final static int isc_partner_idx_not_found = 335544863; + public final static int isc_tra_num_exc = 335544864; + public final static int isc_field_disappeared = 335544865; + public final static int isc_met_wrong_gtt_scope = 335544866; + public final static int isc_subtype_for_internal_use = 335544867; + public final static int isc_illegal_prc_type = 335544868; + public final static int isc_invalid_sort_datatype = 335544869; + public final static int isc_collation_name = 335544870; + public final static int isc_domain_name = 335544871; + public final static int isc_domnotdef = 335544872; + public final static int isc_array_max_dimensions = 335544873; + public final static int isc_max_db_per_trans_allowed = 335544874; + public final static int isc_bad_debug_format = 335544875; + public final static int isc_bad_proc_BLR = 335544876; + public final static int isc_key_too_big = 335544877; + public final static int isc_concurrent_transaction = 335544878; + public final static int isc_not_valid_for_var = 335544879; + public final static int isc_not_valid_for = 335544880; + public final static int isc_need_difference = 335544881; + public final static int isc_long_login = 335544882; + public final static int isc_fldnotdef2 = 335544883; + public final static int isc_invalid_similar_pattern = 335544884; + public final static int isc_bad_teb_form = 335544885; + public final static int isc_tpb_multiple_txn_isolation = 335544886; + public final static int isc_tpb_reserv_before_table = 335544887; + public final static int isc_tpb_multiple_spec = 335544888; + public final static int isc_tpb_option_without_rc = 335544889; + public final static int isc_tpb_conflicting_options = 335544890; + public final static int isc_tpb_reserv_missing_tlen = 335544891; + public final static int isc_tpb_reserv_long_tlen = 335544892; + public final static int isc_tpb_reserv_missing_tname = 335544893; + public final static int isc_tpb_reserv_corrup_tlen = 335544894; + public final static int isc_tpb_reserv_null_tlen = 335544895; + public final static int isc_tpb_reserv_relnotfound = 335544896; + public final static int isc_tpb_reserv_baserelnotfound = 335544897; + public final static int isc_tpb_missing_len = 335544898; + public final static int isc_tpb_missing_value = 335544899; + public final static int isc_tpb_corrupt_len = 335544900; + public final static int isc_tpb_null_len = 335544901; + public final static int isc_tpb_overflow_len = 335544902; + public final static int isc_tpb_invalid_value = 335544903; + public final static int isc_tpb_reserv_stronger_wng = 335544904; + public final static int isc_tpb_reserv_stronger = 335544905; + public final static int isc_tpb_reserv_max_recursion = 335544906; + public final static int isc_tpb_reserv_virtualtbl = 335544907; + public final static int isc_tpb_reserv_systbl = 335544908; + public final static int isc_tpb_reserv_temptbl = 335544909; + public final static int isc_tpb_readtxn_after_writelock = 335544910; + public final static int isc_tpb_writelock_after_readtxn = 335544911; + public final static int isc_time_range_exceeded = 335544912; + public final static int isc_datetime_range_exceeded = 335544913; + public final static int isc_string_truncation = 335544914; + public final static int isc_blob_truncation = 335544915; + public final static int isc_numeric_out_of_range = 335544916; + public final static int isc_shutdown_timeout = 335544917; + public final static int isc_att_handle_busy = 335544918; + public final static int isc_bad_udf_freeit = 335544919; + public final static int isc_eds_provider_not_found = 335544920; + public final static int isc_eds_connection = 335544921; + public final static int isc_eds_preprocess = 335544922; + public final static int isc_eds_stmt_expected = 335544923; + public final static int isc_eds_prm_name_expected = 335544924; + public final static int isc_eds_unclosed_comment = 335544925; + public final static int isc_eds_statement = 335544926; + public final static int isc_eds_input_prm_mismatch = 335544927; + public final static int isc_eds_output_prm_mismatch = 335544928; + public final static int isc_eds_input_prm_not_set = 335544929; + public final static int isc_too_big_blr = 335544930; + public final static int isc_montabexh = 335544931; + public final static int isc_modnotfound = 335544932; + public final static int isc_nothing_to_cancel = 335544933; + public final static int isc_ibutil_not_loaded = 335544934; + public final static int isc_circular_computed = 335544935; + public final static int isc_psw_db_error = 335544936; + public final static int isc_invalid_type_datetime_op = 335544937; + public final static int isc_onlycan_add_timetodate = 335544938; + public final static int isc_onlycan_add_datetotime = 335544939; + public final static int isc_onlycansub_tstampfromtstamp = 335544940; + public final static int isc_onlyoneop_mustbe_tstamp = 335544941; + public final static int isc_invalid_extractpart_time = 335544942; + public final static int isc_invalid_extractpart_date = 335544943; + public final static int isc_invalidarg_extract = 335544944; + public final static int isc_sysf_argmustbe_exact = 335544945; + public final static int isc_sysf_argmustbe_exact_or_fp = 335544946; + public final static int isc_sysf_argviolates_uuidtype = 335544947; + public final static int isc_sysf_argviolates_uuidlen = 335544948; + public final static int isc_sysf_argviolates_uuidfmt = 335544949; + public final static int isc_sysf_argviolates_guidigits = 335544950; + public final static int isc_sysf_invalid_addpart_time = 335544951; + public final static int isc_sysf_invalid_add_datetime = 335544952; + public final static int isc_sysf_invalid_addpart_dtime = 335544953; + public final static int isc_sysf_invalid_add_dtime_rc = 335544954; + public final static int isc_sysf_invalid_diff_dtime = 335544955; + public final static int isc_sysf_invalid_timediff = 335544956; + public final static int isc_sysf_invalid_tstamptimediff = 335544957; + public final static int isc_sysf_invalid_datetimediff = 335544958; + public final static int isc_sysf_invalid_diffpart = 335544959; + public final static int isc_sysf_argmustbe_positive = 335544960; + public final static int isc_sysf_basemustbe_positive = 335544961; + public final static int isc_sysf_argnmustbe_nonneg = 335544962; + public final static int isc_sysf_argnmustbe_positive = 335544963; + public final static int isc_sysf_invalid_zeropowneg = 335544964; + public final static int isc_sysf_invalid_negpowfp = 335544965; + public final static int isc_sysf_invalid_scale = 335544966; + public final static int isc_sysf_argmustbe_nonneg = 335544967; + public final static int isc_sysf_binuuid_mustbe_str = 335544968; + public final static int isc_sysf_binuuid_wrongsize = 335544969; + public final static int isc_missing_required_spb = 335544970; + public final static int isc_net_server_shutdown = 335544971; + public final static int isc_bad_conn_str = 335544972; + public final static int isc_bad_epb_form = 335544973; + public final static int isc_no_threads = 335544974; + public final static int isc_net_event_connect_timeout = 335544975; + public final static int isc_sysf_argmustbe_nonzero = 335544976; + public final static int isc_sysf_argmustbe_range_inc1_1 = 335544977; + public final static int isc_sysf_argmustbe_gteq_one = 335544978; + public final static int isc_sysf_argmustbe_range_exc1_1 = 335544979; + public final static int isc_internal_rejected_params = 335544980; + public final static int isc_sysf_fp_overflow = 335544981; + public final static int isc_udf_fp_overflow = 335544982; + public final static int isc_udf_fp_nan = 335544983; + public final static int isc_instance_conflict = 335544984; + public final static int isc_out_of_temp_space = 335544985; + public final static int isc_eds_expl_tran_ctrl = 335544986; + public final static int isc_no_trusted_spb = 335544987; + public final static int isc_package_name = 335544988; + public final static int isc_cannot_make_not_null = 335544989; + public final static int isc_feature_removed = 335544990; + public final static int isc_view_name = 335544991; + public final static int isc_lock_dir_access = 335544992; + public final static int isc_invalid_fetch_option = 335544993; + public final static int isc_bad_fun_BLR = 335544994; + public final static int isc_func_pack_not_implemented = 335544995; + public final static int isc_proc_pack_not_implemented = 335544996; + public final static int isc_eem_func_not_returned = 335544997; + public final static int isc_eem_proc_not_returned = 335544998; + public final static int isc_eem_trig_not_returned = 335544999; + public final static int isc_eem_bad_plugin_ver = 335545000; + public final static int isc_eem_engine_notfound = 335545001; + public final static int isc_attachment_in_use = 335545002; + public final static int isc_transaction_in_use = 335545003; + public final static int isc_pman_plugin_notfound = 335545004; + public final static int isc_pman_cannot_load_plugin = 335545005; + public final static int isc_pman_entrypoint_notfound = 335545006; + public final static int isc_pman_bad_conf_index = 335545007; + public final static int isc_pman_unknown_instance = 335545008; + public final static int isc_sysf_invalid_trig_namespace = 335545009; + public final static int isc_unexpected_null = 335545010; + public final static int isc_type_notcompat_blob = 335545011; + public final static int isc_invalid_date_val = 335545012; + public final static int isc_invalid_time_val = 335545013; + public final static int isc_invalid_timestamp_val = 335545014; + public final static int isc_invalid_index_val = 335545015; + public final static int isc_formatted_exception = 335545016; + public final static int isc_async_active = 335545017; + public final static int isc_private_function = 335545018; + public final static int isc_private_procedure = 335545019; + public final static int isc_request_outdated = 335545020; + public final static int isc_bad_events_handle = 335545021; + public final static int isc_cannot_copy_stmt = 335545022; + public final static int isc_invalid_boolean_usage = 335545023; + public final static int isc_sysf_argscant_both_be_zero = 335545024; + public final static int isc_spb_no_id = 335545025; + public final static int isc_ee_blr_mismatch_null = 335545026; + public final static int isc_ee_blr_mismatch_length = 335545027; + public final static int isc_ss_out_of_bounds = 335545028; + public final static int isc_missing_data_structures = 335545029; + public final static int isc_protect_sys_tab = 335545030; + public final static int isc_libtommath_generic = 335545031; + public final static int isc_wroblrver2 = 335545032; + public final static int isc_trunc_limits = 335545033; + public final static int isc_info_access = 335545034; + public final static int isc_svc_no_stdin = 335545035; + public final static int isc_svc_start_failed = 335545036; + public final static int isc_svc_no_switches = 335545037; + public final static int isc_svc_bad_size = 335545038; + public final static int isc_no_crypt_plugin = 335545039; + public final static int isc_cp_name_too_long = 335545040; + public final static int isc_cp_process_active = 335545041; + public final static int isc_cp_already_crypted = 335545042; + public final static int isc_decrypt_error = 335545043; + public final static int isc_no_providers = 335545044; + public final static int isc_null_spb = 335545045; + public final static int isc_max_args_exceeded = 335545046; public final static int isc_gfix_db_name = 335740929; public final static int isc_gfix_invalid_sw = 335740930; public final static int isc_gfix_incmp_sw = 335740932; @@ -1291,7 +1507,7 @@ public final static int isc_gfix_recon_fail = 335741018; public final static int isc_gfix_trn_unknown = 335741036; public final static int isc_gfix_mode_req = 335741038; - public final static int isc_gfix_opt_SQL_dialect = 335741039; + public final static int isc_gfix_pzval_req = 335741042; public final static int isc_dsql_dbkey_from_non_table = 336003074; public final static int isc_dsql_transitional_numeric = 336003075; public final static int isc_dsql_dialect_warning_expr = 336003076; @@ -1302,6 +1518,42 @@ public final static int isc_dsql_warn_precision_ambiguous = 336003082; public final static int isc_dsql_warn_precision_ambiguous1 = 336003083; public final static int isc_dsql_warn_precision_ambiguous2 = 336003084; + public final static int isc_dsql_ambiguous_field_name = 336003085; + public final static int isc_dsql_udf_return_pos_err = 336003086; + public final static int isc_dsql_invalid_label = 336003087; + public final static int isc_dsql_datatypes_not_comparable = 336003088; + public final static int isc_dsql_cursor_invalid = 336003089; + public final static int isc_dsql_cursor_redefined = 336003090; + public final static int isc_dsql_cursor_not_found = 336003091; + public final static int isc_dsql_cursor_exists = 336003092; + public final static int isc_dsql_cursor_rel_ambiguous = 336003093; + public final static int isc_dsql_cursor_rel_not_found = 336003094; + public final static int isc_dsql_cursor_not_open = 336003095; + public final static int isc_dsql_type_not_supp_ext_tab = 336003096; + public final static int isc_dsql_feature_not_supported_ods = 336003097; + public final static int isc_primary_key_required = 336003098; + public final static int isc_upd_ins_doesnt_match_pk = 336003099; + public final static int isc_upd_ins_doesnt_match_matching = 336003100; + public final static int isc_upd_ins_with_complex_view = 336003101; + public final static int isc_dsql_incompatible_trigger_type = 336003102; + public final static int isc_dsql_db_trigger_type_cant_change = 336003103; + public final static int isc_dsql_record_version_table = 336003104; + public final static int isc_dyn_filter_not_found = 336068645; + public final static int isc_dyn_func_not_found = 336068649; + public final static int isc_dyn_index_not_found = 336068656; + public final static int isc_dyn_view_not_found = 336068662; + public final static int isc_dyn_domain_not_found = 336068697; + public final static int isc_dyn_cant_modify_auto_trig = 336068717; + public final static int isc_dyn_dup_table = 336068740; + public final static int isc_dyn_proc_not_found = 336068748; + public final static int isc_dyn_exception_not_found = 336068752; + public final static int isc_dyn_proc_param_not_found = 336068754; + public final static int isc_dyn_trig_not_found = 336068755; + public final static int isc_dyn_charset_not_found = 336068759; + public final static int isc_dyn_collation_not_found = 336068760; + public final static int isc_dyn_role_not_found = 336068763; + public final static int isc_dyn_name_longer = 336068767; + public final static int isc_dyn_column_does_not_exist = 336068784; public final static int isc_dyn_role_does_not_exist = 336068796; public final static int isc_dyn_no_grant_admin_opt = 336068797; public final static int isc_dyn_user_not_role_member = 336068798; @@ -1318,6 +1570,45 @@ public final static int isc_dyn_char_fld_too_small = 336068816; public final static int isc_dyn_invalid_dtype_conversion = 336068817; public final static int isc_dyn_dtype_conv_invalid = 336068818; + public final static int isc_dyn_zero_len_id = 336068820; + public final static int isc_dyn_gen_not_found = 336068822; + public final static int isc_max_coll_per_charset = 336068829; + public final static int isc_invalid_coll_attr = 336068830; + public final static int isc_dyn_wrong_gtt_scope = 336068840; + public final static int isc_dyn_coll_used_table = 336068843; + public final static int isc_dyn_coll_used_domain = 336068844; + public final static int isc_dyn_cannot_del_syscoll = 336068845; + public final static int isc_dyn_cannot_del_def_coll = 336068846; + public final static int isc_dyn_table_not_found = 336068849; + public final static int isc_dyn_coll_used_procedure = 336068851; + public final static int isc_dyn_scale_too_big = 336068852; + public final static int isc_dyn_precision_too_small = 336068853; + public final static int isc_dyn_miss_priv_warning = 336068855; + public final static int isc_dyn_ods_not_supp_feature = 336068856; + public final static int isc_dyn_cannot_addrem_computed = 336068857; + public final static int isc_dyn_no_empty_pw = 336068858; + public final static int isc_dyn_dup_index = 336068859; + public final static int isc_dyn_package_not_found = 336068864; + public final static int isc_dyn_schema_not_found = 336068865; + public final static int isc_dyn_cannot_mod_sysproc = 336068866; + public final static int isc_dyn_cannot_mod_systrig = 336068867; + public final static int isc_dyn_cannot_mod_sysfunc = 336068868; + public final static int isc_dyn_invalid_ddl_proc = 336068869; + public final static int isc_dyn_invalid_ddl_trig = 336068870; + public final static int isc_dyn_funcnotdef_package = 336068871; + public final static int isc_dyn_procnotdef_package = 336068872; + public final static int isc_dyn_funcsignat_package = 336068873; + public final static int isc_dyn_procsignat_package = 336068874; + public final static int isc_dyn_defvaldecl_package = 336068875; + public final static int isc_dyn_package_body_exists = 336068877; + public final static int isc_dyn_invalid_ddl_func = 336068878; + public final static int isc_dyn_newfc_oldsyntax = 336068879; + public final static int isc_dyn_func_param_not_found = 336068886; + public final static int isc_dyn_routine_param_not_found = 336068887; + public final static int isc_dyn_routine_param_ambiguous = 336068888; + public final static int isc_dyn_coll_used_function = 336068889; + public final static int isc_dyn_domain_used_function = 336068890; + public final static int isc_dyn_alter_user_no_clause = 336068891; public final static int isc_gbak_unknown_switch = 336330753; public final static int isc_gbak_page_size_missing = 336330754; public final static int isc_gbak_page_size_toobig = 336330755; @@ -1400,8 +1691,138 @@ public final static int isc_gbak_svc_name_missing = 336331025; public final static int isc_gbak_not_ownr = 336331026; public final static int isc_gbak_mode_req = 336331031; + public final static int isc_gbak_just_data = 336331033; + public final static int isc_gbak_data_only = 336331034; + public final static int isc_gbak_missing_interval = 336331078; + public final static int isc_gbak_wrong_interval = 336331079; + public final static int isc_gbak_verify_verbint = 336331081; + public final static int isc_gbak_option_only_restore = 336331082; + public final static int isc_gbak_option_only_backup = 336331083; + public final static int isc_gbak_option_conflict = 336331084; + public final static int isc_gbak_param_conflict = 336331085; + public final static int isc_gbak_option_repeated = 336331086; + public final static int isc_gbak_max_dbkey_recursion = 336331091; + public final static int isc_gbak_max_dbkey_length = 336331092; + public final static int isc_gbak_invalid_metadata = 336331093; + public final static int isc_gbak_invalid_data = 336331094; + public final static int isc_gbak_inv_bkup_ver2 = 336331096; + public final static int isc_gbak_db_format_too_old2 = 336331100; + public final static int isc_dsql_too_old_ods = 336397205; public final static int isc_dsql_table_not_found = 336397206; public final static int isc_dsql_view_not_found = 336397207; + public final static int isc_dsql_line_col_error = 336397208; + public final static int isc_dsql_unknown_pos = 336397209; + public final static int isc_dsql_no_dup_name = 336397210; + public final static int isc_dsql_too_many_values = 336397211; + public final static int isc_dsql_no_array_computed = 336397212; + public final static int isc_dsql_implicit_domain_name = 336397213; + public final static int isc_dsql_only_can_subscript_array = 336397214; + public final static int isc_dsql_max_sort_items = 336397215; + public final static int isc_dsql_max_group_items = 336397216; + public final static int isc_dsql_conflicting_sort_field = 336397217; + public final static int isc_dsql_derived_table_more_columns = 336397218; + public final static int isc_dsql_derived_table_less_columns = 336397219; + public final static int isc_dsql_derived_field_unnamed = 336397220; + public final static int isc_dsql_derived_field_dup_name = 336397221; + public final static int isc_dsql_derived_alias_select = 336397222; + public final static int isc_dsql_derived_alias_field = 336397223; + public final static int isc_dsql_auto_field_bad_pos = 336397224; + public final static int isc_dsql_cte_wrong_reference = 336397225; + public final static int isc_dsql_cte_cycle = 336397226; + public final static int isc_dsql_cte_outer_join = 336397227; + public final static int isc_dsql_cte_mult_references = 336397228; + public final static int isc_dsql_cte_not_a_union = 336397229; + public final static int isc_dsql_cte_nonrecurs_after_recurs = 336397230; + public final static int isc_dsql_cte_wrong_clause = 336397231; + public final static int isc_dsql_cte_union_all = 336397232; + public final static int isc_dsql_cte_miss_nonrecursive = 336397233; + public final static int isc_dsql_cte_nested_with = 336397234; + public final static int isc_dsql_col_more_than_once_using = 336397235; + public final static int isc_dsql_unsupp_feature_dialect = 336397236; + public final static int isc_dsql_cte_not_used = 336397237; + public final static int isc_dsql_col_more_than_once_view = 336397238; + public final static int isc_dsql_unsupported_in_auto_trans = 336397239; + public final static int isc_dsql_eval_unknode = 336397240; + public final static int isc_dsql_agg_wrongarg = 336397241; + public final static int isc_dsql_agg2_wrongarg = 336397242; + public final static int isc_dsql_nodateortime_pm_string = 336397243; + public final static int isc_dsql_invalid_datetime_subtract = 336397244; + public final static int isc_dsql_invalid_dateortime_add = 336397245; + public final static int isc_dsql_invalid_type_minus_date = 336397246; + public final static int isc_dsql_nostring_addsub_dial3 = 336397247; + public final static int isc_dsql_invalid_type_addsub_dial3 = 336397248; + public final static int isc_dsql_invalid_type_multip_dial1 = 336397249; + public final static int isc_dsql_nostring_multip_dial3 = 336397250; + public final static int isc_dsql_invalid_type_multip_dial3 = 336397251; + public final static int isc_dsql_mustuse_numeric_div_dial1 = 336397252; + public final static int isc_dsql_nostring_div_dial3 = 336397253; + public final static int isc_dsql_invalid_type_div_dial3 = 336397254; + public final static int isc_dsql_nostring_neg_dial3 = 336397255; + public final static int isc_dsql_invalid_type_neg = 336397256; + public final static int isc_dsql_max_distinct_items = 336397257; + public final static int isc_dsql_alter_charset_failed = 336397258; + public final static int isc_dsql_comment_on_failed = 336397259; + public final static int isc_dsql_create_func_failed = 336397260; + public final static int isc_dsql_alter_func_failed = 336397261; + public final static int isc_dsql_create_alter_func_failed = 336397262; + public final static int isc_dsql_drop_func_failed = 336397263; + public final static int isc_dsql_recreate_func_failed = 336397264; + public final static int isc_dsql_create_proc_failed = 336397265; + public final static int isc_dsql_alter_proc_failed = 336397266; + public final static int isc_dsql_create_alter_proc_failed = 336397267; + public final static int isc_dsql_drop_proc_failed = 336397268; + public final static int isc_dsql_recreate_proc_failed = 336397269; + public final static int isc_dsql_create_trigger_failed = 336397270; + public final static int isc_dsql_alter_trigger_failed = 336397271; + public final static int isc_dsql_create_alter_trigger_failed = 336397272; + public final static int isc_dsql_drop_trigger_failed = 336397273; + public final static int isc_dsql_recreate_trigger_failed = 336397274; + public final static int isc_dsql_create_collation_failed = 336397275; + public final static int isc_dsql_drop_collation_failed = 336397276; + public final static int isc_dsql_create_domain_failed = 336397277; + public final static int isc_dsql_alter_domain_failed = 336397278; + public final static int isc_dsql_drop_domain_failed = 336397279; + public final static int isc_dsql_create_except_failed = 336397280; + public final static int isc_dsql_alter_except_failed = 336397281; + public final static int isc_dsql_create_alter_except_failed = 336397282; + public final static int isc_dsql_recreate_except_failed = 336397283; + public final static int isc_dsql_drop_except_failed = 336397284; + public final static int isc_dsql_create_sequence_failed = 336397285; + public final static int isc_dsql_create_table_failed = 336397286; + public final static int isc_dsql_alter_table_failed = 336397287; + public final static int isc_dsql_drop_table_failed = 336397288; + public final static int isc_dsql_recreate_table_failed = 336397289; + public final static int isc_dsql_create_pack_failed = 336397290; + public final static int isc_dsql_alter_pack_failed = 336397291; + public final static int isc_dsql_create_alter_pack_failed = 336397292; + public final static int isc_dsql_drop_pack_failed = 336397293; + public final static int isc_dsql_recreate_pack_failed = 336397294; + public final static int isc_dsql_create_pack_body_failed = 336397295; + public final static int isc_dsql_drop_pack_body_failed = 336397296; + public final static int isc_dsql_recreate_pack_body_failed = 336397297; + public final static int isc_dsql_create_view_failed = 336397298; + public final static int isc_dsql_alter_view_failed = 336397299; + public final static int isc_dsql_create_alter_view_failed = 336397300; + public final static int isc_dsql_recreate_view_failed = 336397301; + public final static int isc_dsql_drop_view_failed = 336397302; + public final static int isc_dsql_drop_sequence_failed = 336397303; + public final static int isc_dsql_recreate_sequence_failed = 336397304; + public final static int isc_dsql_drop_index_failed = 336397305; + public final static int isc_dsql_drop_filter_failed = 336397306; + public final static int isc_dsql_drop_shadow_failed = 336397307; + public final static int isc_dsql_drop_role_failed = 336397308; + public final static int isc_dsql_drop_user_failed = 336397309; + public final static int isc_dsql_create_role_failed = 336397310; + public final static int isc_dsql_alter_role_failed = 336397311; + public final static int isc_dsql_alter_index_failed = 336397312; + public final static int isc_dsql_alter_database_failed = 336397313; + public final static int isc_dsql_create_shadow_failed = 336397314; + public final static int isc_dsql_create_filter_failed = 336397315; + public final static int isc_dsql_create_index_failed = 336397316; + public final static int isc_dsql_create_user_failed = 336397317; + public final static int isc_dsql_alter_user_failed = 336397318; + public final static int isc_dsql_grant_failed = 336397319; + public final static int isc_dsql_revoke_failed = 336397320; public final static int isc_gsec_cant_open_db = 336723983; public final static int isc_gsec_switches_error = 336723984; public final static int isc_gsec_no_op_spec = 336723985; @@ -1434,26 +1855,6 @@ public final static int isc_gsec_db_admin_specified = 336724047; public final static int isc_gsec_db_admin_pw_specified = 336724048; public final static int isc_gsec_sql_role_specified = 336724049; - public final static int isc_license_no_file = 336789504; - public final static int isc_license_op_specified = 336789523; - public final static int isc_license_op_missing = 336789524; - public final static int isc_license_inv_switch = 336789525; - public final static int isc_license_inv_switch_combo = 336789526; - public final static int isc_license_inv_op_combo = 336789527; - public final static int isc_license_amb_switch = 336789528; - public final static int isc_license_inv_parameter = 336789529; - public final static int isc_license_param_specified = 336789530; - public final static int isc_license_param_req = 336789531; - public final static int isc_license_syntx_error = 336789532; - public final static int isc_license_dup_id = 336789534; - public final static int isc_license_inv_id_key = 336789535; - public final static int isc_license_err_remove = 336789536; - public final static int isc_license_err_update = 336789537; - public final static int isc_license_err_convert = 336789538; - public final static int isc_license_err_unk = 336789539; - public final static int isc_license_svc_err_add = 336789540; - public final static int isc_license_svc_err_remove = 336789541; - public final static int isc_license_eval_exists = 336789563; public final static int isc_gstat_unknown_switch = 336920577; public final static int isc_gstat_retry = 336920578; public final static int isc_gstat_wrong_ods = 336920579; @@ -1461,7 +1862,69 @@ public final static int isc_gstat_open_err = 336920605; public final static int isc_gstat_read_err = 336920606; public final static int isc_gstat_sysmemex = 336920607; - public final static int isc_err_max = 689; + public final static int isc_fbsvcmgr_bad_am = 336986113; + public final static int isc_fbsvcmgr_bad_wm = 336986114; + public final static int isc_fbsvcmgr_bad_rs = 336986115; + public final static int isc_fbsvcmgr_info_err = 336986116; + public final static int isc_fbsvcmgr_query_err = 336986117; + public final static int isc_fbsvcmgr_switch_unknown = 336986118; + public final static int isc_fbsvcmgr_bad_sm = 336986159; + public final static int isc_fbsvcmgr_fp_open = 336986160; + public final static int isc_fbsvcmgr_fp_read = 336986161; + public final static int isc_fbsvcmgr_fp_empty = 336986162; + public final static int isc_fbsvcmgr_bad_arg = 336986164; + public final static int isc_utl_trusted_switch = 337051649; + public final static int isc_nbackup_missing_param = 337117213; + public final static int isc_nbackup_allowed_switches = 337117214; + public final static int isc_nbackup_unknown_param = 337117215; + public final static int isc_nbackup_unknown_switch = 337117216; + public final static int isc_nbackup_nofetchpw_svc = 337117217; + public final static int isc_nbackup_pwfile_error = 337117218; + public final static int isc_nbackup_size_with_lock = 337117219; + public final static int isc_nbackup_no_switch = 337117220; + public final static int isc_nbackup_err_read = 337117223; + public final static int isc_nbackup_err_write = 337117224; + public final static int isc_nbackup_err_seek = 337117225; + public final static int isc_nbackup_err_opendb = 337117226; + public final static int isc_nbackup_err_fadvice = 337117227; + public final static int isc_nbackup_err_createdb = 337117228; + public final static int isc_nbackup_err_openbk = 337117229; + public final static int isc_nbackup_err_createbk = 337117230; + public final static int isc_nbackup_err_eofdb = 337117231; + public final static int isc_nbackup_fixup_wrongstate = 337117232; + public final static int isc_nbackup_err_db = 337117233; + public final static int isc_nbackup_userpw_toolong = 337117234; + public final static int isc_nbackup_lostrec_db = 337117235; + public final static int isc_nbackup_lostguid_db = 337117236; + public final static int isc_nbackup_err_eofhdrdb = 337117237; + public final static int isc_nbackup_db_notlock = 337117238; + public final static int isc_nbackup_lostguid_bk = 337117239; + public final static int isc_nbackup_page_changed = 337117240; + public final static int isc_nbackup_dbsize_inconsistent = 337117241; + public final static int isc_nbackup_failed_lzbk = 337117242; + public final static int isc_nbackup_err_eofhdrbk = 337117243; + public final static int isc_nbackup_invalid_incbk = 337117244; + public final static int isc_nbackup_unsupvers_incbk = 337117245; + public final static int isc_nbackup_invlevel_incbk = 337117246; + public final static int isc_nbackup_wrong_orderbk = 337117247; + public final static int isc_nbackup_err_eofbk = 337117248; + public final static int isc_nbackup_err_copy = 337117249; + public final static int isc_nbackup_err_eofhdr_restdb = 337117250; + public final static int isc_nbackup_lostguid_l0bk = 337117251; + public final static int isc_nbackup_switchd_parameter = 337117255; + public final static int isc_nbackup_user_stop = 337117257; + public final static int isc_trace_conflict_acts = 337182750; + public final static int isc_trace_act_notfound = 337182751; + public final static int isc_trace_switch_once = 337182752; + public final static int isc_trace_param_val_miss = 337182753; + public final static int isc_trace_param_invalid = 337182754; + public final static int isc_trace_switch_unknown = 337182755; + public final static int isc_trace_switch_svc_only = 337182756; + public final static int isc_trace_switch_user_only = 337182757; + public final static int isc_trace_switch_param_miss = 337182758; + public final static int isc_trace_param_act_notcompat = 337182759; + public final static int isc_trace_mandatory_switch_miss = 337182760; + public final static int isc_err_max = 1170; /*******************/ /* SQL definitions */ Modified: client-java/trunk/src/messages/org/firebirdsql/util/MessageDump.java =================================================================== --- client-java/trunk/src/messages/org/firebirdsql/util/MessageDump.java 2012-11-17 03:40:35 UTC (rev 57357) +++ client-java/trunk/src/messages/org/firebirdsql/util/MessageDump.java 2012-11-17 10:42:26 UTC (rev 57358) @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Firebird Open Source J2EE Connector - JDBC Driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ package org.firebirdsql.util; import java.io.*; @@ -4,22 +24,17 @@ import java.sql.*; import java.util.*; -import org.firebirdsql.jdbc.FBDriver; -import org.firebirdsql.jdbc.FirebirdConnection; - /** - * + * Utility class for generating the property files containing the errorcodes and error messages. */ public class MessageDump { private static final int ISC_CODE = 0x14000000; - private static FirebirdConnection getConnection(String database) - throws Exception { - Class.forName(FBDriver.class.getName()); + private static Connection getConnection(String database) throws Exception { + Class.forName("org.firebirdsql.jdbc.FBDriver"); String url = "jdbc:firebirdsql:" + database; - return (FirebirdConnection) DriverManager.getConnection(url, "SYSDBA", - "masterkey"); + return DriverManager.getConnection(url, "SYSDBA", "masterkey"); } private static int getErrorCode(int code, int number) { @@ -48,11 +63,11 @@ sb.append("%ld"); } else sb.append('%').append(chars[i]); - } else - if (chars[i] == '@') { + } else if (chars[i] == '@') { i++; try { + // Currently assumes parameter-number not to exceed 9. int msgNum = Integer.parseInt("" + chars[i]); sb.append('{').append(Integer.toString(msgNum - 1)).append('}'); } catch(NumberFormatException ex) { @@ -65,9 +80,8 @@ return sb.toString(); } - private static Properties extractProperties(FirebirdConnection connection) - throws Exception { - Properties result = new Properties(); + private static Map<Integer, String> extractErrorMessages(Connection connection) throws Exception { + Map<Integer, String> result = new TreeMap<Integer, String>(); Statement stmt = connection.createStatement(); try { @@ -79,20 +93,18 @@ int number = rs.getInt(2); String message = rs.getString(3); - result.setProperty( - Integer.toString(getErrorCode(code, number)), + result.put( + Integer.valueOf(getErrorCode(code, number)), extractMessage(message)); } - } finally { stmt.close(); } - return result; } - private static Properties extractSQLStates(FirebirdConnection connection) throws SQLException { - Properties result = new Properties(); + private static Map<Integer, String> extractSQLStates(Connection connection) throws SQLException { + Map<Integer, String> result = new TreeMap<Integer, String>(); Statement stmt = connection.createStatement(); try { @@ -104,11 +116,10 @@ int number = rs.getInt(2); String sqlState = rs.getString(3); - result.setProperty( - Integer.toString(getErrorCode(code, number)), + result.put( + Integer.valueOf(getErrorCode(code, number)), extractMessage(sqlState)); } - } finally { stmt.close(); } @@ -117,44 +128,49 @@ } public static void main(String[] args) throws Exception { + if (args.length == 0) { + args = new String[] { "localhost:d:/database/fb_messages.fdb" }; + } - if (args.length == 0) - args = new String[] { "localhost:d:/database/fb_messages.fdb"}; - - FirebirdConnection connection = getConnection(args[0]); + Connection connection = getConnection(args[0]); try { - Properties props = extractProperties(connection); - TreeMap sortedMap = new TreeMap(props); - - store(sortedMap, new FileOutputStream("./error.properties"), ""); + System.out.println("Retrieving error messages"); + final Map<Integer, String> errorMessages = extractErrorMessages(connection); + final FileOutputStream errorStream = new FileOutputStream("./error.properties"); + try { + store(errorMessages, errorStream, null); + } finally { + errorStream.close(); + } - props = extractSQLStates(connection); - TreeMap sqlStates = new TreeMap(props); - - store(sqlStates, new FileOutputStream("./sqlstates.properties"), ""); + System.out.println("Retrieving SQL State values"); + final Map<Integer, String> sqlStates = extractSQLStates(connection); + final FileOutputStream sqlstateStream = new FileOutputStream("./sqlstates.properties"); + try { + store(sqlStates, sqlstateStream, null); + } finally { + sqlstateStream.close(); + } } finally { connection.close(); } } - public static void store(Map map, OutputStream out, String header) + public static void store(Map<Integer, String> map, OutputStream out, String header) throws IOException { BufferedWriter awriter; awriter = new BufferedWriter(new OutputStreamWriter(out, "8859_1")); if (header != null) writeln(awriter, "#" + header); writeln(awriter, "#" + new java.util.Date().toString()); - synchronized (map) { - for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - String key = saveConvert((String)entry.getKey(), true); + for (Map.Entry<Integer, String> entry : map.entrySet()) { + String key = saveConvert(Integer.toString(entry.getKey()), true); - /* - * No need to escape embedded and trailing spaces for value, - * hence pass false to flag. - */ - String val = saveConvert((String)entry.getValue(), false); - writeln(awriter, key + "=" + val); - } + /* + * No need to escape embedded and trailing spaces for value, + * hence pass false to flag. + */ + String val = saveConvert(entry.getValue(), false); + writeln(awriter, key + "=" + val); } awriter.flush(); } Modified: client-java/trunk/src/resources/isc_error_msg.properties =================================================================== --- client-java/trunk/src/resources/isc_error_msg.properties 2012-11-17 03:40:35 UTC (rev 57357) +++ client-java/trunk/src/resources/isc_error_msg.properties 2012-11-17 10:42:26 UTC (rev 57358) @@ -1,5 +1,4 @@ -# -#Tue Oct 19 20:41:05 CEST 2010 +#Sat Nov 17 11:26:48 CET 2012 335544320= 335544321=arithmetic exception, numeric overflow, or string truncation 335544322=invalid database key @@ -231,10 +230,10 @@ 335544548=Attempt to define a second PRIMARY KEY for the same table 335544549=cannot modify or erase a system trigger 335544550=only the owner of a table may reassign ownership -335544551=could not find table/procedure/package for GRANT +335544551=could not find object for GRANT 335544552=could not find column for GRANT 335544553=user does not have GRANT privileges for operation -335544554=table/procedure has non-SQL security class defined +335544554=object has non-SQL security class defined 335544555=column has non-SQL security class defined 335544556=Write-ahead Log without shared cache configuration not allowed 335544557=database shutdown unsuccessful @@ -516,7 +515,7 @@ 335544833=Physical backup is not allowed while Write-Ahead Log is in use 335544834=Cursor is not open 335544835=Target shutdown mode is invalid for database "{0}" -335544836=Concatenation overflow. Resulting string cannot exceed 32K in length. +335544836=Concatenation overflow. Resulting string cannot exceed 32765 bytes in length. 335544837=Invalid offset parameter {0} to SUBSTRING. Only positive integers are allowed. 335544838=Foreign key reference target does not exist 335544839=Foreign key references are present for the record @@ -669,8 +668,8 @@ 335544986=Explicit transaction control is not allowed 335544987=Use of TRUSTED switches in spb_command_line is prohibited 335544988=PACKAGE {0} -335544989=Cannot make field {0} NOT NULL because there are NULLs present -335544990=Feature {0} is deprecated +335544989=Cannot make field {0} of table {1} NOT NULL because there are NULLs present +335544990=Feature {0} is not supported anymore 335544991=VIEW {0} 335544992=Can not access lock files directory {0} 335544993=Fetch option {0} is invalid for a non-scrollable cursor @@ -685,7 +684,7 @@ 335545002=Attachment is in use 335545003=Transaction is in use 335545004=Plugin {0} not found -335545005=Cannot load plugin {0} +335545005=Module {0} exists, but can not be loaded 335545006=Entrypoint of plugin {0} does not exist 335545007=Invalid value {0} for parameter index at PluginImpl\:\:getConfigInfo\: out of bounds 335545008=Plugin {0} does not create {1} instances @@ -695,11 +694,38 @@ 335545012=Invalid date 335545013=Invalid time 335545014=Invalid timestamp -335545015=Invalid index {0} +335545015=Invalid index {0} in function {1} 335545016={0} 335545017=Asynchronous call is already running for this attachment 335545018=Function {0} is private to package {1} 335545019=Procedure {0} is private to package {1} +335545020=Request can't access new records in relation {0} and should be recompiled +335545021=invalid events id (handle) +335545022=Cannot copy statement {0} +335545023=Invalid usage of boolean expression +335545024=Arguments for {0} cannot both be zero +335545025=missing service ID in spb +335545026=External BLR message mismatch\: invalid null descriptor at field {0} +335545027=External BLR message mismatch\: length \= {0}, expected {1} +335545028=Subscript {0} out of bounds [{1}, {2}] +335545029=Install incomplete, please read chapter "Initializing security database" in Quick Start Guide +335545030={0} operation is not allowed for system table {1} +335545031=Libtommath error code {0} in function {1} +335545032=unsupported BLR version (expected between {0} and {1}, encountered {2}) +335545033=expected length {0}, actual {1} +335545034=Wrong info requested in isc_svc_query() for anonymous service +335545035=No isc_info_svc_stdin in user request, but service thread requested stdin data +335545036=Start request for anonymous service is impossible +335545037=All services except for getting server log require switches +335545038=Size of stdin data is more than was requested from client +335545039=Crypt plugin {0} failed to load +335545040=Length of crypt plugin name should not exceed {0} bytes +335545041=Crypt failed - already crypting database +335545042=Crypt failed - database is already in requested state +335545043=Missing crypt plugin, but page appears encrypted +335545044=No providers loaded +335545045=NULL data with non-zero SPB length +335545046=Maximum ({0}) number of arguments exceeded for function {1} 335609856=expected type 335609857=bad block type 335609858=bad block size @@ -1213,7 +1239,7 @@ 335610373=\ -b(uffers) set page buffers <n> 335610374=\ -f(etch_password) fetch password from file 335610375=\ -i(nit_script) startup script <name> -335610376=\ -n(o_banner) do not show the welcome message +335610376=\ -n(obanner) do not show the welcome message 335610377=\ -p(assword) user's password 335610378=\ -tra(ce) show internal parser's tokens 335610379=\ -tru(sted_auth) use trusted authentication @@ -1224,6 +1250,7 @@ 335610384=Start qli without [command] to enter interactive mode 335610385=qli\: ignoring unknown switch {0} 335610386=Warning\: cannot issue DDL statements against database "{0}" +335610387=\ -nod(btriggers) do not run database triggers 335740929=data base file name ({0}) already given 335740930=invalid switch {0} 335740931=gfix version {0} @@ -1374,6 +1401,7 @@ 336003101=UPDATE OR INSERT without MATCHING could not be used with views based on more than one table 336003102=Incompatible trigger type 336003103=Database trigger type can't be changed +336003104=To be used with RDB$RECORD_VERSION, {0} must be a table or a view of single table 336068609=ODS version not supported by DYN 336068610=unsupported DYN verb 336068611=STORE RDB$FIELD_DIMENSIONS failed @@ -1637,12 +1665,19 @@ 336068877=Package body {0} already exists 336068878=Invalid DDL statement for function {0} 336068879=Cannot alter new style function {0} with ALTER EXTERNAL FUNCTION. Use ALTER FUNCTION instead. -336068880=Cannot delete system generator +336068880=Cannot delete system generator {0} 336068881=Identity column {0} of table {1} must be of exact number type with zero scale 336068882=Identity column {0} of table {1} cannot be changed to NULLable 336068883=Identity column {0} of table {1} cannot have default value 336068884=Domain {0} must be of exact number type with zero scale because it's used in an identity column 336068885=Generation of generator name failed +336068886=Parameter {0} in function {1} not found +336068887=Parameter {0} of routine {1} not found +336068888=Parameter {0} of routine {1} is ambiguous (found in both procedures and functions). Use a specifier keyword. +336068889=Collation {0} is used in function {1} (parameter name {2}) and cannot be dropped +336068890=Domain {0} is used in function {1} (parameter nam... [truncated message content] |
From: <mro...@us...> - 2012-11-17 12:56:10
|
Revision: 57359 http://firebird.svn.sourceforge.net/firebird/?rev=57359&view=rev Author: mrotteveel Date: 2012-11-17 12:56:00 +0000 (Sat, 17 Nov 2012) Log Message: ----------- JDBC-266 Incorrect limbo transaction numbers Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/GDSExceptionHelper.java client-java/trunk/src/main/org/firebirdsql/management/FBMaintenanceManager.java client-java/trunk/src/main/org/firebirdsql/management/MaintenanceManager.java client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/GDSExceptionHelper.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/GDSExceptionHelper.java 2012-11-17 10:42:26 UTC (rev 57358) +++ client-java/trunk/src/main/org/firebirdsql/gds/GDSExceptionHelper.java 2012-11-17 12:56:00 UTC (rev 57359) @@ -42,44 +42,50 @@ */ public class GDSExceptionHelper { + private static final String SQLSTATE_CLI_GENERIC_ERROR = "HY000"; + private static final Logger log = LoggerFactory.getLogger(GDSExceptionHelper.class,false); private static final String MESSAGES = "isc_error_msg"; private static final String SQLSTATES = "isc_error_sqlstates"; - private static Properties messages = new Properties(); - private static Properties sqlstates = new Properties(); + private static final Properties messages; + private static final Properties sqlstates; - private static boolean initialized = false; - /** - * This method initializes the messages map. - * @todo think about better exception handling. + * Initializes the messages map. */ - private static void init() { - loadResource(MESSAGES, messages); - loadResource(SQLSTATES, sqlstates); - } - - private static void loadResource(String resource, Properties propeties) { + static { try { - String res = "/" + resource.replace('.','/') + ".properties"; - InputStream in = GDSException.class.getResourceAsStream(res); - - if (in == null) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - in = cl.getResourceAsStream(res); - } - - if (in != null) - propeties.load(in); - + messages = loadResource(MESSAGES); + sqlstates = loadResource(SQLSTATES); } catch (Exception ex) { - if (log!=null) log.info("Exception in init of GDSExceptionHelper", ex); - } finally { - initialized = true; + if (log != null) log.error("Exception in init of GDSExceptionHelper, unable to load error information", ex); + throw new ExceptionInInitializerError(ex); } } + private static Properties loadResource(String resource) throws Exception { + Properties properties = new Properties(); + String res = "/" + resource.replace('.','/') + ".properties"; + InputStream in = GDSException.class.getResourceAsStream(res); + if (in == null) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + in = cl.getResourceAsStream(res); + } + try { + if (in != null) { + properties.load(in); + } else if (log != null) { + log.warn("Unable to load resource; resource " + resource + " is not found"); + } + } finally { + if (in != null) { + in.close(); + } + } + return properties; + } + /** * This method returns a message for the specified error code. * @param code Firebird error code @@ -87,9 +93,8 @@ * where you can set desired parameters. */ public static GDSMessage getMessage(int code) { - if (!initialized) init(); return new GDSMessage(messages.getProperty( - "" + code, "No message for code " + code + " found.")); + Integer.toString(code), "No message for code " + code + " found.")); } /** @@ -100,29 +105,23 @@ * @return string with SQL state, "HY000" if nothing found. */ public static String getSQLState(int code) { - if (!initialized) init(); - String result = sqlstates.getProperty(Integer.toString(code)); - - if (result == null) - result = "HY000"; - - return result; + return sqlstates.getProperty(Integer.toString(code), SQLSTATE_CLI_GENERIC_ERROR); } /** * This class wraps message template obtained from isc_error_msg.properties * file and allows to set parameters to the message. */ - public static class GDSMessage { - private String template; - private String[] params; + public static final class GDSMessage { + private final String template; + private final String[] params; /** * Constructs an instance of GDSMessage for the specified template. */ public GDSMessage(String template) { this.template = template; - params = new String[getParamCount()]; + params = new String[getParamCountInternal()]; } /** @@ -130,9 +129,14 @@ * @return number of parameters. */ public int getParamCount() { + return params.length; + } + + private int getParamCountInternal() { int count = 0; - for(int i = 0; i < template.length(); i++) + for(int i = 0; i < template.length(); i++) { if (template.charAt(i) == '{') count++; + } return count; } @@ -142,8 +146,9 @@ * @param text value of parameter */ public void setParameter(int position, String text) { - if (position < params.length) + if (position < params.length) { params[position] = text; + } } /** Modified: client-java/trunk/src/main/org/firebirdsql/management/FBMaintenanceManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/management/FBMaintenanceManager.java 2012-11-17 10:42:26 UTC (rev 57358) +++ client-java/trunk/src/main/org/firebirdsql/management/FBMaintenanceManager.java 2012-11-17 12:56:00 UTC (rev 57359) @@ -38,23 +38,24 @@ */ package org.firebirdsql.management; - import java.sql.SQLException; -import java.util.StringTokenizer; +import java.util.LinkedList; +import java.util.List; +import org.firebirdsql.gds.GDSException; import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.ServiceRequestBuffer; import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.jdbc.FBSQLException; import java.io.OutputStream; import java.io.PrintStream; import java.io.ByteArrayOutputStream; - - /** * The <code>FBMaintenanceManager</code> class is responsible for replicating * the functionality provided by the <code>gfix</code> command-line tool. + * <p> * Among the responsibilities of this class are: * <ul> * <li>Database shutdown @@ -68,74 +69,57 @@ * <li>Activating and killing shadow files * <li>Displaying, committing, or recovering limbo transactions * </ul> + * </p> * * @author <a href="mailto:gab...@us...">Gabriel Reid</a> * @author <a href="mailto:tst...@us...">Thomas Steinmaurer</a> */ -public class FBMaintenanceManager extends FBServiceManager - implements MaintenanceManager { +public class FBMaintenanceManager extends FBServiceManager implements MaintenanceManager { - /** * Create a new instance of <code>FBMaintenanceManager</code> based on * the default GDSType. */ - public FBMaintenanceManager() - { - super(); + public FBMaintenanceManager() { + super(); } /** * Create a new instance of <code>FBMaintenanceManager</code> based on * a given GDSType. * - * @param gdsType type must be PURE_JAVA, EMBEDDED, or NATIVE + * @param gdsType + * type must be PURE_JAVA, EMBEDDED, or NATIVE */ - public FBMaintenanceManager(String gdsType) - { - super(gdsType); + public FBMaintenanceManager(String gdsType) { + super(gdsType); } /** * Create a new instance of <code>FBMaintenanceManager</code> based on * a given GDSType. * - * @param gdsType The GDS implementation type to use + * @param gdsType + * The GDS implementation type to use */ - public FBMaintenanceManager(GDSType gdsType){ + public FBMaintenanceManager(GDSType gdsType) { super(gdsType); } - /** - * Set the database to have read-write or read-only access. - * - * @param mode Must be either <code>ACCESS_MODE_READ_WRITE</code> - * or <code>ACCESS_MODE_READ_ONLY</code> - * @throws SQLException if a database access error occurs - */ public void setDatabaseAccessMode(int mode) throws SQLException { - - if (mode != ACCESS_MODE_READ_WRITE && mode != ACCESS_MODE_READ_ONLY){ + if (mode != ACCESS_MODE_READ_WRITE && mode != ACCESS_MODE_READ_ONLY) { throw new IllegalArgumentException("mode must be one of " + "ACCESS_MODE_READ_WRITE or ACCESS_MODE_READ_ONLY"); } ServiceRequestBuffer srb = createDefaultPropertiesSRB(); - srb.addArgument(ISCConstants.isc_spb_prp_access_mode, (byte)mode); + srb.addArgument(ISCConstants.isc_spb_prp_access_mode, (byte) mode); executeServicesOperation(srb); } - /** - * Set the database's dialect. - * - * @param dialect The database dialect, must be either 1 or 3 - * @throws SQLException if a database access error occurs - */ public void setDatabaseDialect(int dialect) throws SQLException { - - if (dialect != 1 && dialect != 3){ - throw new IllegalArgumentException("dialect must be either " - + "1 or 3"); + if (dialect != 1 && dialect != 3) { + throw new IllegalArgumentException("dialect must be either 1 or 3"); } ServiceRequestBuffer srb = createDefaultPropertiesSRB(); @@ -143,16 +127,9 @@ executeServicesOperation(srb); } - /** - * Set the default page-buffer count to be cached in the database. The - * Firebird default is 2048. - * - * @param pageCount The number of pages to be cached, must be positive - * @throws SQLException If the given page count cannot be set, or a - * database access error occurs - */ public void setDefaultCacheBuffer(int pageCount) throws SQLException { - if (pageCount < 1){ + // TODO: Set to 0 valid as well? + if (pageCount < 1) { throw new IllegalArgumentException("page count must be positive"); } ServiceRequestBuffer srb = createDefaultPropertiesSRB(); @@ -160,91 +137,34 @@ executeServicesOperation(srb); } - - /** - * Enable or disable forced (synchronous) writes in the database. - * Note, it is considered to be a <b>very</b> bad idea to use buffered - * writing on Windows platforms. - * - * @param forced If <code>true</code>, forced writes will be used in the - * database, otherwise buffered writes will be used. - * @throws SQLException if a database access error occurs - */ public void setForcedWrites(boolean forced) throws SQLException { ServiceRequestBuffer srb = createDefaultPropertiesSRB(); - srb.addArgument(ISCConstants.isc_spb_prp_write_mode, - (byte) (forced ? ISCConstants.isc_spb_prp_wm_sync - : ISCConstants.isc_spb_prp_wm_async)); + srb.addArgument(ISCConstants.isc_spb_prp_write_mode, (byte) (forced ? ISCConstants.isc_spb_prp_wm_sync + : ISCConstants.isc_spb_prp_wm_async)); executeServicesOperation(srb); } - - /** - * Set the page fill strategy for when inserting records. - * <code>pageFill</code> can be one of: - * <ul> - * <li><code>PAGE_FILL_FULL</code> Fully fill database pages - * <li><code>PAGE_FILL_RESERVE</code> Reserve 20% of page space for - * later record deltas - * </ul> - * - * @param pageFill The page-filling strategy, either - * <code>PAGE_FILL_FULL</code> or <code>PAGE_FILL_RESERVE</code> - * @throws SQLException if a database access error occurs - */ public void setPageFill(int pageFill) throws SQLException { - if (pageFill != PAGE_FILL_FULL && pageFill != PAGE_FILL_RESERVE){ - throw new IllegalArgumentException( "Page fill must be either " - + "PAGE_FILL_FULL or PAGE_FILL_RESERVE"); + if (pageFill != PAGE_FILL_FULL && pageFill != PAGE_FILL_RESERVE) { + throw new IllegalArgumentException("Page fill must be either PAGE_FILL_FULL or PAGE_FILL_RESERVE"); } ServiceRequestBuffer srb = createDefaultPropertiesSRB(); - srb.addArgument(ISCConstants.isc_spb_prp_reserve_space, - (byte)pageFill); + srb.addArgument(ISCConstants.isc_spb_prp_reserve_space, (byte) pageFill); executeServicesOperation(srb); } + // ----------- Database Shutdown ------------------- - //----------- Database Shutdown ------------------- - - /** - * Shutdown the current database. - * Shutdown can be done in three modes: - * <ul> - * <li><code>SHUTDOWN_ATTACH</code> - No new non-owner connections - * will be allowed to the database during the shutdown, and shutdown - * is cancelled if there are still processes connected at the end - * of the timeout. - * - * <li><code>SHUTDOWN_TRANSACTIONAL</code> - No new transactions can - * be started during the timeout period, and shutdown is cancelled - * if there are still active transactions at the end of the timeout. - * - * <li><code>SHUTDOWN_FORCE</code> - Forcefully shuts down the - * database at the end of the timeout. - * </ul> - * - * @param shutdownMode One of <code>SHUTDOWN_ATTACH</code>, - * <code>SHUTDOWN_TRANSACTIONAL</code>, - * or <code>SHUTDOWN_FORCE</code>. - * @param timeout The maximum amount of time allocated for the operation, - * in seconds - * @throws SQLException if the requested operation cannot be completed - * within the given timeout, or a database access error occurs - */ - public void shutdownDatabase(int shutdownMode, int timeout) - throws SQLException { - + public void shutdownDatabase(int shutdownMode, int timeout) throws SQLException { if (shutdownMode != SHUTDOWN_ATTACH && shutdownMode != SHUTDOWN_TRANSACTIONAL - && shutdownMode != SHUTDOWN_FORCE){ + && shutdownMode != SHUTDOWN_FORCE) { throw new IllegalArgumentException("Shutdown mode must be " - + "one of: SHUTDOWN_ATTACH, SHUTDOWN_TRANSACTIONAL, " - + "SHUTDOWN_FORCE"); + + "one of: SHUTDOWN_ATTACH, SHUTDOWN_TRANSACTIONAL, SHUTDOWN_FORCE"); } - if (timeout < 0){ - throw new IllegalArgumentException( - "Timeout must be >= 0"); + if (timeout < 0) { + throw new IllegalArgumentException("Timeout must be >= 0"); } ServiceRequestBuffer srb = createDefaultPropertiesSRB(); @@ -252,150 +172,76 @@ executeServicesOperation(srb); } - public void shutdownDatabase(byte operationMode, int shutdownModeEx, int timeout) throws SQLException { + if (operationMode != OPERATION_MODE_MULTI + && operationMode != OPERATION_MODE_SINGLE + && operationMode != OPERATION_MODE_FULL_SHUTDOWN) { + throw new IllegalArgumentException("Operation mode must be one of: OPERATION_MODE_MULTI, " + + "OPERATION_MODE_SINGLE, OPERATION_MODE_FULL_SHUTDOWN"); + } + if (shutdownModeEx != SHUTDOWNEX_FORCE + && shutdownModeEx != SHUTDOWNEX_ATTACHMENTS + && shutdownModeEx != SHUTDOWNEX_TRANSACTIONS) { + throw new IllegalArgumentException("Extended shutdown mode must be " + + "one of: SHUTDOWNEX_FORCE, SHUTDOWNEX_ATTACHMENTS, SHUTDOWNEX_TRANSACTIONS"); + } + if (timeout < 0) { + throw new IllegalArgumentException("Timeout must be >= 0"); + } - if ( - operationMode != OPERATION_MODE_MULTI - && operationMode != OPERATION_MODE_SINGLE - && operationMode != OPERATION_MODE_FULL_SHUTDOWN - ) { - throw new IllegalArgumentException("Operation mode must be " - + "one of: OPERATION_MODE_MULTI, " - + "OPERATION_MODE_SINGLE, OPERATION_MODE_FULL_SHUTDOWN"); - } - if ( - shutdownModeEx != SHUTDOWNEX_FORCE - && shutdownModeEx != SHUTDOWNEX_ATTACHMENTS - && shutdownModeEx != SHUTDOWNEX_TRANSACTIONS - ) { - throw new IllegalArgumentException("Extended shutdown mode must be " - + "one of: SHUTDOWNEX_FORCE, SHUTDOWNEX_ATTACHMENTS, " - + "SHUTDOWNEX_TRANSACTIONS"); - } - if (timeout < 0) { - throw new IllegalArgumentException("Timeout must be >= 0"); - } - - ServiceRequestBuffer srb = createDefaultPropertiesSRB(); - srb.addArgument(ISCConstants.isc_spb_prp_shutdown_mode, operationMode); - srb.addArgument(shutdownModeEx, timeout); - executeServicesOperation(srb); + ServiceRequestBuffer srb = createDefaultPropertiesSRB(); + srb.addArgument(ISCConstants.isc_spb_prp_shutdown_mode, operationMode); + srb.addArgument(shutdownModeEx, timeout); + executeServicesOperation(srb); } - - /** - * Bring a shutdown database online. - * - * @throws SQLException if a database access error occurs - */ public void bringDatabaseOnline() throws SQLException { executePropertiesOperation(ISCConstants.isc_spb_prp_db_online); } - /** - * Bring a shutdown database online with enhanced operation modes - * new since Firebird 2.5. - * - * @throws SQLException if a database access error occurs - */ public void bringDatabaseOnline(byte operationMode) throws SQLException { + if (operationMode != OPERATION_MODE_NORMAL + && operationMode != OPERATION_MODE_MULTI + && operationMode != OPERATION_MODE_SINGLE) { + throw new IllegalArgumentException("Operation mode must be " + + "one of: OPERATION_MODE_NORMAL, OPERATION_MODE_MULTI, OPERATION_MODE_SINGLE"); + } - if ( - operationMode != OPERATION_MODE_NORMAL - && operationMode != OPERATION_MODE_MULTI - && operationMode != OPERATION_MODE_SINGLE - ) { - throw new IllegalArgumentException("Operation mode must be " - + "one of: OPERATION_MODE_NORMAL, OPERATION_MODE_MULTI, " - + "OPERATION_MODE_SINGLE"); - } - - ServiceRequestBuffer srb = createDefaultPropertiesSRB(); - srb.addArgument(ISCConstants.isc_spb_prp_online_mode, operationMode); - executeServicesOperation(srb); + ServiceRequestBuffer srb = createDefaultPropertiesSRB(); + srb.addArgument(ISCConstants.isc_spb_prp_online_mode, operationMode); + executeServicesOperation(srb); } - //-------------- Database Repair ---------------------- + // -------------- Database Repair ---------------------- - /** - * Mark corrupt records in the database as unavailable. - * This operation ensures that the corrupt records are skipped (for - * example, during a subsequent backup). This method is the equivalent - * of <b><code>gfix -mend</code></b>. - * - * @throws SQLException if a database access error occurs - */ public void markCorruptRecords() throws SQLException { executeRepairOperation(ISCConstants.isc_spb_rpr_mend_db); } - /** - * Locate and release database pages that are allocated but unassigned - * to any data structures. This method also reports corrupt structures. - * - * @throws SQLException if a database access error occurs - */ public void validateDatabase() throws SQLException { executeRepairOperation(ISCConstants.isc_spb_rpr_validate_db); } - /** - * Locate and release database pages that are allocated but unassigned - * to any data structures. This method also reports corrupt structures. - * The value supplied for <code>options</code> must be one of the - * following: - * <ul> - * <li>0 - Simple validation - * <li><code>VALIDATE_READ_ONLY</code> - read-only validation, - * no repair - * <li><code>VALIDATE_FULL</code> - full validation and repair - * </ul> - * - * The value for <code>options</code> can additionally be combined in - * a bitmask with <code>VALIDATE_IGNORE_CHECKSUM</code> to ignore - * checksums while performing validation. - * - * @param options Either 0, <code>VALIDATE_READ_ONLY</code>, or - * <code>VALIDATE_FULL</code> - * @throws SQLException if a database access error occurs - */ public void validateDatabase(int options) throws SQLException { - + if (options < 0 || options != 0 && options != VALIDATE_IGNORE_CHECKSUM && (options & ~VALIDATE_IGNORE_CHECKSUM) != VALIDATE_READ_ONLY && (options & ~VALIDATE_IGNORE_CHECKSUM) != VALIDATE_FULL - && (options | - (VALIDATE_READ_ONLY | VALIDATE_IGNORE_CHECKSUM)) != options - && (options | - (VALIDATE_FULL | VALIDATE_IGNORE_CHECKSUM)) != options) { - throw new IllegalArgumentException("options must be either 0, " - + "VALIDATE_READ_ONLY, or VALIDATE_FULL, optionally " - + "combined with VALIDATE_IGNORE_CHECKSUM"); + && (options | (VALIDATE_READ_ONLY | VALIDATE_IGNORE_CHECKSUM)) != options + && (options | (VALIDATE_FULL | VALIDATE_IGNORE_CHECKSUM)) != options) { + throw new IllegalArgumentException("options must be either 0, " + + "VALIDATE_READ_ONLY, or VALIDATE_FULL, optionally combined with VALIDATE_IGNORE_CHECKSUM"); } - ServiceRequestBuffer srb = createRepairSRB( - options | ISCConstants.isc_spb_rpr_validate_db); + ServiceRequestBuffer srb = createRepairSRB(options | ISCConstants.isc_spb_rpr_validate_db); executeServicesOperation(srb); } - + // ----------- Sweeping ------------------------- - //----------- Sweeping ------------------------- - - /** - * Set the database automatic sweep interval to a given number of - * transactions. The Firebird default value is 20,000. If - * <code>transactions</code> is 0, automatic sweeping is disabled. - * - * @param transactions The interval of transactions between automatic - * sweeps of the database. Can be set to 0, which disables - * automatic sweeping of the database. - * @throws SQLException if a database access error occurs - */ public void setSweepThreshold(int transactions) throws SQLException { - if (transactions < 0){ + if (transactions < 0) { throw new IllegalArgumentException("transactions must be >= 0"); } @@ -404,125 +250,105 @@ executeServicesOperation(srb); } - /** - * Perform an immediate sweep of the database. - * - * @throws SQLException if a database access error occurs - */ public void sweepDatabase() throws SQLException { executeRepairOperation(ISCConstants.isc_spb_rpr_sweep_db); } + // ----------- Shadow Files ------------------------------------ - //----------- Shadow Files ------------------------------------ - - /** - * Activate a database shadow file to be used as the actual database. - * This method is the equivalent of <b><code>gfix -activate</code></b>. - * - * @throws SQLException if a database access error occurs - */ public void activateShadowFile() throws SQLException { executePropertiesOperation(ISCConstants.isc_spb_prp_activate); } - /** - * Remove references to unavailable shadow files. This method is the - * equivalent of <b><code>gfix -kill</code></b>. - * - * @throws SQLException if a database access error occurs - */ public void killUnavailableShadows() throws SQLException { executeRepairOperation(ISCConstants.isc_spb_rpr_kill_shadows); } + // ----------- Transaction Management ---------------------------- - - //----------- Transaction Management ---------------------------- - - - /** - * Retrieve the ID of each limbo transaction. The output of this method - * is written to the logger. - * - * @throws SQLException if a database access error occurs - */ public void listLimboTransactions() throws SQLException { + PrintStream ps = new PrintStream(getLogger()); + for (Integer trId : limboTransactionsAsList()) { + ps.print(trId + "\n"); + } + } + + public List<Integer> limboTransactionsAsList() throws SQLException { + // See also fbscvmgr.cpp method printInfo OutputStream saveOut = getLogger(); try { + List<Integer> result = new LinkedList<Integer>(); ByteArrayOutputStream out = new ByteArrayOutputStream(); - PrintStream ps = new PrintStream(saveOut); setLogger(out); executeRepairOperation(ISCConstants.isc_spb_rpr_list_limbo_trans); byte output[] = out.toByteArray(); - int trId = 0, shift = 0; - for (int i = 0; i < output.length; i++){ - if (output[i] == ISCConstants.isc_spb_single_tra_id){ - trId = 0; - shift = 0; - } else if (output[i] == 0 && shift != -1){ - ps.print(trId + "\n"); - shift = -1; - } else if (shift != -1) { - trId += ((output[i] & 0xff) << shift); - shift += 8; + + int idx = 0; + while (idx < output.length) { + switch (output[idx++]) { + case ISCConstants.isc_spb_tra_id: + case ISCConstants.isc_spb_single_tra_id: + case ISCConstants.isc_spb_multi_tra_id: + int trId = getGds().iscVaxInteger(output, idx, 4); + idx += 4; + result.add(Integer.valueOf(trId)); + break; + // Information items we will ignore for now + case ISCConstants.isc_spb_tra_state: + case ISCConstants.isc_spb_tra_advise: + idx++; + break; + case ISCConstants.isc_spb_tra_host_site: + case ISCConstants.isc_spb_tra_remote_site: + case ISCConstants.isc_spb_tra_db_path: + int length = getGds().iscVaxInteger(output, idx, 2); + idx += 2; + idx += length; + break; + default: + GDSException gdsException = new GDSException(ISCConstants.isc_arg_gds, + ISCConstants.isc_fbsvcmgr_info_err); + gdsException.setNext(new GDSException(ISCConstants.isc_arg_number, output[idx - 1] & 0xFF)); + throw new FBSQLException(gdsException); } } + return result; } finally { setLogger(saveOut); } } - - public int[] getLimboTransactions() throws SQLException - { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - setLogger(byteOut); - listLimboTransactions(); - - StringTokenizer limboTransactions = new StringTokenizer(byteOut.toString(),"\n"); - int[] trans = new int[limboTransactions.countTokens()]; - int count = 0; - while(limboTransactions.hasMoreTokens()) - trans[count++] = Integer.parseInt(limboTransactions.nextToken().trim()); + + public int[] getLimboTransactions() throws SQLException { + List<Integer> limboTransactions = limboTransactionsAsList(); + int[] trans = new int[limboTransactions.size()]; + int idx = 0; + for (Integer trId : limboTransactions) { + trans[idx++] = trId.intValue(); + } return trans; } - /** - * Commit a limbo transaction based on its ID. - * - * @param transactionId The ID of the limbo transaction to be committed - * @throws SQLException if a database access error occurs or the - * given transaction ID is not valid - */ public void commitTransaction(int transactionId) throws SQLException { ServiceRequestBuffer srb = createDefaultRepairSRB(); srb.addArgument(ISCConstants.isc_spb_rpr_commit_trans, transactionId); executeServicesOperation(srb); } - /** - * Rollback a limbo transaction based on its ID. - * - * @param transactionId The ID of the limbo transaction to be rolled back - * @throws SQLException if a database access error occurs or the - * given transaction ID is not valid - */ public void rollbackTransaction(int transactionId) throws SQLException { ServiceRequestBuffer srb = createDefaultRepairSRB(); - srb.addArgument( - ISCConstants.isc_spb_rpr_rollback_trans, - transactionId); + srb.addArgument(ISCConstants.isc_spb_rpr_rollback_trans, transactionId); executeServicesOperation(srb); } + // ----------- Private implementation methods -------------------- - //----------- Private imlementation methods -------------------- - /** * Execute a isc_spb_rpr_* (repair) services operation. * - * @param operation The identifier for the operation to be executed - * @throws SQLException if a database access error occurs + * @param operation + * The identifier for the operation to be executed + * @throws SQLException + * if a database access error occurs */ private void executeRepairOperation(int operation) throws SQLException { ServiceRequestBuffer srb = createRepairSRB(operation); @@ -532,22 +358,22 @@ /** * Execute a isc_spb_prp_* (properties) services operation. * - * @param operation The identifier for the operation to be executed - * @throws SQLException if a database access error occurs + * @param operation + * The identifier for the operation to be executed + * @throws SQLException + * if a database access error occurs */ - private void executePropertiesOperation(int operation) - throws SQLException { + private void executePropertiesOperation(int operation) throws SQLException { ServiceRequestBuffer srb = createPropertiesSRB(operation); executeServicesOperation(srb); } - /** * Get a mostly empty properties-operation buffer that can be filled in as * needed. The buffer created by this method cannot have the options * bitmask set on it. */ - private ServiceRequestBuffer createDefaultPropertiesSRB(){ + private ServiceRequestBuffer createDefaultPropertiesSRB() { return createPropertiesSRB(0); } @@ -556,31 +382,29 @@ * needed. The buffer created by this method cannot have the options * bitmask set on it. */ - private ServiceRequestBuffer createDefaultRepairSRB(){ + private ServiceRequestBuffer createDefaultRepairSRB() { return createRepairSRB(0); } - /** * Get a mostly-empty properties-operation request buffer that can be * filled as needed. * - * @param options The options bitmask for the request buffer + * @param options + * The options bitmask for the request buffer */ - private ServiceRequestBuffer createPropertiesSRB(int options){ - return createRequestBuffer( - ISCConstants.isc_action_svc_properties, - options); + private ServiceRequestBuffer createPropertiesSRB(int options) { + return createRequestBuffer(ISCConstants.isc_action_svc_properties, options); } /** * Get a mostly-empty repair-operation request buffer that can be * filled as needed. * - * @param options The options bitmask for the request buffer + * @param options + * The options bitmask for the request buffer */ - private ServiceRequestBuffer createRepairSRB(int options){ + private ServiceRequestBuffer createRepairSRB(int options) { return createRequestBuffer(ISCConstants.isc_action_svc_repair, options); } - } Modified: client-java/trunk/src/main/org/firebirdsql/management/MaintenanceManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/management/MaintenanceManager.java 2012-11-17 10:42:26 UTC (rev 57358) +++ client-java/trunk/src/main/org/firebirdsql/management/MaintenanceManager.java 2012-11-17 12:56:00 UTC (rev 57359) @@ -38,386 +38,477 @@ */ package org.firebirdsql.management; - import java.sql.SQLException; +import java.util.List; import org.firebirdsql.gds.ISCConstants; - /** - * A <code>MaintenanceManager</code> is responsible for replicating - * the functionality provided by the <code>gfix</code> command-line tool. + * A <code>MaintenanceManager</code> is responsible for replicating the + * functionality provided by the <code>gfix</code> command-line tool. + * <p> * Among the responsibilities of this class are: * <ul> - * <li>Database shutdown - * <li>Extended database shutdown/online modes new with Firebird 2.5 - * <li>Changing database mode to read-only or read-write - * <li>Enabling or disabling forced writes in the database - * <li>Changing the dialect of the database - * <li>Setting the cache size at database-level - * <li>Mending databases and making minor repairs - * <li>Sweeping databases - * <li>Displaying, committing, or recovering limbo transactions - * <li>Activating and killing shadow files - * <li>Configuring page fill + * <li>Database shutdown + * <li>Extended database shutdown/online modes + * <li>Changing database mode to read-only or read-write + * <li>Enabling or disabling forced writes in the database + * <li>Changing the dialect of the database + * <li>Setting the cache size at database-level + * <li>Mending databases and making minor repairs + * <li>Sweeping databases + * <li>Displaying, committing, or recovering limbo transactions + * <li>Activating and killing shadow files + * <li>Configuring page fill * </ul> - * + * </p> + * * @author <a href="mailto:gab...@us...">Gabriel Reid</a> * @author <a href="mailto:tst...@us...">Thomas Steinmaurer</a> */ public interface MaintenanceManager extends ServiceManager { - /** + /** * Database read-write mode */ - public static final int ACCESS_MODE_READ_WRITE = ISCConstants.isc_spb_prp_am_readwrite; + int ACCESS_MODE_READ_WRITE = ISCConstants.isc_spb_prp_am_readwrite; /** * Database read-only mode */ - public static final int ACCESS_MODE_READ_ONLY = ISCConstants.isc_spb_prp_am_readonly; + int ACCESS_MODE_READ_ONLY = ISCConstants.isc_spb_prp_am_readonly; /** * Don't allow new connections while waiting to shut down. */ - public static final int SHUTDOWN_ATTACH = ISCConstants.isc_spb_prp_deny_new_attachments; + int SHUTDOWN_ATTACH = ISCConstants.isc_spb_prp_deny_new_attachments; /** * Don't allow new transactions while waiting to shut down. */ - public static final int SHUTDOWN_TRANSACTIONAL = ISCConstants.isc_spb_prp_deny_new_transactions; + int SHUTDOWN_TRANSACTIONAL = ISCConstants.isc_spb_prp_deny_new_transactions; /** * Forced database shutdown. */ - public static final int SHUTDOWN_FORCE = ISCConstants.isc_spb_prp_shutdown_db; + int SHUTDOWN_FORCE = ISCConstants.isc_spb_prp_shutdown_db; /** * Only report corrupt or misallocated structures, don't fix. */ - public static final int VALIDATE_READ_ONLY = ISCConstants.isc_spb_rpr_check_db; + int VALIDATE_READ_ONLY = ISCConstants.isc_spb_rpr_check_db; /** * Ignore checksums during repair operations. */ - public static final int VALIDATE_IGNORE_CHECKSUM = ISCConstants.isc_spb_rpr_ignore_checksum; + int VALIDATE_IGNORE_CHECKSUM = ISCConstants.isc_spb_rpr_ignore_checksum; /** * Do a full check on record and pages structures, releasing unassigned * record fragments. */ - public static final int VALIDATE_FULL = ISCConstants.isc_spb_rpr_full; + int VALIDATE_FULL = ISCConstants.isc_spb_rpr_full; /** * Fully fill pages when inserting records. */ - public static final int PAGE_FILL_FULL = ISCConstants.isc_spb_prp_res_use_full; + int PAGE_FILL_FULL = ISCConstants.isc_spb_prp_res_use_full; /** - * While inserting recrods, reserve 20% of each page for later - * record deltas + * While inserting records, reserve 20% of each page for later record deltas */ - public static final int PAGE_FILL_RESERVE = ISCConstants.isc_spb_prp_res; - + int PAGE_FILL_RESERVE = ISCConstants.isc_spb_prp_res; + /** - * Operation mode normal online. New with Firebird 2.5. + * Operation mode normal online. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final byte OPERATION_MODE_NORMAL = ISCConstants.isc_spb_prp_sm_normal; - + byte OPERATION_MODE_NORMAL = ISCConstants.isc_spb_prp_sm_normal; + /** - * Operation mode multi shutdown/online. New with Firebird 2.5. + * Operation mode multi shutdown/online. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final byte OPERATION_MODE_MULTI = ISCConstants.isc_spb_prp_sm_multi; - + byte OPERATION_MODE_MULTI = ISCConstants.isc_spb_prp_sm_multi; + /** - * Operation mode single shutdown/online. New with Firebird 2.5. + * Operation mode single shutdown/online. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final byte OPERATION_MODE_SINGLE = ISCConstants.isc_spb_prp_sm_single; - + byte OPERATION_MODE_SINGLE = ISCConstants.isc_spb_prp_sm_single; + /** - * Operation mode full shutdown. New with Firebird 2.5. + * Operation mode full shutdown. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final byte OPERATION_MODE_FULL_SHUTDOWN = ISCConstants.isc_spb_prp_sm_full; - + byte OPERATION_MODE_FULL_SHUTDOWN = ISCConstants.isc_spb_prp_sm_full; + /** - * Force shutdown. New with Firebird 2.5. + * Force shutdown. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. + * </p> + * + * @since Firebird 2.5 * @see #shutdownDatabase(byte, int, int) */ - public static final int SHUTDOWNEX_FORCE = ISCConstants.isc_spb_prp_force_shutdown; - + int SHUTDOWNEX_FORCE = ISCConstants.isc_spb_prp_force_shutdown; + /** - * Shutdown attachments. New with Firebird 2.5. + * Shutdown attachments. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final int SHUTDOWNEX_ATTACHMENTS = ISCConstants.isc_spb_prp_attachments_shutdown; + int SHUTDOWNEX_ATTACHMENTS = ISCConstants.isc_spb_prp_attachments_shutdown; /** - * Shutdown transactions. New with Firebird 2.5. + * Shutdown transactions. + * <p> * To be used with the {@link #shutdownDatabase(byte, int, int)} method. - * @see #shutdownDatabase(byte, int, int) + * </p> + * + * @since Firebird 2.5 + * @see #shutdownDatabase(byte, int, int) */ - public static final int SHUTDOWNEX_TRANSACTIONS = ISCConstants.isc_spb_prp_transactions_shutdown; - + int SHUTDOWNEX_TRANSACTIONS = ISCConstants.isc_spb_prp_transactions_shutdown; + /** * Set the database to have read-write or read-only access. - * - * @param mode Must be either <code>ACCESS_MODE_READ_WRITE</code> - * or <code>ACCESS_MODE_READ_ONLY</code> - * @throws SQLException if a database access error occurs + * + * @param mode + * Must be either <code>ACCESS_MODE_READ_WRITE</code> or + * <code>ACCESS_MODE_READ_ONLY</code> + * @throws SQLException + * if a database access error occurs */ - public void setDatabaseAccessMode(int mode) throws SQLException; + void setDatabaseAccessMode(int mode) throws SQLException; /** * Set the database's dialect. - * - * @param dialect The database dialect, must be either 1 or 3 - * @throws SQLException if a database access error occurs + * + * @param dialect + * The database dialect, must be either 1 or 3 + * @throws SQLException + * if a database access error occurs */ - public void setDatabaseDialect(int dialect) throws SQLException; + void setDatabaseDialect(int dialect) throws SQLException; - /** - * Set the default page-buffer count to be cached in the database. The - * Firebird default is 2048. - * - * @param pageCount The number of pages to be cached, must be a positive - * @throws SQLException If the given page count cannot be set, or a - * database access error occurs + * Set the default page-buffer count to be cached in the database. + * + * @param pageCount + * The number of pages to be cached, must be a positive + * @throws SQLException + * If the given page count cannot be set, or a database access + * error occurs */ - public void setDefaultCacheBuffer(int pageCount) throws SQLException; + void setDefaultCacheBuffer(int pageCount) throws SQLException; - /** * Enable or disable forced (synchronous) writes in the database. - * Note, it is considered to be a <b>very</b> bad idea to use buffered - * writing on Windows platforms. - * - * @param forced If <code>true</code>, forced writes will be used in the - * database, otherwise buffered writes will be used. - * @throws SQLException if a database access error occurs + * <p> + * Note, it is considered to be a <b>very</b> bad idea to disable forced + * writes on Windows platforms. + * </p> + * + * @param forced + * If <code>true</code>, forced writes will be used in the + * database, otherwise buffered writes will be used. + * @throws SQLException + * if a database access error occurs */ - public void setForcedWrites(boolean forced) throws SQLException; + void setForcedWrites(boolean forced) throws SQLException; - /** * Set the page fill strategy for when inserting records. + * <p> * <code>pageFill</code> can be one of: * <ul> - * <li><code>PAGE_FILL_FULL</code> Fully fill database pages - * <li><code>PAGE_FILL_RESERVE</code> Reserve 20% of page space for - * later record deltas + * <li><code>PAGE_FILL_FULL</code> Fully fill database pages + * <li><code>PAGE_FILL_RESERVE</code> Reserve 20% of page space for later + * record deltas * </ul> - * - * @param pageFill The page-filling strategy, either - * <code>PAGE_FILL_FULL</code> or <code>PAGE_FILL_RESERVE</code> - * @throws SQLException if a database access error occurs + * </p> + * + * @param pageFill + * The page-filling strategy, either <code>PAGE_FILL_FULL</code> + * or <code>PAGE_FILL_RESERVE</code> + * @throws SQLException + * if a database access error occurs */ - public void setPageFill(int pageFill) throws SQLException; + void setPageFill(int pageFill) throws SQLException; + // ----------- Database Shutdown ------------------- - //----------- Database Shutdown ------------------- - /** * Shutdown the current database. + * <p> * Shutdown can be done in three modes: * <ul> - * <li><code>SHUTDOWN_ATTACH</code> - No new non-owner connections - * will be allowed to the database during the shutdown, and shutdown - * is cancelled if there are still processes connected at the end - * of the timeout. - * - * <li><code>SHUTDOWN_TRANSACTIONAL</code> - No new transactions can - * be started during the timeout period, and shutdown is cancelled - * if there are still active transactions at the end of the timeout. - * - * <li><code>SHUTDOWN_FORCE</code> - Forcefully shuts down the - * database at the end of the timeout. + * <li><code>SHUTDOWN_ATTACH</code> - No new non-owner connections will be + * allowed to the database during the shutdown, and shutdown is cancelled if + * there are still processes connected at the end of the timeout. + * + * <li><code>SHUTDOWN_TRANSACTIONAL</code> - No new transactions can be + * started during the timeout period, and shutdown is cancelled if there are + * still active transactions at the end of the timeout. + * + * <li><code>SHUTDOWN_FORCE</code> - Forcefully shuts down the database at + * the end of the timeout. * </ul> - * - * @param shutdownMode One of <code>SHUTDOWN_ATTACH</code>, - * <code>SHUTDOWN_TRANSACTIONAL</code>, - * or <code>SHUTDOWN_FORCE</code>. - * @param timeout The maximum amount of time allocated for the operation, - * in seconds - * @throws SQLException if the requested operation cannot be completed - * within the given timeout, or a database access error occurs + * </p> + * + * @param shutdownMode + * One of <code>SHUTDOWN_ATTACH</code>, + * <code>SHUTDOWN_TRANSACTIONAL</code>, or + * <code>SHUTDOWN_FORCE</code>. + * @param timeout + * The maximum amount of time allocated for the operation, in + * seconds + * @throws SQLException + * if the requested operation cannot be completed within the + * given timeout, or a database access error occurs */ - public void shutdownDatabase(int shutdownMode, int timeout) - throws SQLException ; + void shutdownDatabase(int shutdownMode, int timeout) throws SQLException; /** - * Shutdown the current database with enhanced modes new since Firebird 2.5. + * Shutdown the current database with enhanced modes (FB 2.5 or higher). + * <p> * There are three operation modes for shutdown available: * <ul> - * <li><code>OPERATION_MODE_MULTI</code> - Multi-user maintenance. Unlimited SYSDBA/database owner connections are allowed. - * - * <li><code>OPERATION_MODE_SINGLE</code> - Single-user maintenance. Only one SYSDBA/database owner connection is allowed. - * - * <li><code>OPERATION_MODE_FULL_SHUTDOWN</code> - Full shutdown. Full exclusive shutdown. No connections are allowed. + * <li><code>OPERATION_MODE_MULTI</code> - Multi-user maintenance. Unlimited + * SYSDBA/database owner connections are allowed. + * <li><code>OPERATION_MODE_SINGLE</code> - Single-user maintenance. Only + * one SYSDBA/database owner connection is allowed. + * <li><code>OPERATION_MODE_FULL_SHUTDOWN</code> - Full shutdown. Full + * exclusive shutdown. No connections are allowed. * </ul> + * </p> + * <p> * There are three extended shutdown modes for shutdown available: * <ul> - * <li><code>SHUTDOWNEX_FORCE</code> - Force shutdown. - * - * <li><code>SHUTDOWNEX_ATTACHMENTS</code> - Shutdown attachments. - * - * <li><code>SHUTDOWNEX_TRANSACTIONS</code> - Shutdown transactions. + * <li><code>SHUTDOWNEX_FORCE</code> - Force shutdown. + * <li><code>SHUTDOWNEX_ATTACHMENTS</code> - Shutdown attachments. + * <li><code>SHUTDOWNEX_TRANSACTIONS</code> - Shutdown transactions. * </ul> - * @param operationMode one of <code>OPERATION_MODE_*</code> operation modes listed above - * @param shutdownModeEx one of <code>SHUTDOWNEX_*</code> extended shutdown modes listed above - * @param timeout The maximum amount of time allocated for the operation, in seconds. 0 = immediately. - * @throws SQLException if the requested operation cannot be completed - * within the given timeout, or a database access error occurs + * </p> + * + * @param operationMode + * one of <code>OPERATION_MODE_*</code> operation modes listed + * above + * @param shutdownModeEx + * one of <code>SHUTDOWNEX_*</code> extended shutdown modes + * listed above + * @param timeout + * The maximum amount of time allocated for the operation, in + * seconds. 0 = immediately. + * @throws SQLException + * if the requested operation cannot be completed within the + * given timeout, or a database access error occurs + * @since Firebird 2.5 */ - public void shutdownDatabase(byte operationMode, int shutdownModeEx, int timeout) throws SQLException ; + void shutdownDatabase(byte operationMode, int shutdownModeEx, int timeout) throws SQLException; - /** * Bring a shutdown database online. - * - * @throws SQLException if a database access error occurs + * + * @throws SQLException + * if a database access error occurs */ - public void bringDatabaseOnline() throws SQLException; + void bringDatabaseOnline() throws SQLException; /** - * Bring a shutdown database online with enhanced operation modes - * new since Firebird 2.5. + * Bring a shutdown database online with enhanced operation modes (FB 2.5 or + * higher). + * <p> * There are three operation modes for bringing a database online available: * <ul> - * <li><code>OPERATION_MODE_NORMAL</code> - Normal operation modes. - * - * <li><code>OPERATION_MODE_MULTI</code> - Multi-user maintenance. Unlimited SYSDBA/database owner connections are allowed. - * - * <li><code>OPERATION_MODE_SINGLE</code> - Single-user maintenance. Only one SYSDBA/database owner connection is allowed. + * <li><code>OPERATION_MODE_NORMAL</code> - Normal operation modes. + * <li><code>OPERATION_MODE_MULTI</code> - Multi-user maintenance. Unlimited + * SYSDBA/database owner connections are allowed. + * <li><code>OPERATION_MODE_SINGLE</code> - Single-user maintenance. Only + * one SYSDBA/database owner connection is allowed. * </ul> - * @throws SQLException if a database access error occurs + * </p> + * + * @throws SQLException + * if a database access error occurs + * @since Firebird 2.5 */ - public void bringDatabaseOnline(byte operationMode) throws SQLException; + void bringDatabaseOnline(byte operationMode) throws SQLException; + // -------------- Database Repair ---------------------- - //-------------- Database Repair ---------------------- - /** * Mark corrupt records in the database as unavailable. - * This operation ensures that the corrupt records are skipped (for - * example, during a subsequent backup). - * - * @throws SQLException if a database access error occurs + * <p> + * This operation ensures that the corrupt records are skipped (for example, + * during a subsequent backup). + * </p> + * + * @throws SQLException + * if a database access error occurs */ - public void markCorruptRecords() throws SQLException; + void markCorruptRecords() throws SQLException; /** - * Locate and release database pages that are allocated but unassigned - * to any data structures. This method also reports corrupt structures. - * - * @throws SQLException if a database access error occurs + * Locate and release database pages that are allocated but unassigned to + * any data structures. This method also reports corrupt structures. + * + * @throws SQLException + * if a database access error occurs */ - public void validateDatabase() throws SQLException; + void validateDatabase() throws SQLException; /** - * Locate and release database pages that are allocated but unassigned - * to any data structures. This method also reports corrupt structures. - * The value supplied for <code>options</code> must be one of the - * following: + * Locate and release database pages that are allocated but unassigned to + * any data structures. This method also reports corrupt structures. + * <p> + * The value supplied for <code>options</code> must be one of the following: * <ul> - * <li>0 - Simple validation - * <li><code>VALIDATE_READ_ONLY</code> - read-only validation, - * no repair - * <li><code>VALIDATE_FULL</code> - full validation and repair + * <li>0 - Simple validation + * <li><code>VALIDATE_READ_ONLY</code> - read-only validation, no repair + * <li><code>VALIDATE_FULL</code> - full validation and repair * </ul> - * - * The value for <code>options</code> can additionally be combined in - * a bitmask with <code>VALIDATE_IGNORE_CHECKSUM</code> to ignore - * checksums while performing validation. - * - * @param options Either 0, <code>VALIDATE_READ_ONLY</code>, or - * <code>VALIDATE_FULL</code> - * @throws SQLException if a database access error occurs + * </p> + * <p> + * The value for <code>options</code> can additionally be combined in a + * bitmask with <code>VALIDATE_IGNORE_CHECKSUM</code> to ignore checksums + * while performing validation. + * </p> + * + * @param options + * Either 0, <code>VALIDATE_READ_ONLY</code>, or + * <code>VALIDATE_FULL</code> + * @throws SQLException + * if a database access error occurs */ - public void validateDatabase(int options) throws SQLException; + void validateDatabase(int options) throws SQLException; - + // ----------- Sweeping ------------------------- - //----------- Sweeping ------------------------- - /** - * Set the database automatic sweep interval to a given number of - * transactions. The Firebird default value is 20,000. If - * <code>transactions</code> is 0, automatic sweeping is disabled. - * - * @param transactions The interval of transactions between automatic - * sweeps of the database. Can be set to 0, which disables - * automatic sweeping of the database. - * @throws SQLException if a database access error occurs + * Set the database automatic sweep interval to a given number of + * transactions. + * <p> + * The Firebird default value is 20,000. If <code>transactions</code> is 0, + * automatic sweeping is disabled. + * </p> + * + * @param transactions + * The interval of transactions between automatic sweeps of the + * database. Can be set to 0, which disables automatic sweeping + * of the database. + * @throws SQLException + * if a database access error occurs */ - public void setSweepThreshold(int transactions) throws SQLException; + void setSweepThreshold(int transactions) throws SQLException; /** * Perform an immediate sweep of the database. - * - * @throws SQLException if a database access error occurs + * + * @throws SQLException + * if a database access error occurs */ - public void sweepDatabase() throws SQLException; + void sweepDatabase() throws SQLException; + // ----------- Shadow Files ------------------------------------ - - //----------- Shadow Files ------------------------------------ - /** * Activate a database shadow file to be used as the actual database. + * <p> * This method is the equivalent of <b><code>gfix -activate</code></b>. - * - * @throws SQLException if a database access error occurs + * </p> + * + * @throws SQLException + * if a database access error occurs */ - public void activateShadowFile() throws SQLException; + void activateShadowFile() throws SQLException; /** - * Remove references to unavailable shadow files. This method is the - * equivalent of <b><code>gfix -kill</code></b>. - * - * @throws SQLException if a database access error occurs + * Remove references to unavailable shadow files. + * <p> + * This method is the equivalent of <b><code>gfix -kill</code></b>. + * </p> + * + * @throws SQLException + * if a database access error occurs */ - public void killUnavailableShadows() throws SQLException; + void killUnavailableShadows() throws SQLException; + // ----------- Transaction Management ---------------------------- + /** + * Retrieve the ID of each limbo transaction. The output of this method is + * written to the logger. + * + * @throws SQLException + * if a database access error occurs + * @deprecated Use {@link #limboTransactionsAsList()} or + * {@link #getLimboTransactions()} instead + */ + @Deprecated + void listLimboTransactions() throws SQLException; + /** + * Retrieve the ID of each limbo transaction as a List of Integer objects. + * + * @throws SQLException + * if a database access error occurs + */ + List<Integer> limboTransactionsAsList() throws SQLException; - //----------- Transaction Management ---------------------------- - /** - * Retrieve the ID of each limbo transaction. The output of this method - * is written to the logger. - * - * @throws SQLException if a database access error occurs + * Retrieve the ID of each limbo transaction as an array of ints. + * + * @throws SQLException + * ... [truncated message content] |
From: <mro...@us...> - 2012-11-22 14:19:14
|
Revision: 57398 http://firebird.svn.sourceforge.net/firebird/?rev=57398&view=rev Author: mrotteveel Date: 2012-11-22 14:19:04 +0000 (Thu, 22 Nov 2012) Log Message: ----------- Add charactersets introduced in Firebird 2.1 and 2.5. Use direct indexing to access CHARSET_MAXIMUM_SIZE instead of searching through array of arrays Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java client-java/trunk/src/resources/isc_encoding_size.properties client-java/trunk/src/resources/isc_encodings.properties Modified: client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java 2012-11-22 14:05:37 UTC (rev 57397) +++ client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java 2012-11-22 14:19:04 UTC (rev 57398) @@ -26,55 +26,67 @@ public class EncodingFactory { - private static final int[][] CHARSET_MAXIMUM_SIZE = new int[][] { - { 0, 1} // NONE - , { 1, 1} // OCTETS - , { 2, 1} // ASCII - , { 3, 3} // UNICODE_FSS - , { 4, 4} // UTF8 - , { 5, 2} // SJIS_0208 - , { 6, 2} // EUJC_0208 - , { 9, 1} // DOS737 - , {10, 1} // DOS437 - , {11, 1} // DOS850 - , {12, 1} // DOS865 - , {13, 1} // DOS775 - , {14, 1} // DOS863 - , {15, 1} // DOS775 - , {16, 1} // DOS858 - , {17, 1} // DOS862 - , {18, 1} // DOS864 - , {19, 1} // NEXT - , {21, 1} // ISO8859_1 - , {22, 1} // ISO8859_2 - , {23, 1} // ISO8859_3 - , {34, 1} // ISO8859_4 - , {35, 1} // ISO8859_5 - , {36, 1} // ISO8859_6 - , {37, 1} // ISO8859_7 - , {38, 1} // ISO8859_8 - , {39, 1} // ISO8859_9 - , {40, 1} // ISO8859_13 - , {44, 2} // KSC_5601 - , {45, 1} // DOS852 - , {46, 1} // DOS857 - , {47, 1} // DOS861 - , {48, 1} // DOS866 - , {49, 1} // DOS869 - , {50, 1} // CYRL - , {51, 1} // WIN1250 - , {52, 1} // WIN1251 - , {53, 1} // WIN1252 - , {54, 1} // WIN1253 - , {55, 1} // WIN1254 - , {56, 2} // BIG_5 - , {57, 2} // GB2312 - , {58, 1} // WIN1255 - , {59, 1} // WIN1256 - , {60, 1} // WIN1257 - , {63, 1} // KOI8R - , {64, 1} // KOI8U - , {65, 1} // WIN1258 + private static final byte[] CHARSET_MAXIMUM_SIZE; + private static final int MAX_CHARSET_ID = 69; + + static { + byte[] maximumSize = new byte[MAX_CHARSET_ID + 1]; + // Fill with 1 as default + Arrays.fill(maximumSize, (byte)1); + maximumSize[0] = 1; // NONE + maximumSize[1] = 1; // OCTETS + maximumSize[2] = 1; // ASCII + maximumSize[3] = 3; // UNICODE_FSS + maximumSize[4] = 4; // UTF8 + maximumSize[5] = 2; // SJIS_0208 + maximumSize[6] = 2; // EUJC_0208 + maximumSize[9] = 1; // DOS737 + maximumSize[10] = 1; // DOS437 + maximumSize[11] = 1; // DOS850 + maximumSize[12] = 1; // DOS865 + maximumSize[13] = 1; // DOS775 + maximumSize[14] = 1; // DOS863 + maximumSize[15] = 1; // DOS775 + maximumSize[16] = 1; // DOS858 + maximumSize[17] = 1; // DOS862 + maximumSize[18] = 1; // DOS864 + maximumSize[19] = 1; // NEXT + maximumSize[21] = 1; // ISO8859_1 + maximumSize[22] = 1; // ISO8859_2 + maximumSize[23] = 1; // ISO8859_3 + maximumSize[34] = 1; // ISO8859_4 + maximumSize[35] = 1; // ISO8859_5 + maximumSize[36] = 1; // ISO8859_6 + maximumSize[37] = 1; // ISO8859_7 + maximumSize[38] = 1; // ISO8859_8 + maximumSize[39] = 1; // ISO8859_9 + maximumSize[40] = 1; // ISO8859_13 + maximumSize[44] = 2; // KSC_5601 + maximumSize[45] = 1; // DOS852 + maximumSize[46] = 1; // DOS857 + maximumSize[47] = 1; // DOS861 + maximumSize[48] = 1; // DOS866 + maximumSize[49] = 1; // DOS869 + maximumSize[50] = 1; // CYRL + maximumSize[51] = 1; // WIN1250 + maximumSize[52] = 1; // WIN1251 + maximumSize[53] = 1; // WIN1252 + maximumSize[54] = 1; // WIN1253 + maximumSize[55] = 1; // WIN1254 + maximumSize[56] = 2; // BIG_5 + maximumSize[57] = 2; // GB2312 + maximumSize[58] = 1; // WIN1255 + maximumSize[59] = 1; // WIN1256 + maximumSize[60] = 1; // WIN1257 + maximumSize[63] = 1; // KOI8R + maximumSize[64] = 1; // KOI8U + maximumSize[65] = 1; // WIN1258 + maximumSize[66] = 1; // TIS620 + maximumSize[67] = 2; // GBK + maximumSize[68] = 2; // CP943C + maximumSize[69] = 4; // GB18030 + + CHARSET_MAXIMUM_SIZE = maximumSize; }; /** @@ -206,12 +218,9 @@ * not found. */ public static int getCharacterSetSize(int characterSetId) { - - for (int i = 0; i < CHARSET_MAXIMUM_SIZE.length; i++) { - if (CHARSET_MAXIMUM_SIZE[i][0] == characterSetId) - return CHARSET_MAXIMUM_SIZE[i][1]; + if (characterSetId >= 0 && characterSetId < CHARSET_MAXIMUM_SIZE.length) { + return CHARSET_MAXIMUM_SIZE[characterSetId]; } - // let's assume that default length is 1 return 1; } Modified: client-java/trunk/src/resources/isc_encoding_size.properties =================================================================== --- client-java/trunk/src/resources/isc_encoding_size.properties 2012-11-22 14:05:37 UTC (rev 57397) +++ client-java/trunk/src/resources/isc_encoding_size.properties 2012-11-22 14:19:04 UTC (rev 57398) @@ -6,7 +6,7 @@ # # where IB_enc is InterBase encoding, and size - max. size of character in bytes # -# Contributor: Roman Rokytskyy +# Contributor: Roman Rokytskyy, Mark Rotteveel #American Standard Code for Information Interchange @@ -144,4 +144,20 @@ KOI8R 1 #KOI encoding for Ukrainian language -KOI8U 1 \ No newline at end of file +KOI8U 1 + +# Charsets added in Firebird 2.1 + +#TIS620 +TIS620 1 + +#GBK +GBK 2 + +#CP943C +CP943C 2 + +# Charsets added in Firebird 2.5 + +#GB18030 +GB18030 4 \ No newline at end of file Modified: client-java/trunk/src/resources/isc_encodings.properties =================================================================== --- client-java/trunk/src/resources/isc_encodings.properties 2012-11-22 14:05:37 UTC (rev 57397) +++ client-java/trunk/src/resources/isc_encodings.properties 2012-11-22 14:19:04 UTC (rev 57398) @@ -9,9 +9,8 @@ # Note, for correct work of some encodings you might need i18n.jar to be # included in your classpath. # -# Contributor: Daniel Marczisovszky, Roman Rokytskyy +# Contributor: Daniel Marczisovszky, Roman Rokytskyy, Mark Rotteveel - #American Standard Code for Information Interchange ASCII US-ASCII @@ -73,10 +72,10 @@ #EUCJ_0208 (not sure) EUC_JP_LINUX #GB2312, EUC encoding, Simplified Chinese -GB_2312 EUC_CN +GB_2312 EUC_CN #GBK, Simplified Chinese -#GB_2312 GBK +GBK GBK #ISO 8859-1, Latin alphabet No. 1 ISO8859_1 ISO-8859-1 @@ -108,7 +107,10 @@ #ISO 8859-13 ISO8859_13 ISO-8859-13 -#Windows Korean +#KS C 5601, EUC encoding, Korean +#KSC_5601 EUC_KR + +#Windows Korean (preferred over EUC_KR?) KSC_5601 MS949 #Windows Japanese @@ -138,15 +140,27 @@ #Windows Turkish WIN1254 Cp1254 -#Windows +#Windows Hebrew WIN1255 Cp1255 -#Windows +#Windows Arabic WIN1256 Cp1256 -#Windows +#Windows Baltic WIN1257 Cp1257 +#KOI8-R, Russian +KOI8R KOI8_R + +#Windows Vietnamese +WIN1258 Cp1258 + +#TIS620, Thai +TIS620 TIS620 + +#Variant of Cp943 +CP943C Cp943C + # Encodings below seem not to have any direct correspondence to # InterBase encodings, however we keep them for the future # Replace the "?" mark with the appropriate InterBase encoding @@ -217,18 +231,6 @@ #Variant of Cp871 with Euro character #? Cp1149 -#Windows Hebrew -#? Cp1255 - -#Windows Arabic -#? Cp1256 - -#Windows Baltic -#? Cp1257 - -#Windows Vietnamese -#? Cp1258 - #IBM OS/2, DOS People's Republic of China (PRC) #? Cp1381 @@ -268,12 +270,6 @@ #EBCDIC 500V1 #? Cp500 -#PC Greek -#? Cp737 - -#PC Baltic -#? Cp775 - #IBM Thailand extended SBCS #? Cp838 @@ -283,24 +279,9 @@ #IBM Hebrew #? Cp856 -#Variant of Cp850 with Euro character -#? Cp858 - -#PC Hebrew -#? Cp862 - -#PC Arabic -#? Cp864 - -#MS-DOS Russian -#? Cp866 - #MS-DOS Pakistan #? Cp868 -#IBM Modern Greek -#? Cp869 - #IBM Multilingual Latin-2 #? Cp870 @@ -346,9 +327,6 @@ #IBM OS/2 Japanese, superset of Cp932 and Shift-JIS #? Cp943 -#Variant of Cp943 -#? Cp943C - #OS/2 Chinese (Taiwan) superset of 938 #? Cp948 @@ -367,9 +345,6 @@ #AIX Korean #? Cp970 -#KS C 5601, EUC encoding, Korean -#? EUC_KR - #CNS11643 (Plane 1-3), EUC encoding, Traditional Chinese #? EUC_TW @@ -433,9 +408,6 @@ #Johab, Korean #? Johab -#KOI8-R, Russian -#? KOI8_R - #Macintosh Arabic #? MacArabic @@ -484,9 +456,6 @@ #Windows Simplified Chinese #? MS936 -#TIS620, Thai -#? TIS620 - #Sixteen-bit Unicode Transformation Format, big-endian byte order, with byte-order mark #? UnicodeBig This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-23 16:45:36
|
Revision: 57403 http://firebird.svn.sourceforge.net/firebird/?rev=57403&view=rev Author: mrotteveel Date: 2012-11-23 16:45:29 +0000 (Fri, 23 Nov 2012) Log Message: ----------- Take out custom code for IP address resolution (fixes JDBC-98) Make sure receive buffer is specified before connect (JDBC-238) Prepare for specifying connect timeout (JDBC-279) Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-23 12:44:27 UTC (rev 57402) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-11-23 16:45:29 UTC (rev 57403) @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; @@ -2007,30 +2008,12 @@ return nextOperation; } - /** - * Returns a newly created socket. This abstract method is necessary because - * of a bug found in the JDK5.0 socket implementation. JDK1.4+ has an - * acceptable work around. - * - * See bug details: - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092063 - * - * @param server - * The server string. - * @param port - * The port to connect to. - * @return A valid socket. - * @throws IOException - * @throws UnknownHostException - */ - protected abstract Socket getSocket(String server, int port) - throws IOException, UnknownHostException; - protected void openSocket(isc_db_handle_impl db, DbAttachInfo dbai, boolean debug, int socketBufferSize, int soTimeout) throws IOException, SocketException, GDSException { try { - db.socket = getSocket(dbai.getServer(), dbai.getPort()); + db.socket = new Socket(); + // TODO: consider not disabling Nagle db.socket.setTcpNoDelay(true); if (soTimeout != -1) @@ -2040,6 +2023,9 @@ db.socket.setReceiveBufferSize(socketBufferSize); db.socket.setSendBufferSize(socketBufferSize); } + // TODO : introduce keep alive + // TODO : introduce connection timeout + db.socket.connect(new InetSocketAddress(dbai.getServer(), dbai.getPort())); if (debug) log.debug("Got socket"); @@ -2593,13 +2579,18 @@ synchronized (svc) { try { try { - svc.socket = getSocket(host, port); + svc.socket = new Socket(); svc.socket.setTcpNoDelay(true); + // TODO: Introduce buffer sizes for services + // TODO: Introduce soTimeout for services // if (socketBufferSize != -1) { // svc.socket.setReceiveBufferSize(socketBufferSize); // svc.socket.setSendBufferSize(socketBufferSize); // } + + // TODO Use connect timeout + svc.socket.connect(new InetSocketAddress(host, port)); if (debug) log.debug("Got socket"); } catch (UnknownHostException ex2) { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java 2012-11-23 12:44:27 UTC (rev 57402) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/JavaGDSImpl.java 2012-11-23 16:45:29 UTC (rev 57403) @@ -1,11 +1,5 @@ package org.firebirdsql.gds.impl.wire; -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.ArrayList; - /** * Implements JDK1.4+ specific socket creation. * @@ -20,92 +14,4 @@ */ public class JavaGDSImpl extends AbstractJavaGDSImpl { - /* - * (non-Javadoc) - * - * @see org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl#getSocket(java.lang.String, - * int) - */ - protected Socket getSocket(String server, int port) throws IOException, - UnknownHostException { - - // Check for a valid ip address. - byte[] address = parseRawAddress(server); - - // Create the socket using an instance of the InetAddress class if the - // ip address is a valid IPV4 or IPV6 address - if (address != null && address.length != 0) - return new Socket(InetAddress.getByAddress(address), port); - else - return new Socket(server, port); - - } - - /** - * Parses a string representation of a raw ip address. Only 4 byte (IPv4) or - * 16 byte (IPv6) are acceptable. - * - * @param server - * a string representation of the host server. - * @return a byte array representing the ip address - */ - public static byte[] parseRawAddress(String server) { - - ArrayList<Byte> result = new ArrayList<Byte>(); - String[] bytes = server.split("\\.|:"); - - try { - // Only 4 byte (IPv4) and 16 byte (IPv6) addresses are acceptable. - if (bytes.length == 4 ) { - // convert each string into a byte. If the string doesn't isn't in - // the range of 0 .. 255 return null. - for (int index = 0; index < bytes.length; index++) { - int value = Integer.parseInt(bytes[index]); - - if (value >= 0 && value <= 255) - result.add((byte) value); - else - return null; - - } - } else - if (bytes.length == 16 || bytes.length == 8) { - - // convert each string into a byte. If the string doesn't isn't in - // the range of 0 .. 255 return null. - for (int index = 0; index < bytes.length; index++) { - - bytes[index] = prependZeros(bytes[index], 4); - String hi = bytes[index].substring(0, 2); - String lo = bytes[index].substring(2); - - int hiValue = Integer.parseInt(hi, 16); - int loValue = Integer.parseInt(lo, 16); - - if (hiValue == -1 || loValue == -1) - return null; - - result.add((byte)hiValue); - result.add((byte)loValue); - - } - } else - return null; - } catch(NumberFormatException ex) { - return null; - } - - byte[] address = new byte[result.size()]; - for(int i = 0 ; i < result.size(); i++) - address[i] = result.get(i); - - return address; - - } - - private static String prependZeros(String s, int totalLength) { - s= "000000000000"+s; // twelve zeros prepended - return s.substring(s.length()-totalLength); // keep the rightmost 13 chars - } - } Modified: client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java 2012-11-23 12:44:27 UTC (rev 57402) +++ client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java 2012-11-23 16:45:29 UTC (rev 57403) @@ -868,21 +868,4 @@ * String(answer)); gds.isc_close_blob(blob1); commit(t1); // * teardownTable2(db1); // dropDatabase(db1); } */ - - public void testIPv6Format() { - byte[] testIPv4 = { 127, 0, 0, 1}; - - // 2001:0db8:85a3:08d3:1319:8a2e:0370:7344 - byte[] testIPv6 = { 32, 1, 13, (byte) 184, (byte) 133, (byte) 163, 8, - (byte) 211, 19, 25, (byte) 138, 46, 3, 112, 115, 68}; - - byte[] ipv4 = JavaGDSImpl.parseRawAddress("127.0.0.1"); - byte[] ipv6 = JavaGDSImpl.parseRawAddress("2001:0db8:85a3:08d3:1319:8a2e:0370:7344"); - - assertTrue(Arrays.equals(ipv4, testIPv4)); - assertTrue(Arrays.equals(ipv6, testIPv6)); - - byte[] dummy = JavaGDSImpl.parseRawAddress("a.b.c.d"); - assertNull(dummy); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-11-23 16:48:32
|
Revision: 57404 http://firebird.svn.sourceforge.net/firebird/?rev=57404&view=rev Author: mrotteveel Date: 2012-11-23 16:48:23 +0000 (Fri, 23 Nov 2012) Log Message: ----------- Misc. changes Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/management/FBStatisticsManager.java client-java/trunk/src/main/org/firebirdsql/pool/FBSimpleDataSource.java client-java/trunk/src/test/org/firebirdsql/jca/TestDataSourceSerialization.java Modified: client-java/trunk/src/main/org/firebirdsql/management/FBStatisticsManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/management/FBStatisticsManager.java 2012-11-23 16:45:29 UTC (rev 57403) +++ client-java/trunk/src/main/org/firebirdsql/management/FBStatisticsManager.java 2012-11-23 16:48:23 UTC (rev 57404) @@ -58,8 +58,7 @@ * * @author <a href="mailto:gab...@us...">Gabriel Reid</a> */ -public class FBStatisticsManager extends FBServiceManager - implements StatisticsManager { +public class FBStatisticsManager extends FBServiceManager implements StatisticsManager { private static final int possibleStatistics = DATA_TABLE_STATISTICS | SYSTEM_TABLE_STATISTICS | INDEX_STATISTICS | @@ -125,17 +124,13 @@ if (i < tableNames.length - 1) commandLine.append(' '); } - - //FIXME should be isc_spb_command_line, but FB 2.0 does not like it srb.addArgument(ISCConstants.isc_spb_command_line, commandLine.toString()); executeServicesOperation(srb); } - //---------- Private implementation methods ----------------- - /** * Get a mostly empty buffer that can be filled in as needed. * The buffer created by this method cannot have the options bitmask @@ -156,5 +151,4 @@ ISCConstants.isc_action_svc_db_stats, options); } - } Modified: client-java/trunk/src/main/org/firebirdsql/pool/FBSimpleDataSource.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/pool/FBSimpleDataSource.java 2012-11-23 16:45:29 UTC (rev 57403) +++ client-java/trunk/src/main/org/firebirdsql/pool/FBSimpleDataSource.java 2012-11-23 16:48:23 UTC (rev 57404) @@ -3,7 +3,7 @@ import org.firebirdsql.gds.impl.GDSType; /** - * @deprecated Use {@link org.firebirdsql.dl.FBSimpleDataSource} + * @deprecated Use {@link org.firebirdsql.ds.FBSimpleDataSource} */ @Deprecated public class FBSimpleDataSource extends org.firebirdsql.ds.FBSimpleDataSource { Modified: client-java/trunk/src/test/org/firebirdsql/jca/TestDataSourceSerialization.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jca/TestDataSourceSerialization.java 2012-11-23 16:45:29 UTC (rev 57403) +++ client-java/trunk/src/test/org/firebirdsql/jca/TestDataSourceSerialization.java 2012-11-23 16:48:23 UTC (rev 57404) @@ -16,47 +16,36 @@ * * All rights reserved. */ - package org.firebirdsql.jca; - - import java.rmi.MarshalledObject; import java.sql.Connection; import javax.sql.DataSource; - /** * TestDataSourceSerialization.java * - * - * Created: Fri Sep 6 11:00:48 2002 - * * @author <a href="mailto:d_j...@us...">David Jencks</a> * @version */ - -public class TestDataSourceSerialization extends TestXABase -{ - public TestDataSourceSerialization(String name) - { +public class TestDataSourceSerialization extends TestXABase { + + public TestDataSourceSerialization(String name) { super(name); } - public void testDataSourceSerialization() throws Exception - { - if (log != null) log.info("testDataSourceSerialization"); + public void testDataSourceSerialization() throws Exception { FBManagedConnectionFactory mcf = initMcf(); DataSource ds = (DataSource)mcf.createConnectionFactory(); - assertTrue("Could not get DataSource", ds != null); + assertNotNull("Could not get DataSource", ds); + Connection c = ds.getConnection(); - assertTrue("Could not get Connection", c != null); + assertNotNull("Could not get Connection", c); + c.close(); - MarshalledObject mo = new MarshalledObject(ds); - ds = (DataSource)mo.get(); + MarshalledObject<DataSource> mo = new MarshalledObject<DataSource>(ds); + ds = mo.get(); c = ds.getConnection(); c.close(); } - - -}// TestDataSourceSerialization +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-12-02 13:45:12
|
Revision: 57438 http://firebird.svn.sourceforge.net/firebird/?rev=57438&view=rev Author: mrotteveel Date: 2012-12-02 13:45:01 +0000 (Sun, 02 Dec 2012) Log Message: ----------- JDBC-279 Add connect timeout Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/ds/FBAbstractCommonDataSource.java client-java/trunk/src/main/org/firebirdsql/ds/FBSimpleDataSource.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionProperties.java client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdConnectionProperties.java client-java/trunk/src/resources/driver_property_info.properties client-java/trunk/src/resources/isc_dpb_types.properties client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java Added Paths: ----------- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnectionTimeout.java Modified: client-java/trunk/src/main/org/firebirdsql/ds/FBAbstractCommonDataSource.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBAbstractCommonDataSource.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBAbstractCommonDataSource.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -199,14 +199,34 @@ } } + /** + * {@inheritDoc} + * <p> + * This property is an alias for the connectTimeout property. + * </p> + */ public int getLoginTimeout() throws SQLException { - return connectionProperties.getSoTimeout() / 1000; + return getConnectTimeout(); } + /** + * {@inheritDoc} + * <p> + * This property is an alias for the connectTimeout property. + * </p> + */ public void setLoginTimeout(int seconds) throws SQLException { - connectionProperties.setSoTimeout(seconds * 1000); + setConnectTimeout(seconds); } + public int getConnectTimeout() { + return connectionProperties.getConnectTimeout(); + } + + public void setConnectTimeout(int connectTimeout) { + connectionProperties.setConnectTimeout(connectTimeout); + } + @Deprecated public String getDatabase() { synchronized(lock) { Modified: client-java/trunk/src/main/org/firebirdsql/ds/FBSimpleDataSource.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/ds/FBSimpleDataSource.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/ds/FBSimpleDataSource.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -59,7 +59,6 @@ protected Reference jndiReference; protected String description; - protected int loginTimeout; /** * Create instance of this class. @@ -380,8 +379,14 @@ mcf.setSoTimeout(soTimeout); } - + public int getConnectTimeout() { + return mcf.getConnectTimeout(); + } + public void setConnectTimeout(int connectTimeout) { + mcf.setConnectTimeout(connectTimeout); + } + /* * INTERFACES IMPLEMENTATION */ @@ -433,24 +438,23 @@ } /** - * Get login timeout specified for this datasource. - * - * @return login timeout of this datasource in seconds. - * - * @throws SQLException if something went wrong. + * {@inheritDoc} + * <p> + * This property is an alias for the connectTimeout property. + * </p> */ public int getLoginTimeout() throws SQLException { - return loginTimeout; + return getConnectTimeout(); } /** - * Set login timeout for this datasource. - * - * @param loginTimeout login timeout in seconds. - * @throws SQLException + * {@inheritDoc} + * <p> + * This property is an alias for the connectTimeout property. + * </p> */ public void setLoginTimeout(int loginTimeout) throws SQLException { - this.loginTimeout = loginTimeout; + setConnectTimeout(loginTimeout); } /** Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -36,6 +36,10 @@ // TODO Checking for validity of dbhandle is inconsistent (sometimes only null check, sometimes also .isValid()) private static Logger log = LoggerFactory.getLogger(BaseGDSImpl.class, false); + + private static final String WARNING_CONNECT_TIMEOUT_NATIVE = + "WARNING: The native driver does not apply connectTimeout for establishing the socket connection (only for protocol negotiation with the Firebird server), " + + "it will not detect unreachable hosts within the specified timeout"; protected static final byte[] DESCRIBE_DATABASE_INFO_BLOCK = new byte[] { ISCConstants.isc_info_db_sql_dialect, @@ -118,6 +122,15 @@ final String filenameCharset; if (databaseParameterBuffer != null) { DatabaseParameterBuffer cleanDPB = ((DatabaseParameterBufferExtension)databaseParameterBuffer).removeExtensionParams(); + if (cleanDPB.hasArgument(DatabaseParameterBuffer.CONNECT_TIMEOUT)) { + // For the native driver isc_dpb_connect_timeout is not a socket connect timeout + // It only applies to the steps for op_accept (negotiating protocol, etc) + if (log != null) { + log.warn(WARNING_CONNECT_TIMEOUT_NATIVE); + } + db_handle.addWarning(new GDSWarning(WARNING_CONNECT_TIMEOUT_NATIVE)); + } + dpbBytes = ((DatabaseParameterBufferImp) cleanDPB).getBytesForNativeCode(); filenameCharset = databaseParameterBuffer.getArgumentAsString(DatabaseParameterBufferExtension.FILENAME_CHARSET); } else { Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -1887,17 +1887,29 @@ boolean debug = log != null && log.isDebugEnabled(); - int socketBufferSize = -1; - int soTimeout = -1; - - if (databaseParameterBuffer.hasArgument(DatabaseParameterBufferExtension.SOCKET_BUFFER_SIZE)) + final int socketBufferSize; + if (databaseParameterBuffer.hasArgument(DatabaseParameterBufferExtension.SOCKET_BUFFER_SIZE)) { socketBufferSize = databaseParameterBuffer.getArgumentAsInt(DatabaseParameterBufferExtension.SOCKET_BUFFER_SIZE); + } else { + socketBufferSize = -1; + } - if (databaseParameterBuffer.hasArgument(DatabaseParameterBufferExtension.SO_TIMEOUT)) + final int soTimeout; + if (databaseParameterBuffer.hasArgument(DatabaseParameterBufferExtension.SO_TIMEOUT)) { soTimeout = databaseParameterBuffer.getArgumentAsInt(DatabaseParameterBufferExtension.SO_TIMEOUT); + } else { + soTimeout = -1; + } + + final int connectTimeout; + if (databaseParameterBuffer.hasArgument(DatabaseParameterBuffer.CONNECT_TIMEOUT)) { + connectTimeout = databaseParameterBuffer.getArgumentAsInt(DatabaseParameterBuffer.CONNECT_TIMEOUT) * 1000; + } else { + connectTimeout = 0; + } try { - openSocket(db, dbai, debug, socketBufferSize, soTimeout); + openSocket(db, dbai, debug, socketBufferSize, soTimeout, connectTimeout); XdrOutputStream out = db.out; XdrInputStream in = db.in; @@ -1987,7 +1999,6 @@ out.writeInt(op_attach); out.writeInt(2); // CONNECT_VERSION2 out.writeInt(1); // arch_generic - // db.out.writeString(file_name); // p_cnct_file out.writeString(fileName); // p_cnct_file out.writeInt(1); // p_cnct_count out.writeBuffer(user_id); // p_cnct_user_id @@ -2009,7 +2020,7 @@ } protected void openSocket(isc_db_handle_impl db, DbAttachInfo dbai, - boolean debug, int socketBufferSize, int soTimeout) throws IOException, + boolean debug, int socketBufferSize, int soTimeout, int connectTimeout) throws IOException, SocketException, GDSException { try { db.socket = new Socket(); @@ -2024,8 +2035,7 @@ db.socket.setSendBufferSize(socketBufferSize); } // TODO : introduce keep alive - // TODO : introduce connection timeout - db.socket.connect(new InetSocketAddress(dbai.getServer(), dbai.getPort())); + db.socket.connect(new InetSocketAddress(dbai.getServer(), dbai.getPort()), connectTimeout); if (debug) log.debug("Got socket"); Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnection.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -101,6 +101,10 @@ dbHandle.addWarning(new GDSWarning(WARNING_NO_CHARSET)); } + if (!dpb.hasArgument(DatabaseParameterBuffer.CONNECT_TIMEOUT) && DriverManager.getLoginTimeout() > 0) { + dpb.addArgument(DatabaseParameterBuffer.CONNECT_TIMEOUT, DriverManager.getLoginTimeout()); + } + gds.iscAttachDatabase(mcf.getDatabase(), dbHandle, dpb); gdsHelper = new GDSHelper(gds, dpb, dbHandle, this); Modified: client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -374,6 +374,14 @@ public void setSoTimeout(int soTimeout) { connectionProperties.setSoTimeout(soTimeout); } + + public int getConnectTimeout() { + return connectionProperties.getConnectTimeout(); + } + + public void setConnectTimeout(int connectTimeout) { + connectionProperties.setConnectTimeout(connectTimeout); + } public int hashCode() { if (hashCode != 0) Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionProperties.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionProperties.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnectionProperties.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -57,6 +57,7 @@ public static final String BUFFERS_NUMBER_PROPERTY = "buffersNumber"; public static final String DEFAULT_HOLDABLE_RS_PROPERTY = "defaultHoldable"; public static final String SO_TIMEOUT = "soTimeout"; + public static final String CONNECT_TIMEOUT = "connectTimeout"; private Map<String, Object> properties = new HashMap<String, Object>(); private String type; @@ -355,7 +356,17 @@ public void setSoTimeout(int soTimeout) { setIntProperty(SO_TIMEOUT, soTimeout); } + + @Override + public int getConnectTimeout() { + return getIntProperty(CONNECT_TIMEOUT); + } + @Override + public void setConnectTimeout(int connectTimeout) { + setIntProperty(CONNECT_TIMEOUT, connectTimeout); + } + public void setNonStandardProperty(String propertyMapping) { char[] chars = propertyMapping.toCharArray(); StringBuilder key = new StringBuilder(); @@ -497,5 +508,4 @@ throw new IllegalArgumentException("Unknown GDS type " + type); return GDSFactory.getGDSForType(gdsType); } - } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdConnectionProperties.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdConnectionProperties.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FirebirdConnectionProperties.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -366,11 +366,45 @@ */ void setTransactionParameters(int isolation, TransactionParameterBuffer tpb); + /** + * Get the default ResultSet holdability. + * + * @return <code>true</code> when ResultSets are holdable by default, <code>false</code> not holdable. + */ boolean isDefaultResultSetHoldable(); + /** + * Sets the default ResultSet holdability. + * + * @param isHoldable <code>true</code> when ResultSets are holdable by default, <code>false</code> not holdable. + */ void setDefaultResultSetHoldable(boolean isHoldable); + /** + * Get the current Socket blocking timeout (SoTimeout). + * + * @return The socket blocking timeout in milliseconds (0 is 'infinite') + */ int getSoTimeout(); + /** + * Set the Socket blocking timeout (SoTimeout). + * + * @param soTimeout Timeout in milliseconds (0 is 'infinite') + */ void setSoTimeout(int soTimeout); + + /** + * Get the current connect timeout. + * + * @return Connect timeout in seconds (0 is 'infinite', or better: OS specific timeout) + */ + int getConnectTimeout(); + + /** + * Set the connect timeout. + * + * @param connectTimout Connect timeout in seconds (0 is 'infinite', or better: OS specific timeout) + */ + void setConnectTimeout(int connectTimeout); } Modified: client-java/trunk/src/resources/driver_property_info.properties =================================================================== --- client-java/trunk/src/resources/driver_property_info.properties 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/resources/driver_property_info.properties 2012-12-02 13:45:01 UTC (rev 57438) @@ -34,5 +34,6 @@ noResultSetTracking isc_dpb_no_result_set_tracking octetsAsBytes isc_dpb_octets_as_bytes -soTimeout isc_dpb_so_timeout +soTimeout isc_dpb_so_timeout # Socket blocking timeout (in milliseconds) +connectTimeout isc_dpb_connect_timeout # Connect timeout (in seconds) columnLabelForName isc_dpb_column_label_for_name # If enabled, the columnLabel (AS clause) is used for the columnName in the metadata \ No newline at end of file Modified: client-java/trunk/src/resources/isc_dpb_types.properties =================================================================== --- client-java/trunk/src/resources/isc_dpb_types.properties 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/resources/isc_dpb_types.properties 2012-12-02 13:45:01 UTC (rev 57438) @@ -15,6 +15,7 @@ isc_dpb_password_enc string isc_dpb_sys_user_name string isc_dpb_user_name string +isc_dpb_connect_timeout int # connect timeout (in seconds) # following properties are extensions from JayBird isc_dpb_socket_buffer_size int Modified: client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java 2012-12-02 13:25:26 UTC (rev 57437) +++ client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -41,6 +41,16 @@ * Helper class for test properties (database user, password, paths etc) */ public final class FBTestProperties { + + static { + // TODO: Technically not needed with JDBC 4.0 autoloading + try { + Class.forName(FBDriver.class.getName()); + } catch (ClassNotFoundException ex) { + throw new ExceptionInInitializerError("No suitable driver."); + } + } + private static ResourceBundle testDefaults = ResourceBundle.getBundle("unit_test_defaults"); public static String getProperty(String property) { @@ -156,12 +166,6 @@ } public static FirebirdConnection getConnectionViaDriverManager() throws SQLException { - try { - Class.forName(FBDriver.class.getName()); - } catch (ClassNotFoundException ex) { - throw new SQLException("No suitable driver."); - } - return (FirebirdConnection) DriverManager.getConnection(getUrl(), getDefaultPropertiesForConnection()); } @@ -172,7 +176,7 @@ * @return Configured FBManager instance used for creation of the database * @throws Exception */ - protected static FBManager defaultDatabaseSetUp() throws Exception { + public static FBManager defaultDatabaseSetUp() throws Exception { FBManager fbManager = createFBManager(); if (getGdsType() == GDSType.getType("PURE_JAVA") @@ -195,7 +199,7 @@ * FBManager instance * @throws Exception */ - protected static void defaultDatabaseTearDown(FBManager fbManager) throws Exception { + public static void defaultDatabaseTearDown(FBManager fbManager) throws Exception { fbManager.dropDatabase(getDatabasePath(), DB_USER, DB_PASSWORD); fbManager.stop(); } Added: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnectionTimeout.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnectionTimeout.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnectionTimeout.java 2012-12-02 13:45:01 UTC (rev 57438) @@ -0,0 +1,175 @@ +/* + * Firebird Open Source J2ee connector - jdbc driver + * + * Distributable under LGPL license. + * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * LGPL License for more details. + * + * This file was created by members of the firebird development team. + * All individual contributions remain the Copyright (C) of those + * individuals. Contributors to this file are either listed here or + * can be obtained from a CVS history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import static org.junit.Assert.*; +import static org.junit.Assume.*; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +import org.firebirdsql.common.FBTestProperties; +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.impl.GDSFactory; +import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.gds.impl.jni.EmbeddedGDSImpl; +import org.firebirdsql.gds.impl.jni.NativeGDSImpl; +import org.firebirdsql.management.FBManager; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests for connection timeouts. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.3 + */ +public class TestFBConnectionTimeout { + // This test does not extend FBJUnit4TestBase as a lot of these tests don't need an actual database + + /** + * IP address which does not exist (we simply assume that this site local address does not exist in + * the network when running the test). This assumption is a lot cheaper than testing various addresses + * or applying some heuristic based on the local interface address. + */ + private static final String NON_EXISTENT_IP = "10.253.253.253"; + /** + * Delta for timeout, it is about 100-120 on my machine + */ + private static final double TIMEOUT_DELTA_MS = 200; + + @BeforeClass + public static void verifyTestType() { + // Test won't work for embedded + assumeTrue(!FBTestProperties.getGdsType().toString().equals(EmbeddedGDSImpl.EMBEDDED_TYPE_NAME)); + // Test won't for for native + assumeTrue(!FBTestProperties.getGdsType().toString().equals(NativeGDSImpl.NATIVE_TYPE_NAME)); + } + + /** + * Test for default connect timeout. + * <p> + * This test is ignored by default, as it is OS dependent (eg on Windows 8 it is 20 seconds). + * </p> + */ + @Test + @Ignore + public void defaultConnectTimeout() { + // Ensure default timeout is used + DriverManager.setLoginTimeout(0); + long startTime = System.currentTimeMillis(); + try { + DriverManager.getConnection("jdbc:firebirdsql://" + NON_EXISTENT_IP + "/db", "sysdba", "masterkey"); + } catch (SQLException e) { + long endTime = System.currentTimeMillis(); + long difference = endTime - startTime; + assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode()); + System.out.printf("Timeout: %f%n", difference / 1000.0); + } + } + + /** + * Test for connect timeout specified through {@link java.sql.DriverManager#setLoginTimeout(int)} + */ + @Test + public void connectTimeoutFromDriverManager() { + // Timeout set through DriverManager + DriverManager.setLoginTimeout(2); + long startTime = System.currentTimeMillis(); + try { + DriverManager.getConnection(buildTestURL(), "sysdba", "masterkey"); + } catch (SQLException e) { + long endTime = System.currentTimeMillis(); + long difference = endTime - startTime; + assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode()); + assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS); + } + } + + /** + * Test for connect timeout specified through connection property (in the url) + */ + @Test + public void connectTimeoutFromProperty() { + // Reset DriverManager timeout + DriverManager.setLoginTimeout(0); + long startTime = System.currentTimeMillis(); + try { + DriverManager.getConnection(buildTestURL() + "?connectTimeout=1", "sysdba", "masterkey"); + } catch (SQLException e) { + long endTime = System.currentTimeMillis(); + long difference = endTime - startTime; + assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode()); + assertEquals("Unexpected timeout duration (in ms)", 1000, difference, TIMEOUT_DELTA_MS); + } + } + + /** + * Test if a normal connection will work when the timeout is specified in the connection properties. + */ + @Test + public void normalConnectionWithTimeoutFromProperty() throws Exception { + // Reset DriverManager timeout + DriverManager.setLoginTimeout(0); + FBManager fbManager = FBTestProperties.defaultDatabaseSetUp(); + try { + Properties properties = FBTestProperties.getDefaultPropertiesForConnection(); + properties.setProperty("connectTimeout", "1"); + Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties); + connection.close(); + } finally { + FBTestProperties.defaultDatabaseTearDown(fbManager); + } + } + + /** + * Test if a normal connection will work when the timeout is specified through DriverManager + */ + @Test + public void normalConnectionWithTimeoutFromDriverManager() throws Exception { + // Reset DriverManager timeout + DriverManager.setLoginTimeout(2); + FBManager fbManager = FBTestProperties.defaultDatabaseSetUp(); + try { + Properties properties = FBTestProperties.getDefaultPropertiesForConnection(); + Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties); + connection.close(); + } finally { + FBTestProperties.defaultDatabaseTearDown(fbManager); + } + } + + /** + * Builds the test URL (to a non-existent IP) for the current GDS testtype. + * + * @return Test URL to a non-existent IP + */ + private static String buildTestURL() { + GDSType gdsType = FBTestProperties.getGdsType(); + try { + return GDSFactory.getJdbcUrl(gdsType, GDSFactory.getDatabasePath(gdsType, NON_EXISTENT_IP, null, "db")); + } catch (GDSException e) { + fail("Unable to generate testURL"); + } + return null; + } +} Property changes on: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnectionTimeout.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2012-12-07 19:57:05
|
Revision: 57459 http://firebird.svn.sourceforge.net/firebird/?rev=57459&view=rev Author: mrotteveel Date: 2012-12-07 19:56:57 +0000 (Fri, 07 Dec 2012) Log Message: ----------- JDBC-288 : FBPreparedStatement and FBCallableStatement not compliant for java.sql.Statement methods Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBCallableStatement.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java 2012-12-07 04:14:40 UTC (rev 57458) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBCallableStatement.java 2012-12-07 19:56:57 UTC (rev 57459) @@ -1257,30 +1257,6 @@ throw new FBDriverNotCapableException(); } - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - throw new FBDriverNotCapableException(); - } - - public boolean execute(String sql, String[] columnNames) throws SQLException { - throw new FBDriverNotCapableException(); - } - /** * Asserts if the current statement has data to return. It checks if the * result set has a row with data. Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java 2012-12-07 04:14:40 UTC (rev 57458) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java 2012-12-07 19:56:57 UTC (rev 57459) @@ -44,6 +44,8 @@ public class FBPreparedStatement extends FBStatement implements FirebirdPreparedStatement { + static final String METHOD_NOT_SUPPORTED = "This method is only supported on Statement and not supported on PreparedStatement and CallableStatement"; + private boolean metaDataQuery; /** @@ -1354,4 +1356,55 @@ throw new FBDriverNotCapableException(); } + // Methods not allowed to be used on PreparedStatement and CallableStatement + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public int executeUpdate(String sql) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public boolean execute(String sql) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public void addBatch(String sql) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public int executeUpdate(String sql, int[] columnIndex) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + throw new FBSQLException(METHOD_NOT_SUPPORTED); + } } Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBCallableStatement.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBCallableStatement.java 2012-12-07 04:14:40 UTC (rev 57458) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBCallableStatement.java 2012-12-07 19:56:57 UTC (rev 57459) @@ -825,11 +825,11 @@ } public void testJdbc181() throws Exception { - PreparedStatement ps = con.prepareCall("{call factorial(?, ?)}"); //con.prepareStatement("EXECUTE PROCEDURE factorial(?, ?)"); + CallableStatement cs = con.prepareCall("{call factorial(?, ?)}"); //con.prepareStatement("EXECUTE PROCEDURE factorial(?, ?)"); try { - ps.setInt(1, 5); - ps.setInt(2, 1); - ResultSet rs = ps.executeQuery(); + cs.setInt(1, 5); + cs.setInt(2, 1); + ResultSet rs = cs.executeQuery(); int counter = 0; int factorial = 1; while(rs.next()) { @@ -840,7 +840,7 @@ factorial *= counter; } } finally { - closeQuietly(ps); + closeQuietly(cs); } } @@ -890,4 +890,161 @@ } // Other closeOnCompletion behavior considered to be sufficiently tested in TestFBStatement + + /** + * The method {@link java.sql.Statement#executeQuery(String)} should not work on CallabeStatement. + */ + public void testUnsupportedExecuteQuery_String() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.executeQuery("SELECT * FROM test_blob"); + fail("Expected SQLException when executing executeQuery(String) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#executeUpdate(String)} should not work on CallabeStatement. + */ + public void testUnsupportedExecuteUpdate_String() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.executeUpdate("SELECT * FROM test_blob"); + fail("Expected SQLException when executing executeUpdate(String) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#execute(String)} should not work on CallabeStatement. + */ + public void testUnsupportedExecute_String() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.execute("SELECT * FROM test_blob"); + fail("Expected SQLException when executing execute(String) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#addBatch(String)} should not work on CallabeStatement. + */ + public void testUnsupportedAddBatch_String() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.addBatch("SELECT * FROM test_blob"); + fail("Expected SQLException when executing addBatch(String) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#executeUpdate(String, int)} should not work on CallabeStatement. + */ + public void testUnsupportedExecuteUpdate_String_int() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.executeUpdate("SELECT * FROM test_blob", Statement.NO_GENERATED_KEYS); + fail("Expected SQLException when executing executeUpdate(String, int) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int[])} should not work on CallabeStatement. + */ + public void testUnsupportedExecuteUpdate_String_intArr() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.executeUpdate("SELECT * FROM test_blob", new int[] { 1 }); + fail("Expected SQLException when executing executeUpdate(String, int[]) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#executeUpdate(String, String[])} should not work on CallabeStatement. + */ + public void testUnsupportedExecuteUpdate_String_StringArr() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.executeUpdate("SELECT * FROM test_blob", new String[] { "col" }); + fail("Expected SQLException when executing executeUpdate(String, String[]) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int)} should not work on CallabeStatement. + */ + public void testUnsupportedExecute_String_int() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.execute("SELECT * FROM test_blob", Statement.NO_GENERATED_KEYS); + fail("Expected SQLException when executing execute(String, int) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int[])} should not work on CallabeStatement. + */ + public void testUnsupportedExecute_String_intArr() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.execute("SELECT * FROM test_blob", new int[] { 1 }); + fail("Expected SQLException when executing execute(String, int[]) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, String[])} should not work on CallabeStatement. + */ + public void testUnsupportedExecute_String_StringArr() throws Exception { + CallableStatement cs = con.prepareCall(EXECUTE_SIMPLE_OUT_PROCEDURE); + try { + cs.execute("SELECT * FROM test_blob", new String[] { "col" }); + fail("Expected SQLException when executing execute(String, String[]) on CallabeStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(cs); + } + } + + private void assertStatementOnlyException(SQLException ex) { + assertEquals("Unexpected SQLState for statement only method called on FBCallableStatement", + FBSQLException.SQL_STATE_GENERAL_ERROR, ex.getSQLState()); + assertEquals("Unexpected exception message for statement only method called on FBCallableStatement", + FBPreparedStatement.METHOD_NOT_SUPPORTED, ex.getMessage()); + } } Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java 2012-12-07 04:14:40 UTC (rev 57458) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBPreparedStatement.java 2012-12-07 19:56:57 UTC (rev 57459) @@ -172,23 +172,164 @@ closeQuietly(updatePs); } } - - public void testMixedExecution() throws Throwable { - PreparedStatement ps = con - .prepareStatement("INSERT INTO test_blob (id, obj_data) VALUES(?, NULL)"); + + /** + * The method {@link java.sql.Statement#executeQuery(String)} should not work on PreparedStatement. + */ + public void testUnsupportedExecuteQuery_String() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); try { - ps.setInt(1, 100); - ps.execute(); - - ResultSet rs = ps.executeQuery("SELECT * FROM test_blob"); - while (rs.next()) { - // nothing - } + ps.executeQuery("SELECT * FROM test_blob"); + fail("Expected SQLException when executing executeQuery(String) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); } finally { closeQuietly(ps); } } + + /** + * The method {@link java.sql.Statement#executeUpdate(String)} should not work on PreparedStatement. + */ + public void testUnsupportedExecuteUpdate_String() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.executeUpdate("SELECT * FROM test_blob"); + fail("Expected SQLException when executing executeUpdate(String) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#execute(String)} should not work on PreparedStatement. + */ + public void testUnsupportedExecute_String() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.execute("SELECT * FROM test_blob"); + fail("Expected SQLException when executing execute(String) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#addBatch(String)} should not work on PreparedStatement. + */ + public void testUnsupportedAddBatch_String() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.addBatch("SELECT * FROM test_blob"); + fail("Expected SQLException when executing addBatch(String) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#executeUpdate(String, int)} should not work on PreparedStatement. + */ + public void testUnsupportedExecuteUpdate_String_int() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.executeUpdate("SELECT * FROM test_blob", Statement.NO_GENERATED_KEYS); + fail("Expected SQLException when executing executeUpdate(String, int) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int[])} should not work on PreparedStatement. + */ + public void testUnsupportedExecuteUpdate_String_intArr() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.executeUpdate("SELECT * FROM test_blob", new int[] { 1 }); + fail("Expected SQLException when executing executeUpdate(String, int[]) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#executeUpdate(String, String[])} should not work on PreparedStatement. + */ + public void testUnsupportedExecuteUpdate_String_StringArr() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.executeUpdate("SELECT * FROM test_blob", new String[] { "col" }); + fail("Expected SQLException when executing executeUpdate(String, String[]) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int)} should not work on PreparedStatement. + */ + public void testUnsupportedExecute_String_int() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.execute("SELECT * FROM test_blob", Statement.NO_GENERATED_KEYS); + fail("Expected SQLException when executing execute(String, int) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, int[])} should not work on PreparedStatement. + */ + public void testUnsupportedExecute_String_intArr() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.execute("SELECT * FROM test_blob", new int[] { 1 }); + fail("Expected SQLException when executing execute(String, int[]) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + + /** + * The method {@link java.sql.Statement#execute(String, String[])} should not work on PreparedStatement. + */ + public void testUnsupportedExecute_String_StringArr() throws Exception { + PreparedStatement ps = con.prepareStatement("SELECT 1 FROM RDB$DATABASE"); + try { + ps.execute("SELECT * FROM test_blob", new String[] { "col" }); + fail("Expected SQLException when executing execute(String, String[]) on PreparedStatement"); + } catch (SQLException ex) { + assertStatementOnlyException(ex); + } finally { + closeQuietly(ps); + } + } + private void assertStatementOnlyException(SQLException ex) { + assertEquals("Unexpected SQLState for statement only method called on FBPreparedStatement", + FBSQLException.SQL_STATE_GENERAL_ERROR, ex.getSQLState()); + assertEquals("Unexpected exception message for statement only method called on FBPreparedStatement", + FBPreparedStatement.METHOD_NOT_SUPPORTED, ex.getMessage()); + } + void checkSelectString(String stringToTest, int id) throws Exception { PreparedStatement selectPs = con .prepareStatement("SELECT obj_data FROM test_blob WHERE id = ?"); @@ -525,7 +666,7 @@ Statement stmt = con.createStatement(); try { - stmt.execute("SELECT * FROM rdb$database"); + stmt.execute("SELECT 1 FROM RDB$DATABASE"); } catch (Throwable t) { fail("Should not throw exception"); } finally { @@ -558,7 +699,7 @@ Statement stmt = con.createStatement(); try { - stmt.execute("SELECT * FROM rdb$database"); + stmt.execute("SELECT 1 FROM RDB$DATABASE"); } catch (Throwable t) { fail("Should not throw exception"); } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |