From: <mro...@us...> - 2015-01-31 13:36:30
|
Revision: 60594 http://sourceforge.net/p/firebird/code/60594 Author: mrotteveel Date: 2015-01-31 13:36:20 +0000 (Sat, 31 Jan 2015) Log Message: ----------- Refactor DatatypeCoder to include IEncodingFactory Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/BigEndianDatatypeCoder.java client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/LittleEndianDatatypeCoder.java client-java/trunk/src/main/org/firebirdsql/encodings/Encoding.java client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java client-java/trunk/src/main/org/firebirdsql/encodings/EncodingGeneric.java client-java/trunk/src/main/org/firebirdsql/encodings/EncodingSingleByte.java client-java/trunk/src/main/org/firebirdsql/gds/XSQLVAR.java client-java/trunk/src/main/org/firebirdsql/gds/ng/DatatypeCoder.java client-java/trunk/src/main/org/firebirdsql/gds/ng/DefaultDatatypeCoder.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBFloatField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBIntegerField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBLongField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBShortField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBStringField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimeField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimestampField.java Property Changed: ---------------- client-java/trunk/src/test/org/firebirdsql/encodings/testUnsupportedCharsetEncodings.xml client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/BigEndianDatatypeCoder.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/BigEndianDatatypeCoder.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/BigEndianDatatypeCoder.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -20,6 +20,7 @@ */ package org.firebirdsql.gds.ng.jna; +import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.ng.DefaultDatatypeCoder; /** @@ -33,15 +34,10 @@ */ public final class BigEndianDatatypeCoder extends DefaultDatatypeCoder { - private static final BigEndianDatatypeCoder INSTANCE = new BigEndianDatatypeCoder(); - - public static BigEndianDatatypeCoder getInstance() { - return INSTANCE; + public BigEndianDatatypeCoder(IEncodingFactory encodingFactory) { + super(encodingFactory); } - private BigEndianDatatypeCoder() { - } - @Override public byte[] encodeShort(short value) { byte ret[] = new byte[2]; Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -59,10 +59,8 @@ private static final Logger log = LoggerFactory.getLogger(JnaDatabase.class); private static final ParameterConverter PARAMETER_CONVERTER = new JnaParameterConverter(); - private static final DatatypeCoder datatypeCoder = - java.nio.ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN - ? LittleEndianDatatypeCoder.getInstance() - : BigEndianDatatypeCoder.getInstance(); + private static final boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN; + private final DatatypeCoder datatypeCoder; public static final int STATUS_VECTOR_SIZE = 20; public static final int MAX_STATEMENT_LENGTH = 64 * 1024; @@ -75,6 +73,11 @@ public JnaDatabase(JnaConnection jnaConnection) { this.jnaConnection = jnaConnection; clientLibrary = jnaConnection.getClientLibrary(); + if (bigEndian) { + datatypeCoder = new BigEndianDatatypeCoder(jnaConnection.getEncodingFactory()); + } else { + datatypeCoder = new LittleEndianDatatypeCoder(jnaConnection.getEncodingFactory()); + } } /** @@ -352,7 +355,7 @@ @Override public final DatatypeCoder getDatatypeCoder() { - return JnaDatabase.datatypeCoder; + return datatypeCoder; } /** Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/LittleEndianDatatypeCoder.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/LittleEndianDatatypeCoder.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/LittleEndianDatatypeCoder.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -20,6 +20,7 @@ */ package org.firebirdsql.gds.ng.jna; +import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.ng.DefaultDatatypeCoder; /** @@ -33,15 +34,10 @@ */ public final class LittleEndianDatatypeCoder extends DefaultDatatypeCoder { - private static final LittleEndianDatatypeCoder INSTANCE = new LittleEndianDatatypeCoder(); - - public static LittleEndianDatatypeCoder getInstance() { - return INSTANCE; + public LittleEndianDatatypeCoder(IEncodingFactory encodingFactory) { + super(encodingFactory); } - private LittleEndianDatatypeCoder() { - } - @Override public byte[] encodeShort(short value) { byte ret[] = new byte[2]; Modified: client-java/trunk/src/main/org/firebirdsql/encodings/Encoding.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/Encoding.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/encodings/Encoding.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -66,11 +66,11 @@ String decodeFromCharset(byte[] in, int offset, int length); /** - * Derives an {@link Encoding} that applies the specified character translation + * Derives an {@link Encoding} that applies the specified character translation. * * @param translator * The translation to apply - * @return The derived Encoding + * @return The derived Encoding, or this encoding if {@code translator} is {@code null} */ Encoding withTranslation(CharacterTranslator translator); } Modified: client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/encodings/EncodingFactory.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -231,6 +231,7 @@ @Override public CharacterTranslator getCharacterTranslator(String mappingPath) throws SQLException { + if (mappingPath == null) return null; CharacterTranslator translator = translations.get(mappingPath); if (translator != null) { return translator; Modified: client-java/trunk/src/main/org/firebirdsql/encodings/EncodingGeneric.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/EncodingGeneric.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/encodings/EncodingGeneric.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -30,7 +30,7 @@ * although {@link EncodingSingleByte} is more efficient for shorter strings. * </p> */ -public final class EncodingGeneric implements Encoding { +final class EncodingGeneric implements Encoding { // TODO Test claim that EncodingSingleByte is more efficient // Some testing seems to indicate that EncodingSingleByte is (slightly) faster for up to +/- 1500-2000 chars), @@ -38,7 +38,7 @@ private final Charset charset; - public EncodingGeneric(final Charset charset) { + EncodingGeneric(final Charset charset) { this.charset = charset; } @@ -59,6 +59,7 @@ @Override public Encoding withTranslation(final CharacterTranslator translator) { + if (translator == null) return this; return new EncodingGenericWithTranslation(translator); } @@ -75,6 +76,7 @@ * The translation to apply */ private EncodingGenericWithTranslation(CharacterTranslator translator) { + assert translator != null : "CharacterTranslator should never be null"; this.translator = translator; } Modified: client-java/trunk/src/main/org/firebirdsql/encodings/EncodingSingleByte.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/EncodingSingleByte.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/encodings/EncodingSingleByte.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -25,7 +25,7 @@ /** * Implementation of {@link Encoding} for single byte character sets. */ -public final class EncodingSingleByte implements Encoding { +final class EncodingSingleByte implements Encoding { private final char[] byteToChar; private final byte[] charToByte; @@ -36,6 +36,8 @@ } EncodingSingleByte(final Charset charset, final CharacterTranslator translator) { + assert charset != null : "charset should not be null"; + assert translator != null : "translator should not be null"; byteToChar = new char[256]; charToByte = new byte[256 * 256]; this.charset = charset; @@ -75,6 +77,9 @@ @Override public Encoding withTranslation(final CharacterTranslator translator) { - return new EncodingSingleByte(charset, translator); + if (translator != null) { + return new EncodingSingleByte(charset, translator); + } + return this; } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/XSQLVAR.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/XSQLVAR.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/gds/XSQLVAR.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -1,4 +1,6 @@ /* + * $Id$ + * * Public Firebird Java API. * * Redistribution and use in source and binary forms, with or without @@ -33,18 +35,18 @@ */ package org.firebirdsql.gds; +import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.encodings.EncodingFactory; +import org.firebirdsql.encodings.IEncodingFactory; +import org.firebirdsql.gds.ng.DatatypeCoder; + import java.sql.Date; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; -import java.util.Arrays; import java.util.Calendar; import java.util.GregorianCalendar; -import org.firebirdsql.encodings.Encoding; -import org.firebirdsql.encodings.EncodingFactory; -import org.firebirdsql.gds.ng.DatatypeCoder; - /** * The class <code>XSQLDA</code> is a java mapping of the XSQLVAR server * data structure used to represent one column for input and output. @@ -262,15 +264,15 @@ * a given encoding. * * @param value The <code>String</code> to be encoded - * @param encoding The encoding to use in the encoding process + * @param javaEncoding The encoding to use in the encoding process * @param mappingPath The character mapping path to be used in the encoding * @return The value of <code>value</code> as a <code>byte</code> array * @throws java.sql.SQLException if the given encoding cannot be found, or an error * occurs during the encoding */ - public byte[] encodeString(String value, String encoding, String mappingPath) throws SQLException { + public byte[] encodeString(String value, String javaEncoding, String mappingPath) throws SQLException { if (coder == null) - coder = EncodingFactory.getEncoding(encoding, mappingPath); + coder = EncodingFactory.getEncoding(javaEncoding, mappingPath); return coder.encodeToCharset(value); } @@ -299,15 +301,15 @@ * using a given encoding. * * @param value The value to be decoded - * @param encoding The encoding to be used in the decoding process + * @param javaEncoding The encoding to be used in the decoding process * @param mappingPath The character mapping path to be used in the decoding * @return The decoded <code>String</code> * @throws java.sql.SQLException if the given encoding cannot be found, or an * error occurs during the decoding */ - public String decodeString(byte[] value, String encoding, String mappingPath) throws SQLException{ + public String decodeString(byte[] value, String javaEncoding, String mappingPath) throws SQLException{ if (coder == null) - coder = EncodingFactory.getEncoding(encoding, mappingPath); + coder = EncodingFactory.getEncoding(javaEncoding, mappingPath); return coder.decodeFromCharset(value); } @@ -535,6 +537,11 @@ return result; } + @Override + public IEncodingFactory getEncodingFactory() { + return EncodingFactory.getDefaultInstance(); + } + /** * Helper Class to encode/decode times/dates */ Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/DatatypeCoder.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/DatatypeCoder.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/DatatypeCoder.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -20,6 +20,8 @@ */ package org.firebirdsql.gds.ng; +import org.firebirdsql.encodings.IEncodingFactory; + import java.sql.Date; import java.sql.SQLException; import java.sql.Time; @@ -144,14 +146,15 @@ * a given encoding. * * @param value The <code>String</code> to be encoded - * @param encoding The encoding to use in the encoding process + * @param javaEncoding The java encoding to use in the encoding process * @param mappingPath The character mapping path to be used in the encoding * @return The value of <code>value</code> as a <code>byte</code> array * @throws java.sql.SQLException if the given encoding cannot be found, or an error * occurs during the encoding */ - byte[] encodeString(String value, String encoding, String mappingPath) throws SQLException; + byte[] encodeString(String value, String javaEncoding, String mappingPath) throws SQLException; + // TODO Is below method needed? // /** // * Encode a <code>byte</code> array using a given encoding. // * @@ -169,13 +172,13 @@ * using a given encoding. * * @param value The value to be decoded - * @param encoding The encoding to be used in the decoding process + * @param javaEncoding The java encoding to be used in the decoding process * @param mappingPath The character mapping path to be used in the decoding * @return The decoded <code>String</code> * @throws java.sql.SQLException if the given encoding cannot be found, or an * error occurs during the decoding */ - String decodeString(byte[] value, String encoding, String mappingPath) throws SQLException; + String decodeString(byte[] value, String javaEncoding, String mappingPath) throws SQLException; /** * Encode a <code>Timestamp</code> using a given <code>Calendar</code>. @@ -380,4 +383,9 @@ * @return Byte array for timestamp */ byte[] encodeLocalDateTime(int year, int month, int day, int hour, int minute, int second, int nanos); + + /** + * @return The encoding factory. + */ + IEncodingFactory getEncodingFactory(); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/DefaultDatatypeCoder.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/DefaultDatatypeCoder.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/DefaultDatatypeCoder.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -21,6 +21,7 @@ package org.firebirdsql.gds.ng; import org.firebirdsql.encodings.EncodingFactory; +import org.firebirdsql.encodings.IEncodingFactory; import java.sql.Date; import java.sql.SQLException; @@ -44,13 +45,22 @@ */ public class DefaultDatatypeCoder implements DatatypeCoder { - private static final DefaultDatatypeCoder INSTANCE = new DefaultDatatypeCoder(); + private static final DefaultDatatypeCoder INSTANCE = new DefaultDatatypeCoder(EncodingFactory.getDefaultInstance()); - public static DefaultDatatypeCoder getInstance() { + private final IEncodingFactory encodingFactory; + + /** + * @return DatatypeCoder with the default {@link org.firebirdsql.encodings.EncodingFactory}. + */ + public static DefaultDatatypeCoder getDefaultInstance() { return INSTANCE; } - protected DefaultDatatypeCoder() { + public DefaultDatatypeCoder(IEncodingFactory encodingFactory) { + if (encodingFactory == null) { + throw new NullPointerException("encodingFactory should not be null"); + } + this.encodingFactory = encodingFactory; } @Override @@ -148,15 +158,21 @@ } @Override - public byte[] encodeString(String value, String encoding, String mappingPath) throws SQLException { - // TODO This is not how this should be done; needs to be changed - return EncodingFactory.getEncoding(encoding, mappingPath).encodeToCharset(value); + public byte[] encodeString(String value, String javaEncoding, String mappingPath) throws SQLException { + // TODO mappingPath (or translator) might need to be property of DefaultDataTypeCoder itself, and not handed over at each invocation + return encodingFactory + .getEncodingForCharsetAlias(javaEncoding) + .withTranslation(encodingFactory.getCharacterTranslator(mappingPath)) + .encodeToCharset(value); } @Override - public String decodeString(byte[] value, String encoding, String mappingPath) throws SQLException { - // TODO This is not how this should be done; needs to be changed - return EncodingFactory.getEncoding(encoding, mappingPath).decodeFromCharset(value); + public String decodeString(byte[] value, String javaEncoding, String mappingPath) throws SQLException { + // TODO mappingPath (or translator) might need to be property of DefaultDataTypeCoder itself, and not handed over at each invocation + return encodingFactory + .getEncodingForCharsetAlias(javaEncoding) + .withTranslation(encodingFactory.getCharacterTranslator(mappingPath)) + .decodeFromCharset(value); } // times,dates... @@ -373,6 +389,11 @@ return result; } + @Override + public IEncodingFactory getEncodingFactory() { + return encodingFactory; + } + /** * Helper Class to encode/decode times/dates */ Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -45,6 +45,7 @@ private static final Logger log = LoggerFactory.getLogger(AbstractFbWireDatabase.class); protected final ProtocolDescriptor protocolDescriptor; + private final DatatypeCoder datatypeCoder; protected final WireConnection connection; /** @@ -61,6 +62,7 @@ if (descriptor == null) throw new IllegalArgumentException("parameter descriptor should be non-null"); this.connection = connection; protocolDescriptor = descriptor; + datatypeCoder = new DefaultDatatypeCoder(connection.getEncodingFactory()); } @Override @@ -80,7 +82,7 @@ @Override public final DatatypeCoder getDatatypeCoder() { - return DefaultDatatypeCoder.getInstance(); + return datatypeCoder; } /** Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBDatabaseMetaData.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -1795,7 +1795,7 @@ procedureNamePattern = "%"; } - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(9, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(9, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "PROCEDURE_CAT", "PROCEDURES").addField() .at(1).simple(SQL_VARYING, 31, "PROCEDURE_SCHEM", "ROCEDURES").addField() .at(2).simple(SQL_VARYING, 31, "PROCEDURE_NAME", "PROCEDURES").addField() @@ -1976,7 +1976,7 @@ String columnNamePattern) throws SQLException { checkCatalogAndSchema(catalog, schemaPattern); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(20, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(20, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "PROCEDURE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "PROCEDURE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "PROCEDURE_NAME", "COLUMNINFO").addField() @@ -2318,7 +2318,7 @@ * @exception SQLException if a database access error occurs */ public ResultSet getCatalogs() throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "TABLECATALOGS").addField() .toRowDescriptor(); @@ -2341,7 +2341,7 @@ * @exception SQLException if a database access error occurs */ public ResultSet getTableTypes() throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_TYPE", "TABLETYPES").addField() .toRowDescriptor(); @@ -2469,7 +2469,7 @@ throws SQLException { checkCatalogAndSchema(catalog, schemaPattern); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(24, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(24, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "COLUMNINFO").addField() @@ -2888,7 +2888,7 @@ String table, String columnNamePattern) throws SQLException { checkCatalogAndSchema(catalog, schema); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "COLUMNPRIV").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "COLUMNPRIV").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "COLUMNPRIV").addField() @@ -3042,7 +3042,7 @@ } protected final RowDescriptor buildTablePrivilegeRSMetaData() { - return new RowDescriptorBuilder(7, DefaultDatatypeCoder.getInstance()) + return new RowDescriptorBuilder(7, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "TABLEPRIV").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "TABLEPRIV").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "TABLEPRIV").addField() @@ -3128,7 +3128,7 @@ */ public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_SHORT, 0, "SCOPE", "ROWIDENTIFIER").addField() .at(1).simple(SQL_VARYING, 31, "COLUMN_NAME", "ROWIDENTIFIER").addField() .at(2).simple(SQL_SHORT, 0, "DATA_TYPE", "ROWIDENTIFIER").addField() @@ -3238,7 +3238,7 @@ * @exception SQLException if a database access error occurs */ public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(8, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_SHORT, 0, "SCOPE", "VERSIONCOL").addField() .at(1).simple(SQL_VARYING, 31, "COLUMN_NAME", "VERSIONCOL").addField() .at(2).simple(SQL_SHORT, 0, "DATA_TYPE", "VERSIONCOL").addField() @@ -3292,7 +3292,7 @@ String table) throws SQLException { checkCatalogAndSchema(catalog, schema); - RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "COLUMNINFO").addField() @@ -3459,7 +3459,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { checkCatalogAndSchema(catalog, schema); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "PKTABLE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "PKTABLE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "PKTABLE_NAME", "COLUMNINFO").addField() @@ -3621,7 +3621,7 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { checkCatalogAndSchema(catalog, schema); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "PKTABLE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "PKTABLE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "PKTABLE_NAME", "COLUMNINFO").addField() @@ -3796,7 +3796,7 @@ checkCatalogAndSchema(primaryCatalog, primarySchema); checkCatalogAndSchema(foreignCatalog, foreignSchema); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(14, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "PKTABLE_CAT", "COLUMNINFO").addField() .at(1).simple(SQL_VARYING, 31, "PKTABLE_SCHEM", "COLUMNINFO").addField() .at(2).simple(SQL_VARYING, 31, "PKTABLE_NAME", "COLUMNINFO").addField() @@ -3929,7 +3929,7 @@ * @exception SQLException if a database access error occurs */ public ResultSet getTypeInfo() throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(18, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(18, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TYPE_NAME", "TYPEINFO").addField() .at(1).simple(SQL_SHORT, 0, "DATA_TYPE", "TYPEINFO").addField() .at(2).simple(SQL_LONG, 0, "PRECISION", "TYPEINFO").addField() @@ -4133,7 +4133,7 @@ boolean unique, boolean approximate) throws SQLException { checkCatalogAndSchema(catalog, schema); - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(13, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(13, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "INDEXINFO").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "INDEXINFO").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "INDEXINFO").addField() @@ -4424,7 +4424,7 @@ * {@inheritDoc} */ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(7, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(7, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TYPE_CAT", "UDT").addField() .at(1).simple(SQL_VARYING, 31, "TYPE_SCHEM", "UDT").addField() .at(2).simple(SQL_VARYING, 31, "TYPE_NAME", "UDT").addField() @@ -4456,7 +4456,7 @@ * {@inheritDoc} */ public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(21, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(21, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TYPE_CAT", "ATTRIBUTES").addField() .at(1).simple(SQL_VARYING, 31, "TYPE_SCHEM", "ATTRIBUTES").addField() .at(2).simple(SQL_VARYING, 31, "TYPE_NAME", "ATTRIBUTES").addField() @@ -4531,7 +4531,7 @@ * {@inheritDoc} */ public ResultSet getSuperTypes(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TYPE_CAT", "SUPERTYPES").addField() .at(1).simple(SQL_VARYING, 31, "TYPE_SCHEM", "SUPERTYPES").addField() .at(2).simple(SQL_VARYING, 31, "TYPE_NAME", "SUPERTYPES").addField() @@ -4549,7 +4549,7 @@ * {@inheritDoc} */ public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(4, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(4, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_CAT", "SUPERTABLES").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_SCHEM", "SUPERTABLES").addField() .at(2).simple(SQL_VARYING, 31, "TABLE_NAME", "SUPERTABLES").addField() @@ -4668,7 +4668,7 @@ */ public ResultSet getClientInfoProperties() throws SQLException { // TODO Return context info? - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(4, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(4, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "NAME", "CLIENTINFO").addField() .at(1).simple(SQL_LONG, 4, "MAX_LEN", "CLIENTINFO").addField() .at(2).simple(SQL_VARYING, 31, "DEFAULT", "CLIENTINFO").addField() @@ -4774,7 +4774,7 @@ */ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { // FIXME implement this method to return actual result - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(17, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(17, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "FUNCTION_CAT", "FUNCTION_COLUMNS").addField() .at(1).simple(SQL_VARYING, 31, "FUNCTION_SCHEM", "FUNCTION_COLUMNS").addField() .at(2).simple(SQL_VARYING, 31, "FUNCTION_NAME", "FUNCTION_COLUMNS").addField() @@ -4847,7 +4847,7 @@ */ public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { // FIXME implement this method to return actual result - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(6, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "FUNCTION_CAT", "FUNCTIONS").addField() .at(1).simple(SQL_VARYING, 31, "FUNCTION_SCHEM", "FUNCTIONS").addField() .at(2).simple(SQL_VARYING, 31, "FUNCTION_NAME", "FUNCTIONS").addField() @@ -4884,7 +4884,7 @@ * @since 1.6 */ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - final RowDescriptor rowDescriptor = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getInstance()) + final RowDescriptor rowDescriptor = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getDefaultInstance()) .at(0).simple(SQL_VARYING, 31, "TABLE_SCHEM", "TABLESCHEMAS").addField() .at(1).simple(SQL_VARYING, 31, "TABLE_CATALOG", "TABLESCHEMAS").addField() .toRowDescriptor(); Index: client-java/trunk/src/test/org/firebirdsql/encodings/testUnsupportedCharsetEncodings.xml =================================================================== --- client-java/trunk/src/test/org/firebirdsql/encodings/testUnsupportedCharsetEncodings.xml 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/encodings/testUnsupportedCharsetEncodings.xml 2015-01-31 13:36:20 UTC (rev 60594) Property changes on: client-java/trunk/src/test/org/firebirdsql/encodings/testUnsupportedCharsetEncodings.xml ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Modified: client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -32,25 +32,25 @@ /** * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> - * @since 2.3 + * @since 3.0 */ public class TestRowDescriptorBuilder { private static final List<FieldDescriptor> TEST_FIELD_DESCRIPTORS; static { List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(); - fields.add(new FieldDescriptor(DefaultDatatypeCoder.getInstance(), 1, 1, 1, 1, "1", "1", "1", "1", "1")); - fields.add(new FieldDescriptor(DefaultDatatypeCoder.getInstance(), 2, 2, 2, 2, "2", "2", "2", "2", "2")); - fields.add(new FieldDescriptor(DefaultDatatypeCoder.getInstance(), 3, 3, 3, 3, "3", "3", "3", "3", "3")); + fields.add(new FieldDescriptor(DefaultDatatypeCoder.getDefaultInstance(), 1, 1, 1, 1, "1", "1", "1", "1", "1")); + fields.add(new FieldDescriptor(DefaultDatatypeCoder.getDefaultInstance(), 2, 2, 2, 2, "2", "2", "2", "2", "2")); + fields.add(new FieldDescriptor(DefaultDatatypeCoder.getDefaultInstance(), 3, 3, 3, 3, "3", "3", "3", "3", "3")); TEST_FIELD_DESCRIPTORS = Collections.unmodifiableList(fields); } - private static final FieldDescriptor SOURCE = new FieldDescriptor(DefaultDatatypeCoder.getInstance(), 1, 2, 3, 4, "5", "6", "7", "8", "9"); + private static final FieldDescriptor SOURCE = new FieldDescriptor(DefaultDatatypeCoder.getDefaultInstance(), 1, 2, 3, 4, "5", "6", "7", "8", "9"); @Test public void testEmptyField() { - FieldDescriptor descriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getInstance()) + FieldDescriptor descriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getDefaultInstance()) .toFieldDescriptor(); assertEquals("Unexpected Type", 0, descriptor.getType()); @@ -67,7 +67,7 @@ @Test public void testBasicFieldInitialization() { FieldDescriptor descriptor = - new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setType(1) .setSubType(2) .setScale(3) @@ -92,7 +92,7 @@ @Test public void testCopyFrom() { - FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getInstance()) + FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getDefaultInstance()) .copyFieldFrom(SOURCE) .toFieldDescriptor(); @@ -109,7 +109,7 @@ @Test public void testResetField() { - FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getInstance()) + FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getDefaultInstance()) .copyFieldFrom(SOURCE) .resetField() .toFieldDescriptor(); @@ -127,7 +127,7 @@ @Test public void testEmpty() { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(0, DefaultDatatypeCoder.getDefaultInstance()) .toRowDescriptor(); assertEquals("Unexpected count of fields in RowDescriptor", 0, rowDescriptor.getCount()); @@ -135,7 +135,7 @@ @Test public void testBasicInitialization() { - RowDescriptorBuilder builder = new RowDescriptorBuilder(TEST_FIELD_DESCRIPTORS.size(), DefaultDatatypeCoder.getInstance()); + RowDescriptorBuilder builder = new RowDescriptorBuilder(TEST_FIELD_DESCRIPTORS.size(), DefaultDatatypeCoder.getDefaultInstance()); for (FieldDescriptor fieldDescriptor : TEST_FIELD_DESCRIPTORS) { builder.addField(fieldDescriptor); } @@ -147,7 +147,7 @@ @Test public void testAddingFieldsChained() { - RowDescriptorBuilder descriptorBuilder = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getInstance()) + RowDescriptorBuilder descriptorBuilder = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getDefaultInstance()) .setType(1) .setSubType(1) .setFieldName("Field1") @@ -178,7 +178,7 @@ @Test public void testAddingFieldsChained_DifferentOrder() { - RowDescriptorBuilder descriptorBuilder = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getInstance()) + RowDescriptorBuilder descriptorBuilder = new RowDescriptorBuilder(2, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(1) .setType(1) .setSubType(1) Property changes on: client-java/trunk/src/test/org/firebirdsql/gds/ng/fields/TestRowDescriptorBuilder.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -79,7 +79,7 @@ protected FieldDataProvider fieldData; protected final RowDescriptorBuilder rowDescriptorBuilder = - new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()); + new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()); protected FieldDescriptor fieldDescriptor; protected T field; Property changes on: client-java/trunk/src/test/org/firebirdsql/jdbc/field/BaseJUnit4TestFBField.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBBigDecimalField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -580,21 +580,21 @@ } private static FieldDescriptor createShortFieldDescriptor(int scale) { - return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setType(ISCConstants.SQL_SHORT) .setScale(scale) .toFieldDescriptor(); } private static FieldDescriptor createIntegerFieldDescriptor(int scale) { - return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setType(ISCConstants.SQL_LONG) .setScale(scale) .toFieldDescriptor(); } private static FieldDescriptor createLongFieldDescriptor(int scale) { - return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + return new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setType(ISCConstants.SQL_INT64) .setScale(scale) .toFieldDescriptor(); Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBFloatField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBFloatField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBFloatField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -42,7 +42,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_FLOAT) .addField() Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBIntegerField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBIntegerField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBIntegerField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -42,7 +42,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_LONG) .addField() Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBLongField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBLongField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBLongField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -42,7 +42,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_INT64) .addField() Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -58,7 +58,7 @@ @Before public void setUp() throws Exception { fieldData = context.mock(FieldDataProvider.class); - FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + FieldDescriptor fieldDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .toFieldDescriptor(); field = new FBNullField(fieldDescriptor, fieldData, Types.NULL); } Property changes on: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBNullField.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBShortField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBShortField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBShortField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -42,7 +42,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_SHORT) .addField() Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBStringField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBStringField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBStringField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -52,7 +52,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_TEXT) .setLength(TEST_STRING_SIZE) Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimeField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimeField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimeField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -44,7 +44,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_TYPE_TIME) .addField() Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimestampField.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimestampField.java 2015-01-31 00:22:53 UTC (rev 60593) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/field/TestFBTimestampField.java 2015-01-31 13:36:20 UTC (rev 60594) @@ -42,7 +42,7 @@ @Before public void setUp() throws SQLException { - RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getInstance()) + RowDescriptor rowDescriptor = new RowDescriptorBuilder(1, DefaultDatatypeCoder.getDefaultInstance()) .setFieldIndex(0) .setType(ISCConstants.SQL_TIMESTAMP) .addField() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-02-07 12:43:36
|
Revision: 60640 http://sourceforge.net/p/firebird/code/60640 Author: mrotteveel Date: 2015-02-07 12:43:33 +0000 (Sat, 07 Feb 2015) Log Message: ----------- Change XSD to have EncodingDefinition as a separate type. Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/encodings/DefaultEncodingSet.java client-java/trunk/src/main/org/firebirdsql/encodings/xml/Encodings.java client-java/trunk/src/main/org/firebirdsql/encodings/xml/ObjectFactory.java client-java/trunk/src/main/org/firebirdsql/encodings/xml/encodings.xsd Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/encodings/xml/EncodingDefinitionType.java Property Changed: ---------------- client-java/trunk/src/resources/org/firebirdsql/encodings/default-firebird-encodings.xml Modified: client-java/trunk/src/main/org/firebirdsql/encodings/DefaultEncodingSet.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/DefaultEncodingSet.java 2015-02-07 10:57:13 UTC (rev 60639) +++ client-java/trunk/src/main/org/firebirdsql/encodings/DefaultEncodingSet.java 2015-02-07 12:43:33 UTC (rev 60640) @@ -20,6 +20,7 @@ */ package org.firebirdsql.encodings; +import org.firebirdsql.encodings.xml.EncodingDefinitionType; import org.firebirdsql.encodings.xml.Encodings; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -130,7 +131,7 @@ return Collections.emptyList(); } List<EncodingDefinition> encodingSet = new ArrayList<EncodingDefinition>(); - for (Encodings.EncodingDefinition definition : encodings.getEncodingDefinition()) { + for (EncodingDefinitionType definition : encodings.getEncodingDefinition()) { final EncodingDefinition encoding = createEncodingDefinition(definition); if (encoding != null) { encodingSet.add(encoding); @@ -150,7 +151,7 @@ * XML definition of the encoding * @return Encoding instance or <code>null</code> if creating the instance failed for any reason. */ - protected EncodingDefinition createEncodingDefinition(final Encodings.EncodingDefinition definition) { + protected EncodingDefinition createEncodingDefinition(final EncodingDefinitionType definition) { try { if (definition.getEncodingDefinitionImplementation() != null) { return createEncodingDefinitionImplementation(definition); @@ -185,7 +186,7 @@ * the * expectations. */ - protected EncodingDefinition createEncodingDefinitionImplementation(final Encodings.EncodingDefinition definition) { + protected EncodingDefinition createEncodingDefinitionImplementation(final EncodingDefinitionType definition) { assert definition.getEncodingDefinitionImplementation() != null; try { final Class<?> encodingClazz = Class.forName(definition.getEncodingDefinitionImplementation()); Added: client-java/trunk/src/main/org/firebirdsql/encodings/xml/EncodingDefinitionType.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/xml/EncodingDefinitionType.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/encodings/xml/EncodingDefinitionType.java 2015-02-07 12:43:33 UTC (rev 60640) @@ -0,0 +1,247 @@ + +package org.firebirdsql.encodings.xml; + +import javax.annotation.Generated; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + + +/** + * Definition of the mapping of a Firebird encoding for use in Jaybird + * + * <p>Java class for EncodingDefinitionType complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType name="EncodingDefinitionType"> + * <simpleContent> + * <extension base="<http://www.w3.org/2001/XMLSchema>string"> + * <attribute name="firebirdName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> + * <attribute name="javaName" type="{http://www.w3.org/2001/XMLSchema}string" /> + * <attribute name="characterSetId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" /> + * <attribute name="maxBytesPerCharacter" type="{http://www.w3.org/2001/XMLSchema}int" default="1" /> + * <attribute name="encodingDefinitionImplementation" type="{http://www.w3.org/2001/XMLSchema}string" /> + * <attribute name="firebirdOnly" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" /> + * </extension> + * </simpleContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "EncodingDefinitionType", propOrder = { + "value" +}) +@Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") +public class EncodingDefinitionType { + + @XmlValue + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected String value; + @XmlAttribute(name = "firebirdName", required = true) + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected String firebirdName; + @XmlAttribute(name = "javaName") + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected String javaName; + @XmlAttribute(name = "characterSetId", required = true) + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected int characterSetId; + @XmlAttribute(name = "maxBytesPerCharacter") + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected Integer maxBytesPerCharacter; + @XmlAttribute(name = "encodingDefinitionImplementation") + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected String encodingDefinitionImplementation; + @XmlAttribute(name = "firebirdOnly") + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected Boolean firebirdOnly; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the firebirdName property. + * + * @return + * possible object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public String getFirebirdName() { + return firebirdName; + } + + /** + * Sets the value of the firebirdName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setFirebirdName(String value) { + this.firebirdName = value; + } + + /** + * Gets the value of the javaName property. + * + * @return + * possible object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public String getJavaName() { + return javaName; + } + + /** + * Sets the value of the javaName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setJavaName(String value) { + this.javaName = value; + } + + /** + * Gets the value of the characterSetId property. + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public int getCharacterSetId() { + return characterSetId; + } + + /** + * Sets the value of the characterSetId property. + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setCharacterSetId(int value) { + this.characterSetId = value; + } + + /** + * Gets the value of the maxBytesPerCharacter property. + * + * @return + * possible object is + * {@link Integer } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public int getMaxBytesPerCharacter() { + if (maxBytesPerCharacter == null) { + return 1; + } else { + return maxBytesPerCharacter; + } + } + + /** + * Sets the value of the maxBytesPerCharacter property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setMaxBytesPerCharacter(Integer value) { + this.maxBytesPerCharacter = value; + } + + /** + * Gets the value of the encodingDefinitionImplementation property. + * + * @return + * possible object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public String getEncodingDefinitionImplementation() { + return encodingDefinitionImplementation; + } + + /** + * Sets the value of the encodingDefinitionImplementation property. + * + * @param value + * allowed object is + * {@link String } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setEncodingDefinitionImplementation(String value) { + this.encodingDefinitionImplementation = value; + } + + /** + * Gets the value of the firebirdOnly property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public boolean isFirebirdOnly() { + if (firebirdOnly == null) { + return false; + } else { + return firebirdOnly; + } + } + + /** + * Sets the value of the firebirdOnly property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public void setFirebirdOnly(Boolean value) { + this.firebirdOnly = value; + } + +} Property changes on: client-java/trunk/src/main/org/firebirdsql/encodings/xml/EncodingDefinitionType.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: client-java/trunk/src/main/org/firebirdsql/encodings/xml/Encodings.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/xml/Encodings.java 2015-02-07 10:57:13 UTC (rev 60639) +++ client-java/trunk/src/main/org/firebirdsql/encodings/xml/Encodings.java 2015-02-07 12:43:33 UTC (rev 60640) @@ -6,10 +6,8 @@ import javax.annotation.Generated; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.XmlValue; /** @@ -22,20 +20,7 @@ * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> - * <element name="encodingDefinition" maxOccurs="unbounded" minOccurs="0"> - * <complexType> - * <simpleContent> - * <extension base="<http://www.w3.org/2001/XMLSchema>string"> - * <attribute name="firebirdName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="javaName" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="characterSetId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" /> - * <attribute name="maxBytesPerCharacter" type="{http://www.w3.org/2001/XMLSchema}int" default="1" /> - * <attribute name="encodingDefinitionImplementation" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="firebirdOnly" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" /> - * </extension> - * </simpleContent> - * </complexType> - * </element> + * <element name="encodingDefinition" type="{http://www.firebirdsql.org/schemas/Jaybird/encodings/1}EncodingDefinitionType" maxOccurs="unbounded" minOccurs="0"/> * </sequence> * </restriction> * </complexContent> @@ -49,11 +34,11 @@ "encodingDefinition" }) @XmlRootElement(name = "encodings") -@Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") +@Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") public class Encodings { - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected List<Encodings.EncodingDefinition> encodingDefinition; + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + protected List<EncodingDefinitionType> encodingDefinition; /** * Gets the value of the encodingDefinition property. @@ -73,252 +58,16 @@ * * <p> * Objects of the following type(s) are allowed in the list - * {@link Encodings.EncodingDefinition } + * {@link EncodingDefinitionType } * * */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public List<Encodings.EncodingDefinition> getEncodingDefinition() { + @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2015-02-07T01:31:12+01:00", comments = "JAXB RI v2.2.4-2") + public List<EncodingDefinitionType> getEncodingDefinition() { if (encodingDefinition == null) { - encodingDefinition = new ArrayList<Encodings.EncodingDefinition>(); + encodingDefinition = new ArrayList<EncodingDefinitionType>(); } return this.encodingDefinition; } - - /** - * <p>Java class for anonymous complex type. - * - * <p>The following schema fragment specifies the expected content contained within this class. - * - * <pre> - * <complexType> - * <simpleContent> - * <extension base="<http://www.w3.org/2001/XMLSchema>string"> - * <attribute name="firebirdName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="javaName" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="characterSetId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" /> - * <attribute name="maxBytesPerCharacter" type="{http://www.w3.org/2001/XMLSchema}int" default="1" /> - * <attribute name="encodingDefinitionImplementation" type="{http://www.w3.org/2001/XMLSchema}string" /> - * <attribute name="firebirdOnly" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" /> - * </extension> - * </simpleContent> - * </complexType> - * </pre> - * - * - */ - @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "value" - }) - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public static class EncodingDefinition { - - @XmlValue - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected String value; - @XmlAttribute(name = "firebirdName", required = true) - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected String firebirdName; - @XmlAttribute(name = "javaName") - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected String javaName; - @XmlAttribute(name = "characterSetId", required = true) - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected int characterSetId; - @XmlAttribute(name = "maxBytesPerCharacter") - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected Integer maxBytesPerCharacter; - @XmlAttribute(name = "encodingDefinitionImplementation") - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected String encodingDefinitionImplementation; - @XmlAttribute(name = "firebirdOnly") - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - protected Boolean firebirdOnly; - - /** - * Gets the value of the value property. - * - * @return - * possible object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public String getValue() { - return value; - } - - /** - * Sets the value of the value property. - * - * @param value - * allowed object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setValue(String value) { - this.value = value; - } - - /** - * Gets the value of the firebirdName property. - * - * @return - * possible object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public String getFirebirdName() { - return firebirdName; - } - - /** - * Sets the value of the firebirdName property. - * - * @param value - * allowed object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setFirebirdName(String value) { - this.firebirdName = value; - } - - /** - * Gets the value of the javaName property. - * - * @return - * possible object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public String getJavaName() { - return javaName; - } - - /** - * Sets the value of the javaName property. - * - * @param value - * allowed object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setJavaName(String value) { - this.javaName = value; - } - - /** - * Gets the value of the characterSetId property. - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public int getCharacterSetId() { - return characterSetId; - } - - /** - * Sets the value of the characterSetId property. - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setCharacterSetId(int value) { - this.characterSetId = value; - } - - /** - * Gets the value of the maxBytesPerCharacter property. - * - * @return - * possible object is - * {@link Integer } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public int getMaxBytesPerCharacter() { - if (maxBytesPerCharacter == null) { - return 1; - } else { - return maxBytesPerCharacter; - } - } - - /** - * Sets the value of the maxBytesPerCharacter property. - * - * @param value - * allowed object is - * {@link Integer } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setMaxBytesPerCharacter(Integer value) { - this.maxBytesPerCharacter = value; - } - - /** - * Gets the value of the encodingDefinitionImplementation property. - * - * @return - * possible object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public String getEncodingDefinitionImplementation() { - return encodingDefinitionImplementation; - } - - /** - * Sets the value of the encodingDefinitionImplementation property. - * - * @param value - * allowed object is - * {@link String } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setEncodingDefinitionImplementation(String value) { - this.encodingDefinitionImplementation = value; - } - - /** - * Gets the value of the firebirdOnly property. - * - * @return - * possible object is - * {@link Boolean } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public boolean isFirebirdOnly() { - if (firebirdOnly == null) { - return false; - } else { - return firebirdOnly; - } - } - - /** - * Sets the value of the firebirdOnly property. - * - * @param value - * allowed object is - * {@link Boolean } - * - */ - @Generated(value = "com.sun.tools.internal.xjc.Driver", date = "2013-07-12T10:45:51+02:00", comments = "JAXB RI v2.2.4-2") - public void setFirebirdOnly(Boolean value) { - this.firebirdOnly = value; - } - - } - } Modified: client-java/trunk/src/main/org/firebirdsql/encodings/xml/ObjectFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/xml/ObjectFactory.java 2015-02-07 10:57:13 UTC (rev 60639) +++ client-java/trunk/src/main/org/firebirdsql/encodings/xml/ObjectFactory.java 2015-02-07 12:43:33 UTC (rev 60640) @@ -38,11 +38,11 @@ } /** - * Create an instance of {@link Encodings.EncodingDefinition } + * Create an instance of {@link EncodingDefinitionType } * */ - public Encodings.EncodingDefinition createEncodingsEncodingDefinition() { - return new Encodings.EncodingDefinition(); + public EncodingDefinitionType createEncodingDefinitionType() { + return new EncodingDefinitionType(); } } Modified: client-java/trunk/src/main/org/firebirdsql/encodings/xml/encodings.xsd =================================================================== --- client-java/trunk/src/main/org/firebirdsql/encodings/xml/encodings.xsd 2015-02-07 10:57:13 UTC (rev 60639) +++ client-java/trunk/src/main/org/firebirdsql/encodings/xml/encodings.xsd 2015-02-07 12:43:33 UTC (rev 60640) @@ -25,69 +25,69 @@ ~ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ~ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> -<xs:schema targetNamespace="http://www.firebirdsql.org/schemas/Jaybird/encodings/1" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> +<xs:schema targetNamespace="http://www.firebirdsql.org/schemas/Jaybird/encodings/1" xmlns="http://www.firebirdsql.org/schemas/Jaybird/encodings/1" + attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="encodings"> <xs:complexType> <xs:sequence> - <xs:element name="encodingDefinition" maxOccurs="unbounded" minOccurs="0"> - <xs:annotation> - <xs:documentation>Definition of the mapping of a Firebird encoding for use in Jaybird</xs:documentation> - </xs:annotation> - <xs:complexType> - <xs:simpleContent> - <xs:extension base="xs:string"> - <xs:attribute type="xs:string" name="firebirdName" use="required"> - <xs:annotation> - <xs:documentation>The Firebird name of the encoding</xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:string" name="javaName" use="optional"> - <xs:annotation> - <xs:documentation> - The Java name of the encoding (if available). If both javaName and the encodingImplementation are not specified, then - this element is purely informational. In that case Jaybird will not support this character set (with the explicit exception of NONE and OCTETS). - If the specified Java encoding does not exist, this encoding will be purely informational (it will behave as if no javaName was specified). - If the javaName is illegal according to the rules established in java.nio.charset.Charset, this encoding will be ignored. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:int" name="characterSetId" use="required"> - <xs:annotation> - <xs:documentation> - The Firebird id of the character set (as listed in RDB$CHARACTER_SETS). Value 127 (CS_dynamic) is not allowed and will be ignored. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:int" name="maxBytesPerCharacter" use="optional" default="1"> - <xs:annotation> - <xs:documentation> - The maximum number of bytes per character, defaults to 1. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:string" name="encodingDefinitionImplementation" use="optional"> - <xs:annotation> - <xs:documentation> - Fully qualified name of a class implementing org.firebirdsql.encodings.EncodingDefinition to provide custom encoding/decoding. This class must - provide a no-arg constructor. If this attribute is not specified, then Jaybird will use one of its own EncodingDefinition implementations based on - the information provided. If both javaName and the encodingImplementation are not specified, then this element is purely informational. - In that case Jaybird will not support this character set (with the explicit exception of NONE and OCTETS). - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:boolean" name="firebirdOnly" use="optional" default="false"> - <xs:annotation> - <xs:documentation> - If set to true, this encoding will only be mapped by its Firebird encoding name. This is for example used to map Firebird encoding - UNICODE-FSS to Java encoding UTF-8, but in reverse Java encoding UTF-8 is mapped to Firebird encoding UTF8. Defaults to false. - </xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:extension> - </xs:simpleContent> - </xs:complexType> - </xs:element> + <xs:element name="encodingDefinition" maxOccurs="unbounded" minOccurs="0" type="EncodingDefinitionType" /> </xs:sequence> </xs:complexType> </xs:element> + <xs:complexType name="EncodingDefinitionType"> + <xs:annotation> + <xs:documentation>Definition of the mapping of a Firebird encoding for use in Jaybird</xs:documentation> + </xs:annotation> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute type="xs:string" name="firebirdName" use="required"> + <xs:annotation> + <xs:documentation>The Firebird name of the encoding</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="javaName" use="optional"> + <xs:annotation> + <xs:documentation> + The Java name of the encoding (if available). If both javaName and the encodingImplementation are not specified, then + this element is purely informational. In that case Jaybird will not support this character set (with the explicit exception of NONE and OCTETS). + If the specified Java encoding does not exist, this encoding will be purely informational (it will behave as if no javaName was specified). + If the javaName is illegal according to the rules established in java.nio.charset.Charset, this encoding will be ignored. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:int" name="characterSetId" use="required"> + <xs:annotation> + <xs:documentation> + The Firebird id of the character set (as listed in RDB$CHARACTER_SETS). Value 127 (CS_dynamic) is not allowed and will be ignored. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:int" name="maxBytesPerCharacter" use="optional" default="1"> + <xs:annotation> + <xs:documentation> + The maximum number of bytes per character, defaults to 1. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="encodingDefinitionImplementation" use="optional"> + <xs:annotation> + <xs:documentation> + Fully qualified name of a class implementing org.firebirdsql.encodings.EncodingDefinition to provide custom encoding/decoding. This class must + provide a no-arg constructor. If this attribute is not specified, then Jaybird will use one of its own EncodingDefinition implementations based on + the information provided. If both javaName and the encodingImplementation are not specified, then this element is purely informational. + In that case Jaybird will not support this character set (with the explicit exception of NONE and OCTETS). + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:boolean" name="firebirdOnly" use="optional" default="false"> + <xs:annotation> + <xs:documentation> + If set to true, this encoding will only be mapped by its Firebird encoding name. This is for example used to map Firebird encoding + UNICODE-FSS to Java encoding UTF-8, but in reverse Java encoding UTF-8 is mapped to Firebird encoding UTF8. Defaults to false. + </xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:simpleContent> + </xs:complexType> </xs:schema> \ No newline at end of file Index: client-java/trunk/src/resources/org/firebirdsql/encodings/default-firebird-encodings.xml =================================================================== --- client-java/trunk/src/resources/org/firebirdsql/encodings/default-firebird-encodings.xml 2015-02-07 10:57:13 UTC (rev 60639) +++ client-java/trunk/src/resources/org/firebirdsql/encodings/default-firebird-encodings.xml 2015-02-07 12:43:33 UTC (rev 60640) Property changes on: client-java/trunk/src/resources/org/firebirdsql/encodings/default-firebird-encodings.xml ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-02-07 14:17:27
|
Revision: 60644 http://sourceforge.net/p/firebird/code/60644 Author: mrotteveel Date: 2015-02-07 14:17:15 +0000 (Sat, 07 Feb 2015) Log Message: ----------- Remove old GDS methods no longer referenced + remove old tests no longer needed Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/GDS.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java Removed Paths: ------------- client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgds.java client-java/trunk/src/test/org/firebirdsql/gds/impl/jni/TestNgdsBlobReadBug.java client-java/trunk/src/test/org/firebirdsql/gds/impl/wire/TestGds.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/GDS.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/GDS.java 2015-02-07 14:01:21 UTC (rev 60643) +++ client-java/trunk/src/main/org/firebirdsql/gds/GDS.java 2015-02-07 14:17:15 UTC (rev 60644) @@ -73,22 +73,6 @@ IscTrHandle createIscTrHandle(); /** - * Factory method to create a new {@link IscStmtHandle} instance - * specific to the implementation of this interface. - * - * @return A new {@link IscStmtHandle} instance - */ - IscStmtHandle createIscStmtHandle(); - - /** - * Factory method to create a new {@link IscBlobHandle} instance - * specific to the implementation of this interface. - * - * @return A new {@link IscBlobHandle} instance - */ - IscBlobHandle createIscBlobHandle(); - - /** * Factory method to create a new {@link IscSvcHandle} instance * that is linked to the current <code>GDS</code> implemenation. * @@ -127,14 +111,6 @@ DatabaseParameterBuffer createDatabaseParameterBuffer(); /** - * Create a new {@link BlobParameterBuffer} instance for setting blob - * parameters in the current GDS implementation. - * - * @return A new {@link BlobParameterBuffer} - */ - BlobParameterBuffer createBlobParameterBuffer(); - - /** * Create new {@link TransactionParameterBuffer} instance for setting * transaction parameters in the current GDS implementation. * @@ -150,27 +126,6 @@ // -------------------- Database functions ----------------------- /** - * Create a database based on the supplied filename and database parameters. - * The supplied <code>IscDbHandle</code> is attached to the newly - * created database. - * - * @param fileName - * The filename for the new database, including host and port. - * The expected format is host:port:filepath. The value for host - * is localhost if not supplied. The value for port is 3050 if - * not supplied. - * @param dbHandle - * The handle to attach to the new database - * @param databaseParameterBuffer - * The parameters for the new database and attachment to it - * @throws GDSException - * if an error occurs while creating the database - */ - void iscCreateDatabase(String fileName, IscDbHandle dbHandle, - DatabaseParameterBuffer databaseParameterBuffer) - throws GDSException; - - /** * Attach to an existing database via a filename. * * @@ -223,16 +178,6 @@ */ void iscDetachDatabase(IscDbHandle dbHandle) throws GDSException; - /** - * Drop (delete) the database to which <code>IscDbHandle</code> is attached. - * - * @param dbHandle - * Handle to the database to be dropped - * @throws GDSException - * if an error occurs while dropping the database - */ - void iscDropDatabase(IscDbHandle dbHandle) throws GDSException; - // ------------------ Transactions ------------------------- /** * Start a transaction based on a handle to a transaction. @@ -252,224 +197,11 @@ void iscStartTransaction(IscTrHandle trHandle, IscDbHandle dbHandle, TransactionParameterBuffer tpb) throws GDSException; - /** - * Commit a transaction. - * - * @param trHandle - * Handle to the transaction to be committed. - * @throws GDSException - * if an error occurs while committing the transaction - */ - void iscCommitTransaction(IscTrHandle trHandle) throws GDSException; - void iscPrepareTransaction(IscTrHandle trHandle) throws GDSException; // ---------------------- Dynamic SQL ------------------------ /** - * Allocate a dynamic SQL (DSQL) statement on the database to which - * <code>IscDbHandle</code> is attached. - * - * @param dbHandle - * Handle to the database where the statement is to be allocated - * @param stmtHandle - * Handle to attach to the newly allocated statement - * @throws GDSException - * if an error occurs while allocating the statement - */ - void iscDsqlAllocateStatement(IscDbHandle dbHandle, IscStmtHandle stmtHandle) - throws GDSException; - - /** - * Execute a statement with outgoing and incoming data. - * - * @param trHandle - * Handle to the transaction in which the statement is to be - * executed - * @param stmtHandle - * Handle to the statement to be executed - * @param daVersion - * Version of XSQLDA to be used - * @param inXSQLDA - * Data to be sent to the database for the statement - * @param outXSQLDA - * Holder for data to be received from executing the statement - * @throws GDSException - * if an error occurs while executing the statement - */ - void iscDsqlExecute2(IscTrHandle trHandle, IscStmtHandle stmtHandle, - int daVersion, XSQLDA inXSQLDA, XSQLDA outXSQLDA) - throws GDSException; - - /** - * Execute a string SQL statement directly, without first allocating a - * statement handle. Data is retrieved using this method. - * - * @param dbHandle - * Handle to the database where the statement is to be executed - * @param trHandle - * Handle to the transaction in which the statement is to be - * executed - * @param statement - * byte array holding the SQL to be executed - * @param dialect - * Interbase dialect for the SQL, should be one of the - * <code>SQL_DIALECT_*</code> constants from - * {@link ISCConstants} - * @param inXSQLDA - * Data to be sent to the database for the statement - * @param outXSQLDA - * Placeholder for data retrieved from executing the SQL - * statement - * @throws GDSException - * if an error occurs while executing the statement - */ - void iscDsqlExecImmed2(IscDbHandle dbHandle, IscTrHandle trHandle, - String statement, int dialect, XSQLDA inXSQLDA, XSQLDA outXSQLDA) - throws GDSException; - - /** - * @deprecated use - * {@link #iscDsqlExecImmed2(IscDbHandle, IscTrHandle, byte[], int, XSQLDA, XSQLDA)} - */ - @Deprecated - void iscDsqlExecImmed2(IscDbHandle dbHandle, IscTrHandle trHandle, - String statement, String encoding, int dialect, XSQLDA inXSQLDA, - XSQLDA outXSQLDA) throws GDSException; - - /** - * Execute a string SQL statement directly, without first allocating a - * statement handle. Output data from executing the statement is stored in - * outXSQLDA. - * - * @param dbHandle - * Handle to the database where the statement is to be executed - * @param trHandle - * Handle to the transaction in which the statement is to be - * executed - * @param statement - * byte array holding the SQL to be executed - * @param dialect - * Interbase dialect for the SQL, should be one of the - * <code>SQL_DIALECT_*</code> constants from - * {@link ISCConstants} - * @param inXSQLDA - * Data to be sent to the database for the statement - * @param outXSQLDA - * Holder for data retrieved from the database - * @throws GDSException - * if an error occurs while executing the statement - */ - void iscDsqlExecImmed2(IscDbHandle dbHandle, IscTrHandle trHandle, - byte[] statement, int dialect, XSQLDA inXSQLDA, XSQLDA outXSQLDA) - throws GDSException; - - /** - * Retrieve record data from a statement. A maximum of - * <code>fetchSize</code> records will be fetched. - * - * @param stmt_handle - * Handle to the statement for which records are to be fetched - * @param daVersion - * Version of XSQLDA to be used - * @param xsqlda - * Holder for records that are fetched - * @param fetchSize - * The maximum number of records to be fetched - * @throws GDSException - * if an error occurs while fetching the records - */ - void iscDsqlFetch(IscStmtHandle stmt_handle, int daVersion, XSQLDA xsqlda, - int fetchSize) throws GDSException; - - /** - * Free a statement in the database that is pointed to by a valid handle. - * The statement can be closed or fully deallocated, depending on the value - * of <code>option</code>. <code>option</code> should be one of - * {@link ISCConstants#DSQL_drop} or {@link ISCConstants#DSQL_close}. - * - * @param stmtHandle - * Handle to the statement to be freed - * @param option - * Option to be used when freeing the statement. If the value is - * {@link ISCConstants#DSQL_drop}, the statement will be - * deallocated, if the value is {@link ISCConstants#DSQL_close}, - * the statement will only be closed - * @throws GDSException If an error occurs freeing the statement - */ - void iscDsqlFreeStatement(IscStmtHandle stmtHandle, int option) - throws GDSException; - - /** - * Prepare a string SQL statement for execution in the database. - * - * @param trHandle - * Handle to the transaction in which the SQL statement is to be - * prepared - * @param stmtHandle - * Handle to the statement for which the SQL is to be prepared - * @param statement - * The SQL statement to be prepared - * @param dialect - * Interbase dialect for the SQL, should be one of the - * <code>SQL_DIALECT_*</code> constants from - * {@link ISCConstants} - * @return A datastructure with data about the prepared statement - * @throws GDSException - * if an error occurs while preparing the SQL - */ - XSQLDA iscDsqlPrepare(IscTrHandle trHandle, IscStmtHandle stmtHandle, - String statement, int dialect) throws GDSException; - - /** - * @deprecated use - * {@link #iscDsqlPrepare(IscTrHandle, IscStmtHandle, byte[], int)} - */ - @Deprecated - XSQLDA iscDsqlPrepare(IscTrHandle trHandle, IscStmtHandle stmtHandle, - String statement, String encoding, int dialect) throws GDSException; - - /** - * Prepare a string SQL statement for execution in the database. - * - * @param trHandle - * Handle to the transaction in which the SQL statement is to be - * prepared - * @param stmtHandle - * Handle to the statement for which the SQL is to be prepared - * @param statement - * byte-array with containing the SQL to be prepared - * @param dialect - * Interbase dialect for the SQL, should be one of the - * <code>SQL_DIALECT_*</code> constants from - * {@link ISCConstants} - * @return A datastructure with data about the prepared statement - * @throws GDSException - * if an error occurs while preparing the SQL - */ - XSQLDA iscDsqlPrepare(IscTrHandle trHandle, IscStmtHandle stmtHandle, - byte[] statement, int dialect) throws GDSException; - - /** - * Retrieve data about a statement. The parameters that are requested are - * defined by the <code>isc_info_sql_*</code> constants defined in - * {@link ISCConstants}. An array with corresponding values for the - * requested parameters is returned. - * - * @param stmtHandle - * Handle to the statement about which data is to be retrieved - * @param items - * Array of parameters whose values are to be retrieved - * @param bufferLength - * The length of the byte-array to be returned - * @return An array of values corresponding to the requested parameters - * @throws GDSException - * if an error occurs while retrieving the statement info - */ - byte[] iscDsqlSqlInfo(IscStmtHandle stmtHandle, byte[] items, - int bufferLength) throws GDSException; - - /** * Retrieve an integer value from a sequence of bytes. * <p> * Behaviour is undefined for length > 4 @@ -542,43 +274,6 @@ BlobParameterBuffer blobParameterBuffer) throws GDSException; /** - * Fetch a segment of a blob. - * - * @param blob - * Handle to the blob from which a segment is to be fetched - * @param maxread - * The maximum number of bytes to attempt to fetch - * @return A segment of data from the blob, with maximum length of - * <code>maxread</code> - * @throws GDSException - * if an error occurs while fetching the blob segment - */ - byte[] iscGetSegment(IscBlobHandle blob, int maxread) throws GDSException; - - /** - * Write a segment of data to a blob. - * - * @param blob_handle - * Handle to the blob to which data is to be written - * @param buffer - * Data to be written to the blob - * @throws GDSException - * if an error occurs while writing to the blob - */ - void iscPutSegment(IscBlobHandle blob_handle, byte[] buffer) - throws GDSException; - - /** - * Close an open blob. - * - * @param blob - * Handle to the blob to be closed - * @throws GDSException - * if an error occurs while closing the blob - */ - void iscCloseBlob(IscBlobHandle blob) throws GDSException; - - /** * Seek to a given position in a blob. <code>seekMode</code> is used in * the same way as the system fseek call, i.e.: * <ul> 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 2015-02-07 14:01:21 UTC (rev 60643) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2015-02-07 14:17:15 UTC (rev 60644) @@ -20,9 +20,6 @@ */ package org.firebirdsql.gds.impl.jni; -import java.io.UnsupportedEncodingException; - -import org.firebirdsql.encodings.EncodingFactory; import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.AbstractGDS; import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; @@ -30,6 +27,8 @@ import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; +import java.io.UnsupportedEncodingException; + public abstract class BaseGDSImpl extends AbstractGDS { // TODO Synchronization seems to be inconsistent: sometimes on dbhandle, sometimes on this (and sometimes on blobhandle) @@ -53,26 +52,14 @@ protected abstract String getServerUrl(String file_name) throws GDSException; - public BlobParameterBuffer createBlobParameterBuffer() { - return new BlobParameterBufferImp(); - } - public DatabaseParameterBuffer createDatabaseParameterBuffer() { return new DatabaseParameterBufferImp(); } - public IscBlobHandle createIscBlobHandle() { - return new isc_blob_handle_impl(); - } - public IscDbHandle createIscDbHandle() { return new isc_db_handle_impl(); } - public IscStmtHandle createIscStmtHandle() { - return new isc_stmt_handle_impl(); - } - public IscSvcHandle createIscSvcHandle() { return new isc_svc_handle_impl(); } @@ -142,51 +129,6 @@ AbstractGDS.DESCRIBE_DATABASE_INFO_BLOCK, 1024), db_handle); } - // isc_close_blob - // --------------------------------------------------------------------------------------------- - public void iscCloseBlob(IscBlobHandle blob_handle) throws GDSException { - IscDbHandle db = blob_handle.getDb(); - if (db == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - IscTrHandle tr = blob_handle.getTr(); - if (tr == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - - synchronized (db) { - native_isc_close_blob(blob_handle); - } - - tr.removeBlob(blob_handle); - } - - // isc_commit_transaction - // --------------------------------------------------------------------------------------------- - public void iscCommitTransaction(IscTrHandle tr_handle) throws GDSException { - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - IscDbHandle db = tr_handle.getDbHandle(); - if (db == null || !db.isValid()) - throw new GDSException(ISCConstants.isc_bad_db_handle); - - synchronized (db) { - if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED - && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { - throw new GDSException(ISCConstants.isc_tra_state); - } - - tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); - - native_isc_commit_transaction(tr_handle); - - tr_handle.setState(IscTrHandle.NOTRANSACTION); - - tr_handle.unsetDbHandle(); - } - } - // isc_create_blob2 // --------------------------------------------------------------------------------------------- public void iscCreateBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, @@ -215,42 +157,6 @@ } } - // isc_create_database - // --------------------------------------------------------------------------------------------- - public void iscCreateDatabase(String file_name, IscDbHandle db_handle, - DatabaseParameterBuffer dpb) - throws GDSException { - if (db_handle == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - final byte[] dpbBytes = (dpb == null ? null - : ((DatabaseParameterBufferImp) dpb) - .getBytesForNativeCode()); - - synchronized (db_handle) { - String serverUrl = getServerUrl(file_name); - - byte[] urlData; - try { - String filenameCharset = (dpb != null ? dpb.getArgumentAsString(DatabaseParameterBufferExtension.FILENAME_CHARSET) : null); - if (filenameCharset != null) - urlData = serverUrl.getBytes(filenameCharset); - else - urlData = serverUrl.getBytes(); - - byte[] nullTerminated = new byte[urlData.length + 1]; - System.arraycopy(urlData, 0, nullTerminated, 0, urlData.length); - urlData = nullTerminated; - - } catch(UnsupportedEncodingException ex) { - throw new GDSException(ISCConstants.isc_bad_dpb_content); - } - - native_isc_create_database(urlData, db_handle, dpbBytes); - } - } - // isc_attach_database // --------------------------------------------------------------------------------------------- public byte[] iscDatabaseInfo(IscDbHandle db_handle, byte[] items, @@ -282,282 +188,6 @@ } } - // isc_drop_database - // --------------------------------------------------------------------------------------------- - public void iscDropDatabase(IscDbHandle db_handle) throws GDSException { - if (db_handle == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - synchronized (db_handle) { - native_isc_drop_database(db_handle); - } - } - - // isc_dsql_allocate_statement - // --------------------------------------------------------------------------------------------- - public void iscDsqlAllocateStatement(IscDbHandle db_handle, - IscStmtHandle stmt_handle) throws GDSException { - - if (db_handle == null) { - throw new GDSException(ISCConstants.isc_bad_db_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_handle.setRsr_rdb(db_handle); - stmt_handle.setAllRowsFetched(false); - } - } - - public void iscDsqlExecImmed2(IscDbHandle db_handle, IscTrHandle tr_handle, - byte[] statement, int dialect, XSQLDA in_xsqlda, XSQLDA out_xsqlda) - throws GDSException { - - synchronized (db_handle) { - native_isc_dsql_exec_immed2(db_handle, tr_handle, - getZeroTerminatedArray(statement), dialect, in_xsqlda, - out_xsqlda); - } - } - - 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); - } - - @Deprecated - public void iscDsqlExecImmed2(IscDbHandle db_handle, IscTrHandle tr_handle, - String statement, String encoding, int dialect, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException { - try { - synchronized (db_handle) { - native_isc_dsql_exec_immed2(db_handle, tr_handle, - getByteArrayForString(statement, encoding), dialect, - in_xsqlda, out_xsqlda); - } - } catch (UnsupportedEncodingException e) { - throw new GDSException("Unsupported encoding. " + e.getMessage()); - } - } - - // isc_dsql_execute2 - // --------------------------------------------------------------------------------------------- - public void iscDsqlExecute2(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, int da_version, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException { - - synchronized (stmt_handle.getRsr_rdb()) { - native_isc_dsql_execute2(tr_handle, stmt_handle, da_version, - in_xsqlda, out_xsqlda); /* TODO Fetch Statements */ - - if (stmt_handle.getOutSqlda() != null) stmt_handle.notifyOpenResultSet(); - - if (out_xsqlda != null) { - // this would be an Execute procedure - stmt_handle.ensureCapacity(1); - readSQLData(out_xsqlda, stmt_handle); - stmt_handle.setAllRowsFetched(true); - stmt_handle.setSingletonResult(true); - } else { - stmt_handle.setAllRowsFetched(false); - stmt_handle.setSingletonResult(false); - } - - stmt_handle.registerTransaction(tr_handle); - } - } - - // isc_dsql_fetch - // --------------------------------------------------------------------------------------------- - public void iscDsqlFetch(IscStmtHandle stmt_handle, int da_version, - XSQLDA xsqlda, int fetchSize) throws GDSException { - // FIXME fetchSize is ignored - fetchSize = 1; - - if (stmt_handle == null) { - throw new GDSException(ISCConstants.isc_bad_req_handle); - } - if (xsqlda == null) { - throw new GDSException(ISCConstants.isc_dsql_sqlda_err); - } - // TODO: Above declares fetchSize = 1, so parameter is ignored and this check is not necessary - if (fetchSize <= 0) { - throw new GDSException(ISCConstants.isc_dsql_sqlda_err); - } - - IscDbHandle db = stmt_handle.getRsr_rdb(); - - synchronized (db) { - // Apply fetchSize - // Fetch next batch of rows - 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_handle); - } else { - stmt_handle.setAllRowsFetched(true); - return; - } - } finally { - stmt_handle.notifyOpenResultSet(); - } - } - } - } - - // isc_dsql_free_statement - // --------------------------------------------------------------------------------------------- - public void iscDsqlFreeStatement(IscStmtHandle stmt_handle, int option) - throws GDSException { - if (stmt_handle == null) { - throw new GDSException(ISCConstants.isc_bad_req_handle); - } - 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; } - - if (option == ISCConstants.DSQL_drop) { - 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 { - IscTrHandle tr = stmt_handle.getTransaction(); - if (tr != null) - tr.unregisterStatementFromTransaction(stmt_handle); - } finally { - stmt_handle.unregisterTransaction(); - } - - } - } - - // isc_dsql_free_statement - // --------------------------------------------------------------------------------------------- - public XSQLDA iscDsqlPrepare(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, byte[] statement, int dialect) - throws GDSException { - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - - if (stmt_handle == null) { - throw new GDSException(ISCConstants.isc_bad_req_handle); - } - - synchronized (stmt_handle.getRsr_rdb()) { - stmt_handle.setInSqlda(null); - stmt_handle.setOutSqlda(null); - - stmt_handle.setOutSqlda(native_isc_dsql_prepare(tr_handle, stmt_handle, - getZeroTerminatedArray(statement), dialect)); - - getStatementType(stmt_handle); - - return stmt_handle.getOutSqlda(); - } - } - - /** - * Find out the type of the specified statement. - * - * @param stmt instance of {@link isc_stmt_handle_impl}. - * - * @throws GDSException if error occured. - */ - private void getStatementType(IscStmtHandle stmt) throws GDSException { - final byte [] REQUEST = new byte [] { - ISCConstants.isc_info_sql_stmt_type, - ISCConstants.isc_info_end }; - - int bufferSize = 1024; - byte[] buffer; - - buffer = iscDsqlSqlInfo(stmt, REQUEST, bufferSize); - - /* - if (buffer[0] == ISCConstants.isc_info_end){ - throw new GDSException("Statement info could not be retrieved"); - } - */ - - int dataLength = -1; - for (int i = 0; i < buffer.length; i++){ - switch(buffer[i]){ - case ISCConstants.isc_info_sql_stmt_type: - dataLength = iscVaxInteger2(buffer, ++i); - i += 2; - stmt.setStatementType(iscVaxInteger(buffer, i, dataLength)); - i += dataLength; - break; - case ISCConstants.isc_info_end: - case 0: - break; - default: - throw new GDSException("Unknown data block [" - + buffer[i] + "]"); - } - } - } - - // isc_dsql_free_statement - // --------------------------------------------------------------------------------------------- - public XSQLDA iscDsqlPrepare(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, String statement, int dialect) - throws GDSException { - return iscDsqlPrepare(tr_handle, stmt_handle, statement, "NONE", - dialect); - } - - @Deprecated - public XSQLDA iscDsqlPrepare(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, String statement, String encoding, - int dialect) throws GDSException { - try { - return iscDsqlPrepare(tr_handle, stmt_handle, - getByteArrayForString(statement, encoding), dialect); - } catch (UnsupportedEncodingException e) { - throw new GDSException("Unsupported encoding. " + e.getMessage()); - } - } - - // isc_dsql_sql_info - // --------------------------------------------------------------------------------------------- - public byte[] iscDsqlSqlInfo(IscStmtHandle stmt_handle, byte[] items, - int buffer_length) throws GDSException { - synchronized (stmt_handle.getRsr_rdb()) { - return native_isc_dsql_sql_info(stmt_handle, items, buffer_length); - } - } - - // isc_get_segment - // --------------------------------------------------------------------------------------------- - public byte[] iscGetSegment(IscBlobHandle blob, int maxread) - throws GDSException { - synchronized (blob.getDb()) { - return native_isc_get_segment(blob, maxread); - } - } - // isc_open_blob2 // --------------------------------------------------------------------------------------------- public void iscOpenBlob2(IscDbHandle db_handle, IscTrHandle tr_handle, @@ -605,15 +235,6 @@ } } - // isc_put_segment - // --------------------------------------------------------------------------------------------- - public void iscPutSegment(IscBlobHandle blob_handle, byte[] buffer) - throws GDSException { - synchronized (blob_handle.getDb()) { - native_isc_put_segment(blob_handle, buffer); - } - } - public void iscSeekBlob(IscBlobHandle handle, int position, int mode) throws GDSException { isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; @@ -718,18 +339,9 @@ public abstract void native_isc_attach_database(byte[] file_name, IscDbHandle db_handle, byte[] dpbBytes); - public abstract void native_isc_close_blob(IscBlobHandle blob) - throws GDSException; - - public abstract void native_isc_commit_transaction(IscTrHandle tr_handle) - throws GDSException; - public abstract void native_isc_create_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); - public abstract void native_isc_create_database(byte[] file_name, - IscDbHandle db_handle, byte[] dpbBytes); - public abstract void native_isc_database_info(IscDbHandle db_handle, int item_length, byte[] items, int buffer_length, byte[] buffer) throws GDSException; @@ -737,46 +349,12 @@ public abstract void native_isc_detach_database(IscDbHandle db_handle) throws GDSException; - public abstract void native_isc_drop_database(IscDbHandle db_handle) - throws GDSException; - - public abstract void native_isc_dsql_allocate_statement( - IscDbHandle db_handle, IscStmtHandle stmt_handle) - throws GDSException; - - public abstract void native_isc_dsql_exec_immed2(IscDbHandle db_handle, - IscTrHandle tr_handle, byte[] statement, int dialect, - XSQLDA in_xsqlda, XSQLDA out_xsqlda) throws GDSException; - - public abstract void native_isc_dsql_execute2(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, int da_version, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException; - - public abstract boolean native_isc_dsql_fetch(IscStmtHandle stmt_handle, - int da_version, XSQLDA xsqlda, int fetchSize) throws GDSException; - - public abstract void native_isc_dsql_free_statement( - IscStmtHandle stmt_handle, int option) throws GDSException; - - public abstract XSQLDA native_isc_dsql_prepare(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, byte[] statement, int dialect) - throws GDSException; - - public abstract byte[] native_isc_dsql_sql_info(IscStmtHandle stmt_handle, - byte[] items, int buffer_length) throws GDSException; - - public abstract byte[] native_isc_get_segment(IscBlobHandle blob, - int maxread) throws GDSException; - public abstract void native_isc_open_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); public abstract void native_isc_prepare_transaction(IscTrHandle tr_handle) throws GDSException; - public abstract void native_isc_put_segment(IscBlobHandle blob_handle, - byte[] buffer) throws GDSException; - public abstract void native_isc_seek_blob(isc_blob_handle_impl handle, int position, int mode) throws GDSException; @@ -818,43 +396,6 @@ return new TransactionParameterBufferImpl(); } - protected 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][]; - for (int i = 0; i < numCols; i++) { - - // isc_vax_integer( xsqlda.sqlvar[i].sqldata, 0, - // xsqlda.sqlvar[i].sqldata.length ); - - row[i] = xsqlda.sqlvar[i].sqldata; - } - if (stmt != null) stmt.addRow(row); - } - - protected byte[] getByteArrayForString(String statement, String encoding) - throws UnsupportedEncodingException { - String javaEncoding = null; - if (encoding != null && !"NONE".equals(encoding)) - javaEncoding = EncodingFactory.getJavaEncoding(encoding); - - final byte[] stringBytes; - if (javaEncoding != null) - stringBytes = statement.getBytes(javaEncoding); - else - stringBytes = statement.getBytes(); - - return getZeroTerminatedArray(stringBytes); - } - - protected byte[] getZeroTerminatedArray(byte[] stringBytes) { - final byte[] zeroTermBytes = new byte[stringBytes.length + 1]; - System.arraycopy(stringBytes, 0, zeroTermBytes, 0, stringBytes.length); - zeroTermBytes[stringBytes.length] = 0; - - return zeroTermBytes; - } - public int iscQueueEvents(IscDbHandle dbHandle, EventHandle eventHandle, EventHandler eventHandler) throws GDSException { 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 2015-02-07 14:01:21 UTC (rev 60643) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java 2015-02-07 14:17:15 UTC (rev 60644) @@ -164,18 +164,9 @@ public native void native_isc_attach_database(byte[] file_name, IscDbHandle db_handle, byte[] dpbBytes); - public native void native_isc_close_blob(IscBlobHandle blob) - throws GDSException; - - public native void native_isc_commit_transaction(IscTrHandle tr_handle) - throws GDSException; - public native void native_isc_create_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); - public native void native_isc_create_database(byte[] file_name, - IscDbHandle db_handle, byte[] dpbBytes); - public native void native_isc_database_info(IscDbHandle db_handle, int item_length, byte[] items, int buffer_length, byte[] buffer) throws GDSException; @@ -183,46 +174,12 @@ public native void native_isc_detach_database(IscDbHandle db_handle) throws GDSException; - public native void native_isc_drop_database(IscDbHandle db_handle) - throws GDSException; - - public native void native_isc_dsql_allocate_statement( - IscDbHandle db_handle, IscStmtHandle stmt_handle) - throws GDSException; - - public native void native_isc_dsql_exec_immed2(IscDbHandle db_handle, - IscTrHandle tr_handle, byte[] statement, int dialect, - XSQLDA in_xsqlda, XSQLDA out_xsqlda) throws GDSException; - - public native void native_isc_dsql_execute2(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, int da_version, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException; - - public native boolean native_isc_dsql_fetch(IscStmtHandle stmt_handle, - int da_version, XSQLDA xsqlda, int fetchSize) throws GDSException; - - public native void native_isc_dsql_free_statement( - IscStmtHandle stmt_handle, int option) throws GDSException; - - public native XSQLDA native_isc_dsql_prepare(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, byte[] statement, int dialect) - throws GDSException; - - public native byte[] native_isc_dsql_sql_info(IscStmtHandle stmt_handle, - byte[] items, int buffer_length) throws GDSException; - - public native byte[] native_isc_get_segment(IscBlobHandle blob, int maxread) - throws GDSException; - public native void native_isc_open_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); public native void native_isc_prepare_transaction(IscTrHandle tr_handle) throws GDSException; - public native void native_isc_put_segment(IscBlobHandle blob_handle, - byte[] buffer) throws GDSException; - public native void native_isc_seek_blob(isc_blob_handle_impl handle, int position, int mode) throws GDSException; 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 2015-02-07 14:01:21 UTC (rev 60643) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2015-02-07 14:17:15 UTC (rev 60644) @@ -26,44 +26,26 @@ */ package org.firebirdsql.gds.impl.wire; +import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.encodings.EncodingDefinition; +import org.firebirdsql.encodings.EncodingFactory; +import org.firebirdsql.gds.*; +import org.firebirdsql.gds.impl.AbstractGDS; +import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; +import org.firebirdsql.gds.impl.DbAttachInfo; +import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.logging.Logger; +import org.firebirdsql.logging.LoggerFactory; + import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketException; -import java.net.UnknownHostException; - +import java.net.*; import java.nio.charset.Charset; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Collections; +import java.util.HashMap; import java.util.Map; -import java.util.HashMap; -import org.firebirdsql.encodings.Encoding; -import org.firebirdsql.encodings.EncodingDefinition; -import org.firebirdsql.encodings.EncodingFactory; -import org.firebirdsql.gds.BlobParameterBuffer; -import org.firebirdsql.gds.DatabaseParameterBuffer; -import org.firebirdsql.gds.GDS; -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.IscBlobHandle; -import org.firebirdsql.gds.IscDbHandle; -import org.firebirdsql.gds.IscStmtHandle; -import org.firebirdsql.gds.IscSvcHandle; -import org.firebirdsql.gds.IscTrHandle; -import org.firebirdsql.gds.ServiceParameterBuffer; -import org.firebirdsql.gds.ServiceRequestBuffer; -import org.firebirdsql.gds.TransactionParameterBuffer; -import org.firebirdsql.gds.XSQLDA; -import org.firebirdsql.gds.XSQLVAR; -import org.firebirdsql.gds.EventHandle; -import org.firebirdsql.gds.EventHandler; -import org.firebirdsql.gds.impl.*; -import org.firebirdsql.logging.Logger; -import org.firebirdsql.logging.LoggerFactory; - import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.*; /** @@ -79,76 +61,12 @@ private static Logger log = LoggerFactory.getLogger(AbstractJavaGDSImpl.class); - private static final byte[] zero = new XSQLVAR().encodeInt(0); - private static final byte[] minusOne = new XSQLVAR().encodeInt(-1); - - static final int MAX_BUFFER_SIZE = 1024; - - // TODO: sql_prepare_info* and describe_select_info* are identical, remove one? - - final static byte[] sql_prepare_info2 = new byte[] { - ISCConstants.isc_info_sql_stmt_type, - ISCConstants.isc_info_sql_select, - ISCConstants.isc_info_sql_describe_vars, - ISCConstants.isc_info_sql_sqlda_seq, - ISCConstants.isc_info_sql_type, ISCConstants.isc_info_sql_sub_type, - ISCConstants.isc_info_sql_scale, ISCConstants.isc_info_sql_length, - ISCConstants.isc_info_sql_field, - ISCConstants.isc_info_sql_relation, - ISCConstants.isc_info_sql_relation_alias, - ISCConstants.isc_info_sql_owner, ISCConstants.isc_info_sql_alias, - ISCConstants.isc_info_sql_describe_end}; - - /** - * Info buffer for Firebird 1.5 and below - it does not support the relation - * alias info item. - */ - final static byte[] sql_prepare_info15 = new byte[] { - ISCConstants.isc_info_sql_stmt_type, - ISCConstants.isc_info_sql_select, - ISCConstants.isc_info_sql_describe_vars, - ISCConstants.isc_info_sql_sqlda_seq, - ISCConstants.isc_info_sql_type, ISCConstants.isc_info_sql_sub_type, - ISCConstants.isc_info_sql_scale, ISCConstants.isc_info_sql_length, - ISCConstants.isc_info_sql_field, - ISCConstants.isc_info_sql_relation, - ISCConstants.isc_info_sql_owner, ISCConstants.isc_info_sql_alias, - ISCConstants.isc_info_sql_describe_end}; - public AbstractJavaGDSImpl() { super(GDSType.getType(PURE_JAVA_TYPE_NAME)); } // Database functions - /** - * <code>isc_create_database</code> creates a database based on the file - * name and Clumplet of database properties supplied. The supplied db handle - * is attached to the newly created database. - * - * @param file_name - * a <code>String</code> the file name, including host and - * port, for the database. The expected format is - * host:port:path_to_file. The value for host is localhost if not - * supplied. The value for port is 3050 if not supplied. - * @param db_handle - * an <code>isc_db_handle</code> The db handle to attach to the - * new database. - * @param databaseParameterBuffer - * a <code>Clumplet</code> The parameters for the new database - * and the attachment to it. See docs for dpb (database parameter - * block.) - * @exception GDSException - * if an error occurs - */ - public void iscCreateDatabase(String file_name, IscDbHandle db_handle, - DatabaseParameterBuffer databaseParameterBuffer) - throws GDSException { - - DbAttachInfo dbai = new DbAttachInfo(file_name); - internalAttachDatabase(dbai, db_handle, databaseParameterBuffer, true); - } - public void iscAttachDatabase(String connectString, IscDbHandle db_handle, DatabaseParameterBuffer databaseParameterBuffer) throws GDSException { @@ -339,33 +257,6 @@ } } - public void iscDropDatabase(IscDbHandle db_handle) throws GDSException { - - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - - if (db == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - synchronized (db) { - - try { - if (debug) - log.debug("op_drop_database "); - db.out.writeInt(op_drop_database); - db.out.writeInt(db.getRdbId()); - db.out.flush(); - if (debug) - log.debug("sent"); - receiveResponse(db, -1); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_network_error); - } - } - - } - // Transaction functions public void iscStartTransaction(IscTrHandle tr_handle, @@ -411,46 +302,6 @@ } - public void iscCommitTransaction(IscTrHandle tr_handle) throws GDSException { - boolean debug = log != null && log.isDebugEnabled(); - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - - 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_handle.getState() != IscTrHandle.TRANSACTIONSTARTED - && tr_handle.getState() != IscTrHandle.TRANSACTIONPREPARED) { - throw new GDSException(ISCConstants.isc_tra_state); - } - tr_handle.setState(IscTrHandle.TRANSACTIONCOMMITTING); - - try { - if (debug) { - log.debug("op_commit "); - log.debug("tr.rtr_id: " + tr_handle.getTransactionId()); - } - db.out.writeInt(op_commit); - db.out.writeInt(tr_handle.getTransactionId()); - db.out.flush(); - if (debug) - log.debug("sent"); - receiveResponse(db, -1); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - - tr_handle.setState(IscTrHandle.NOTRANSACTION); - tr_handle.unsetDbHandle(); - } - - } - public void iscPrepareTransaction(IscTrHandle tr_handle) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); @@ -480,553 +331,6 @@ } } - // Dynamic SQL - - public void iscDsqlAllocateStatement(IscDbHandle db_handle, - IscStmtHandle stmt_handle) throws GDSException { - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) 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); - } - - synchronized (db) { - try { - if (debug) - log.debug("op_allocate_statement "); - db.out.writeInt(op_allocate_statement); - db.out.writeInt(db.getRdbId()); - db.out.flush(); - if (debug) - log.debug("sent"); - receiveResponse(db, -1); - stmt_handle.setRsrId(db.getResp_object()); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - - stmt_handle.setRsr_rdb(db); - - // TODO implement statement handle tracking correctly - // db.rdb_sql_requests.addElement(stmt); - stmt_handle.setAllRowsFetched(false); - } - - } - - public void iscDsqlExecute2(IscTrHandle tr_handle, - IscStmtHandle stmt_handle, int da_version, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException { - - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) stmt_handle.getRsr_rdb(); - - // Test Handles needed here - synchronized (db) { - XdrOutputStream out = db.out; - try { - if (debug) - log.debug((out_xsqlda == null) ? "op_execute " - : "op_execute2 "); - - out.writeInt((out_xsqlda == null) ? op_execute : op_execute2); - out.writeInt(stmt_handle.getRsrId()); - out.writeInt(tr_handle.getTransactionId()); - - if (in_xsqlda != null) { - out.writeBuffer(in_xsqlda.blr); - out.writeInt(0); // message number = in_message_type - out.writeInt(1); // stmt->rsr_bind_format - writeSQLData(out, in_xsqlda); - } else { - out.writeBuffer(null); - out.writeInt(0); // message number = in_message_type - out.writeInt(0); // stmt->rsr_bind_format - } - - if (out_xsqlda != null) { - stmt_handle.clearRows(); - // only need to clear if there is a - out.writeBuffer(out_xsqlda.blr); - out.writeInt(0); // out_message_number = out_message_type - } - out.flush(); - if (stmt_handle.getOutSqlda() != null) - stmt_handle.notifyOpenResultSet(); - if (debug) - log.debug("sent"); - int op = nextOperation(db.in); - if (op == op_sql_response) { - // this would be an Execute procedure - stmt_handle.ensureCapacity(1); - receiveSqlResponse(db, out_xsqlda, (isc_stmt_handle_impl) stmt_handle); - op = nextOperation(db.in); - stmt_handle.setAllRowsFetched(true); - stmt_handle.setSingletonResult(true); - } else { - stmt_handle.setSingletonResult(false); - stmt_handle.setAllRowsFetched(false); - } // end of else - receiveResponse(db, op); - - stmt_handle.registerTransaction(tr_handle); - - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - } - } - - /** - * Write a set of SQL data from a <code>XSQLDA</code> data structure. - * - * @param xsqlda - * The datastructure containing the SQL data to be written - * @throws IOException - * if an error occurs while writing to the - * underlying output stream - */ - protected void writeSQLData(XdrOutputStream out, XSQLDA xsqlda) throws IOException { - for (int i = 0; i < xsqlda.sqld; i++) { - XSQLVAR xsqlvar = xsqlda.sqlvar[i]; - if (log != null && log.isDebugEnabled()) { - if (xsqlvar.sqldata == null) { - log.debug("sqldata null in writeSQLData: " + xsqlvar); - } - } - int len = xsqlda.ioLength[i]; - byte[] buffer = xsqlvar.sqldata; - int tempType = xsqlvar.sqltype & ~1; - if (tempType == ISCConstants.SQL_NULL) { - out.write(xsqlvar.sqldata != null ? zero : minusOne, 0, 4, 0); - } else if (len == 0) { - if (buffer != null) { - len = buffer.length; - out.writeInt(len); - out.write(buffer, 0, len, (4 - len) & 3); - // sqlind - out.write(zero, 0, 4, 0); - } else { - out.writeInt(0); - // sqlind - out.write(minusOne, 0, 4, 0); - } - } else if (len < 0) { - if (buffer != null) { - out.write(buffer, 0, -len, 0); - // sqlind - out.write(zero, 0, 4, 0); - } else { - out.writePadding(-len, 0x20); - // sqlind - out.write(minusOne, 0, 4, 0); - } - } else { - // decrement length because it was incremented before - // increment happens in calculateIOLength - len--; - if (buffer != null) { - int buflen = buffer.length; - if (buflen >= len) { - out.write(buffer, 0, len, (4 - len) & 3); - } else { - out.write(buffer, 0, buflen, 0); - out.writePadding(len - buflen + ((4 - len) & 3), 0x20); - } - // sqlind - out.write(zero, 0, 4, 0); - } else { - out.writePadding(len + ((4 - len) & 3), 0x20); - // sqlind - out.write(minusOne, 0, 4, 0); - } - } - } - } - - /** - * Read a row of SQL data and store it in the results set of a statement. - * - * @param ioLength - * array containing the lengths of each column in the - * data row that is to be read - * @param stmt - * The statement where the row is to be stored - * @throws IOException - * if an error occurs while reading from the - * underlying input stream - */ - public void readSQLData(XdrInputStream in, 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][]; - byte[] buffer; - for (int i = 0; i < numCols; i++) { - int len = ioLength[i]; - if (len == 0) { - len = in.readInt(); - buffer = new byte[len]; - in.readFully(buffer, 0, len); - in.skipPadding(len); - } else if (len < 0) { - buffer = new byte[-len]; - in.readFully(buffer, 0, -len); - } else { - // len is incremented to avoid value 0 so it must be decremented - len--; - buffer = new byte[len]; - in.readFully(buffer, 0, len); - in.skipPadding(len); - } - if (in.readInt() == -1) - buffer = null; - row[i] = buffer; - } - if (stmt != null) - stmt.addRow(row); - } - - 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 - iscDsqlExecImmed2(db_handle, tr_handle, statement, "NONE", dialect, - in_xsqlda, out_xsqlda); - } - - @Deprecated - public void iscDsqlExecImmed2(IscDbHandle db_handle, IscTrHandle tr_handle, - String statement, String encoding, int dialect, XSQLDA in_xsqlda, - XSQLDA out_xsqlda) throws GDSException { - iscDsqlExecImmed2(db_handle, tr_handle, getByteArrayForString(db_handle, statement, encoding), - dialect, in_xsqlda, out_xsqlda); - } - - public void iscDsqlExecImmed2(IscDbHandle db_handle, IscTrHandle tr_handle, - byte[] statement, int dialect, XSQLDA in_xsqlda, XSQLDA out_xsqlda) - throws GDSException { - - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - - // Test Handles - - synchronized (db) { - XdrOutputStream out = db.out; - try { - - if (in_xsqlda == null && out_xsqlda == null) { - if (debug) - log.debug("op_exec_immediate "); - out.writeInt(op_exec_immediate); - } else { - if (debug) - log.debug("op_exec_immediate2 "); - out.writeInt(op_exec_immediate2); - - if (in_xsqlda != null) { - out.writeBuffer(in_xsqlda.blr); - out.writeInt(0); - out.writeInt(1); - writeSQLData(out, in_xsqlda); - } else { - out.writeBuffer(null); - out.writeInt(0); - out.writeInt(0); - } - if (out_xsqlda != null) - out.writeBuffer(out_xsqlda.blr); - else - out.writeBuffer(null); - out.writeInt(0); - } - - out.writeInt(tr_handle.getTransactionId()); - out.writeInt(0); - out.writeInt(dialect); - out.writeBuffer(statement); - out.writeString("", db.getEncodingFactory().getDefaultEncoding()); - out.writeInt(0); - out.flush(); - - if (debug) - log.debug("sent"); - - int op = nextOperation(db.in); - if (op == op_sql_response) { - receiveSqlResponse(db, out_xsqlda, null); - op = nextOperation(db.in); - } - receiveResponse(db, op); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - } - } - - public void iscDsqlFetch(IscStmtHandle stmt_handle, int da_version, - XSQLDA xsqlda, int fetchSize) throws GDSException { - - if (stmt_handle == null) { - throw new GDSException(ISCConstants.isc_bad_req_handle); - } - if (xsqlda == null) { - throw new GDSException(ISCConstants.isc_dsql_sqlda_err); - } - - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) stmt_handle.getRsr_rdb(); - - if (db == null || !db.isValid()) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - if (fetchSize <= 0) { - throw new GDSException(ISCConstants.isc_dsql_sqlda_err); - } - // Apply fetchSize - synchronized (db) { - XdrOutputStream out = db.out; - XdrInputStream in = db.in; - try { - // Fetch next batch of rows - stmt_handle.ensureCapacity(fetchSize); - if (debug) - log.debug("op_fetch "); - out.writeInt(op_fetch); - out.writeInt(stmt_handle.getRsrId()); - out.writeBuffer(xsqlda.blr); - out.writeInt(0); // p_sqldata_message_number - out.writeInt(fetchSize); // p_sqldata_messages - out.flush(); - if (debug) - log.debug("sent"); - - int op = nextOperation(db.in); - stmt_handle.notifyOpenResultSet(); - if (op == op_fetch_response) { - - int sqldata_status; - int sqldata_messages; - - do { - sqldata_status = in.readInt(); - sqldata_messages = in.readInt(); - - if (sqldata_messages > 0 && sqldata_status == 0) { - readSQLData(in, xsqlda.ioLength, stmt_handle); - // TODO Replace with while - do { - op = nextOperation(db.in); - if (op == op_response) { - receiveResponse(db, op); - } - } while (false); - } - - } while (sqldata_messages > 0 && sqldata_status == 0); - - if (sqldata_status == 100) { - if (debug) - log.debug("all rows successfully fetched"); - stmt_handle.setAllRowsFetched(true); - } - } else { - receiveResponse(db, op); - } - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - } - } - - public static void calculateIOLength(XSQLDA xsqlda) { - xsqlda.ioLength = new int[xsqlda.sqld]; - for (int i = 0; i < xsqlda.sqld; i++) { - switch (xsqlda.sqlvar[i].sqltype & ~1) { - case ISCConstants.SQL_TEXT: - xsqlda.ioLength[i] = xsqlda.sqlvar[i].sqllen + 1; - break; - case ISCConstants.SQL_VARYING: - xsqlda.ioLength[i] = 0; - break; - case ISCConstants.SQL_SHORT: - case ISCConstants.SQL_LONG: - case ISCConstants.SQL_FLOAT: - case ISCConstants.SQL_TYPE_TIME: - case ISCConstants.SQL_TYPE_DATE: - xsqlda.ioLength[i] = -4; - break; - // case SQL_D_FLOAT: - // break; - case ISCConstants.SQL_DOUBLE: - case ISCConstants.SQL_TIMESTAMP: - case ISCConstants.SQL_BLOB: - case ISCConstants.SQL_ARRAY: - case ISCConstants.SQL_QUAD: - c... [truncated message content] |
From: <mro...@us...> - 2015-02-07 14:48:06
|
Revision: 60645 http://sourceforge.net/p/firebird/code/60645 Author: mrotteveel Date: 2015-02-07 14:47:57 +0000 (Sat, 07 Feb 2015) Log Message: ----------- Remove old GDS methods no longer referenced + remove old tests no longer needed Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/GDS.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbTransaction.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Transaction.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -217,6 +217,7 @@ public JnaTransaction startTransaction(TransactionParameterBuffer tpb) throws SQLException { checkConnected(); if (!(tpb instanceof TransactionParameterBufferImpl)) { + // TODO Should we support this? TransactionParameterBufferImpl tempTpb = new TransactionParameterBufferImpl(); for (Parameter parameter : tpb) { parameter.copyTo(tempTpb, getEncoding()); @@ -281,6 +282,11 @@ } @Override + public TransactionParameterBufferImpl createTransactionParameterBuffer() { + return new TransactionParameterBufferImpl(); + } + + @Override public byte[] getDatabaseInfo(final byte[] requestItems, final int maxBufferLength) throws SQLException { final ByteBuffer responseBuffer = ByteBuffer.allocateDirect(maxBufferLength); synchronized (getSynchronizationObject()) { Modified: client-java/trunk/src/main/org/firebirdsql/gds/GDS.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/GDS.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/GDS.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -178,30 +178,7 @@ */ void iscDetachDatabase(IscDbHandle dbHandle) throws GDSException; - // ------------------ Transactions ------------------------- /** - * Start a transaction based on a handle to a transaction. - * - * @param trHandle - * Handle to the transaction that is to be started - * @param dbHandle - * Handle to the database in which the transaction is to be - * started - * @param tpb - * Transaction Parameter Block in the form of a byte array, - * contains parameter data for the transaction attributes - * @throws GDSException - * if an error occurs while starting the transaction - * @see #createIscTrHandle() - */ - void iscStartTransaction(IscTrHandle trHandle, IscDbHandle dbHandle, - TransactionParameterBuffer tpb) throws GDSException; - - void iscPrepareTransaction(IscTrHandle trHandle) throws GDSException; - - // ---------------------- Dynamic SQL ------------------------ - - /** * Retrieve an integer value from a sequence of bytes. * <p> * Behaviour is undefined for length > 4 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 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -216,25 +216,6 @@ } } - // isc_prepare_transaction - // --------------------------------------------------------------------------------------------- - public void iscPrepareTransaction(IscTrHandle tr_handle) - throws GDSException { - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - - synchronized (tr_handle.getDbHandle()) { - if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { throw new GDSException( - ISCConstants.isc_tra_state); } - tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); - - native_isc_prepare_transaction(tr_handle); - - tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); - } - } - public void iscSeekBlob(IscBlobHandle handle, int position, int mode) throws GDSException { isc_blob_handle_impl blob = (isc_blob_handle_impl) handle; @@ -306,36 +287,6 @@ } } - // isc_start_transaction - // --------------------------------------------------------------------------------------------- - public void iscStartTransaction(IscTrHandle tr_handle, - IscDbHandle db_handle, TransactionParameterBuffer tpb) - throws GDSException { - TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; - - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - - if (db_handle == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - synchronized (db_handle) { - if (tr_handle.getState() != IscTrHandle.NOTRANSACTION) - throw new GDSException(ISCConstants.isc_tra_state); - - tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); - - byte[] arg = tpbImpl.getBytesForNativeCode(); - native_isc_start_transaction(tr_handle, db_handle, arg); - - tr_handle.setDbHandle(db_handle); - - tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); - } - } - public abstract void native_isc_attach_database(byte[] file_name, IscDbHandle db_handle, byte[] dpbBytes); @@ -352,9 +303,6 @@ public abstract void native_isc_open_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); - public abstract void native_isc_prepare_transaction(IscTrHandle tr_handle) - throws GDSException; - public abstract void native_isc_seek_blob(isc_blob_handle_impl handle, int position, int mode) throws GDSException; @@ -374,11 +322,6 @@ public abstract void native_isc_service_start(IscSvcHandle serviceHandle, byte[] serviceParameterBuffer) throws GDSException; - public abstract void native_isc_start_transaction(IscTrHandle tr_handle, - IscDbHandle db_handle, - // Set tpb) throws GDSException; - byte[] tpb) throws GDSException; - public abstract int native_isc_que_events(IscDbHandle db_handle, EventHandleImp eventHandle, EventHandler handler) throws GDSException; 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 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/JniGDSImpl.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -177,9 +177,6 @@ public native void native_isc_open_blob2(IscDbHandle db, IscTrHandle tr, IscBlobHandle blob, byte[] dpbBytes); - public native void native_isc_prepare_transaction(IscTrHandle tr_handle) - throws GDSException; - public native void native_isc_seek_blob(isc_blob_handle_impl handle, int position, int mode) throws GDSException; @@ -198,10 +195,6 @@ public native void native_isc_service_start(IscSvcHandle serviceHandle, byte[] serviceParameterBuffer) throws GDSException; - public native void native_isc_start_transaction(IscTrHandle tr_handle, - IscDbHandle db_handle, - byte[] tpb) throws GDSException; - public native int native_isc_que_events(IscDbHandle db_handle, EventHandleImp eventHandle, EventHandler handler) throws GDSException; Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -48,7 +48,7 @@ byteArrayOutputStream.write(ISCConstants.isc_tpb_version3); try { - super.writeArgumentsTo(byteArrayOutputStream); + writeArgumentsTo(byteArrayOutputStream); } catch (IOException e) { // Ignoring IOException, not thrown by ByteArrayOutputStream } 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 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -257,80 +257,6 @@ } } - // Transaction functions - - public void iscStartTransaction(IscTrHandle tr_handle, - IscDbHandle db_handle, - TransactionParameterBuffer tpb) throws GDSException { - - boolean debug = log != null && log.isDebugEnabled(); - isc_db_handle_impl db = (isc_db_handle_impl) db_handle; - - TransactionParameterBufferImpl tpbImpl = (TransactionParameterBufferImpl) tpb; - - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - if (db == null) { - throw new GDSException(ISCConstants.isc_bad_db_handle); - } - - synchronized (db) { - if (tr_handle.getState() != IscTrHandle.NOTRANSACTION) { - throw new GDSException(ISCConstants.isc_tra_state); - } - tr_handle.setState(IscTrHandle.TRANSACTIONSTARTING); - - try { - if (debug) - log.debug("op_transaction "); - db.out.writeInt(op_transaction); - db.out.writeInt(db.getRdbId()); - db.out.writeTyped(ISCConstants.isc_tpb_version3, tpbImpl); - db.out.flush(); - if (debug) - log.debug("sent"); - receiveResponse(db, -1); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_network_error, ex); - } - tr_handle.setTransactionId(db.getResp_object()); - - tr_handle.setDbHandle(db); - tr_handle.setState(IscTrHandle.TRANSACTIONSTARTED); - } - - } - - public void iscPrepareTransaction(IscTrHandle tr_handle) - throws GDSException { - boolean debug = log != null && log.isDebugEnabled(); - if (tr_handle == null) { - throw new GDSException(ISCConstants.isc_bad_trans_handle); - } - isc_db_handle_impl db = (isc_db_handle_impl) tr_handle.getDbHandle(); - - synchronized (db) { - if (tr_handle.getState() != IscTrHandle.TRANSACTIONSTARTED) { - throw new GDSException(ISCConstants.isc_tra_state); - } - tr_handle.setState(IscTrHandle.TRANSACTIONPREPARING); - try { - if (debug) - log.debug("op_prepare "); - db.out.writeInt(op_prepare); - db.out.writeInt(tr_handle.getTransactionId()); - db.out.flush(); - if (debug) - log.debug("sent"); - receiveResponse(db, -1); - } catch (IOException ex) { - throw new GDSException(ISCConstants.isc_net_read_err); - } - tr_handle.setState(IscTrHandle.TRANSACTIONPREPARED); - } - } - // ----------------------------------------------- // Blob methods // ----------------------------------------------- Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -157,6 +157,13 @@ BlobParameterBuffer createBlobParameterBuffer(); /** + * Creates a transaction parameter buffer that is usable with {@link #startTransaction(org.firebirdsql.gds.TransactionParameterBuffer)}. + * + * @return A transaction parameter buffer + */ + TransactionParameterBuffer createTransactionParameterBuffer(); + + /** * Request database info. * * @param requestItems Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/FbTransaction.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbTransaction.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/FbTransaction.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -82,7 +82,8 @@ * Prepare the transaction for two-phase commit/rollback. * * @param recoveryInformation - * Transaction recovery information (stored in RDB$TRANSACTION_DESCRIPTION of RDB$TRANSACTIONS) + * Transaction recovery information (stored in RDB$TRANSACTION_DESCRIPTION of RDB$TRANSACTIONS), + * or {@code null} to prepare without recovery information. * @throws SQLException */ void prepare(byte[] recoveryInformation) throws SQLException; Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -24,6 +24,7 @@ import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.BlobParameterBuffer; import org.firebirdsql.gds.impl.wire.BlobParameterBufferImp; +import org.firebirdsql.gds.impl.wire.TransactionParameterBufferImpl; import org.firebirdsql.gds.impl.wire.XdrInputStream; import org.firebirdsql.gds.impl.wire.XdrOutputStream; import org.firebirdsql.gds.ng.*; @@ -135,6 +136,11 @@ } @Override + public TransactionParameterBufferImpl createTransactionParameterBuffer() { + return new TransactionParameterBufferImpl(); + } + + @Override public void consumePackets(int numberOfResponses, WarningMessageCallback warningCallback) { while (numberOfResponses > 0) { numberOfResponses--; Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Transaction.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Transaction.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Transaction.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -145,9 +145,14 @@ synchronized (getDatabase().getSynchronizationObject()) { try { final XdrOutputStream xdrOut = getXdrOut(); - xdrOut.writeInt(op_prepare2); - xdrOut.writeInt(handle); - xdrOut.writeBuffer(recoveryInformation); + if (recoveryInformation != null) { + xdrOut.writeInt(op_prepare2); + xdrOut.writeInt(handle); + xdrOut.writeBuffer(recoveryInformation); + } else { + xdrOut.writeInt(op_prepare); + xdrOut.writeInt(handle); + } xdrOut.flush(); } catch (IOException ioex) { throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException(); Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBConnection.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -229,7 +229,7 @@ } public TransactionParameterBuffer createTransactionParameterBuffer() throws SQLException { - return getInternalAPIHandler().newTransactionParameterBuffer(); + return getFbDatabase().createTransactionParameterBuffer(); } public void setTransactionParameters(int isolationLevel, TransactionParameterBuffer tpb) throws SQLException { Modified: client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java 2015-02-07 14:17:15 UTC (rev 60644) +++ client-java/trunk/src/test/org/firebirdsql/management/TestFBMaintenanceManager.java 2015-02-07 14:47:57 UTC (rev 60645) @@ -3,6 +3,8 @@ import org.firebirdsql.common.FBJUnit4TestBase; import org.firebirdsql.gds.*; import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.gds.ng.FbDatabase; +import org.firebirdsql.gds.ng.FbTransaction; import org.firebirdsql.jdbc.FBConnection; import org.junit.Before; import org.junit.Rule; @@ -479,19 +481,12 @@ private void createLimboTransaction(int count) throws Exception { FBConnection conn = (FBConnection) getConnectionViaDriverManager(); try { - GDS gds = conn.getInternalAPIHandler(); - DatabaseParameterBuffer dpb = gds.createDatabaseParameterBuffer(); - dpb.addArgument(DatabaseParameterBuffer.USER, DB_USER); - dpb.addArgument(DatabaseParameterBuffer.PASSWORD, DB_PASSWORD); - IscDbHandle dbh = gds.createIscDbHandle(); - gds.iscAttachDatabase(getdbpath(DB_NAME), dbh, dpb); + final FbDatabase fbDatabase = conn.getFbDatabase(); for (int i = 0; i < count; i++) { - TransactionParameterBuffer tpBuf = gds.newTransactionParameterBuffer(); - IscTrHandle trh = gds.createIscTrHandle(); - gds.iscStartTransaction(trh, dbh, tpBuf); - gds.iscPrepareTransaction(trh); + TransactionParameterBuffer tpBuf = conn.createTransactionParameterBuffer(); + FbTransaction transaction = fbDatabase.startTransaction(tpBuf); + transaction.prepare(null); } - gds.iscDetachDatabase(dbh); } finally { conn.close(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-02-14 13:18:04
|
Revision: 60685 http://sourceforge.net/p/firebird/code/60685 Author: mrotteveel Date: 2015-02-14 13:17:53 +0000 (Sat, 14 Feb 2015) Log Message: ----------- Unify the wire protocol and JNI parameter buffers to a single implementation per parameter buffer type. Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaBlob.java client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaParameterConverter.java client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaBlob.java client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/BlobParameterBuffer.java client-java/trunk/src/main/org/firebirdsql/gds/ParameterBuffer.java client-java/trunk/src/main/org/firebirdsql/gds/ParameterBufferHelper.java client-java/trunk/src/main/org/firebirdsql/gds/impl/ParameterBufferBase.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/gds/impl/wire/XdrOutputStream.java client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbBlob.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbConnectionProperties.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireBlob.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Database.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10InputBlob.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10OutputBlob.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10ParameterConverter.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version12/V12ParameterConverter.java client-java/trunk/src/main/org/firebirdsql/jca/FBConnectionRequestInfo.java client-java/trunk/src/test/org/firebirdsql/gds/ng/AbstractStatementTest.java client-java/trunk/src/test/org/firebirdsql/gds/ng/AbstractTransactionTest.java client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/BaseTestV10Blob.java client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10Database.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/impl/BlobParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/DatabaseParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceRequestBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/TransactionParameterBufferImpl.java Removed Paths: ------------- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BlobParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/DatabaseParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceRequestBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/BlobParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/DatabaseParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/ParameterBufferBase.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/ServiceParameterBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/ServiceRequestBufferImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/TransactionParameterBufferImpl.java Property Changed: ---------------- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbConnectionProperties.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaBlob.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaBlob.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaBlob.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -25,7 +25,6 @@ import com.sun.jna.ptr.ShortByReference; import org.firebirdsql.gds.BlobParameterBuffer; import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.impl.jni.BlobParameterBufferImp; import org.firebirdsql.gds.ng.AbstractFbBlob; import org.firebirdsql.gds.ng.FbBlob; import org.firebirdsql.gds.ng.FbExceptionBuilder; @@ -93,10 +92,10 @@ throw new FbExceptionBuilder().nonTransientException(ISCConstants.isc_segstr_no_op).toSQLException(); } - final BlobParameterBufferImp blobParameterBuffer = (BlobParameterBufferImp) getBlobParameterBuffer(); + final BlobParameterBuffer blobParameterBuffer = getBlobParameterBuffer(); final byte[] bpb; if (blobParameterBuffer != null) { - bpb = blobParameterBuffer.getBytesForNativeCode(); + bpb = blobParameterBuffer.toBytesWithType(); } else { bpb = new byte[0]; } @@ -249,11 +248,6 @@ } } - @Override - protected boolean isValidBlobParameterBufferClass(Class<? extends BlobParameterBuffer> blobParameterBufferClass) { - return org.firebirdsql.gds.impl.jni.BlobParameterBufferImp.class.isAssignableFrom(blobParameterBufferClass); - } - private void processStatusVector() throws SQLException { getDatabase().processStatusVector(statusVector, null); } Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -26,10 +26,9 @@ import org.firebirdsql.encodings.EncodingDefinition; import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.*; +import org.firebirdsql.gds.impl.BlobParameterBufferImp; import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; -import org.firebirdsql.gds.impl.jni.BlobParameterBufferImp; -import org.firebirdsql.gds.impl.jni.DatabaseParameterBufferImp; -import org.firebirdsql.gds.impl.jni.TransactionParameterBufferImpl; +import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; import org.firebirdsql.gds.ng.*; import org.firebirdsql.gds.ng.listeners.TransactionListener; import org.firebirdsql.jdbc.FBSQLException; @@ -123,19 +122,12 @@ attachOrCreate(dpb, false); } - protected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create) throws SQLException { + protected void attachOrCreate(final DatabaseParameterBuffer dpb, final boolean create) throws SQLException { if (isAttached()) { throw new SQLException("Already attached to a database"); } - if (!(dpb instanceof DatabaseParameterBufferImp)) { - DatabaseParameterBuffer tempDpb = new DatabaseParameterBufferImp(); - for (Parameter parameter : dpb) { - parameter.copyTo(tempDpb, getEncoding()); - } - dpb = tempDpb; - } final byte[] dbName = getEncoding().encodeToCharset(getDatabaseUrl()); - final byte[] dpbArray = ((DatabaseParameterBufferImp) dpb).getBytesForNativeCode(); + final byte[] dpbArray = dpb.toBytesWithType(); synchronized (getSynchronizationObject()) { try { @@ -214,18 +206,10 @@ } @Override - public JnaTransaction startTransaction(TransactionParameterBuffer tpb) throws SQLException { + public JnaTransaction startTransaction(final TransactionParameterBuffer tpb) throws SQLException { checkConnected(); - if (!(tpb instanceof TransactionParameterBufferImpl)) { - // TODO Should we support this? - TransactionParameterBufferImpl tempTpb = new TransactionParameterBufferImpl(); - for (Parameter parameter : tpb) { - parameter.copyTo(tempTpb, getEncoding()); - } - tpb = tempTpb; - } final IntByReference transactionHandle = new IntByReference(0); - byte[] tpbArray = ((TransactionParameterBufferImpl) tpb).getBytesForNativeCode(); + byte[] tpbArray = tpb.toBytesWithType(); synchronized (getSynchronizationObject()) { clientLibrary.isc_start_transaction(statusVector, transactionHandle, (short) 1, handle, (short) tpbArray.length, tpbArray); processStatusVector(); Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaParameterConverter.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaParameterConverter.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaParameterConverter.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -23,7 +23,7 @@ import org.firebirdsql.encodings.Encoding; import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.DatabaseParameterBuffer; -import org.firebirdsql.gds.impl.jni.DatabaseParameterBufferImp; +import org.firebirdsql.gds.impl.DatabaseParameterBufferImp; import org.firebirdsql.gds.ng.AbstractParameterConverter; import org.firebirdsql.gds.ng.IConnectionProperties; import org.firebirdsql.gds.ng.ParameterConverter; Modified: client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaBlob.java =================================================================== --- client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaBlob.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaBlob.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -23,7 +23,7 @@ import org.firebirdsql.gds.BlobParameterBuffer; import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.TransactionParameterBuffer; -import org.firebirdsql.gds.impl.jni.TransactionParameterBufferImpl; +import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; import org.firebirdsql.gds.ng.*; import org.firebirdsql.gds.ng.fields.FieldValue; import org.firebirdsql.gds.ng.fields.RowValue; Modified: client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java =================================================================== --- client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -24,7 +24,7 @@ import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.TransactionParameterBuffer; import org.firebirdsql.gds.impl.GDSServerVersion; -import org.firebirdsql.gds.impl.wire.TransactionParameterBufferImpl; +import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; import org.firebirdsql.gds.ng.FbConnectionProperties; import org.firebirdsql.gds.ng.FbDatabase; import org.firebirdsql.gds.ng.FbTransaction; Modified: client-java/trunk/src/main/org/firebirdsql/gds/BlobParameterBuffer.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/BlobParameterBuffer.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/BlobParameterBuffer.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -24,7 +24,6 @@ */ package org.firebirdsql.gds; - /** * Instance of this interface represents a BLOB Parameter Buffer from the * Firebird API documentation and specifies attributes for @@ -44,7 +43,7 @@ * for more details). * </ul> */ -public interface BlobParameterBuffer { +public interface BlobParameterBuffer extends ParameterBuffer { int SOURCE_TYPE = ISCConstants.isc_bpb_source_type; int TARGET_TYPE = ISCConstants.isc_bpb_target_type; @@ -59,35 +58,32 @@ int TYPE_STREAM = ISCConstants.isc_bpb_type_stream; /** - * Set a void (valueless) parameter on this - * <code>BlobParameterBuffer</code>. + * Set a void (valueless) parameter on this {@code BlobParameterBuffer}. * - * @param argumentType The parameter to be set, either an - * <code>ISCConstantsone.isc_bpb_*</code> constant, or one of the - * fields of this interface + * @param argumentType The parameter to be set, either an {@code ISCConstants.isc_bpb_*} constant, or one of the + * constants of this interface */ + @Override void addArgument(int argumentType); /** - * Set a <code>String</code> parameter on this - * <code>BlobParameterBuffer</code>. + * Set a {@code String} parameter on this {@code BlobParameterBuffer}. * - * @param argumentType The parameter to be set, either an - * <code>ISCConstantsone.isc_bpb_*</code> constant, or one of the - * fields of this interface + * @param argumentType The parameter to be set, either an {@code ISCConstants.isc_bpb_*} constant, or one of the + * constants of this interface * @param value The value to set for the given parameter */ + @Override void addArgument(int argumentType, String value); /** - * Set an <code>int</code> parameter on this - * <code>BlobParameterBuffer</code>. + * Set an {@code int} parameter on this {@code BlobParameterBuffer}. * - * @param argumentType The parameter to be set, either an - * <code>ISCConstantsone.isc_bpb_*</code> constant, or one of the - * fields of this interface + * @param argumentType The parameter to be set, either an {@code ISCConstants.isc_bpb_*} constant, or one of the + * constants of this interface * @param value The value to set for the given parameter */ + @Override void addArgument(int argumentType, int value); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ParameterBuffer.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ParameterBuffer.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/ParameterBuffer.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -27,7 +27,10 @@ package org.firebirdsql.gds; import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.gds.impl.wire.Xdrable; +import java.io.IOException; +import java.io.OutputStream; import java.util.Iterator; /** @@ -42,7 +45,13 @@ * @since 3.0 */ public interface ParameterBuffer extends Iterable<Parameter> { + /** + * @return The parameter buffer type identifier + */ + int getType(); + + /** * Add argument with no parameters. * * @param argumentType @@ -140,4 +149,41 @@ */ @Override Iterator<Parameter> iterator(); + + /** + * Writes the arguments in the implementation specific serialization into the {@code OutputStream}. + * + * @param outputStream + * The {@code OutputStream} to write to + * @throws IOException + * Errors produced by the output stream during writes + */ + void writeArgumentsTo(OutputStream outputStream) throws IOException; + + /** + * @return {@code Xdrable} to write (and optionally read) this instance as Xdr. + */ + Xdrable toXdrable(); + + /** + * Converts this parameter buffer to a byte array. + * <p> + * This byte array includes the extra header-bytes (if any), but does not include the type information + * </p> + * + * @return Byte array with serialization of this parameter buffer + * @see #toBytesWithType() + */ + byte[] toBytes(); + + /** + * Converts this parameter buffer to a byte array with type information. + * <p> + * This byte array includes the type information and the extra header bytes (if any). + * </p> + * + * @return Byte array with serialization of this parameter buffer + * @see #toBytes() + */ + byte[] toBytesWithType(); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ParameterBufferHelper.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ParameterBufferHelper.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/ParameterBufferHelper.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,6 +1,8 @@ /* - * Firebird Open Source J2ee connector - jdbc driver + * $Id$ * + * Firebird Open Source JavaEE Connector - JDBC Driver + * * Distributable under LGPL license. * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html * @@ -12,11 +14,10 @@ * 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. + * can be obtained from a source control history command. * * All rights reserved. */ - package org.firebirdsql.gds; import java.io.IOException; Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/BlobParameterBufferImp.java (from rev 60640, client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/BlobParameterBufferImp.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/BlobParameterBufferImp.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/BlobParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -0,0 +1,35 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.BlobParameterBuffer; +import org.firebirdsql.gds.ISCConstants; + +/** + * Implementation of BlobParameterBuffer. + */ +public class BlobParameterBufferImp extends ParameterBufferBase implements BlobParameterBuffer { + + public BlobParameterBufferImp() { + super(ISCConstants.isc_bpb_version1); + } + +} Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/DatabaseParameterBufferImp.java (from rev 60640, client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/DatabaseParameterBufferImp.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/DatabaseParameterBufferImp.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/DatabaseParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -0,0 +1,55 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.DatabaseParameterBuffer; +import org.firebirdsql.gds.ISCConstants; + +/** + * Implementation for DatabaseParameterBuffer. + */ +public final class DatabaseParameterBufferImp extends ParameterBufferBase implements DatabaseParameterBufferExtension { + + public DatabaseParameterBufferImp() { + super(ISCConstants.isc_dpb_version1); + } + + @Override + public DatabaseParameterBuffer deepCopy() { + final DatabaseParameterBufferImp copy = new DatabaseParameterBufferImp(); + + // All the Argument sub classes are immutable so to make a 'deep' copy this is all we have to do. + copy.getArgumentsList().addAll(this.getArgumentsList()); + + return copy; + } + + @Override + public DatabaseParameterBuffer removeExtensionParams() { + final DatabaseParameterBuffer copy = deepCopy(); + + for (int i = 0; i < DatabaseParameterBufferExtension.EXTENSION_PARAMETERS.length; i++) { + copy.removeArgument(DatabaseParameterBufferExtension.EXTENSION_PARAMETERS[i]); + } + + return copy; + } +} Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/ParameterBufferBase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/ParameterBufferBase.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/ParameterBufferBase.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -24,7 +24,11 @@ import org.firebirdsql.gds.Parameter; import org.firebirdsql.gds.ParameterBuffer; import org.firebirdsql.gds.impl.argument.*; +import org.firebirdsql.gds.impl.wire.XdrInputStream; +import org.firebirdsql.gds.impl.wire.XdrOutputStream; +import org.firebirdsql.gds.impl.wire.Xdrable; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.Serializable; @@ -33,13 +37,46 @@ import java.util.List; /** + * Base class for parameter buffers + * * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> */ -public class ParameterBufferBase implements ParameterBuffer, Serializable { +public abstract class ParameterBufferBase implements ParameterBuffer, Serializable { private final List<Argument> arguments = new ArrayList<Argument>(); + private static final byte[] NO_HEADER_BYTES = {}; + + private final int type; + private final byte[] extraHeaderBytes; + + /** + * Creates a {@code ParameterBufferBase}. + * + * @param type Firebird type/version code for the parameter buffer + */ + protected ParameterBufferBase(int type) { + this(type, NO_HEADER_BYTES); + } + + /** + * Creates a {@code ParameterBufferBase} with extra bytes in the header. + * + * @param type Firebird type/version code for the parameter buffer + * @param extraHeaderBytes Extra bytes to add as a header to the buffer + */ + protected ParameterBufferBase(int type, byte[] extraHeaderBytes) { + assert extraHeaderBytes != null : "extraHeaderBytes cannot be null"; + this.type = type; + this.extraHeaderBytes = extraHeaderBytes; + } + @Override + public final int getType() { + return type; + } + + @Override public void addArgument(int argumentType, String value) { getArgumentsList().add(new StringArgument(argumentType, value)); } @@ -118,9 +155,14 @@ } } - public int getLength() { + @Override + public Xdrable toXdrable() { + return new ParameterBufferXdrable(); + } + + protected int getLength() { final List<Argument> argumentsList = getArgumentsList(); - int length = 0; + int length = extraHeaderBytes.length; for (final Argument currentArgument : argumentsList) { length += currentArgument.getLength(); } @@ -132,6 +174,31 @@ } @Override + public byte[] toBytes() { + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + try { + bout.write(extraHeaderBytes); + writeArgumentsTo(bout); + } catch (IOException e) { + // Doesn't happen with ByteArrayOutputStream + } + return bout.toByteArray(); + } + + @Override + public byte[] toBytesWithType() { + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + try { + bout.write(getType()); + bout.write(extraHeaderBytes); + writeArgumentsTo(bout); + } catch (IOException e) { + // Doesn't happen with ByteArrayOutputStream + } + return bout.toByteArray(); + } + + @Override public boolean equals(Object other) { if (other == null || !(this.getClass().isAssignableFrom(other.getClass()))) return false; @@ -144,4 +211,25 @@ public int hashCode() { return getArgumentsList().hashCode(); } + + /** + * Default implementation for serializing the parameter buffer to the XDR output stream + */ + private class ParameterBufferXdrable implements Xdrable { + @Override + public int getLength() { + return ParameterBufferBase.this.getLength(); + } + + @Override + public void read(XdrInputStream inputStream, int length) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final XdrOutputStream outputStream) throws IOException { + outputStream.write(extraHeaderBytes); + writeArgumentsTo(outputStream); + } + } } Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceParameterBufferImp.java (from rev 60640, client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/ServiceParameterBufferImp.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceParameterBufferImp.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -0,0 +1,35 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.ServiceParameterBuffer; + +/** + * Implementation of ServiceParameterBuffer. + */ +public class ServiceParameterBufferImp extends org.firebirdsql.gds.impl.ParameterBufferBase implements ServiceParameterBuffer { + + public ServiceParameterBufferImp() { + super(ISCConstants.isc_spb_version, new byte[] { ISCConstants.isc_spb_current_version }); + } + +} \ No newline at end of file Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceRequestBufferImp.java (from rev 60640, client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/ServiceRequestBufferImp.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceRequestBufferImp.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/ServiceRequestBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -0,0 +1,121 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.ServiceRequestBuffer; +import org.firebirdsql.gds.impl.argument.NumericArgument; +import org.firebirdsql.gds.impl.argument.StringArgument; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * Implementation of ServiceRequestBufferImp. + */ +public class ServiceRequestBufferImp extends ParameterBufferBase implements ServiceRequestBuffer { + + /** + * Every ServiceRequestBuffer has an associated taskIdentifier. + * + * @param taskIdentifier + * Service request task + */ + public ServiceRequestBufferImp(int taskIdentifier) { + super(ISCConstants.isc_spb_current_version, new byte[] { (byte) taskIdentifier }); + } + + @Override + public void addArgument(int argumentType, String value) { + getArgumentsList().add(new ServiceStringArgument(argumentType, value)); + } + + @Override + public void addArgument(int argumentType, String value, Encoding encoding) { + getArgumentsList().add(new ServiceStringArgument(argumentType, value, encoding)); + } + + @Override + public void addArgument(int argumentType, int value) { + + getArgumentsList().add(new NumericArgument(argumentType, value) { + + @Override + public int getLength() { + return 5; + } + + @Override + protected void writeValue(OutputStream outputStream, int value) throws IOException { + outputStream.write(value); + outputStream.write(value >> 8); + outputStream.write(value >> 16); + outputStream.write(value >> 24); + } + }); + } + + @Override + public void addArgument(int argumentType, byte value) { + getArgumentsList().add(new NumericArgument(argumentType, value) { + + @Override + public int getLength() { + return 2; + } + + @Override + protected void writeValue(OutputStream outputStream, int value) throws IOException { + outputStream.write(value); + } + }); + } + + private static final class ServiceStringArgument extends StringArgument { + + @Deprecated + public ServiceStringArgument(int argumentType, String value) { + super(argumentType, value); + } + + public ServiceStringArgument(int argumentType, String value, Encoding encoding) { + super(argumentType, value, encoding); + } + + @Override + public int getLength() { + return super.getLength() + 1; + } + + @Override + protected void writeLength(int length, OutputStream outputStream) throws IOException { + outputStream.write(length); + outputStream.write(length >> 8); + } + + @Override + protected int getMaxSupportedLength() { + // TODO Check if this might be signed + return 65535; + } + } +} \ No newline at end of file Copied: client-java/trunk/src/main/org/firebirdsql/gds/impl/TransactionParameterBufferImpl.java (from rev 60640, client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/TransactionParameterBufferImpl.java) =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/TransactionParameterBufferImpl.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/TransactionParameterBufferImpl.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -0,0 +1,44 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.impl; + +import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.TransactionParameterBuffer; + +/** + * Implementation of the {@link org.firebirdsql.gds.TransactionParameterBuffer} interface. + */ +public final class TransactionParameterBufferImpl extends ParameterBufferBase implements TransactionParameterBuffer { + + public TransactionParameterBufferImpl() { + super(ISCConstants.isc_tpb_version3); + } + + @Override + public TransactionParameterBuffer deepCopy() { + final TransactionParameterBufferImpl result = new TransactionParameterBufferImpl(); + + result.getArgumentsList().addAll(this.getArgumentsList()); + + return result; + } + +} 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 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BaseGDSImpl.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,8 +1,8 @@ /* * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver * + * Firebird Open Source JavaEE Connector - JDBC Driver + * * Distributable under LGPL license. * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html * @@ -14,16 +14,14 @@ * 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. + * can be obtained from a source control history command. * * All rights reserved. */ package org.firebirdsql.gds.impl.jni; import org.firebirdsql.gds.*; -import org.firebirdsql.gds.impl.AbstractGDS; -import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; -import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.gds.impl.*; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -94,7 +92,7 @@ db_handle.addWarning(new GDSWarning(WARNING_CONNECT_TIMEOUT_NATIVE)); } - dpbBytes = ((DatabaseParameterBufferImp) cleanDPB).getBytesForNativeCode(); + dpbBytes = cleanDPB.toBytes(); filenameCharset = databaseParameterBuffer.getArgumentAsString(DatabaseParameterBufferExtension.FILENAME_CHARSET); } else { dpbBytes = null; @@ -160,9 +158,8 @@ public void iscServiceAttach(String service, IscSvcHandle serviceHandle, ServiceParameterBuffer serviceParameterBuffer) throws GDSException { - final ServiceParameterBufferImp serviceParameterBufferImp = (ServiceParameterBufferImp) serviceParameterBuffer; - final byte[] serviceParameterBufferBytes = serviceParameterBufferImp == null ? null - : serviceParameterBufferImp.toByteArray(); + final byte[] serviceParameterBufferBytes = serviceParameterBuffer == null ? null + : serviceParameterBuffer.toBytesWithType(); synchronized (serviceHandle) { if (serviceHandle.isValid()) @@ -186,13 +183,10 @@ ServiceParameterBuffer serviceParameterBuffer, ServiceRequestBuffer serviceRequestBuffer, byte[] resultBuffer) throws GDSException { - final ServiceParameterBufferImp serviceParameterBufferImp = (ServiceParameterBufferImp) serviceParameterBuffer; - final byte[] serviceParameterBufferBytes = serviceParameterBufferImp == null ? null - : serviceParameterBufferImp.toByteArray(); + final byte[] serviceParameterBufferBytes = serviceParameterBuffer == null ? null + : serviceParameterBuffer.toBytesWithType(); - final ServiceRequestBufferImp serviceRequestBufferImp = (ServiceRequestBufferImp) serviceRequestBuffer; - final byte[] serviceRequestBufferBytes = serviceRequestBufferImp == null ? null - : serviceRequestBufferImp.toByteArray(); + final byte[] serviceRequestBufferBytes = serviceRequestBuffer == null ? null : serviceRequestBuffer.toBytes(); synchronized (serviceHandle) { if (serviceHandle.isNotValid()) @@ -206,9 +200,7 @@ public void iscServiceStart(IscSvcHandle serviceHandle, ServiceRequestBuffer serviceRequestBuffer) throws GDSException { - final ServiceRequestBufferImp serviceRequestBufferImp = (ServiceRequestBufferImp) serviceRequestBuffer; - final byte[] serviceRequestBufferBytes = serviceRequestBufferImp == null ? null - : serviceRequestBufferImp.toByteArray(); + final byte[] serviceRequestBufferBytes = serviceRequestBuffer == null ? null : serviceRequestBuffer.toBytes(); synchronized (serviceHandle) { if (serviceHandle.isNotValid()) Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BlobParameterBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BlobParameterBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/BlobParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,66 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.jni; - -import org.firebirdsql.gds.BlobParameterBuffer; -import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.impl.ParameterBufferBase; -import org.firebirdsql.gds.impl.argument.NumericArgument; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class BlobParameterBufferImp extends ParameterBufferBase implements BlobParameterBuffer { - - @Override - public void addArgument(int argumentType, int value) { - if (value > 65535) - throw new RuntimeException("Blob parameter buffer value out of range for type " + argumentType); - - getArgumentsList().add(new NumericArgument(argumentType, value) { - @Override - protected void writeValue(OutputStream outputStream, int value) throws IOException { - outputStream.write(2); - outputStream.write(value); - outputStream.write(value >> 8); - } - }); - } - - /** - * Method for obtaining buffer suitable for passing to native method. - * - * @return Buffer for native method - */ - public byte[] getBytesForNativeCode() { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - byteArrayOutputStream.write(ISCConstants.isc_bpb_version1); - - try { - super.writeArgumentsTo(byteArrayOutputStream); - } catch (IOException e) { - // Ignoring IOException, not thrown by ByteArrayOutputStream - } - - return byteArrayOutputStream.toByteArray(); - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/DatabaseParameterBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/DatabaseParameterBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/DatabaseParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,72 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.jni; - -import org.firebirdsql.gds.DatabaseParameterBuffer; -import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; -import org.firebirdsql.gds.impl.ParameterBufferBase; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -public class DatabaseParameterBufferImp extends ParameterBufferBase implements DatabaseParameterBufferExtension { - - @Override - public DatabaseParameterBuffer deepCopy() { - final DatabaseParameterBufferImp copy = new DatabaseParameterBufferImp(); - - // All the Argument sub classes are immutable so to make a 'deep' copy - // this is all we have to do. - copy.getArgumentsList().addAll(this.getArgumentsList()); - - return copy; - } - - /** - * Method for obtaining buffer suitable for passing to native method. - * - * @return Buffer for native method - */ - public byte[] getBytesForNativeCode() { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - byteArrayOutputStream.write(ISCConstants.isc_dpb_version1); - - try { - super.writeArgumentsTo(byteArrayOutputStream); - } catch (IOException e) { - // Ignoring IOException, not thrown by ByteArrayOutputStream - } - - return byteArrayOutputStream.toByteArray(); - } - - @Override - public DatabaseParameterBuffer removeExtensionParams() { - DatabaseParameterBuffer copy = deepCopy(); - - for (int i = 0; i < DatabaseParameterBufferExtension.EXTENSION_PARAMETERS.length; i++) { - copy.removeArgument(DatabaseParameterBufferExtension.EXTENSION_PARAMETERS[i]); - } - - return copy; - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceParameterBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceParameterBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,55 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.jni; - -import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.ServiceParameterBuffer; -import org.firebirdsql.gds.impl.ParameterBufferBase; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * ngds implementation for ServiceParameterBuffer. - */ -class ServiceParameterBufferImp extends ParameterBufferBase implements ServiceParameterBuffer { - - /** - * Package local method for obtaining buffer suitable for passing to native - * method. - * - * @return Buffer for native method - */ - byte[] toByteArray() { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - - byteArrayOutputStream.write(ISCConstants.isc_spb_version); - byteArrayOutputStream.write(ISCConstants.isc_spb_current_version); - - try { - super.writeArgumentsTo(byteArrayOutputStream); - } catch (IOException e) { - // Ignoring IOException, not thrown by ByteArrayOutputStream - } - - return byteArrayOutputStream.toByteArray(); - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceRequestBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceRequestBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/ServiceRequestBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,142 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.jni; - -import org.firebirdsql.encodings.Encoding; -import org.firebirdsql.gds.ServiceRequestBuffer; -import org.firebirdsql.gds.impl.ParameterBufferBase; -import org.firebirdsql.gds.impl.argument.NumericArgument; -import org.firebirdsql.gds.impl.argument.StringArgument; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * ngds implementation for ServiceRequestBufferImp. - */ -class ServiceRequestBufferImp extends ParameterBufferBase implements ServiceRequestBuffer { - - private final int taskIdentifier; - - /** - * Every ServiceRequestBuffer has an associated taskIdentifier. - * - * @param taskIdentifier - * Service request task - */ - ServiceRequestBufferImp(int taskIdentifier) { - this.taskIdentifier = taskIdentifier; - } - - @Override - public void addArgument(int argumentType, String value) { - getArgumentsList().add(new ServiceStringArgument(argumentType, value)); - } - - @Override - public void addArgument(int argumentType, String value, Encoding encoding) { - getArgumentsList().add(new ServiceStringArgument(argumentType, value, encoding)); - } - - @Override - public void addArgument(int argumentType, int value) { - getArgumentsList().add(new NumericArgument(argumentType, value) { - - @Override - public int getLength() { - return 5; - } - - @Override - protected void writeValue(OutputStream outputStream, int value) throws IOException { - outputStream.write(value); - outputStream.write(value >> 8); - outputStream.write(value >> 16); - outputStream.write(value >> 24); - } - }); - } - - @Override - public void addArgument(int argumentType, byte value) { - getArgumentsList().add(new NumericArgument(argumentType, value) { - - @Override - public int getLength() { - return 2; - } - - @Override - protected void writeValue(OutputStream outputStream, final int value) throws IOException { - outputStream.write(value); - } - }); - } - - /** - * Package local method for obtaining buffer suitable for passing to native - * method. - * - * @return Buffer for native method - */ - byte[] toByteArray() { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - byteArrayOutputStream.write(taskIdentifier); - - try { - super.writeArgumentsTo(byteArrayOutputStream); - } catch (IOException e) { - // Ignoring IOException, not thrown by ByteArrayOutputStream - } - - return byteArrayOutputStream.toByteArray(); - } - - private static final class ServiceStringArgument extends StringArgument { - - @Deprecated - public ServiceStringArgument(int argumentType, String value) { - super(argumentType, value); - } - - public ServiceStringArgument(int argumentType, String value, Encoding encoding) { - super(argumentType, value, encoding); - } - - @Override - public int getLength() { - return super.getLength() + 1; - } - - @Override - protected void writeLength(int length, OutputStream outputStream) throws IOException { - outputStream.write(length); - outputStream.write(length >> 8); - } - - @Override - protected int getMaxSupportedLength() { - // TODO Check if this might be signed - return 65535; - } - } -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/TransactionParameterBufferImpl.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,59 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.jni; - -import org.firebirdsql.gds.ISCConstants; -import org.firebirdsql.gds.TransactionParameterBuffer; -import org.firebirdsql.gds.impl.ParameterBufferBase; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -public class TransactionParameterBufferImpl extends ParameterBufferBase implements TransactionParameterBuffer { - - @Override - public TransactionParameterBuffer deepCopy() { - TransactionParameterBufferImpl result = new TransactionParameterBufferImpl(); - - result.getArgumentsList().addAll(this.getArgumentsList()); - - return result; - } - - /** - * Method for obtaining buffer suitable for passing to native method. - * - * @return Buffer for native method - */ - public byte[] getBytesForNativeCode() { - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - - byteArrayOutputStream.write(ISCConstants.isc_tpb_version3); - - try { - writeArgumentsTo(byteArrayOutputStream); - } catch (IOException e) { - // Ignoring IOException, not thrown by ByteArrayOutputStream - } - - return byteArrayOutputStream.toByteArray(); - } -} 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 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,8 +1,8 @@ /* * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver * + * Firebird Open Source JavaEE Connector - JDBC Driver + * * Distributable under LGPL license. * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html * @@ -14,7 +14,7 @@ * 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. + * can be obtained from a source control history command. * * All rights reserved. */ @@ -30,10 +30,7 @@ import org.firebirdsql.encodings.EncodingDefinition; import org.firebirdsql.encodings.EncodingFactory; import org.firebirdsql.gds.*; -import org.firebirdsql.gds.impl.AbstractGDS; -import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension; -import org.firebirdsql.gds.impl.DbAttachInfo; -import org.firebirdsql.gds.impl.GDSType; +import org.firebirdsql.gds.impl.*; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -111,11 +108,11 @@ db.out.writeString(dbai.getFileName(), filenameEncoding); databaseParameterBuffer = ((DatabaseParameterBufferExtension) - databaseParameterBuffer).removeExtensionParams(); + databaseParameterBuffer).removeExtensionParams(); addProcessId(databaseParameterBuffer); addProcessName(databaseParameterBuffer); - db.out.writeTyped(ISCConstants.isc_dpb_version1, (Xdrable) databaseParameterBuffer); + db.out.writeTyped(databaseParameterBuffer); db.out.flush(); if (debug) log.debug("sent"); @@ -688,8 +685,7 @@ svc.out.writeInt(0); svc.out.writeString(serviceMgrStr, svc.getEncodingFactory().getDefaultEncoding()); - svc.out.writeTyped(ISCConstants.isc_spb_version, - (Xdrable) serviceParameterBuffer); + svc.out.writeTyped(serviceParameterBuffer); svc.out.flush(); if (debug) @@ -877,7 +873,7 @@ svc.out.writeInt(svc.getHandle()); svc.out.writeInt(0); - svc.out.writeBuffer(svcBuff.toByteArray()); + svc.out.writeBuffer(svcBuff.toBytes()); svc.out.flush(); receiveResponse(svc, -1); @@ -891,14 +887,10 @@ } } - public void iscServiceQuery(IscSvcHandle serviceHandle, - ServiceParameterBuffer serviceParameterBuffer, - ServiceRequestBuffer serviceRequestBuffer, byte[] resultBuffer) - throws GDSException { + public void iscServiceQuery(IscSvcHandle serviceHandle, ServiceParameterBuffer serviceParameterBuffer, + ServiceRequestBuffer serviceRequestBuffer, byte[] resultBuffer) throws GDSException { isc_svc_handle_impl svc = (isc_svc_handle_impl) serviceHandle; - ServiceParameterBufferImp spb = (ServiceParameterBufferImp) serviceParameterBuffer; - ServiceRequestBufferImp srb = (ServiceRequestBufferImp) serviceRequestBuffer; if (svc == null || svc.out == null) throw new GDSException(ISCConstants.isc_bad_svc_handle); @@ -907,8 +899,8 @@ svc.out.writeInt(op_service_info); svc.out.writeInt(svc.getHandle()); svc.out.writeInt(0); - svc.out.writeBuffer(spb != null ? spb.toByteArray() : null); - svc.out.writeBuffer(srb != null ? srb.toByteArray() : null); + svc.out.writeBuffer(serviceParameterBuffer != null ? serviceParameterBuffer.toBytes() : null); + svc.out.writeBuffer(serviceRequestBuffer != null ? serviceRequestBuffer.toBytes() : null); svc.out.writeInt(resultBuffer.length); svc.out.flush(); Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/BlobParameterBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/BlobParameterBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/BlobParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,29 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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 source control history command. - * - * All rights reserved. - */ -package org.firebirdsql.gds.impl.wire; - -import org.firebirdsql.gds.BlobParameterBuffer; - -/** - * jdgs implementation for BlobParameterBuffer. The base class ParameterBufferBase contains the implementation. - */ -public class BlobParameterBufferImp extends ParameterBufferBase implements BlobParameterBuffer { -} Deleted: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/DatabaseParameterBufferImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/DatabaseParameterBufferImp.java 2015-02-14 08:11:48 UTC (rev 60684) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/DatabaseParameterBufferImp.java 2015-02-14 13:17:53 UTC (rev 60685) @@ -1,53 +0,0 @@ -/* - * $Id$ - * - * Firebird Open Source JavaEE 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) o... [truncated message content] |
From: <mro...@us...> - 2015-02-14 14:18:26
|
Revision: 60688 http://sourceforge.net/p/firebird/code/60688 Author: mrotteveel Date: 2015-02-14 14:18:18 +0000 (Sat, 14 Feb 2015) Log Message: ----------- Move iscVax* methods to helper class as they are not implementation dependent Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbTransaction.java client-java/trunk/src/main/org/firebirdsql/gds/ng/BlobLengthProcessor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/ExecutionPlanProcessor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/SqlCountProcessor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10InputBlob.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java client-java/trunk/src/test/org/firebirdsql/management/TestBackupManager.java client-java/trunk/src/test/org/firebirdsql/management/TestFBManager.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/VaxEncoding.java Added: client-java/trunk/src/main/org/firebirdsql/gds/VaxEncoding.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/VaxEncoding.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/VaxEncoding.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -0,0 +1,113 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds; + +/** + * Helper methods for decoding Vax style (little endian) integers as used by Firebird from byte arrays. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public final class VaxEncoding { + + private VaxEncoding() { + // No instances + } + + /** + * Reads Vax style integers from the supplied buffer, starting at {@code startPosition} and reading for + * {@code length} bytes. + * <p> + * This method is useful for lengths up to 4 bytes (ie normal Java integers ({@code int}). For larger lengths it + * will return {@code 0}. Use {@link #iscVaxLong(byte[], int, int)} for reading values with length up to 8 bytes. + * For decoding 2 byte integers, use {@link #iscVaxInteger2(byte[], int)}. + * </p> + * + * @param buffer + * The byte array from which the integer is to be retrieved + * @param startPosition + * The offset starting position from which to start retrieving byte values + * @return The integer value retrieved from the bytes + * @see #iscVaxLong(byte[], int, int) + * @see #iscVaxInteger2(byte[], int) + */ + public static int iscVaxInteger(final byte[] buffer, final int startPosition, int length) { + if (length > 4) { + return 0; + } + int value = 0; + int shift = 0; + + int index = startPosition; + while (--length >= 0) { + value += (buffer[index++] & 0xff) << shift; + shift += 8; + } + return value; + } + + /** + * Reads Vax style integers from the supplied buffer, starting at {@code startPosition} and reading for + * {@code length} bytes. + * <p> + * This method is useful for lengths up to 8 bytes (ie normal Java longs ({@code long}). For larger lengths it will + * return {@code 0}. + * </p> + * + * @param buffer + * The byte array from which the integer is to be retrieved + * @param startPosition + * The offset starting position from which to start retrieving byte values + * @return The integer value retrieved from the bytes + * @see #iscVaxLong(byte[], int, int) + * @see #iscVaxInteger2(byte[], int) + */ + public static long iscVaxLong(final byte[] buffer, final int startPosition, int length) { + if (length > 8) { + return 0; + } + long value = 0; + int shift = 0; + + int index = startPosition; + while (--length >= 0) { + value += (buffer[index++] & 0xffL) << shift; + shift += 8; + } + return value; + } + + /** + * Variant of {@link #iscVaxInteger(byte[], int, int)} specifically for two-byte integers. + * + * @param buffer + * The byte array from which the integer is to be retrieved + * @param startPosition + * The offset starting position from which to start retrieving byte values + * @return The integer value retrieved from the bytes + * @see #iscVaxInteger(byte[], int, int) + * @see #iscVaxLong(byte[], int, int) + */ + public static int iscVaxInteger2(final byte[] buffer, final int startPosition) { + return (buffer[startPosition] & 0xff) | ((buffer[startPosition + 1] & 0xff) << 8); + } + +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/VaxEncoding.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbDatabase.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbDatabase.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -37,6 +37,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.firebirdsql.gds.ISCConstants.*; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; /** * Abstract implementation of {@link org.firebirdsql.gds.ng.FbDatabase} with behavior common to the various @@ -52,8 +54,7 @@ /** * Info-request block for database information. * <p> - * TODO Move to FbDatabase interface? Will this vary with versions of - * Firebird? + * TODO Move to FbDatabase interface? Will this vary with versions of Firebird? * </p> */ // @formatter:off @@ -311,43 +312,6 @@ return infoProcessor.process(responseBuffer); } - @Override - public int iscVaxInteger(final byte[] buffer, final int startPosition, int length) { - if (length > 4) { - return 0; - } - int value = 0; - int shift = 0; - - int index = startPosition; - while (--length >= 0) { - value += (buffer[index++] & 0xff) << shift; - shift += 8; - } - return value; - } - - @Override - public long iscVaxLong(final byte[] buffer, final int startPosition, int length) { - if (length > 8) { - return 0; - } - long value = 0; - int shift = 0; - - int index = startPosition; - while (--length >= 0) { - value += (buffer[index++] & 0xffL) << shift; - shift += 8; - } - return value; - } - - @Override - public int iscVaxInteger2(final byte[] buffer, final int startPosition) { - return (buffer[startPosition] & 0xff) | ((buffer[startPosition + 1] & 0xff) << 8); - } - protected byte[] getDescribeDatabaseInfoBlock() { return DESCRIBE_DATABASE_INFO_BLOCK; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbTransaction.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbTransaction.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/AbstractFbTransaction.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -29,6 +29,9 @@ import java.util.EnumSet; import java.util.Set; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; +import static org.firebirdsql.gds.VaxEncoding.iscVaxLong; + /** * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> * @since 3.0 @@ -114,8 +117,8 @@ // TODO Message, SQL state, error code? throw new SQLException("Unexpected response buffer"); } - int length = getDatabase().iscVaxInteger2(infoResponse, 1); - return getDatabase().iscVaxLong(infoResponse, 3, length); + int length = iscVaxInteger2(infoResponse, 1); + return iscVaxLong(infoResponse, 3, length); } }); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/BlobLengthProcessor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/BlobLengthProcessor.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/BlobLengthProcessor.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -24,6 +24,9 @@ import java.sql.SQLException; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; +import static org.firebirdsql.gds.VaxEncoding.iscVaxLong; + /** * Blob information processor for retrieving blob length. * @@ -47,8 +50,8 @@ if (infoResponse.length == 0 || infoResponse[0] != ISCConstants.isc_info_blob_total_length) throw new FbExceptionBuilder().exception(ISCConstants.isc_req_sync).toSQLException(); - int dataLength = blob.getDatabase().iscVaxInteger2(infoResponse, 1); - return blob.getDatabase().iscVaxLong(infoResponse, 3, dataLength); + int dataLength = iscVaxInteger2(infoResponse, 1); + return iscVaxLong(infoResponse, 3, dataLength); } public byte[] getBlobLengthItems() { Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/ExecutionPlanProcessor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/ExecutionPlanProcessor.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/ExecutionPlanProcessor.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -24,6 +24,8 @@ import java.sql.SQLException; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; + /** * InfoProcessor to retrieve the (normal) execution plan of a statement. * @@ -64,7 +66,7 @@ throw new FbExceptionBuilder().exception(ISCConstants.isc_infunk).toSQLException(); } - int len = statement.getDatabase().iscVaxInteger2(buffer, 1); + int len = iscVaxInteger2(buffer, 1); if (len > 1) { // Trimming, because first character is a linefeed (0x0A) // Not skipping to prevent (potential) encoding issues Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -29,7 +29,6 @@ import org.firebirdsql.encodings.Encoding; import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.BlobParameterBuffer; -import org.firebirdsql.gds.DatabaseParameterBuffer; import org.firebirdsql.gds.TransactionParameterBuffer; import org.firebirdsql.gds.impl.GDSServerVersion; import org.firebirdsql.gds.ng.listeners.DatabaseListener; @@ -287,62 +286,4 @@ */ void removeDatabaseListener(DatabaseListener listener); - /** - * Reads Vax style integers from the supplied buffer, starting at - * <code>startPosition</code> and reading for <code>length</code> bytes. - * <p> - * This method is useful for lengths up to 4 bytes (ie normal Java integers - * (<code>int</code>). For larger lengths it will return 0. Use - * {@link #iscVaxLong(byte[], int, int)} for reading values with length up - * to 8 bytes. - * </p> - * - * @param buffer - * The byte array from which the integer is to be retrieved - * @param startPosition - * The offset starting position from which to start retrieving - * byte values - * @return The integer value retrieved from the bytes - * @see #iscVaxLong(byte[], int, int) - * @see #iscVaxInteger2(byte[], int) - */ - int iscVaxInteger(byte[] buffer, int startPosition, int length); - - /** - * Reads Vax style integers from the supplied buffer, starting at - * <code>startPosition</code> and reading for <code>length</code> bytes. - * <p> - * This method is useful for lengths up to 8 bytes (ie normal Java longs ( - * <code>long</code>). For larger lengths it will return 0. - * </p> - * - * @param buffer - * The byte array from which the integer is to be retrieved - * @param startPosition - * The offset starting position from which to start retrieving - * byte values - * @return The integer value retrieved from the bytes - * @see #iscVaxLong(byte[], int, int) - * @see #iscVaxInteger2(byte[], int) - */ - long iscVaxLong(byte[] buffer, int startPosition, int length); - - /** - * Variant of {@link #iscVaxInteger(byte[], int, int)} specifically - * for two-byte integers. - * <p> - * Implementations can either delegate to {@link #iscVaxInteger(byte[], int, int)}, - * or implement an optimized version. - * </p> - * - * @param buffer - * The byte array from which the integer is to be retrieved - * @param startPosition - * The offset starting position from which to start retrieving - * byte values - * @return The integer value retrieved from the bytes - * @see #iscVaxInteger(byte[], int, int) - * @see #iscVaxLong(byte[], int, int) - */ - int iscVaxInteger2(byte[] buffer, int startPosition); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/SqlCountProcessor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/SqlCountProcessor.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/SqlCountProcessor.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -24,6 +24,9 @@ import java.sql.SQLException; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; +import static org.firebirdsql.gds.VaxEncoding.iscVaxLong; + /** * Info processor for retrieving affected record count. * @@ -56,9 +59,9 @@ long selectCount = 0; int t; while ((t = infoResponse[pos++]) != ISCConstants.isc_info_end) { - final int countLength = statement.getDatabase().iscVaxInteger2(infoResponse, pos); + final int countLength = iscVaxInteger2(infoResponse, pos); pos += 2; - final long count = statement.getDatabase().iscVaxLong(infoResponse, pos, countLength); + final long count = iscVaxLong(infoResponse, pos, countLength); switch (t) { case ISCConstants.isc_info_req_select_count: selectCount = count; Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/StatementInfoProcessor.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -28,6 +28,9 @@ import java.sql.SQLException; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; + /** * InfoProcessor to retrieve the statement information associated with {@link org.firebirdsql.gds.ng.AbstractFbStatement#getStatementInfoRequestItems()} * and {@link org.firebirdsql.gds.ng.AbstractFbStatement#getParameterDescriptionInfoRequestItems()}. @@ -232,15 +235,15 @@ } private int readIntValue(StatementInfo info) { - int len = database.iscVaxInteger2(info.buffer, info.currentIndex); + int len = iscVaxInteger2(info.buffer, info.currentIndex); info.currentIndex += 2; - int value = database.iscVaxInteger(info.buffer, info.currentIndex, len); + int value = iscVaxInteger(info.buffer, info.currentIndex, len); info.currentIndex += len; return value; } private String readStringValue(StatementInfo info) { - int len = database.iscVaxInteger2(info.buffer, info.currentIndex); + int len = iscVaxInteger2(info.buffer, info.currentIndex); info.currentIndex += 2; // TODO use correct characterset String value = new String(info.buffer, info.currentIndex, len); Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10InputBlob.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10InputBlob.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10InputBlob.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -31,6 +31,7 @@ import java.io.IOException; import java.sql.SQLException; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.*; /** @@ -131,7 +132,7 @@ final ByteArrayOutputStream bos = new ByteArrayOutputStream(actualSize); int position = 0; while (position < responseBuffer.length) { - int segmentLength = database.iscVaxInteger2(responseBuffer, position); + int segmentLength = iscVaxInteger2(responseBuffer, position); position += 2; bos.write(responseBuffer, position, segmentLength); position += segmentLength; Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBConnection.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -375,7 +375,7 @@ while(reply[i] != ISCConstants.isc_info_end) { switch(reply[i++]) { case ISCConstants.isc_info_user_names : - database.iscVaxInteger(reply, i, 2); // can be ignored + //iscVaxInteger2(reply, i); // can be ignored i += 2; int strLen = reply[i] & 0xff; i += 1; Modified: client-java/trunk/src/test/org/firebirdsql/management/TestBackupManager.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/management/TestBackupManager.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/test/org/firebirdsql/management/TestBackupManager.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -15,6 +15,8 @@ import static org.firebirdsql.common.FBTestProperties.*; import static org.firebirdsql.common.JdbcResourceHelper.closeQuietly; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; /** * TODO: This test assumes it is run against localhost @@ -191,8 +193,8 @@ final byte[] databaseInfo = currentDatabase.getDatabaseInfo( new byte[] { ISCConstants.isc_info_page_size }, 10); assertEquals("Unexpected info item", ISCConstants.isc_info_page_size, databaseInfo[0]); - int length = currentDatabase.iscVaxInteger2(databaseInfo, 1); - int pageSize = currentDatabase.iscVaxInteger(databaseInfo, 3, length); + int length = iscVaxInteger2(databaseInfo, 1); + int pageSize = iscVaxInteger(databaseInfo, 3, length); assertEquals("Unexpected page size", 16384, pageSize); } finally { closeQuietly(con); Modified: client-java/trunk/src/test/org/firebirdsql/management/TestFBManager.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/management/TestFBManager.java 2015-02-14 13:50:15 UTC (rev 60687) +++ client-java/trunk/src/test/org/firebirdsql/management/TestFBManager.java 2015-02-14 14:18:18 UTC (rev 60688) @@ -30,6 +30,8 @@ import java.sql.DriverManager; import static org.firebirdsql.common.FBTestProperties.*; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger; +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2; import static org.junit.Assert.*; /** @@ -102,8 +104,8 @@ final byte[] databaseInfo = currentDatabase.getDatabaseInfo( new byte[] { ISCConstants.isc_info_page_size }, 10); assertEquals("Unexpected info item", ISCConstants.isc_info_page_size, databaseInfo[0]); - int length = currentDatabase.iscVaxInteger2(databaseInfo, 1); - int pageSize = currentDatabase.iscVaxInteger(databaseInfo, 3, length); + int length = iscVaxInteger2(databaseInfo, 1); + int pageSize = iscVaxInteger(databaseInfo, 3, length); assertEquals("Unexpected page size", 16384, pageSize); } finally { connection.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-02-15 15:00:53
|
Revision: 60697 http://sourceforge.net/p/firebird/code/60697 Author: mrotteveel Date: 2015-02-15 15:00:50 +0000 (Sun, 15 Feb 2015) Log Message: ----------- Minor code reformatting/cleanup Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/test/org/firebirdsql/event/TestFBEventManager.java Modified: client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-02-15 13:48:56 UTC (rev 60696) +++ client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-02-15 15:00:50 UTC (rev 60697) @@ -49,6 +49,7 @@ import org.firebirdsql.gds.impl.GDSType; import org.firebirdsql.gds.impl.GDSFactory; import org.firebirdsql.jdbc.FBSQLException; +import org.firebirdsql.util.SQLExceptionChainBuilder; import java.util.Map; import java.util.Set; @@ -61,7 +62,7 @@ import java.sql.SQLException; /** - * An <code>EventListener</code> implementation to listen for database events. + * An {@link org.firebirdsql.event.EventManager} implementation to listen for database events. * * @author <a href="mailto:gab...@us...">Gabriel Reid</a> */ @@ -93,8 +94,7 @@ public void connect() throws SQLException { if (connected){ - throw new IllegalStateException( - "Connect called while already connected"); + throw new IllegalStateException("Connect called while already connected"); } DatabaseParameterBuffer dpb = gds.createDatabaseParameterBuffer(); dpb.addArgument(DatabaseParameterBuffer.USER, user); @@ -114,14 +114,14 @@ public void disconnect() throws SQLException { if (!connected){ - throw new IllegalStateException( - "Disconnect called while not connected"); + throw new IllegalStateException("Disconnect called while not connected"); } + SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<SQLException>(); for (String eventName : new HashSet<String>(handlerMap.keySet())) { try { unregisterListener(eventName); } catch (GDSException e1){ - throw new FBSQLException(e1); + chain.append(new FBSQLException(e1)); } } @@ -131,18 +131,19 @@ try { gds.iscDetachDatabase(dbHandle); } catch (GDSException e2){ - throw new FBSQLException(e2); + chain.append(new FBSQLException(e2)); } connected = false; eventDispatcher.stop(); - + // join the thread and wait until it dies try { dispatchThread.join(); } catch(InterruptedException ex) { - throw new FBSQLException(ex); + chain.append(new FBSQLException(ex)); } + if (chain.hasException()) throw chain.getException(); } public boolean isConnected() { @@ -190,11 +191,11 @@ } /** - * Get the time in milliseconds, after which the async threa will exit from - * the {@link Object#wait(long)} method and check whether it was stopped or - * not. + * Get the time in milliseconds, after which the async thread will exit from the {@link Object#wait(long)} method + * and check whether it was stopped or not. * <p> - * Default value is 1000 (1 second); + * Default value is 1000 (1 second). + * </p> * * @return wait timeout in milliseconds */ @@ -202,13 +203,12 @@ return waitTimeout; } - /** - * Set the time in milliseconds, after which the async threa will exit from - * the {@link Object#wait(long)} method and check whether it was stopped or - * not. + * Set the time in milliseconds, after which the async thread will exit from the {@link Object#wait(long)} method + * and check whether it was stopped or not. * <p> - * Default value is 1000 (1 second); + * Default value is 1000 (1 second). + * </p> * * @param waitTimeout wait timeout in milliseconds */ @@ -216,11 +216,9 @@ this.waitTimeout = waitTimeout; } - public void addEventListener( - String eventName, EventListener listener) throws SQLException { + public void addEventListener(String eventName, EventListener listener) throws SQLException { if (!connected){ - throw new IllegalStateException( - "Can't add event listeners to disconnected EventManager"); + throw new IllegalStateException("Can't add event listeners to disconnected EventManager"); } if (listener == null || eventName == null){ throw new NullPointerException(); @@ -239,8 +237,7 @@ } } - public void removeEventListener( - String eventName, EventListener listener) throws SQLException { + public void removeEventListener(String eventName, EventListener listener) throws SQLException { if (eventName == null || listener == null){ throw new NullPointerException(); } @@ -258,16 +255,13 @@ } } - public int waitForEvent(String eventName) - throws InterruptedException, SQLException { + public int waitForEvent(String eventName) throws InterruptedException, SQLException { return waitForEvent(eventName, 0); } - public int waitForEvent(String eventName, final int timeout) - throws InterruptedException, SQLException { + public int waitForEvent(String eventName, final int timeout) throws InterruptedException, SQLException { if (!connected){ - throw new IllegalStateException( - "Can't wait for events with disconnected EventManager"); + throw new IllegalStateException("Can't wait for events with disconnected EventManager"); } if (eventName == null){ throw new NullPointerException(); @@ -308,16 +302,14 @@ public synchronized void register() throws GDSException { if (cancelled){ - throw new IllegalStateException( - "Trying to register a cancelled event handler"); + throw new IllegalStateException("Trying to register a cancelled event handler"); } gds.iscQueueEvents(dbHandle, eventHandle, this); } public synchronized void unregister() throws GDSException { if (cancelled){ - throw new IllegalStateException( - "Trying to cancel a cancelled event handler"); + throw new IllegalStateException("Trying to cancel a cancelled event handler"); } gds.iscCancelEvents(dbHandle, eventHandle); cancelled = true; @@ -332,11 +324,8 @@ } if (initialized && !cancelled){ + DatabaseEvent event = new DatabaseEventImpl(eventHandle.getEventName(), eventHandle.getEventCount()); - DatabaseEvent event = new DatabaseEventImpl( - eventHandle.getEventName(), - eventHandle.getEventCount()); - synchronized (eventQueue){ eventQueue.add(event); eventQueue.notify(); @@ -365,7 +354,7 @@ public void run(){ running = true; - List<DatabaseEvent> events = new ArrayList<DatabaseEvent>(); + final List<DatabaseEvent> events = new ArrayList<DatabaseEvent>(); while (running){ synchronized (eventQueue){ while (eventQueue.isEmpty() && running){ @@ -378,9 +367,8 @@ } for (DatabaseEvent event : events) { - Set<EventListener> listenerSet = null; synchronized (listenerMap){ - listenerSet = listenerMap.get(event.getEventName()); + Set<EventListener> listenerSet = listenerMap.get(event.getEventName()); if (listenerSet != null){ for (EventListener listener : listenerSet) { listener.eventOccurred(event); @@ -392,14 +380,13 @@ } } } - } class OneTimeEventListener implements EventListener { private int eventCount = -1; - private Object lock; + private final Object lock; public OneTimeEventListener(Object lock){ this.lock = lock; 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 2015-02-15 13:48:56 UTC (rev 60696) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2015-02-15 15:00:50 UTC (rev 60697) @@ -360,9 +360,8 @@ if (debug) log.debug("op_accept "); - - int nextOperation = nextOperation(in); - return nextOperation; + + return nextOperation(in); } private String getSystemUser() { @@ -978,19 +977,12 @@ db.in.readRawBuffer(respLen); readStatusVector(db); - db.eventCoordinator = - new EventCoordinatorImp(auxHandle, ipAddress, port); + db.eventCoordinator = new EventCoordinatorImp(auxHandle, ipAddress, port); } - db.eventCoordinator.queueEvents( - db, - (EventHandleImp)eventHandle, - eventHandler); + db.eventCoordinator.queueEvents(db, (EventHandleImp) eventHandle, eventHandler); } catch (IOException ioe){ - throw new GDSException( - ISCConstants.isc_arg_gds, - ISCConstants.isc_net_read_err, - ioe.getMessage()); + throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_net_read_err, ioe.getMessage()); } } @@ -1047,11 +1039,10 @@ private final int port; private int eventsId; isc_db_handle_impl db; - private final Map<String, EventGlob> globMap = Collections.synchronizedMap(new HashMap<String, EventGlob>()); + private final Map<Integer, EventGlob> globMap = Collections.synchronizedMap(new HashMap<Integer, EventGlob>()); private volatile boolean running = true; - public EventCoordinatorImp(int handle, String ipAddress, int port) - throws GDSException { + public EventCoordinatorImp(int handle, String ipAddress, int port) throws GDSException { this.handle = handle; this.ipAddress = ipAddress; this.port = port; @@ -1062,8 +1053,7 @@ } public boolean cancelEvents(EventHandleImp eventHandle){ - return globMap.remove( - Integer.toString(eventHandle.getLocalId())) != null; + return globMap.remove(eventHandle.getLocalId()) != null; } public void run(){ @@ -1092,14 +1082,13 @@ int shift = 0; if (buffer.length > 4) { - for (int i = buffer.length - 4; - i < buffer.length; i++){ + for (int i = buffer.length - 4; i < buffer.length; i++){ count += ((buffer[i] & 0xff) << shift); shift += 8; } } - EventGlob glob = globMap.remove(Integer.toString(eventId)); + EventGlob glob = globMap.remove(eventId); if (glob != null){ glob.getEventHandle().setInternalCount(count); glob.getEventHandler().eventOccurred(); @@ -1137,15 +1126,9 @@ db.out = new XdrOutputStream(db.socket.getOutputStream()); db.in = new XdrInputStream(db.socket.getInputStream()); } catch (UnknownHostException uhe){ - throw new GDSException( - ISCConstants.isc_arg_gds, - ISCConstants.isc_network_error, - ipAddress, uhe); + throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error, ipAddress, uhe); } catch (IOException ioe){ - throw new GDSException( - ISCConstants.isc_arg_gds, - ISCConstants.isc_network_error, - ipAddress, ioe); + throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error, ipAddress, ioe); } } @@ -1157,9 +1140,8 @@ db.invalidate(); } - public void queueEvents(isc_db_handle_impl mainDb, - EventHandleImp eventHandle, - EventHandler eventHandler) throws GDSException { + public void queueEvents(isc_db_handle_impl mainDb, EventHandleImp eventHandle, EventHandler eventHandler) + throws GDSException { synchronized (mainDb){ try { synchronized (globMap){ @@ -1176,16 +1158,11 @@ receiveResponse(mainDb,-1); int eventId = mainDb.getResp_object(); eventHandle.setEventId(eventId); - globMap.put( - Integer.toString(eventHandle.getLocalId()), - new EventGlob(eventHandler, eventHandle)); + globMap.put(eventHandle.getLocalId(), new EventGlob(eventHandler, eventHandle)); } } catch (IOException ioe){ - throw new GDSException( - ISCConstants.isc_arg_gds, - ISCConstants.isc_net_read_err, - ioe.getMessage()); + throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_net_read_err, ioe.getMessage()); } } } Modified: client-java/trunk/src/test/org/firebirdsql/event/TestFBEventManager.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/event/TestFBEventManager.java 2015-02-15 13:48:56 UTC (rev 60696) +++ client-java/trunk/src/test/org/firebirdsql/event/TestFBEventManager.java 2015-02-15 15:00:50 UTC (rev 60697) @@ -256,13 +256,13 @@ class AccumulatingEventListener implements EventListener { - private int eventCount = 0; + private volatile int eventCount = 0; public int getTotalEvents(){ return eventCount; } - public void eventOccurred(DatabaseEvent event){ + public synchronized void eventOccurred(DatabaseEvent event){ eventCount += event.getEventCount(); } } @@ -278,8 +278,7 @@ public void run(){ try { Connection conn = getConnectionViaDriverManager(); - PreparedStatement stmt = conn.prepareStatement( - "INSERT INTO TEST VALUES (?)"); + PreparedStatement stmt = conn.prepareStatement("INSERT INTO TEST VALUES (?)"); try { for (int i = 0; i < count; i++){ stmt.setInt(1, i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-03-07 10:40:26
|
Revision: 60855 http://sourceforge.net/p/firebird/code/60855 Author: mrotteveel Date: 2015-03-07 10:40:23 +0000 (Sat, 07 Mar 2015) Log Message: ----------- Miscellaneous fixes suggested by findbugs Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/ByteArrayArgument.java client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/NumericArgument.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestMultithreadedAccess.java Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java 2015-03-07 10:00:13 UTC (rev 60854) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/GDSFactory.java 2015-03-07 10:40:23 UTC (rev 60855) @@ -30,6 +30,7 @@ import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; +import java.io.Serializable; import java.util.*; import java.util.Map.Entry; @@ -50,7 +51,7 @@ * puts the most short JDBC URLs at the end of the list, so the correct * default protocol handling can be implemented. */ - private static class ReversedStringComparator implements Comparator<String> { + private static class ReversedStringComparator implements Comparator<String>, Serializable { public int compare(String s1, String s2) { // note, we compare here s2 to s1, Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/ByteArrayArgument.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/ByteArrayArgument.java 2015-03-07 10:00:13 UTC (rev 60854) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/ByteArrayArgument.java 2015-03-07 10:40:23 UTC (rev 60855) @@ -94,4 +94,12 @@ return this.getType() == otherByteArrayArgument.getType() && Arrays.equals(this.value, otherByteArrayArgument.value); } + + @Override + public int hashCode() { + int result = 23; + result = 41 * result + getType(); + result = 41 * result + Arrays.hashCode(value); + return result; + } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/NumericArgument.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/NumericArgument.java 2015-03-07 10:00:13 UTC (rev 60854) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/argument/NumericArgument.java 2015-03-07 10:40:23 UTC (rev 60855) @@ -74,4 +74,12 @@ return this.getType() == otherNumericArgument.getType() && this.value == otherNumericArgument.value; } + + @Override + public int hashCode() { + int result = 23; + result = 41 * result + getType(); + result = 41 * result + value; + return result; + } } Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestMultithreadedAccess.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestMultithreadedAccess.java 2015-03-07 10:00:13 UTC (rev 60854) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestMultithreadedAccess.java 2015-03-07 10:40:23 UTC (rev 60855) @@ -214,10 +214,8 @@ protected ResultSet executeQuery(int id) throws SQLException { String sql = MessageFormat.format( - sqlTemplate, - new Object[]{ - new Integer(id) - }); + sqlTemplate, + id); System.out.println(sql); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-03-08 13:19:53
|
Revision: 60873 http://sourceforge.net/p/firebird/code/60873 Author: mrotteveel Date: 2015-03-08 13:19:50 +0000 (Sun, 08 Mar 2015) Log Message: ----------- JDBC-384 Fix for LibreOffice doesn't display tables with more than 41 records * enforce holdability to hold cursors over commit always for OOREMOTE protocol * remove separate OOStatement and OOPreparedStatement as they are not needed (and their creation in OOConnection was incorrect) * removal of unnecessary metadata overrides Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/logging/ConsoleLogger.java client-java/trunk/src/main/org/firebirdsql/logging/Logger.java client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOConnection.java client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OODatabaseMetaData.java client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java Added Paths: ----------- client-java/trunk/src/test/org/firebirdsql/jdbc/TestAutoCommitBehaviour.java Removed Paths: ------------- client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOPreparedStatement.java client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOStatement.java Modified: client-java/trunk/src/main/org/firebirdsql/logging/ConsoleLogger.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/logging/ConsoleLogger.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/main/org/firebirdsql/logging/ConsoleLogger.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -27,7 +27,7 @@ */ final class ConsoleLogger implements Logger { - private static final boolean debugEnabled = true; + private static final boolean debugEnabled = false; private static final boolean traceEnabled = true; private static final boolean infoEnabled = true; private static final boolean warnEnabled = true; Modified: client-java/trunk/src/main/org/firebirdsql/logging/Logger.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/logging/Logger.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/main/org/firebirdsql/logging/Logger.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -27,7 +27,7 @@ * @author <a href="mailto:br...@us...">Blas Rodriguez Somoza</a> * @version 1.0 */ -public interface Logger{ +public interface Logger { boolean isDebugEnabled(); 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 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -1,8 +1,8 @@ /* * $Id$ - * - * Firebird Open Source J2ee connector - jdbc driver * + * Firebird Open Source JavaEE Connector - JDBC Driver + * * Distributable under LGPL license. * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html * @@ -14,7 +14,7 @@ * 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. + * can be obtained from a source control history command. * * All rights reserved. */ @@ -31,8 +31,7 @@ private static final String[] TYPE_ALIASES = new String[] {}; - private static final String[] JDBC_PROTOCOLS = new String[] { - "jdbc:firebird:oo:", "jdbc:firebirdsql:oo:"}; + private static final String[] JDBC_PROTOCOLS = new String[] { "jdbc:firebird:oo:", "jdbc:firebirdsql:oo:"}; public String getPluginName() { return "GDS implementation for OpenOffice."; @@ -55,11 +54,9 @@ return JDBC_PROTOCOLS; } - public String getDatabasePath(String server, Integer port, String path) - throws GDSException { + public String getDatabasePath(String server, Integer port, String path) throws GDSException { if (server == null) - throw new GDSException("Server name/address is required " - + "for pure Java implementation."); + throw new GDSException("Server name/address is required for pure Java implementation."); if (path == null) throw new GDSException("Database name/path is required."); Modified: client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOConnection.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOConnection.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOConnection.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -20,46 +20,44 @@ */ package org.firebirdsql.jdbc.oo; -import java.sql.*; - import org.firebirdsql.jca.FBManagedConnection; -import org.firebirdsql.jdbc.*; +import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.logging.Logger; +import org.firebirdsql.logging.LoggerFactory; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; + public class OOConnection extends FBConnection { + private static final Logger log = LoggerFactory.getLogger(OOConnection.class); + private OODatabaseMetaData metaData; public OOConnection(FBManagedConnection mc) { super(mc); + try { + super.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + } catch (SQLException e) { + // ignore + log.debug("Unexpected exception setting holdability", e); + } } + @Override + public void setHoldability(int holdability) { + if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) return; + + final String message = "Holdability not modified. OpenOffice/LibreOffice compatibility always uses HOLD_CURSORS_OVER_COMMIT"; + log.debug(message); + addWarning(new SQLWarning(message)); + } + public synchronized DatabaseMetaData getMetaData() throws SQLException { if (metaData == null) metaData = new OODatabaseMetaData(this); return metaData; } - public synchronized Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - Statement stmt = new OOStatement(getGDSHelper(), resultSetType, - resultSetConcurrency, resultSetHoldability, txCoordinator); - - activeStatements.add(stmt); - return stmt; - } - - public synchronized PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability, boolean metaData, boolean generatedKeys) throws SQLException { - FBObjectListener.StatementListener coordinator = txCoordinator; - if (metaData) - coordinator = new InternalTransactionCoordinator.MetaDataTransactionCoordinator(txCoordinator); - - FBObjectListener.BlobListener blobCoordinator; - blobCoordinator = metaData ? null : txCoordinator; - - PreparedStatement stmt = new OOPreparedStatement(getGDSHelper(), sql, resultSetType, resultSetConcurrency, - resultSetHoldability, coordinator, blobCoordinator, metaData, false, generatedKeys); - - activeStatements.add(stmt); - return stmt; - } } Modified: client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OODatabaseMetaData.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OODatabaseMetaData.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OODatabaseMetaData.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -20,17 +20,20 @@ */ package org.firebirdsql.jdbc.oo; +import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.XSQLVAR; +import org.firebirdsql.gds.ng.fields.RowDescriptor; +import org.firebirdsql.gds.ng.fields.RowValue; +import org.firebirdsql.jdbc.FBConnection; +import org.firebirdsql.jdbc.FBDatabaseMetaData; +import org.firebirdsql.jdbc.FBResultSet; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.firebirdsql.gds.*; -import org.firebirdsql.gds.ng.fields.RowDescriptor; -import org.firebirdsql.gds.ng.fields.RowValue; -import org.firebirdsql.jdbc.*; - public class OODatabaseMetaData extends FBDatabaseMetaData { public OODatabaseMetaData(FBConnection c) throws SQLException { @@ -58,7 +61,7 @@ if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; FBResultSet rs = (FBResultSet) super.getTables(catalog, schemaPattern, - tableNamePattern, types); + tableNamePattern, types); if (rs.next()) { rs.beforeFirst(); @@ -78,7 +81,7 @@ if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; FBResultSet rs = (FBResultSet) super.getColumns(catalog, schemaPattern, - tableNamePattern, columnNamePattern); + tableNamePattern, columnNamePattern); if (rs.next()) { rs.beforeFirst(); @@ -89,7 +92,7 @@ String upperColumnNamePattern = columnNamePattern.toUpperCase(); rs = (FBResultSet) super.getColumns(catalog, schemaPattern, - upperTableNamePattern, columnNamePattern); + upperTableNamePattern, columnNamePattern); if (rs.next()) { rs.beforeFirst(); @@ -97,7 +100,7 @@ } rs = (FBResultSet) super.getColumns(catalog, schemaPattern, - tableNamePattern, upperColumnNamePattern); + tableNamePattern, upperColumnNamePattern); if (rs.next()) { rs.beforeFirst(); @@ -105,136 +108,37 @@ } return super.getColumns(catalog, schemaPattern, upperTableNamePattern, - upperColumnNamePattern); + upperColumnNamePattern); } - @Override - public ResultSet getBestRowIdentifier(String catalog, String schema, - String table, int scope, boolean nullable) throws SQLException { - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getBestRowIdentifier(catalog, schema, table, scope, - nullable); - } - - @Override - public ResultSet getColumnPrivileges(String catalog, String schema, - String table, String columnNamePattern) throws SQLException { - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getColumnPrivileges(catalog, schema, table, - columnNamePattern); - } - - @Override - public ResultSet getCrossReference(String primaryCatalog, - String primarySchema, String primaryTable, String foreignCatalog, - String foreignSchema, String foreignTable) throws SQLException { - if (DEFAULT_SCHEMA.equals(primarySchema)) primarySchema = null; - - if (DEFAULT_SCHEMA.equals(foreignSchema)) foreignSchema = null; - - return super.getCrossReference(primaryCatalog, primarySchema, - primaryTable, foreignCatalog, foreignSchema, foreignTable); - } - - @Override - public ResultSet getExportedKeys(String catalog, String schema, String table) - throws SQLException { - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getExportedKeys(catalog, schema, table); - } - - @Override - public ResultSet getImportedKeys(String catalog, String schema, String table) - throws SQLException { - - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getImportedKeys(catalog, schema, table); - } - - @Override - public ResultSet getIndexInfo(String catalog, String schema, String table, - boolean unique, boolean approximate) throws SQLException { - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getIndexInfo(catalog, schema, table, unique, approximate); - } - - @Override - public ResultSet getPrimaryKeys(String catalog, String schema, String table) - throws SQLException { - if (DEFAULT_SCHEMA.equals(schema)) schema = null; - - return super.getPrimaryKeys(catalog, schema, table); - } - - @Override - public ResultSet getProcedureColumns(String catalog, String schemaPattern, - String procedureNamePattern, String columnNamePattern) - throws SQLException { - - if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; - - return super.getProcedureColumns(catalog, schemaPattern, - procedureNamePattern, columnNamePattern); - } - - @Override - public ResultSet getProcedures(String catalog, String schemaPattern, - String procedureNamePattern) throws SQLException { - if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; - - return super - .getProcedures(catalog, schemaPattern, procedureNamePattern); - } - - @Override - public ResultSet getSuperTables(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { - if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; - - return super.getSuperTables(catalog, schemaPattern, tableNamePattern); - } - - @Override - public ResultSet getSuperTypes(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { - if (DEFAULT_SCHEMA.equals(schemaPattern)) schemaPattern = null; - - return super.getSuperTypes(catalog, schemaPattern, tableNamePattern); - } - - private static final String GET_TABLE_PRIVILEGES_START_1 = - "SELECT " + - "null as TABLE_CAT, " + - "null as TABLE_SCHEM, " + - "RDB$RELATION_NAME as TABLE_NAME, " + - "RDB$GRANTOR as GRANTOR, " + - "RDB$USER as GRANTEE, " + - "RDB$PRIVILEGE as PRIVILEGE, " + - "RDB$GRANT_OPTION as IS_GRANTABLE " + - "FROM RDB$USER_PRIVILEGES " + - "WHERE "; - private static final String GET_TABLE_PRIVILEGES_END_1 = - " CURRENT_USER IN (RDB$USER, RDB$GRANTOR) AND RDB$FIELD_NAME IS NULL AND RDB$OBJECT_TYPE = 0"; + private static final String GET_TABLE_PRIVILEGES_START_1 = + "SELECT " + + "null as TABLE_CAT, " + + "null as TABLE_SCHEM, " + + "RDB$RELATION_NAME as TABLE_NAME, " + + "RDB$GRANTOR as GRANTOR, " + + "RDB$USER as GRANTEE, " + + "RDB$PRIVILEGE as PRIVILEGE, " + + "RDB$GRANT_OPTION as IS_GRANTABLE " + + "FROM RDB$USER_PRIVILEGES " + + "WHERE "; + private static final String GET_TABLE_PRIVILEGES_END_1 = + " CURRENT_USER IN (RDB$USER, RDB$GRANTOR) AND RDB$FIELD_NAME IS NULL AND RDB$OBJECT_TYPE = 0"; private static final String GET_TABLE_PRIVILEGES_START_2 = - "UNION " + - "SELECT " + - "null as TABLE_CAT, " + - "null as TABLE_SCHEM, " + - "RDB$RELATION_NAME as TABLE_NAME, " + - "RDB$GRANTOR as GRANTOR, " + - "CURRENT_USER as GRANTEE, " + - "RDB$PRIVILEGE as PRIVILEGE, " + - "RDB$GRANT_OPTION as IS_GRANTABLE " + - "FROM RDB$USER_PRIVILEGES " + - "WHERE "; + "UNION " + + "SELECT " + + "null as TABLE_CAT, " + + "null as TABLE_SCHEM, " + + "RDB$RELATION_NAME as TABLE_NAME, " + + "RDB$GRANTOR as GRANTOR, " + + "CURRENT_USER as GRANTEE, " + + "RDB$PRIVILEGE as PRIVILEGE, " + + "RDB$GRANT_OPTION as IS_GRANTABLE " + + "FROM RDB$USER_PRIVILEGES " + + "WHERE "; private static final String GET_TABLE_PRIVILEGES_END_2 = - " RDB$USER IN (CURRENT_ROLE, 'PUBLIC') AND RDB$FIELD_NAME IS NULL AND RDB$OBJECT_TYPE = 0 " + - "ORDER BY 3, 6"; + " RDB$USER IN (CURRENT_ROLE, 'PUBLIC') AND RDB$FIELD_NAME IS NULL AND RDB$OBJECT_TYPE = 0 " + + "ORDER BY 3, 6"; @Override public ResultSet getTablePrivileges(String catalog, String schemaPattern, @@ -248,14 +152,14 @@ Clause tableClause1 = new Clause("RDB$RELATION_NAME", tableNamePattern); Clause tableClause2 = new Clause("RDB$RELATION_NAME", tableNamePattern); - + String sql = GET_TABLE_PRIVILEGES_START_1; sql += tableClause1.getCondition(); sql += GET_TABLE_PRIVILEGES_END_1; sql += GET_TABLE_PRIVILEGES_START_2; sql += tableClause2.getCondition(); sql += GET_TABLE_PRIVILEGES_END_2; - + // check the original case identifiers first List<String> params = new ArrayList<String>(); if (!tableClause1.getCondition().equals("")) { @@ -266,7 +170,7 @@ } ResultSet rs = doQuery(sql, params); - + // if nothing found, check the uppercased identifiers if (!rs.next()) { params.clear(); @@ -276,14 +180,14 @@ if (!tableClause2.getCondition().equals("")) { params.add(tableClause2.getValue()); } - + rs = doQuery(sql, params); - + // if nothing found, return an empty result set if (!rs.next()) return new FBResultSet(rowDescriptor, Collections.<RowValue>emptyList()); } - + return processTablePrivileges(rowDescriptor, rs); } } Deleted: client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOPreparedStatement.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOPreparedStatement.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOPreparedStatement.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -1,33 +0,0 @@ -package org.firebirdsql.jdbc.oo; - -import java.sql.*; - -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.*; -import org.firebirdsql.jdbc.FBObjectListener.BlobListener; -import org.firebirdsql.jdbc.FBObjectListener.StatementListener; - -public class OOPreparedStatement extends FBPreparedStatement { - - public OOPreparedStatement(GDSHelper c, int rsType, int rsConcurrency, - int rsHoldability, StatementListener statementListener, - BlobListener blobListener) throws SQLException { - super(c, rsType, rsConcurrency, rsHoldability, statementListener, - blobListener); - } - - public OOPreparedStatement(GDSHelper c, String sql, int rsType, - int rsConcurrency, int rsHoldability, - StatementListener statementListener, BlobListener blobListener, - boolean metaDataQuery, boolean standaloneConnection, boolean generatedKeys) throws SQLException { - super(c, sql, rsType, rsConcurrency, rsHoldability, statementListener, - blobListener, metaDataQuery, standaloneConnection, generatedKeys); - } - - public void completeStatement() throws SQLException { - // workaround - do not close the result set, OpenOffice gets crazy - - if (!completed) notifyStatementCompleted(); - } - -} Deleted: client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOStatement.java =================================================================== --- client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOStatement.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/openoffice/org/firebirdsql/jdbc/oo/OOStatement.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -1,27 +0,0 @@ -package org.firebirdsql.jdbc.oo; - -import java.sql.SQLException; - -import org.firebirdsql.gds.impl.GDSHelper; -import org.firebirdsql.jdbc.*; -import org.firebirdsql.jdbc.FBObjectListener.StatementListener; - -public class OOStatement extends FBStatement { - - public OOStatement(GDSHelper c, int rsType, int rsConcurrency, - int rsHoldability, StatementListener statementListener) - throws SQLException { - super(c, rsType, rsConcurrency, rsHoldability, statementListener); - } - - public void completeStatement() throws SQLException { - // workaround - do not close the result set, OpenOffice gets crazy - // TODO Test if this is still necessary after the changes of JDBC-304 - if (!completed) notifyStatementCompleted(); - } - - public void completeStatement(CompletionReason reason) throws SQLException { - // TODO Test if this is still necessary after the changes of JDBC-304 - if (!completed) notifyStatementCompleted(); - } -} Modified: client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java 2015-03-08 13:18:02 UTC (rev 60872) +++ client-java/trunk/src/test/org/firebirdsql/common/FBTestProperties.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -137,8 +137,11 @@ public static FirebirdSupportInfo getDefaultSupportInfo() { try { if (firebirdSupportInfo == null) { - final FBServiceManager fbServiceManager = new FBServiceManager(getGdsType()); - if (getGdsType() == GDSType.getType("PURE_JAVA") || getGdsType() == GDSType.getType("NATIVE")) { + final GDSType gdsType = getGdsType(); + final FBServiceManager fbServiceManager = new FBServiceManager(gdsType); + if (gdsType == GDSType.getType("PURE_JAVA") + || gdsType == GDSType.getType("NATIVE") + || gdsType == GDSType.getType("OOREMOTE") ) { fbServiceManager.setHost(DB_SERVER_URL); fbServiceManager.setPort(DB_SERVER_PORT); } @@ -157,8 +160,11 @@ gdsTypeToUrlPrefixMap.put(GDSType.getType("PURE_JAVA"), "jdbc:firebirdsql:"); gdsTypeToUrlPrefixMap.put(GDSType.getType("EMBEDDED"), "jdbc:firebirdsql:embedded:"); gdsTypeToUrlPrefixMap.put(GDSType.getType("NATIVE"), "jdbc:firebirdsql:native:"); + gdsTypeToUrlPrefixMap.put(GDSType.getType("LOCAL"), "jdbc:firebirdsql:local:"); + gdsTypeToUrlPrefixMap.put(GDSType.getType("OOREMOTE"), "jdbc:firebirdsql:oo:"); + + // Not part of Jaybird: gdsTypeToUrlPrefixMap.put(GDSType.getType("ORACLE_MODE"), "jdbc:firebirdsql:oracle:"); - gdsTypeToUrlPrefixMap.put(GDSType.getType("LOCAL"), "jdbc:firebirdsql:local:"); gdsTypeToUrlPrefixMap.put(GDSType.getType("NIO"), "jdbc:firebirdsql:nio:"); } @@ -201,8 +207,10 @@ * @throws Exception */ public static void defaultDatabaseSetUp(FBManager fbManager) throws Exception { - if (getGdsType() == GDSType.getType("PURE_JAVA") - || getGdsType() == GDSType.getType("NATIVE")) { + final GDSType gdsType = getGdsType(); + if (gdsType == GDSType.getType("PURE_JAVA") + || gdsType == GDSType.getType("NATIVE") + || gdsType == GDSType.getType("OOREMOTE")) { fbManager.setServer(DB_SERVER_URL); fbManager.setPort(DB_SERVER_PORT); } Added: client-java/trunk/src/test/org/firebirdsql/jdbc/TestAutoCommitBehaviour.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestAutoCommitBehaviour.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestAutoCommitBehaviour.java 2015-03-08 13:19:50 UTC (rev 60873) @@ -0,0 +1,146 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.jdbc; + +import org.firebirdsql.common.FBJUnit4TestBase; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; + +import static org.firebirdsql.common.FBTestProperties.getConnectionViaDriverManager; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; +import static org.junit.Assume.assumeThat; + +/** + * Tests for behaviour surrounding autocommit. + * <p> + * Tests in this class are specifically concerned with interactions between statements and result sets during + * autocommit. A lot of the autocommit behaviour is tested elsewhere. + * </p> + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 2.2 + */ +public class TestAutoCommitBehaviour extends FBJUnit4TestBase { + + private static final String CREATE_ID_TABLE = "CREATE TABLE ID_TABLE (ID INTEGER PRIMARY KEY)"; + private static final String INSERT_ID_TABLE = "INSERT INTO ID_TABLE (ID) VALUES (?)"; + private static final String SELECT_ALL_ID_TABLE = "SELECT ID FROM ID_TABLE"; + private static final int MAX_ID = 50; + + @Before + public void setUp() throws Exception { + Connection connection = getConnectionViaDriverManager(); + try { + Statement stmt = connection.createStatement(); + stmt.execute(CREATE_ID_TABLE); + stmt.close(); + + connection.setAutoCommit(false); + PreparedStatement pstmt = connection.prepareStatement(INSERT_ID_TABLE); + try { + for (int idValue = 1; idValue <= MAX_ID; idValue++) { + pstmt.setInt(1, idValue); + pstmt.addBatch(); + } + pstmt.executeBatch(); + connection.commit(); + } catch (Exception ex) { + connection.rollback(); + } finally { + pstmt.close(); + } + } finally { + connection.close(); + } + } + + /** + * Executing another statement in autocommit should close any previously opened result set if it isn't holdable. + */ + @Test + public void testDifferentStatementExecution_ClosesResultSet() throws Exception { + Connection connection = getConnectionViaDriverManager(); + try { + // Check actual holdability, for example OOConnection forces HOLD_CURSORS_OVER_COMMIT always + assumeThat("Test requires ResultSet.CLOSE_CURSORS_AT_COMMIT", connection.getHoldability(), + is(ResultSet.CLOSE_CURSORS_AT_COMMIT)); + + Statement stmt1 = connection.createStatement(); + Statement stmt2 = connection.createStatement(); + + ResultSet rs1 = stmt1.executeQuery(SELECT_ALL_ID_TABLE); + assertTrue("Expected a row", rs1.next()); + assertFalse("Expected rs1 open", rs1.isClosed()); + + ResultSet rs2 = stmt2.executeQuery(SELECT_ALL_ID_TABLE); + + assertTrue("Expected rs1 closed", rs1.isClosed()); + + try { + rs1.next(); + fail("Expected exception on rs1.next()"); + } catch (SQLException ex) { + assertEquals("The result set is closed", ex.getMessage()); + } + + for (int count = 1; count <= MAX_ID; count++) { + assertTrue("Expected true for rs2.next() nr " + count, rs2.next()); + } + } finally { + connection.close(); + } + } + + /** + * Executing another statement in autocommit and the result set is holdable should keep it open. + */ + @Test + public void testHoldableDifferentStatementExecution_ResultSetRemainsOpen() throws Exception { + Connection connection = getConnectionViaDriverManager(); + + try { + connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + Statement stmt1 = connection.createStatement(); + Statement stmt2 = connection.createStatement(); + + ResultSet rs1 = stmt1.executeQuery(SELECT_ALL_ID_TABLE); + assertTrue("Expected a row", rs1.next()); + assertFalse("Expected rs1 open", rs1.isClosed()); + + ResultSet rs2 = stmt2.executeQuery(SELECT_ALL_ID_TABLE); + + assertFalse("Expected rs1 open", rs1.isClosed()); + + for (int count = 2; count <= MAX_ID; count++) { + assertTrue("Expected true for rs1.next() nr " + count, rs1.next()); + } + + for (int count = 1; count <= MAX_ID; count++) { + assertTrue("Expected true for rs2.next() nr " + count, rs2.next()); + } + } finally { + connection.close(); + } + } +} Property changes on: client-java/trunk/src/test/org/firebirdsql/jdbc/TestAutoCommitBehaviour.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-03-08 17:09:58
|
Revision: 60875 http://sourceforge.net/p/firebird/code/60875 Author: mrotteveel Date: 2015-03-08 17:09:45 +0000 (Sun, 08 Mar 2015) Log Message: ----------- Implement new event handling in the wire protocol implementation Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java client-java/trunk/src/main/org/firebirdsql/gds/EventHandler.java client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EventHandleImp.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/EventHandleImp.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/ProtocolDescriptor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10Database.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/Version10Descriptor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version11/Version11Descriptor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version12/Version12Descriptor.java client-java/trunk/src/test/org/firebirdsql/event/TestFBEventManager.java client-java/trunk/src/test/org/firebirdsql/gds/ng/EmptyProtocolDescriptor.java Added Paths: ----------- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListener.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListenerDispatcher.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousProcessor.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/FbWireAsynchronousChannel.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/WireEventHandle.java client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10AsynchronousChannel.java client-java/trunk/src/test/org/firebirdsql/common/SimpleServer.java client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/SimpleChannelListener.java client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10EventHandling.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -348,6 +348,26 @@ return datatypeCoder; } + @Override + public EventHandle createEventHandle(String eventName, EventHandler eventHandler) { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void countEvents(EventHandle eventHandle) throws SQLException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void queueEvent(EventHandle eventHandle) throws SQLException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void cancelEvent(EventHandle eventHandle) throws SQLException { + throw new UnsupportedOperationException("Not implemented"); + } + /** * Builds the database URL for the library. * Modified: client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -40,26 +40,23 @@ */ package org.firebirdsql.event; -import org.firebirdsql.gds.GDS; -import org.firebirdsql.gds.GDSException; -import org.firebirdsql.gds.DatabaseParameterBuffer; import org.firebirdsql.gds.EventHandle; -import org.firebirdsql.gds.IscDbHandle; - +import org.firebirdsql.gds.impl.GDSFactory; import org.firebirdsql.gds.impl.GDSType; -import org.firebirdsql.gds.impl.GDSFactory; +import org.firebirdsql.gds.ng.FbConnectionProperties; +import org.firebirdsql.gds.ng.FbDatabase; +import org.firebirdsql.gds.ng.FbDatabaseFactory; +import org.firebirdsql.gds.ng.IConnectionProperties; import org.firebirdsql.jdbc.FBSQLException; +import org.firebirdsql.logging.Logger; +import org.firebirdsql.logging.LoggerFactory; import org.firebirdsql.util.SQLExceptionChainBuilder; -import java.util.Map; -import java.util.Set; -import java.util.List; -import java.util.HashMap; -import java.util.HashSet; -import java.util.ArrayList; -import java.util.Collections; - import java.sql.SQLException; +import java.util.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; /** * An {@link org.firebirdsql.event.EventManager} implementation to listen for database events. @@ -68,44 +65,38 @@ */ public class FBEventManager implements EventManager { - private GDS gds; - private IscDbHandle dbHandle; + private static final Logger log = LoggerFactory.getLogger(FBEventManager.class); + + private final GDSType gdsType; + private FbDatabase fbDatabase; + private final IConnectionProperties connectionProperties = new FbConnectionProperties(); private boolean connected = false; - private String user = ""; - private String password = ""; - private String database = ""; - private int port = 3050; - private String host = "localhost"; private final Map<String, Set<EventListener>> listenerMap = Collections.synchronizedMap(new HashMap<String, Set<EventListener>>()); private final Map<String, GdsEventHandler> handlerMap = Collections.synchronizedMap(new HashMap<String, GdsEventHandler>()); - private final List<DatabaseEvent> eventQueue = new ArrayList<DatabaseEvent>(); + private final BlockingQueue<DatabaseEvent> eventQueue = new LinkedBlockingQueue<DatabaseEvent>(); private EventDispatcher eventDispatcher; private Thread dispatchThread; - private long waitTimeout = 1000; + private volatile long waitTimeout = 1000; + @SuppressWarnings("UnusedDeclaration") public FBEventManager() { - this(GDSFactory.getDefaultGDSType()); + this(GDSFactory.getDefaultGDSType()); } - public FBEventManager(GDSType gdsType){ - gds = GDSFactory.getGDSForType(gdsType); - dbHandle = gds.createIscDbHandle(); + public FBEventManager(GDSType gdsType) { + this.gdsType = gdsType; } public void connect() throws SQLException { - if (connected){ + if (connected) { throw new IllegalStateException("Connect called while already connected"); } - DatabaseParameterBuffer dpb = gds.createDatabaseParameterBuffer(); - dpb.addArgument(DatabaseParameterBuffer.USER, user); - dpb.addArgument(DatabaseParameterBuffer.PASSWORD, password); - try { - String connString = GDSFactory.getDatabasePath(gds.getType(), host, port, database); - gds.iscAttachDatabase(connString, dbHandle, dpb); - } catch (GDSException e){ - throw new FBSQLException(e); - } + final FbDatabaseFactory databaseFactory = GDSFactory.getDatabaseFactoryForType(gdsType); + + fbDatabase = databaseFactory.connect(connectionProperties); + fbDatabase.attach(); connected = true; + eventDispatcher = new EventDispatcher(); dispatchThread = new Thread(eventDispatcher); dispatchThread.setDaemon(true); @@ -113,36 +104,41 @@ } public void disconnect() throws SQLException { - if (!connected){ + if (!connected) { throw new IllegalStateException("Disconnect called while not connected"); } SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<SQLException>(); - for (String eventName : new HashSet<String>(handlerMap.keySet())) { + try { try { - unregisterListener(eventName); - } catch (GDSException e1){ - chain.append(new FBSQLException(e1)); + for (String eventName : new HashSet<String>(handlerMap.keySet())) { + try { + unregisterListener(eventName); + } catch (SQLException e) { + chain.append(e); + } catch (Exception e) { + chain.append(new SQLException(e)); + } + } + } finally { + handlerMap.clear(); + listenerMap.clear(); + try { + fbDatabase.detach(); + } catch (SQLException e) { + chain.append(e); + } + connected = false; } - } + } finally { + eventDispatcher.stop(); - handlerMap.clear(); - listenerMap.clear(); - - try { - gds.iscDetachDatabase(dbHandle); - } catch (GDSException e2){ - chain.append(new FBSQLException(e2)); + // join the thread and wait until it dies + try { + dispatchThread.join(); + } catch (InterruptedException ex) { + chain.append(new FBSQLException(ex)); + } } - connected = false; - - eventDispatcher.stop(); - - // join the thread and wait until it dies - try { - dispatchThread.join(); - } catch(InterruptedException ex) { - chain.append(new FBSQLException(ex)); - } if (chain.hasException()) throw chain.getException(); } @@ -150,55 +146,56 @@ return connected; } - public void setUser(String user){ - this.user = user; + public void setUser(String user) { + connectionProperties.setUser(user); } - public String getUser(){ - return this.user; + public String getUser() { + return connectionProperties.getUser(); } - public void setPassword(String password){ - this.password = password; + public void setPassword(String password) { + connectionProperties.setPassword(password); } - public String getPassword(){ - return this.password; + public String getPassword() { + return connectionProperties.getPassword(); } - public void setDatabase(String database){ - this.database = database; + public void setDatabase(String database) { + connectionProperties.setDatabaseName(database); } - public String getDatabase(){ - return this.database; + public String getDatabase() { + return connectionProperties.getDatabaseName(); } - public String getHost(){ - return this.host; + public String getHost() { + return connectionProperties.getServerName(); } - public void setHost(String host){ - this.host = host; + public void setHost(String host) { + connectionProperties.setServerName(host); } - - public int getPort(){ - return this.port; + + public int getPort() { + return connectionProperties.getPortNumber(); } - public void setPort(int port){ - this.port = port; + public void setPort(int port) { + connectionProperties.setPortNumber(port); } - + /** * Get the time in milliseconds, after which the async thread will exit from the {@link Object#wait(long)} method * and check whether it was stopped or not. * <p> * Default value is 1000 (1 second). * </p> - * + * * @return wait timeout in milliseconds */ + @SuppressWarnings("UnusedDeclaration") public long getWaitTimeout() { return waitTimeout; } @@ -209,27 +206,25 @@ * <p> * Default value is 1000 (1 second). * </p> - * - * @param waitTimeout wait timeout in milliseconds + * + * @param waitTimeout + * wait timeout in milliseconds */ - public void setWaitTimeout(long waitTimeout) { + @SuppressWarnings("UnusedDeclaration") + public synchronized void setWaitTimeout(long waitTimeout) { this.waitTimeout = waitTimeout; } public void addEventListener(String eventName, EventListener listener) throws SQLException { - if (!connected){ + if (!connected) { throw new IllegalStateException("Can't add event listeners to disconnected EventManager"); } - if (listener == null || eventName == null){ + if (listener == null || eventName == null) { throw new NullPointerException(); } - synchronized (listenerMap){ - if (!listenerMap.containsKey(eventName)){ - try { - registerListener(eventName); - } catch (GDSException e){ - throw new FBSQLException(e); - } + synchronized (listenerMap) { + if (!listenerMap.containsKey(eventName)) { + registerListener(eventName); listenerMap.put(eventName, new HashSet<EventListener>()); } Set<EventListener> listenerSet = listenerMap.get(eventName); @@ -238,19 +233,15 @@ } public void removeEventListener(String eventName, EventListener listener) throws SQLException { - if (eventName == null || listener == null){ + if (eventName == null || listener == null) { throw new NullPointerException(); } Set<EventListener> listenerSet = listenerMap.get(eventName); - if (listenerSet != null){ + if (listenerSet != null) { listenerSet.remove(listener); - if (listenerSet.isEmpty()){ + if (listenerSet.isEmpty()) { listenerMap.remove(eventName); - try { - unregisterListener(eventName); - } catch (GDSException e){ - throw new FBSQLException(e); - } + unregisterListener(eventName); } } } @@ -260,123 +251,113 @@ } public int waitForEvent(String eventName, final int timeout) throws InterruptedException, SQLException { - if (!connected){ + if (!connected) { throw new IllegalStateException("Can't wait for events with disconnected EventManager"); } - if (eventName == null){ + if (eventName == null) { throw new NullPointerException(); } final Object lock = new Object(); OneTimeEventListener listener = new OneTimeEventListener(lock); - synchronized (lock){ - addEventListener(eventName, listener); - lock.wait(timeout); + try { + synchronized (lock) { + addEventListener(eventName, listener); + lock.wait(timeout); + } + } finally { + removeEventListener(eventName, listener); } - - removeEventListener(eventName, listener); return listener.getEventCount(); } - private void registerListener(String eventName) throws GDSException { + private void registerListener(String eventName) throws SQLException { GdsEventHandler handler = new GdsEventHandler(eventName); handlerMap.put(eventName, handler); handler.register(); } - private void unregisterListener(String eventName) throws GDSException { + private void unregisterListener(String eventName) throws SQLException { GdsEventHandler handler = handlerMap.get(eventName); - handler.unregister(); - handlerMap.remove(eventName); + try { + handler.unregister(); + } finally { + handlerMap.remove(eventName); + } } class GdsEventHandler implements org.firebirdsql.gds.EventHandler { - private EventHandle eventHandle; + private final EventHandle eventHandle; private boolean initialized = false; private boolean cancelled = false; - public GdsEventHandler(String eventName) throws GDSException { - eventHandle = gds.createEventHandle(eventName); - gds.iscEventBlock(eventHandle); + public GdsEventHandler(String eventName) { + eventHandle = fbDatabase.createEventHandle(eventName, this); } - public synchronized void register() throws GDSException { - if (cancelled){ + public synchronized void register() throws SQLException { + if (cancelled) { throw new IllegalStateException("Trying to register a cancelled event handler"); } - gds.iscQueueEvents(dbHandle, eventHandle, this); + fbDatabase.queueEvent(eventHandle); } - public synchronized void unregister() throws GDSException { - if (cancelled){ - throw new IllegalStateException("Trying to cancel a cancelled event handler"); - } - gds.iscCancelEvents(dbHandle, eventHandle); + public synchronized void unregister() throws SQLException { + if (cancelled) return; + fbDatabase.cancelEvent(eventHandle); cancelled = true; } - public synchronized void eventOccurred() { - if (!cancelled){ + public synchronized void eventOccurred(EventHandle eventHandle) { + if (!cancelled) { try { - gds.iscEventCounts(eventHandle); - } catch (GDSException e1){ - e1.printStackTrace(); + fbDatabase.countEvents(eventHandle); + } catch (SQLException e) { + log.warn("Exception processing event counts", e); } - if (initialized && !cancelled){ - DatabaseEvent event = new DatabaseEventImpl(eventHandle.getEventName(), eventHandle.getEventCount()); - - synchronized (eventQueue){ - eventQueue.add(event); - eventQueue.notify(); - } + if (initialized && !cancelled) { + eventQueue.add(new DatabaseEventImpl(eventHandle.getEventName(), eventHandle.getEventCount())); } else { initialized = true; } - + try { register(); - } catch (GDSException e2){ - e2.printStackTrace(); + } catch (SQLException e) { + log.warn("Exception registering for event", e); } - } + } } - } class EventDispatcher implements Runnable { - + private volatile boolean running = false; - public void stop(){ + public void stop() { running = false; } - public void run(){ + public void run() { running = true; - final List<DatabaseEvent> events = new ArrayList<DatabaseEvent>(); - while (running){ - synchronized (eventQueue){ - while (eventQueue.isEmpty() && running){ - try { - eventQueue.wait(waitTimeout); - } catch (InterruptedException ie){ } - } - events.addAll(eventQueue); - eventQueue.clear(); - } - - for (DatabaseEvent event : events) { - synchronized (listenerMap){ + DatabaseEvent event; + while (running) { + try { + event = eventQueue.poll(waitTimeout, TimeUnit.MILLISECONDS); + if (event == null) continue; + + synchronized (listenerMap) { Set<EventListener> listenerSet = listenerMap.get(event.getEventName()); - if (listenerSet != null){ + if (listenerSet != null) { for (EventListener listener : listenerSet) { listener.eventOccurred(event); } } } + } catch (InterruptedException ie) { + // Ignore interruption; continue if not explicitly stopped } - events.clear(); } } } @@ -388,44 +369,44 @@ private final Object lock; - public OneTimeEventListener(Object lock){ + public OneTimeEventListener(Object lock) { this.lock = lock; } - public void eventOccurred(DatabaseEvent event){ - if (eventCount == -1){ + public void eventOccurred(DatabaseEvent event) { + if (eventCount == -1) { eventCount = event.getEventCount(); } - synchronized (lock){ - lock.notify(); + synchronized (lock) { + lock.notifyAll(); } } - public int getEventCount(){ + public int getEventCount() { return eventCount; } } class DatabaseEventImpl implements DatabaseEvent { - + private int eventCount; private String eventName; - public DatabaseEventImpl(String eventName, int eventCount){ + public DatabaseEventImpl(String eventName, int eventCount) { this.eventName = eventName; this.eventCount = eventCount; } - public int getEventCount(){ + public int getEventCount() { return this.eventCount; } - public String getEventName(){ + public String getEventName() { return this.eventName; } - public String toString(){ + public String toString() { return "DatabaseEvent['" + eventName + " * " + eventCount + "]"; } } Modified: client-java/trunk/src/main/org/firebirdsql/gds/EventHandler.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/EventHandler.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/EventHandler.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -1,4 +1,6 @@ /* + * $Id$ + * * Public Firebird Java API. * * Redistribution and use in source and binary forms, with or without @@ -22,7 +24,6 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package org.firebirdsql.gds; /** @@ -32,7 +33,10 @@ /** * Called when a database event occurs. + * + * @param eventHandle + * The event handle */ - public void eventOccurred(); + public void eventOccurred(EventHandle eventHandle); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EventHandleImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EventHandleImp.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/jni/EventHandleImp.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -94,4 +94,5 @@ public int getEventStructHandle(){ return this.eventStructHandle; } + } 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 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/AbstractJavaGDSImpl.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -1087,7 +1087,7 @@ EventGlob glob = globMap.remove(eventId); if (glob != null){ glob.getEventHandle().setInternalCount(count); - glob.getEventHandler().eventOccurred(); + glob.getEventHandler().eventOccurred(glob.getEventHandle()); } break; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/EventHandleImp.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/EventHandleImp.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/impl/wire/EventHandleImp.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -94,7 +94,7 @@ byte[] toByteArray() throws IOException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - XdrOutputStream xdr = new XdrOutputStream(byteOut); + XdrOutputStream xdr = new XdrOutputStream(byteOut, false); byte[] eventNameBytes = this.eventName.getBytes(); xdr.write(1); // Event version Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -29,6 +29,8 @@ import org.firebirdsql.encodings.Encoding; import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.BlobParameterBuffer; +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; import org.firebirdsql.gds.TransactionParameterBuffer; import org.firebirdsql.gds.impl.GDSServerVersion; import org.firebirdsql.gds.ng.listeners.DatabaseListener; @@ -286,4 +288,47 @@ */ void removeDatabaseListener(DatabaseListener listener); + /** + * Creates an event handle for this database type. + * <p> + * The returned event handle can be used with {@link #queueEvent(org.firebirdsql.gds.EventHandle)}. + * </p> + * + * @param eventName + * Name of the event + * @param eventHandler + * The event handler to call when the event occurred + * @return A suitable event handle instance + */ + EventHandle createEventHandle(String eventName, EventHandler eventHandler); + + /** + * Counts the events occurred. + * + * @param eventHandle + * The event handle + * @throws SQLException + * When the count can not be done (as - for example - the event handle is of the wrong type) + */ + void countEvents(EventHandle eventHandle) throws SQLException; + + /** + * Queues a wait for an event. + * + * @param eventHandle + * The event handle (created using {@link #createEventHandle(String, EventHandler)} of this instance). + * @throws SQLException + * For errors establishing the asynchronous channel, or for queuing the event. + */ + void queueEvent(EventHandle eventHandle) throws SQLException; + + /** + * Cancels a registered event. + * + * @param eventHandle + * The event handle to cancel + * @throws SQLException + * For errors cancelling the event + */ + void cancelEvent(EventHandle eventHandle) throws SQLException; } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -23,6 +23,8 @@ import org.firebirdsql.encodings.Encoding; import org.firebirdsql.encodings.IEncodingFactory; import org.firebirdsql.gds.BlobParameterBuffer; +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; import org.firebirdsql.gds.impl.BlobParameterBufferImp; import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; import org.firebirdsql.gds.impl.wire.XdrInputStream; @@ -120,6 +122,19 @@ return super.isAttached() && connection.isConnected(); } + /** + * Checks if a physical connection to the server is established and if the + * connection is attached to a database. + * <p> + * This method calls {@link #checkConnected()}, so it is not necessary to + * call both. + * </p> + * + * @throws SQLException + * If the database not connected or attached. + */ + protected abstract void checkAttached() throws SQLException; + @Override public FbBlob createBlobForOutput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer) throws SQLException { return protocolDescriptor.createOutputBlob(this, (FbWireTransaction) transaction, blobParameterBuffer); @@ -225,4 +240,24 @@ protected final void writeDirect(byte[] data) throws IOException { connection.writeDirect(data); } + + public EventHandle createEventHandle(String eventName, EventHandler eventHandler) { + return new WireEventHandle(eventName, eventHandler, getEncoding()); + } + + public void countEvents(EventHandle eventHandle) throws SQLException { + if (!(eventHandle instanceof WireEventHandle)) + throw new SQLException("Invalid event handle, type: " + eventHandle.getClass().getName()); + + ((WireEventHandle) eventHandle).calculateCount(); + } + + /** + * Initializes the asynchronous channel (for event notification). + * + * @throws java.sql.SQLException + * For errors establishing the channel, or if the channel already exists. + */ + // TODO make protected? + public abstract FbWireAsynchronousChannel initAsynchronousChannel() throws SQLException; } Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListener.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListener.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListener.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,73 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.wire; + +/** + * Listener interface for events on the asynchronous channel. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public interface AsynchronousChannelListener { + + /** + * Signals the closing of an asynchronous channel. + * <p> + * Fired before the channel is actually closed. + * </p> + * + * @param channel The channel that is being closed + */ + void channelClosing(FbWireAsynchronousChannel channel); + + /** + * Signals that an event has been received. + * <p> + * Implementations should take care to only perform short processing on the current thread. If longer or + * complicated processing is necessary, please offload it to another thread or executor. + * </p> + * + * @param channel The channel that received the event + * @param event The event received + */ + void eventReceived(FbWireAsynchronousChannel channel, Event event); + + /** + * Event count notification + */ + public class Event { + private final int eventId; + private final int eventCount; + + public Event(int eventId, int eventCount) { + this.eventId = eventId; + this.eventCount = eventCount; + } + + public int getEventId() { + return eventId; + } + + public int getEventCount() { + return eventCount; + } + } +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListener.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListenerDispatcher.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListenerDispatcher.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListenerDispatcher.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,55 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.wire; + +import org.firebirdsql.gds.ng.listeners.AbstractListenerDispatcher; + +/** + * Dispatcher for {@link org.firebirdsql.gds.ng.wire.AsynchronousChannelListener}. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public class AsynchronousChannelListenerDispatcher extends AbstractListenerDispatcher<AsynchronousChannelListener> + implements AsynchronousChannelListener { + + @Override + public void channelClosing(FbWireAsynchronousChannel channel) { + for (AsynchronousChannelListener listener : this) { + try { + listener.channelClosing(channel); + } catch (Exception ex) { + // ignore // TODO: Log + } + } + } + + @Override + public void eventReceived(FbWireAsynchronousChannel channel, Event event) { + for (AsynchronousChannelListener listener : this) { + try { + listener.eventReceived(channel, event); + } catch (Exception ex) { + // ignore // TODO: Log + } + } + } +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousChannelListenerDispatcher.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousProcessor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousProcessor.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousProcessor.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,186 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.wire; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.sql.SQLException; +import java.util.*; + +/** + * Process asynchronous channels for notification of events. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public class AsynchronousProcessor { + + /** + * Initialize on demand holder + */ + private static class ProcessorHolder { + private static final AsynchronousProcessor INSTANCE = new AsynchronousProcessor(); + } + + private final AsynchronousChannelListener channelListener = new ProcessorChannelListener(); + private final List<FbWireAsynchronousChannel> newChannels = + Collections.synchronizedList(new ArrayList<FbWireAsynchronousChannel>()); + private final SelectorTask selectorTask = new SelectorTask(); + private final Selector selector; + + private AsynchronousProcessor() { + try { + selector = Selector.open(); + } catch (IOException e) { + throw new IllegalStateException("Unable to initialize asynchronous processor", e); + } + Thread selectorThread = new Thread(selectorTask, "Jaybird asynchronous processing"); + selectorThread.setDaemon(true); + selectorThread.start(); + } + + /** + * @return Singleton instance + */ + public static AsynchronousProcessor getInstance() { + return ProcessorHolder.INSTANCE; + } + + /** + * Registers an asynchronous channel with the asynchronous processor. + * + * @param channel + * The channel to register + */ + public void registerAsynchronousChannel(FbWireAsynchronousChannel channel) { + newChannels.add(channel); + channel.addChannelListener(channelListener); + selector.wakeup(); + } + + // TODO Reduce visibility or remove entirely? + public void shutdown() { + selectorTask.stop(); + selector.wakeup(); + } + + private class ProcessorChannelListener implements AsynchronousChannelListener { + @Override + public void channelClosing(FbWireAsynchronousChannel channel) { + if (!newChannels.remove(channel)) { + // TODO Replace with map from channel to selectionkey? + for (SelectionKey key : new ArrayList<SelectionKey>(selector.keys())) { + if (key.isValid() && key.attachment() == channel) { + key.cancel(); + break; + } + } + } + channel.removeChannelListener(this); + } + + @Override + public void eventReceived(FbWireAsynchronousChannel channel, Event event) { + // Ignore + } + } + + private class SelectorTask implements Runnable { + + private volatile boolean running = true; + + @Override + public void run() { + while (running) { + try { + synchronized (newChannels) { + for (FbWireAsynchronousChannel channel : newChannels) { + addChannel(channel); + } + newChannels.clear(); + } + + if (selector.select() == 0) continue; + + final Set<SelectionKey> selectedKeys = selector.selectedKeys(); + synchronized (selectedKeys) { + Iterator<SelectionKey> selectedKeysIterator = selectedKeys.iterator(); + while (selectedKeysIterator.hasNext()) { + final SelectionKey selectionKey = selectedKeysIterator.next(); + selectedKeysIterator.remove(); + if (!selectionKey.isValid()) continue; + + if (selectionKey.isReadable()) { + handleReadable(selectionKey); + } + } + } + } catch (IOException ex) { + // TODO check necessary handling + } + } + try { + selector.close(); + } catch (IOException e) { + // ignore // todo log + } + } + + private void addChannel(FbWireAsynchronousChannel channel) throws ClosedChannelException { + try { + channel.getSocketChannel().register(selector, SelectionKey.OP_READ, channel); + } catch (SQLException ex) { + // channel closed, remove listener + channel.removeChannelListener(channelListener); + } + } + + private void handleReadable(SelectionKey selectionKey) { + try { + SocketChannel socketChannel = (SocketChannel) selectionKey.channel(); + FbWireAsynchronousChannel channel = (FbWireAsynchronousChannel) selectionKey.attachment(); + + final ByteBuffer eventBuffer = channel.getEventBuffer(); + int count = socketChannel.read(eventBuffer); + if (count > 0) { + eventBuffer.flip(); + channel.processEventData(); + } else if (count < 0) { + try { + channel.close(); + } catch (SQLException e) { + // ignore // todo log + } + } + } catch (IOException e) { + // TODO handle; log + } + } + + private void stop() { + running = false; + } + } +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/AsynchronousProcessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/FbWireAsynchronousChannel.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/FbWireAsynchronousChannel.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/FbWireAsynchronousChannel.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,128 @@ +/* + * $Id$ + * + * Public Firebird Java API. + * + * 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. + */ +package org.firebirdsql.gds.ng.wire; + +import org.firebirdsql.gds.EventHandle; + +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.sql.SQLException; + +/** + * Interface for the asynchronous channel used for event notification. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public interface FbWireAsynchronousChannel { + + /** + * Connects the asynchronous channel to the specified port. + * + * @param hostName + * Hostname + * @param portNumber + * The port number + * @param auxHandle + * Handle identifier for this asynchronous channel + * @throws java.sql.SQLException + * For errors connecting, or if the connection is already established + */ + void connect(String hostName, int portNumber, int auxHandle) throws SQLException; + + /** + * Disconnect the asynchronous channel. + * <p> + * Once closed, the connection can be reestablished using {@link #connect(String, int, int)}. + * </p> + * <p> + * Calling {@code close} on a closed channel is a no-op; no exception should be thrown. + * </p> + * + * @throws SQLException + * For errors closing the channel + */ + void close() throws SQLException; + + /** + * @return {@code true} if connected, otherwise {@code false} + */ + boolean isConnected(); + + /** + * Register a listener for this channel. + * + * @param listener Listener + */ + void addChannelListener(AsynchronousChannelListener listener); + + /** + * Remove a listener from this channel + * + * @param listener Listener + */ + void removeChannelListener(AsynchronousChannelListener listener); + + /** + * @return The socket channel associated with this asynchronous channel + * @throws java.sql.SQLException + * If not currently connected + */ + SocketChannel getSocketChannel() throws SQLException; + + /** + * @return The byte buffer for event data + */ + ByteBuffer getEventBuffer(); + + /** + * Process the current event data in the buffer. + * <p> + * This is only to be called by the {@link org.firebirdsql.gds.ng.wire.AsynchronousProcessor}. Implementations + * should be ready to deal with incomplete data in the event buffer (eg by not processing). + * </p> + */ + void processEventData(); + + /** + * Queues a wait for an event. + * + * @param eventHandle + * Event handle + */ + void queueEvent(EventHandle eventHandle) throws SQLException; + + /** + * Cancels a registered event. + * + * @param eventHandle + * The event handle to cancel + * @throws SQLException + * For errors cancelling the event + */ + void cancelEvent(EventHandle eventHandle) throws SQLException; +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/FbWireAsynchronousChannel.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/ProtocolDescriptor.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/ProtocolDescriptor.java 2015-03-08 13:20:06 UTC (rev 60874) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/ProtocolDescriptor.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -157,4 +157,14 @@ */ FbWireBlob createInputBlob(FbWireDatabase database, FbWireTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId); + + /** + * Create a disconnected asynchronous channel. + * + * @param database + * The parent database handle. + * @return Asynchronous channel implementation + */ + FbWireAsynchronousChannel createAsynchronousChannel(FbWireDatabase database); + } Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/WireEventHandle.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/WireEventHandle.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/WireEventHandle.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,134 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.wire; + +import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; +import org.firebirdsql.gds.impl.wire.XdrOutputStream; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Event handle for the wire protocol. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public class WireEventHandle implements EventHandle, AsynchronousChannelListener { + + private static final AtomicInteger localEventId = new AtomicInteger(); + + private final String eventName; + private final byte[] eventNameBytes; + private volatile int eventCount; + private int internalCount; + private int previousInternalCount; + private final EventHandler eventHandler; + private int localId; + private int eventId; + + public WireEventHandle(String eventName, EventHandler eventHandler, Encoding encoding) { + this.eventName = eventName; + this.eventHandler = eventHandler; + eventNameBytes = encoding.encodeToCharset(eventName); + if (eventNameBytes.length > 256) { + throw new IllegalArgumentException("Event name as bytes too long"); + } + } + + @Override + public String getEventName() { + return eventName; + } + + public synchronized void calculateCount() { + // TODO Can't we just set the count directly? + eventCount = internalCount - previousInternalCount; + previousInternalCount = internalCount; + } + + @Override + public int getEventCount() { + return eventCount; + } + + /** + * @param eventId The server side id of this event + */ + public synchronized void setEventId(int eventId) { + this.eventId = eventId; + } + + @Override + public synchronized int getEventId() { + return eventId; + } + + /** + * Generates a new local id for this event. + */ + public synchronized int assignNewLocalId() { + localId = localEventId.incrementAndGet(); + return localId; + } + + /** + * @return The current local id of this event. + */ + public synchronized int getLocalId() { + return localId; + } + + public byte[] toByteArray() throws IOException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + XdrOutputStream xdr = new XdrOutputStream(byteOut, false); + + xdr.write(1); // Event version + xdr.write(eventNameBytes.length); + xdr.write(eventNameBytes); + final int currentInternalCount = internalCount; + for (int shift = 0; shift <= 24; shift += 8) { + // Write count as VAX integer + xdr.write((currentInternalCount >> shift) & 0xff); + } + + return byteOut.toByteArray(); + } + + @Override + public void channelClosing(FbWireAsynchronousChannel channel) { + channel.removeChannelListener(this); + } + + @Override + public void eventReceived(FbWireAsynchronousChannel channel, Event event) { + if (event.getEventId() != getLocalId()) return; + + channel.removeChannelListener(this); + synchronized (this) { + internalCount = event.getEventCount(); + } + eventHandler.eventOccurred(this); + } +} Property changes on: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/WireEventHandle.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10AsynchronousChannel.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10AsynchronousChannel.java (rev 0) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/wire/version10/V10AsynchronousChannel.java 2015-03-08 17:09:45 UTC (rev 60875) @@ -0,0 +1,292 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.wire.version10; + +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.ISCConstants; +import org.firebirdsql.gds.impl.wire.XdrOutputStream; +import org.firebirdsql.gds.ng.FbDatabase; +import org.firebirdsql.gds.ng.FbExceptionBuilder; +import org.firebirdsql.gds.ng.listeners.DefaultDatabaseListener; +import org.firebirdsql.gds.ng.wire.*; +import org.firebirdsql.logging.Logger; +import org.firebirdsql.logging.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.sql.SQLException; +import java.sql.SQLNonTransientException; + +import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger; +import static org.firebirdsql.gds.impl.wire.WireProtocolConstants.*; + +/** + * Asynchronous channel implementation for the V10 wire protocol. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public class V10AsynchronousChannel implements FbWireAsynchronousChannel { + + private static Logger log = LoggerFactory.getLogger(V10AsynchronousChannel.class); + + private final AsynchronousChannelListenerDispatcher channelListenerDispatcher = new AsynchronousChannelListenerDispatcher(); + private final FbWireDatabase database; + /* + * Expecting: + * single operation: 1 byte (op_dummy, op_exit, op_disconnect) + * + * Normal response: + * (see processing) + * + * Event: + * - 1 byte operation (op_event) + * - 4 bytes db handle + * - 4 bytes event buffer length + * - buffer consisting of + * -- 1 byte event buffer version (1) + * -- 1 byte event name length + * -- max 256 bytes event name + * -- 4 bytes event count (vax integer) + * - 8 bytes AST info + * - 4 bytes event id + * + * Total: 282 per event; allocating 2048 to have sufficient space (TODO: might not be enough for 'normal' response) + */ + private final ByteBuffer eventBuffer = ByteBuffer.allocate(2048); + private int auxHandle; + private SocketChannel socketChannel; + + public V10AsynchronousChannel(FbWireDatabase database) { + this.database = database; + database.addDatabaseListener(new ChannelDatabaseLister()); + } + + @Override + public void connect(String hostName, int portNumber, int auxHandle) throws SQLException { + if (isConnected()) throw new SQLException("Asynchronous channel already established"); + this.auxHandle = auxHandle; + try { + socketChannel = SocketChannel.open(); + socketChannel.socket().setTcpNoDelay(true); + SocketAddress socketAddress = new InetSocketAddress(hostName, portNumber); + socketChannel.connect(socketAddress); + socketChannel.configureBlocking(false); + } catch (IOException ex) { + throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException(); + } + } + + @Override + public void close() throws SQLException { + if (!isConnected()) return; + channelListenerDispatcher.channelClosing(this); + try { + socketChannel.close(); + } catch (IOException ex) { + throw new SQLException("Unable to close asynchronous channel", ex); + } finally { + socketChannel = null; + } + } + + @Override + public boolean isConnected() { + return socketChannel != null && socketChannel.isConnected(); + } + + @Override + public void addChannelListener(AsynchronousChannelListener listener) { + channelListenerDispatcher.addListener(listener); + } + + @Override + public void removeChannelListener(AsynchronousChannelListener listener) { + channelListenerDispatcher.removeListener(listener); + } + + @Override + public SocketChannel getSocketChannel() throws SQLException { + if (!isConnected()) throw new SQLException("Asynchronous channel not connected"); + return socketChannel; + } + + @Override + public ByteBuffer getEventBuffer() { + return eventBuffer; + } + + @Override + public void processEventData() { + // TODO We assume the caller has called eventBuffer.flip() is that wise, or should we do that here? + try { + bufferProcessing: + while (eventBuffer.hasRemaining()) { + ev... [truncated message content] |
From: <mro...@us...> - 2015-03-19 20:21:48
|
Revision: 61028 http://sourceforge.net/p/firebird/code/61028 Author: mrotteveel Date: 2015-03-19 20:21:40 +0000 (Thu, 19 Mar 2015) Log Message: ----------- JDBC-385 Test case for custom exception messages (+ touch up documentation in org.firebirdsql.util.FirebirdSupportInfo Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java Modified: client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java 2015-03-19 20:09:29 UTC (rev 61027) +++ client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java 2015-03-19 20:21:40 UTC (rev 61028) @@ -29,6 +29,11 @@ /** * Helper class that reports if a Firebird version supports a specific feature. Intended as a repository for * tests to check their assumptions, or decide on test or application behavior based on functionality support. + * <p> + * Primary reason for existence of this class is to support version dependent tests in the Jaybird test suite, so + * feature checks were only added when they were necessary for the test suite. That said: if you miss feature checks, + * don't hesitate to create an issue in the <a href="http://tracker.firebirdsql.org/browse/JDBC">Jaybird tracker</a>. + * </p> * * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> * @since 3.0 @@ -171,7 +176,11 @@ } /** - * @param protocolVersion Protocol version number + * Checks support for protocol versions. The check is limited to those protocol versions supported by Jaybird (10-12 + * at this time). + * + * @param protocolVersion + * Protocol version number * @return {@code true} when the database supports the specified protocol */ public boolean supportsProtocol(int protocolVersion) { @@ -188,6 +197,13 @@ } /** + * @return {@code true} when custom exception messages are supported. + */ + public boolean supportsCustomExceptionMessages() { + return serverVersion.isEqualOrAbove(1, 5); + } + + /** * @return {@code true} when parametrized exceptions are supported. */ public boolean supportsParametrizedExceptions() { @@ -217,13 +233,20 @@ * A database connection (NOTE: {@link java.sql.Connection} is used, but it must be or unwrap to a * {@link org.firebirdsql.jdbc.FBConnection}. * @return FirebirdVersionSupport instance + * @throws java.lang.IllegalArgumentException + * When the provided connection is not an instance of or wrapper for + * {@link org.firebirdsql.jdbc.FBConnection} + * @throws java.lang.IllegalStateException + * When an SQLException occurs unwrapping the connection, or creating + * the {@link org.firebirdsql.util.FirebirdSupportInfo} instance */ public static FirebirdSupportInfo supportInfoFor(java.sql.Connection connection) { try { if (connection.isWrapperFor(FBConnection.class)) { return supportInfoFor(connection.unwrap(FBConnection.class).getFbDatabase()); } else { - throw new IllegalArgumentException("connection needs to be an FBConnection"); + throw new IllegalArgumentException( + "connection needs to be (or unwrap to) an org.firebirdsql.jdbc.FBConnection"); } } catch (SQLException e) { throw new IllegalStateException(e); Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java 2015-03-19 20:09:29 UTC (rev 61027) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java 2015-03-19 20:21:40 UTC (rev 61028) @@ -917,6 +917,36 @@ } /** + * Tests if Firebird 1.5+ custom exception messages work. + */ + @Test + public void testCustomExceptionMessage() throws Exception { + assumeTrue("Test requires custom exception messages", supportInfoFor(con).supportsCustomExceptionMessages()); + + //@formatter:off + executeDDL(con, "CREATE EXCEPTION simple_exception 'Standard message'"); + executeDDL(con, + "CREATE PROCEDURE testexception " + + "AS " + + "BEGIN " + + " EXCEPTION simple_exception 'Custom message';" + + "END"); + //@formatter:on + + Statement stmt = con.createStatement(); + try { + expectedException.expect(allOf( + isA(SQLException.class), + message(containsString("; Custom message; ")) + )); + + stmt.execute("EXECUTE PROCEDURE testexception"); + } finally { + stmt.close(); + } + } + + /** * Tests if Firebird 3 parametrized exceptions are correctly rendered. */ @Test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-03-21 16:31:52
|
Revision: 61043 http://sourceforge.net/p/firebird/code/61043 Author: mrotteveel Date: 2015-03-21 16:31:45 +0000 (Sat, 21 Mar 2015) Log Message: ----------- Disable blob flush tests for implementations using fbclient, as those don't flush to server like the pure java implementation does. Modified Paths: -------------- client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBBlobOutputStream.java 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 2015-03-21 16:15:42 UTC (rev 61042) +++ client-java/trunk/src/openoffice/org/firebirdsql/gds/impl/oo/OOGDSFactoryPlugin.java 2015-03-21 16:31:45 UTC (rev 61043) @@ -27,7 +27,7 @@ public class OOGDSFactoryPlugin extends BaseGDSFactoryPlugin { - private static final String TYPE_NAME = "OOREMOTE"; + public static final String TYPE_NAME = "OOREMOTE"; private static final String[] TYPE_ALIASES = new String[] {}; Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBBlobOutputStream.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBBlobOutputStream.java 2015-03-21 16:15:42 UTC (rev 61042) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBBlobOutputStream.java 2015-03-21 16:31:45 UTC (rev 61043) @@ -22,6 +22,9 @@ import org.firebirdsql.common.DataGenerator; import org.firebirdsql.common.FBJUnit4TestBase; +import org.firebirdsql.common.FBTestProperties; +import org.firebirdsql.gds.impl.oo.OOGDSFactoryPlugin; +import org.firebirdsql.gds.impl.wire.JavaGDSImpl; import org.junit.After; import org.junit.Rule; import org.junit.Test; @@ -29,13 +32,16 @@ import java.io.IOException; import java.sql.Connection; +import java.util.Arrays; import static org.firebirdsql.common.FBTestProperties.getConnectionViaDriverManager; import static org.firebirdsql.common.matchers.SQLExceptionMatchers.message; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.isA; +import static org.hamcrest.Matchers.isIn; import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeThat; /** * Tests for {@link org.firebirdsql.jdbc.FBBlobOutputStream}. @@ -66,6 +72,8 @@ @Test public void testWrite_byteArr_lengthEqualToBuffer_notWrittenImmediately() throws Exception { + assumePureJavaTestType(); + initDefault(); stream.write(new byte[]{ 1, 2, 3, 4 }); @@ -78,6 +86,8 @@ @Test public void testWrite_byteArr_lengthSmallerThanBuffer_notWrittenImmediately() throws Exception { + assumePureJavaTestType(); + initDefault(); stream.write(new byte[]{ 1, 2, 3, 4 }, 0, 3); assertEquals("Partial array writes (smaller than internal buffer) are buffered", 0, stream.length()); @@ -114,6 +124,8 @@ @Test public void testWrite_byteArr_halfAndRemainderPlus1OfBufferSize_writtenOnSecondWrite() throws Exception { + assumePureJavaTestType(); + initDefault(); byte[] data = DataGenerator.createRandomBytes(((FBBlob) stream.getBlob()).getBufferLength()); int halfLength = data.length / 2; @@ -130,6 +142,8 @@ @Test public void testWrite_byteArr_largerThanBufferSize_writtenImmediately() throws Exception { + assumePureJavaTestType(); + initDefault(); byte[] data = DataGenerator.createRandomBytes((int) (((FBBlob) stream.getBlob()).getBufferLength() * 1.5)); @@ -216,6 +230,8 @@ @Test public void testWrite_byte_notWrittenImmediately() throws Exception { + assumePureJavaTestType(); + initDefault(); stream.write(1); @@ -255,4 +271,10 @@ message(equalTo("Output stream is already closed.")) )); } + + private void assumePureJavaTestType() { + assumeThat("Test only works with pure java implementations", FBTestProperties.GDS_TYPE, isIn(Arrays.asList( + JavaGDSImpl.PURE_JAVA_TYPE_NAME, + OOGDSFactoryPlugin.TYPE_NAME))); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-04-04 16:56:21
|
Revision: 61237 http://sourceforge.net/p/firebird/code/61237 Author: mrotteveel Date: 2015-04-04 16:56:12 +0000 (Sat, 04 Apr 2015) Log Message: ----------- JNA Event handling (work in progress) Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/WinFbClientLibrary.java client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10EventHandling.java Added Paths: ----------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java client-java/trunk/src/test/org/firebirdsql/gds/ng/SimpleEventHandler.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -20,6 +20,7 @@ */ package org.firebirdsql.gds.ng.jna; +import com.sun.jna.Platform; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import org.firebirdsql.encodings.Encoding; @@ -34,6 +35,7 @@ import org.firebirdsql.jdbc.FBSQLException; import org.firebirdsql.jna.fbclient.FbClientLibrary; import org.firebirdsql.jna.fbclient.ISC_STATUS; +import org.firebirdsql.jna.fbclient.WinFbClientLibrary; import org.firebirdsql.logging.Logger; import org.firebirdsql.logging.LoggerFactory; @@ -41,6 +43,7 @@ import java.nio.ByteOrder; import java.sql.SQLException; import java.sql.SQLNonTransientException; +import java.sql.SQLTransientException; import java.sql.SQLWarning; import static org.firebirdsql.gds.ISCConstants.*; @@ -349,23 +352,86 @@ } @Override - public EventHandle createEventHandle(String eventName, EventHandler eventHandler) { - throw new UnsupportedOperationException("Not implemented"); + public JnaEventHandle createEventHandle(String eventName, EventHandler eventHandler) throws SQLException { + final JnaEventHandle eventHandle = new JnaEventHandle(eventName, eventHandler, getEncoding()); + + int size; + synchronized (getSynchronizationObject()) { + size = clientLibrary.isc_event_block(eventHandle.getEventBuffer(), eventHandle.getResultBuffer(), + (short) 1, eventHandle.getEventNameMemory()); + } + eventHandle.setSize(size); + + return eventHandle; } @Override public void countEvents(EventHandle eventHandle) throws SQLException { - throw new UnsupportedOperationException("Not implemented"); + if (!(eventHandle instanceof JnaEventHandle)) { + // TODO SQLState and/or Firebird specific error + throw new SQLNonTransientException(String.format("Invalid event handle type: %s, expected: %s", + eventHandle.getClass(), JnaEventHandle.class)); + } + JnaEventHandle jnaEventHandle = (JnaEventHandle) eventHandle; + + final ISC_STATUS[] localStatusVector = new ISC_STATUS[STATUS_VECTOR_SIZE]; + synchronized (getSynchronizationObject()) { + synchronized (eventHandle) { + clientLibrary.isc_event_counts(localStatusVector, + (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(), jnaEventHandle.getResultBuffer().getValue()); + } + } + jnaEventHandle.setEventCount(localStatusVector[0].intValue()); } @Override public void queueEvent(EventHandle eventHandle) throws SQLException { - throw new UnsupportedOperationException("Not implemented"); + checkConnected(); + if (!(eventHandle instanceof JnaEventHandle)) { + // TODO SQLState and/or Firebird specific error + throw new SQLNonTransientException(String.format("Invalid event handle type: %s, expected: %s", + eventHandle.getClass(), JnaEventHandle.class)); + } + JnaEventHandle jnaEventHandle = (JnaEventHandle) eventHandle; + if (jnaEventHandle.getSize() == -1) { + // TODO SQLState and/or Firebird specific error + throw new SQLTransientException("Event handle hasn't been initialized"); + } + + synchronized (getSynchronizationObject()) { + synchronized (eventHandle) { + System.out.println("Before queue " + jnaEventHandle.getEventName()); + jnaEventHandle.debugMemoryDump(); + if (Platform.isWindows()) { + ((WinFbClientLibrary) clientLibrary).isc_que_events(statusVector, getJnaHandle(), jnaEventHandle.getJnaEventId(), + (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(), + (WinFbClientLibrary.IscEventStdCallback) jnaEventHandle.getCallback(), jnaEventHandle.getResultBuffer().getValue()); + } else { + clientLibrary.isc_que_events(statusVector, getJnaHandle(), jnaEventHandle.getJnaEventId(), + (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(), + jnaEventHandle.getCallback(), jnaEventHandle.getResultBuffer().getValue()); + } + } + processStatusVector(); + } } @Override public void cancelEvent(EventHandle eventHandle) throws SQLException { - throw new UnsupportedOperationException("Not implemented"); + checkConnected(); + if (!(eventHandle instanceof JnaEventHandle)) { + // TODO SQLState and/or Firebird specific error + throw new SQLNonTransientException(String.format("Invalid event handle type: %s, expected: %s", + eventHandle.getClass(), JnaEventHandle.class)); + } + JnaEventHandle jnaEventHandle = (JnaEventHandle) eventHandle; + + synchronized (getSynchronizationObject()) { + synchronized (eventHandle) { + clientLibrary.isc_cancel_events(statusVector, getJnaHandle(), jnaEventHandle.getJnaEventId()); + processStatusVector(); + } + } } /** Added: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java (rev 0) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -0,0 +1,170 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng.jna; + +import com.sun.jna.Memory; +import com.sun.jna.Platform; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; +import org.firebirdsql.encodings.Encoding; +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; +import org.firebirdsql.jna.fbclient.FbClientLibrary; +import org.firebirdsql.jna.fbclient.WinFbClientLibrary; + +/** + * Event handle for the JNA protocol. + * + * @author <a href="mailto:mro...@us...">Mark Rotteveel</a> + * @since 3.0 + */ +public class JnaEventHandle implements EventHandle { + + private final String eventName; + private final byte[] eventNameBytes; + private final Memory eventNameMemory; + private volatile int eventCount; + private final EventHandler eventHandler; + private final IntByReference eventId = new IntByReference(0); + private int size = -1; + private final PointerByReference eventBuffer = new PointerByReference(); + private final PointerByReference resultBuffer = new PointerByReference(); + private final JnaEventHandle.JnaEventCallback callback = createEventCallback(); + + JnaEventHandle(String eventName, EventHandler eventHandler, Encoding encoding) { + this.eventName = eventName; + this.eventHandler = eventHandler; + // Requires null-termination + eventNameBytes = encoding.encodeToCharset(eventName + '\0'); + if (eventNameBytes.length > 256) { + throw new IllegalArgumentException("Event name as bytes too long"); + } + eventNameMemory = new Memory(eventNameBytes.length); + eventNameMemory.write(0, eventNameBytes, 0, eventNameBytes.length); + } + + @Override + public String getEventName() { + return eventName; + } + + void setEventCount(int eventCount) { + this.eventCount = eventCount; + } + + @Override + public int getEventCount() { + return eventCount; + } + + @Override + public int getEventId() { + return eventId.getValue(); + } + + /** + * @return The JNA Event id + */ + IntByReference getJnaEventId() { + return eventId; + } + + /** + * @return Null-terminated name of the event. + */ + public byte[] getEventNameBytes() { + return eventNameBytes; + } + + public Memory getEventNameMemory() { + return eventNameMemory; + } + + /** + * @param size Size of the event buffers + */ + void setSize(int size) { + this.size = size; + } + + /** + * @return Size of the event buffers + */ + int getSize() { + return size; + } + + /** + * @return The event buffer with the last queued count + */ + PointerByReference getEventBuffer() { + return eventBuffer; + } + + /** + * @return The result buffer with the last received count + */ + PointerByReference getResultBuffer() { + return resultBuffer; + } + + /** + * @return Event callback + */ + FbClientLibrary.IscEventCallback getCallback() { + return callback; + } + + void debugMemoryDump() { + System.out.println("Event Buffer"); + System.out.println(getEventBuffer().getValue().dump(0, size)); + System.out.println("Result Buffer"); + System.out.println(getResultBuffer().getValue().dump(0, size)); + } + + private JnaEventCallback createEventCallback() { + return Platform.isWindows() + ? new WinJnaEventCallback() + : new JnaEventCallback(); + } + + private class JnaEventCallback implements FbClientLibrary.IscEventCallback { + @Override + public void apply(Pointer resultBuffer, short eventBufferLength, Pointer eventBuffer) { + synchronized (JnaEventHandle.this) { + final int length = eventBufferLength & 0xFFFF; + if (length == 0 || eventBuffer == null) return; + byte[] tempBuffer = new byte[length]; + eventBuffer.read(0, tempBuffer, 0, length); + resultBuffer.write(0, tempBuffer, 0, length); + + debugMemoryDump(); + } + + // TODO Push to executor? + eventHandler.eventOccurred(JnaEventHandle.this); + } + } + + private class WinJnaEventCallback extends JnaEventCallback implements WinFbClientLibrary.IscEventStdCallback { + } +} Property changes on: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -48,13 +48,23 @@ @SuppressWarnings("UnusedDeclaration") public interface FbClientLibrary { - /// <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h</i> - public interface FbShutdownCallback extends Callback { + /** + * FbShutdown callback. + * <p> + * <b>Important:</b> On windows, use {@link org.firebirdsql.jna.fbclient.WinFbClientLibrary.FbShutdownStdCallback} + * </p> + */ + interface FbShutdownCallback extends Callback { int apply(int reason, int mask, Pointer arg); } - /// <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h</i> - public interface IscEventCallback extends Callback { - void apply(Pointer voidPtr1, short ISC_USHORT1, Pointer ISC_UCHARPtr1); + /** + * IscEvent callback. + * <p> + * <b>Important:</b> On windows, use {@link org.firebirdsql.jna.fbclient.WinFbClientLibrary.IscEventStdCallback} + * </p> + */ + interface IscEventCallback extends Callback { + void apply(Pointer resultBuffer, short eventBufferLength, Pointer eventBuffer); } /** * Original signature : <code>ISC_STATUS isc_attach_database(ISC_STATUS*, short, const ISC_SCHAR*, isc_db_handle*, short, const ISC_SCHAR*)</code><br> @@ -130,7 +140,7 @@ * Original signature : <code>ISC_STATUS isc_cancel_events(ISC_STATUS*, isc_db_handle*, ISC_LONG*)</code><br> * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h:492</i> */ - ISC_STATUS isc_cancel_events(ISC_STATUS[] statusVector, IntByReference dbHandle, IntBuffer eventIds); + ISC_STATUS isc_cancel_events(ISC_STATUS[] statusVector, IntByReference dbHandle, IntByReference eventId); /** * Original signature : <code>ISC_STATUS isc_close_blob(ISC_STATUS*, isc_blob_handle*)</code><br> * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h:496</i> @@ -324,7 +334,7 @@ * Original signature : <code>void isc_event_counts(ISC_ULONG*, short, ISC_UCHAR*, const ISC_UCHAR*)</code><br> * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h:663</i> */ - void isc_event_counts(ISC_STATUS[] statusVector, short bufferLength, ByteBuffer eventBuffer, byte[] resultBuffer); + void isc_event_counts(ISC_STATUS[] statusVector, short bufferLength, Pointer eventBuffer, Pointer resultBuffer); /** * 17 May 2001 - isc_expand_dpb is DEPRECATED<br> * Original signature : <code>void isc_expand_dpb(ISC_SCHAR**, short*, null)</code><br> @@ -408,8 +418,8 @@ * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h:747</i> * TODO: Currently does not satisfy requirements in documentation! */ - ISC_STATUS isc_que_events(ISC_STATUS[] statusVector, IntByReference dbHandle, IntBuffer eventId, short length, - byte[] eventBuffer, IscEventCallback eventFunction, Pointer eventFunctionArg); + ISC_STATUS isc_que_events(ISC_STATUS[] statusVector, IntByReference dbHandle, IntByReference eventId, short length, + Pointer eventBuffer, IscEventCallback eventFunction, Pointer eventFunctionArg); /** * Original signature : <code>ISC_STATUS isc_rollback_retaining(ISC_STATUS*, isc_tr_handle*)</code><br> * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h:755</i> Modified: client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/WinFbClientLibrary.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/WinFbClientLibrary.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/WinFbClientLibrary.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -20,6 +20,8 @@ */ package org.firebirdsql.jna.fbclient; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.IntByReference; import com.sun.jna.win32.StdCallLibrary; /** @@ -35,4 +37,24 @@ * @since 3.0 */ public interface WinFbClientLibrary extends FbClientLibrary, StdCallLibrary { + /** + * FbShutdown Callback following the StdCall conventions + * <p> + * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h</i> + * </p> + */ + interface FbShutdownStdCallback extends FbShutdownCallback, StdCallLibrary.StdCallCallback { + } + + /** + * IscEvent Callback following the StdCall conventions + * <p> + * <i>native declaration : C:\Program Files\Firebird\Firebird_2_5\include\ibase.h</i> + * </p> + */ + interface IscEventStdCallback extends IscEventCallback, StdCallLibrary.StdCallCallback { + } + + ISC_STATUS isc_que_events(ISC_STATUS[] statusVector, IntByReference dbHandle, IntByReference eventId, short length, + Pointer eventBuffer, IscEventStdCallback eventFunction, Pointer eventFunctionArg); } Modified: client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java =================================================================== --- client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -20,15 +20,16 @@ */ package org.firebirdsql.gds.ng.jna; +import com.sun.jna.Native; import org.firebirdsql.common.FBTestProperties; +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.TransactionParameterBuffer; import org.firebirdsql.gds.impl.GDSServerVersion; import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; -import org.firebirdsql.gds.ng.FbConnectionProperties; -import org.firebirdsql.gds.ng.FbDatabase; -import org.firebirdsql.gds.ng.FbTransaction; -import org.firebirdsql.gds.ng.TransactionState; +import org.firebirdsql.gds.ng.*; +import org.firebirdsql.gds.ng.fields.RowValue; import org.firebirdsql.jdbc.FBSQLException; import org.firebirdsql.management.FBManager; import org.junit.BeforeClass; @@ -56,6 +57,21 @@ // TODO Check if tests can be unified with equivalent wire protocol tests // TODO Assert in tests need to be checked (and more need to be added) + //@formatter:off + public static final String TABLE_DEF = + "CREATE TABLE TEST (" + + " TESTVAL INTEGER NOT NULL" + + ")"; + + public static final String TRIGGER_DEF = + "CREATE TRIGGER INSERT_TRIG " + + " FOR TEST AFTER INSERT " + + "AS BEGIN " + + " POST_EVENT 'TEST_EVENT_A';" + + " POST_EVENT 'TEST_EVENT_B';" + + "END"; + //@formatter:on + @Rule public final ExpectedException expectedException = ExpectedException.none(); @@ -286,6 +302,98 @@ } @Test + public void testCreateEventHandle() throws Exception { + FBManager fbManager = createFBManager(); + defaultDatabaseSetUp(fbManager); + try { + JnaDatabase db = factory.connect(connectionInfo); + try { + db.attach(); + + JnaEventHandle eventHandle = db.createEventHandle("TEST_EVENT", new EventHandler() { + @Override + public void eventOccurred(EventHandle eventHandle) { } + }); + + assertNotEquals("Event handle should have a size set", -1, eventHandle.getSize()); + } finally { + safelyClose(db); + } + } finally { + defaultDatabaseTearDown(fbManager); + } + } + + @Test + public void testQueueEvent_andNotification() throws Exception { + FBManager fbManager = createFBManager(); + defaultDatabaseSetUp(fbManager); + try { + JnaDatabase db = factory.connect(connectionInfo); + try { + db.attach(); + + FbTransaction transaction = getTransaction(db); + final FbStatement statement = db.createStatement(transaction); + statement.prepare(TABLE_DEF); + statement.execute(RowValue.EMPTY_ROW_VALUE); + statement.prepare(TRIGGER_DEF); + statement.execute(RowValue.EMPTY_ROW_VALUE); + transaction.commit(); + + SimpleEventHandler eventHandler = new SimpleEventHandler(); + + EventHandle eventHandleA = db.createEventHandle("TEST_EVENT_A", eventHandler); + db.queueEvent(eventHandleA); + EventHandle eventHandleB = db.createEventHandle("TEST_EVENT_B", eventHandler); + db.queueEvent(eventHandleB); + + Thread.sleep(50); + eventHandler.clearEvents(); + db.countEvents(eventHandleA); +// System.out.println("A"); +// ((JnaEventHandle) eventHandleA).debugMemoryDump(); + db.queueEvent(eventHandleA); + db.countEvents(eventHandleB); +// System.out.println("B"); +// ((JnaEventHandle) eventHandleB).debugMemoryDump(); + db.queueEvent(eventHandleB); + +// assertTrue("Expected events to not have been triggered", eventHandler.getReceivedEventHandles().isEmpty()); +// +// transaction = getTransaction(db); +// statement.setTransaction(transaction); +// statement.prepare("INSERT INTO TEST VALUES (1)"); +// statement.execute(RowValue.EMPTY_ROW_VALUE); +// transaction.commit(); +// +// int retry = 0; +// while (!eventHandler.getReceivedEventHandles().contains(eventHandleA) && retry++ < 10) { +// Thread.sleep(50); +// } +// +// db.countEvents(eventHandleA); +// assertEquals(1, eventHandleA.getEventCount()); +// +// retry = 0; +// while (!eventHandler.getReceivedEventHandles().contains(eventHandleB) && retry++ < 10) { +// Thread.sleep(50); +// } +// +// db.countEvents(eventHandleB); +// assertEquals(1, eventHandleB.getEventCount()); + + db.cancelEvent(eventHandleA); + db.cancelEvent(eventHandleB); + } finally { + safelyClose(db); + } + } finally { + defaultDatabaseTearDown(fbManager); + } + } + + @Test public void testExecuteImmediate_createDatabase() throws Exception { JnaDatabase db = factory.connect(connectionInfo); try { @@ -313,6 +421,7 @@ try { db.detach(); } catch (SQLException ex) { + ex.printStackTrace(); // ignore (TODO: log) } } Modified: client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/main/org/firebirdsql/event/FBEventManager.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -291,7 +291,7 @@ private boolean initialized = false; private boolean cancelled = false; - public GdsEventHandler(String eventName) { + public GdsEventHandler(String eventName) throws SQLException { eventHandle = fbDatabase.createEventHandle(eventName, this); } Modified: client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/main/org/firebirdsql/gds/ng/FbDatabase.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -299,8 +299,9 @@ * @param eventHandler * The event handler to call when the event occurred * @return A suitable event handle instance + * @throws java.sql.SQLException For errors creating the event handle */ - EventHandle createEventHandle(String eventName, EventHandler eventHandler); + EventHandle createEventHandle(String eventName, EventHandler eventHandler) throws SQLException; /** * Counts the events occurred. Added: client-java/trunk/src/test/org/firebirdsql/gds/ng/SimpleEventHandler.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/ng/SimpleEventHandler.java (rev 0) +++ client-java/trunk/src/test/org/firebirdsql/gds/ng/SimpleEventHandler.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -0,0 +1,51 @@ +/* + * $Id$ + * + * Firebird Open Source JavaEE 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 source control history command. + * + * All rights reserved. + */ +package org.firebirdsql.gds.ng; + +import org.firebirdsql.gds.EventHandle; +import org.firebirdsql.gds.EventHandler; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** +* @author <a href="mailto:mro...@us...">Mark Rotteveel</a> +*/ +public class SimpleEventHandler implements EventHandler { + + private final List<EventHandle> receivedEventHandles = Collections.synchronizedList(new ArrayList<EventHandle>()); + + @Override + public void eventOccurred(EventHandle eventHandle) { + receivedEventHandles.add(eventHandle); + } + + public List<EventHandle> getReceivedEventHandles() { + synchronized (receivedEventHandles) { + return new ArrayList<EventHandle>(receivedEventHandles); + } + } + + public void clearEvents() { + receivedEventHandles.clear(); + } +} Property changes on: client-java/trunk/src/test/org/firebirdsql/gds/ng/SimpleEventHandler.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-java-source \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10EventHandling.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10EventHandling.java 2015-04-04 16:41:59 UTC (rev 61236) +++ client-java/trunk/src/test/org/firebirdsql/gds/ng/wire/version10/TestV10EventHandling.java 2015-04-04 16:56:12 UTC (rev 61237) @@ -25,15 +25,11 @@ import org.firebirdsql.common.SimpleServer; import org.firebirdsql.encodings.EncodingFactory; import org.firebirdsql.gds.EventHandle; -import org.firebirdsql.gds.EventHandler; import org.firebirdsql.gds.ISCConstants; import org.firebirdsql.gds.TransactionParameterBuffer; import org.firebirdsql.gds.impl.TransactionParameterBufferImpl; import org.firebirdsql.gds.impl.wire.XdrOutputStream; -import org.firebirdsql.gds.ng.FbConnectionProperties; -import org.firebirdsql.gds.ng.FbDatabase; -import org.firebirdsql.gds.ng.FbStatement; -import org.firebirdsql.gds.ng.FbTransaction; +import org.firebirdsql.gds.ng.*; import org.firebirdsql.gds.ng.fields.RowValue; import org.firebirdsql.gds.ng.wire.*; import org.junit.After; @@ -43,8 +39,6 @@ import java.io.OutputStream; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static org.firebirdsql.common.FBTestProperties.DB_PASSWORD; @@ -417,20 +411,4 @@ tpb.addArgument(ISCConstants.isc_tpb_wait); return db.startTransaction(tpb); } - - protected static class SimpleEventHandler implements EventHandler { - - private final List<EventHandle> receivedEventHandles = Collections.synchronizedList(new ArrayList<EventHandle>()); - - @Override - public void eventOccurred(EventHandle eventHandle) { - receivedEventHandles.add(eventHandle); - } - - public List<EventHandle> getReceivedEventHandles() { - synchronized (receivedEventHandles) { - return new ArrayList<EventHandle>(receivedEventHandles); - } - } - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-04-11 16:11:18
|
Revision: 61291 http://sourceforge.net/p/firebird/code/61291 Author: mrotteveel Date: 2015-04-11 16:11:16 +0000 (Sat, 11 Apr 2015) Log Message: ----------- JDBC-390 Support obtaining update count after statement that produces a result set. Modified Paths: -------------- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2015-04-11 16:04:47 UTC (rev 61290) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java 2015-04-11 16:11:16 UTC (rev 61291) @@ -782,11 +782,16 @@ try { // TODO: add a statement listener for controlling information exchange + // TODO Is this still correct in light of the listener in FBStatement fbStatement.execute(fieldValues); - isResultSet = fbStatement.getFieldDescriptor().getCount() > 0; - return isResultSet; - } finally { - hasMoreResults = true; + boolean hasResultSet = fbStatement.getFieldDescriptor().getCount() > 0; + currentStatementResult = hasResultSet + ? StatementResult.RESULT_SET + : StatementResult.UPDATE_COUNT; + return hasResultSet; + } catch (SQLException e) { + currentStatementResult = StatementResult.NO_MORE_RESULTS; + throw e; } } } Modified: client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java 2015-04-11 16:04:47 UTC (rev 61290) +++ client-java/trunk/src/main/org/firebirdsql/jdbc/FBStatement.java 2015-04-11 16:11:16 UTC (rev 61291) @@ -20,11 +20,10 @@ */ package org.firebirdsql.jdbc; -import java.sql.*; -import java.util.*; - -import org.firebirdsql.gds.*; -import org.firebirdsql.gds.impl.*; +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.gds.ng.FbStatement; import org.firebirdsql.gds.ng.SqlCountHolder; import org.firebirdsql.gds.ng.StatementState; @@ -35,17 +34,21 @@ import org.firebirdsql.jdbc.escape.FBEscapedParser.EscapeParserMode; import org.firebirdsql.logging.LoggerFactory; +import java.sql.*; +import java.util.*; + /** - * <P>The object used for executing a static SQL statement - * and obtaining the results produced by it. + * The object used for executing a static SQL statement and obtaining the results produced by it. * - * <P>Only one <code>ResultSet</code> object per <code>Statement</code> object + * <p> + * Only one <code>ResultSet</code> object per <code>Statement</code> object * can be open at any point in * time. Therefore, if the reading of one <code>ResultSet</code> object is interleaved * with the reading of another, each must have been generated by * different <code>Statement</code> objects. All statement <code>execute</code> * methods implicitly close a statement's current <code>ResultSet</code> object * if an open one exists. + * </p> * * @see Connection#createStatement * @see ResultSet @@ -62,7 +65,7 @@ protected FbStatement fbStatement; - //The normally retrieved resultset. (no autocommit, not a cached rs). + //The normally retrieved result set. (no autocommit, not a cached rs). private FBResultSet currentRs; private SqlCountHolder sqlCountHolder; @@ -75,9 +78,7 @@ protected SQLWarning firstWarning; - // If the last executedStatement returns ResultSet or UpdateCount - protected boolean isResultSet; - protected boolean hasMoreResults; + protected StatementResult currentStatementResult = StatementResult.NO_MORE_RESULTS; // Singleton result indicates it is a stored procedure or [INSERT | UPDATE | DELETE] ... RETURNING ... protected boolean isSingletonResult; @@ -887,6 +888,7 @@ * @see #execute */ public ResultSet getResultSet() throws SQLException { + checkValidity(); return getResultSet(false); } @@ -905,7 +907,7 @@ // A generated keys query does not produce a normal result set (but EXECUTE PROCEDURE or INSERT ... RETURNING without Statement.RETURN_GENERATED_KEYS do) // TODO Behavior might not be correct for callable statement implementation - if (!isGeneratedKeyQuery()) { + if (!isGeneratedKeyQuery() && currentStatementResult == StatementResult.RESULT_SET) { if (!isSingletonResult) { currentRs = new FBResultSet(gdsHelper, this, fbStatement, resultSetListener, metaDataQuery, rsType, rsConcurrency, rsHoldability, false); @@ -932,47 +934,44 @@ * @see #execute */ public int getUpdateCount() throws SQLException { - if (isResultSet || (sqlCountHolder == null && !hasMoreResults)) + checkValidity(); + + if (currentStatementResult != StatementResult.UPDATE_COUNT) { return -1; - else { - if (sqlCountHolder == null) { - sqlCountHolder = fbStatement.getSqlCounts(); - } - try { - int insCount = sqlCountHolder.getIntegerInsertCount(); - int updCount = sqlCountHolder.getIntegerUpdateCount(); - int delCount = sqlCountHolder.getIntegerDeleteCount(); - return Math.max(Math.max(updCount, delCount), insCount); - } finally { - hasMoreResults = false; - } } + populateSqlCounts(); + int insCount = sqlCountHolder.getIntegerInsertCount(); + int updCount = sqlCountHolder.getIntegerUpdateCount(); + int delCount = sqlCountHolder.getIntegerDeleteCount(); + return Math.max(Math.max(updCount, delCount), insCount); } + private void populateSqlCounts() throws SQLException { + if (sqlCountHolder == null) { + sqlCountHolder = fbStatement.getSqlCounts(); + } + } + private static final int INSERTED_ROWS_COUNT = 1; private static final int UPDATED_ROWS_COUNT = 2; private static final int DELETED_ROWS_COUNT = 3; - - private int getChangedRowsCount(int type) throws SQLException { - if (isResultSet || (sqlCountHolder == null && !hasMoreResults)) + + private int getChangedRowsCount(int type) throws SQLException { + if (currentStatementResult != StatementResult.UPDATE_COUNT) { return -1; - else { - if (sqlCountHolder == null) { - sqlCountHolder = fbStatement.getSqlCounts(); - } - switch(type) { - case INSERTED_ROWS_COUNT : - return sqlCountHolder.getIntegerInsertCount(); - case UPDATED_ROWS_COUNT : - return sqlCountHolder.getIntegerUpdateCount(); - case DELETED_ROWS_COUNT : - return sqlCountHolder.getIntegerDeleteCount(); - default : - throw new IllegalArgumentException( - "Specified type is unknown."); - } } - } + populateSqlCounts(); + switch (type) { + case INSERTED_ROWS_COUNT: + return sqlCountHolder.getIntegerInsertCount(); + case UPDATED_ROWS_COUNT: + return sqlCountHolder.getIntegerUpdateCount(); + case DELETED_ROWS_COUNT: + return sqlCountHolder.getIntegerDeleteCount(); + default: + throw new IllegalArgumentException(String.format("Specified type %d is unknown.", type)); + } + } public int getDeletedRowsCount() throws SQLException { return getChangedRowsCount(DELETED_ROWS_COUNT); @@ -1007,8 +1006,7 @@ } public boolean getMoreResults(int mode) throws SQLException { - // TODO evaluate if right assignment here - hasMoreResults = false; + checkValidity(); boolean closeResultSet = mode == Statement.CLOSE_ALL_RESULTS || mode == Statement.CLOSE_CURRENT_RESULT; @@ -1016,8 +1014,10 @@ if (closeResultSet && currentRs != null) { closeResultSet(true); } - - return hasMoreResults; + currentStatementResult = currentStatementResult.nextResult(); + + // Technically the statement below is always false, as only the first result is ever a ResultSet + return currentStatementResult == StatementResult.RESULT_SET; } /** @@ -1385,11 +1385,8 @@ return trimmedSql.startsWith("EXECUTE"); } - protected boolean internalExecute(String sql) - throws GDSException, SQLException - { - if (closed) - throw new FBSQLException("Statement is already closed."); + protected boolean internalExecute(String sql) throws GDSException, SQLException { + checkValidity(); // closeResultSet(false); // TODO Consider use/implementation of execute immediate? @@ -1402,21 +1399,21 @@ hasMoreResults = true; isResultSet = fixedStmt.getOutSqlda().sqld > 0; */ - return isResultSet; + return currentStatementResult == StatementResult.RESULT_SET; } protected void prepareFixedStatement(String sql) throws SQLException { // TODO: Statement should be created and allocated at FBStatement creation only. if (fbStatement == null) { fbStatement = gdsHelper.allocateStatement(); - fbStatement.addStatementListener(createStatementLister()); + fbStatement.addStatementListener(createStatementListener()); } else { fbStatement.setTransaction(gdsHelper.getCurrentTransaction()); } fbStatement.prepare(escapedProcessing ? nativeSQL(sql) : sql); } - protected void addWarning(SQLWarning warning){ + protected void addWarning(SQLWarning warning) { if (firstWarning == null) { firstWarning = warning; } else { @@ -1588,7 +1585,7 @@ * Reasons for statement completion. This is intended for the {@link InternalTransactionCoordinator} to * notify the statement on why it should complete. * <p> - * TODO: This is a bit of kludge to fix <a href="http://tracker.firebirdsql.org/browse/JDBC-304">JDBC-304</a> in 2.2.x, might need some more polish for 2.3 + * TODO: This is a bit of kludge to fix <a href="http://tracker.firebirdsql.org/browse/JDBC-304">JDBC-304</a> in 2.2.x, might need some more polish for 3.0 * </p> * @since 2.2.3 */ @@ -1598,12 +1595,41 @@ } /** + * The current result of a statement. + */ + protected enum StatementResult { + RESULT_SET { + @Override + public StatementResult nextResult() { + return UPDATE_COUNT; + } + }, + UPDATE_COUNT { + @Override + public StatementResult nextResult() { + return NO_MORE_RESULTS; + } + }, + NO_MORE_RESULTS { + @Override + public StatementResult nextResult() { + return NO_MORE_RESULTS; + } + }; + + /** + * @return Next result + */ + public abstract StatementResult nextResult(); + } + + /** * Creates the {@link org.firebirdsql.gds.ng.listeners.StatementListener} to be associated with the instance of * {@link org.firebirdsql.gds.ng.FbStatement} created for this {@link FBStatement} or subclasses. * * @return instance of {@link org.firebirdsql.gds.ng.listeners.StatementListener} */ - protected StatementListener createStatementLister() { + protected StatementListener createStatementListener() { return new FBStatementListener(); } @@ -1627,9 +1653,9 @@ public void statementExecuted(FbStatement sender, boolean hasResultSet, boolean hasSingletonResult) { if (!isValidSender(sender)) return; // TODO If true create ResultSet and attach listener to sender - isResultSet = hasResultSet; - // TODO Is this also valid for CallableStatement? - hasMoreResults = hasResultSet || hasSingletonResult && !isGeneratedKeyQuery(); + currentStatementResult = hasResultSet || hasSingletonResult && !isGeneratedKeyQuery() + ? StatementResult.RESULT_SET + : StatementResult.UPDATE_COUNT; isSingletonResult = hasSingletonResult; } @@ -1643,8 +1669,7 @@ case EXECUTING: singletonResult = null; sqlCountHolder = null; - hasMoreResults = false; - isResultSet = false; + currentStatementResult = StatementResult.NO_MORE_RESULTS; isSingletonResult = false; try { clearWarnings(); Modified: client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java =================================================================== --- client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java 2015-04-11 16:04:47 UTC (rev 61290) +++ client-java/trunk/src/main/org/firebirdsql/util/FirebirdSupportInfo.java 2015-04-11 16:11:16 UTC (rev 61291) @@ -119,6 +119,13 @@ } /** + * @return <code>true</code> when UPDATE ... RETURNING ... is supported + */ + public boolean supportsUpdateReturning() { + return serverVersion.isEqualOrAbove(2, 1); + } + + /** * @return <code>true</code> when the server knows the UTF8 character set (NOTE: For firebird 1.5 it is an alias for * UNICODE_FSS) */ Modified: client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java =================================================================== --- client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java 2015-04-11 16:04:47 UTC (rev 61290) +++ client-java/trunk/src/test/org/firebirdsql/jdbc/TestFBStatement.java 2015-04-11 16:11:16 UTC (rev 61291) @@ -974,6 +974,35 @@ } } + @Test + public void testRetrievingUpdateCountAndResultSet() throws Exception { + assumeTrue("Test requires UPDATE .. RETURNING .. support", supportInfoFor(con).supportsUpdateReturning()); + executeDDL(con, CREATE_TABLE); + + Statement stmt = con.createStatement(); + try { + boolean isResultSet = stmt.execute("INSERT INTO test(col1) VALUES(5) RETURNING col1"); + + assertTrue("Expected first result to be a result set", isResultSet); + ResultSet rs = stmt.getResultSet(); + assertNotNull("Result set should not be null", rs); + assertTrue("Expected a row in the result set", rs.next()); + assertEquals("Unexpected value in result set", 5, rs.getInt(1)); + assertFalse("Expected only one row", rs.next()); + assertEquals("Update count should be -1 before first call to getMoreResults", -1, stmt.getUpdateCount()); + + assertFalse("Next result should not be a result set", stmt.getMoreResults()); + assertNull("Expected null result set", stmt.getResultSet()); + assertEquals("Update count should be 1 after first call to getMoreResults", 1, stmt.getUpdateCount()); + + assertFalse("Next result should not be a result set", stmt.getMoreResults()); + assertNull("Expected null result set", stmt.getResultSet()); + assertEquals("Update count should be -1 after second call to getMoreResults", -1, stmt.getUpdateCount()); + } finally { + stmt.close(); + } + } + private void prepareTestData() throws SQLException { executeCreateTable(con, CREATE_TABLE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mro...@us...> - 2015-04-19 12:38:19
|
Revision: 61365 http://sourceforge.net/p/firebird/code/61365 Author: mrotteveel Date: 2015-04-19 12:38:11 +0000 (Sun, 19 Apr 2015) Log Message: ----------- JNA events (work in progress) Modified Paths: -------------- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-04-19 11:45:53 UTC (rev 61364) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java 2015-04-19 12:38:11 UTC (rev 61365) @@ -374,14 +374,14 @@ } JnaEventHandle jnaEventHandle = (JnaEventHandle) eventHandle; - final ISC_STATUS[] localStatusVector = new ISC_STATUS[STATUS_VECTOR_SIZE]; synchronized (getSynchronizationObject()) { synchronized (eventHandle) { - clientLibrary.isc_event_counts(localStatusVector, + clientLibrary.isc_event_counts(statusVector, (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(), jnaEventHandle.getResultBuffer().getValue()); + processStatusVector(); } } - jnaEventHandle.setEventCount(localStatusVector[0].intValue()); + jnaEventHandle.setEventCount(statusVector[0].intValue()); } @Override @@ -400,8 +400,6 @@ synchronized (getSynchronizationObject()) { synchronized (eventHandle) { - System.out.println("Before queue " + jnaEventHandle.getEventName()); - jnaEventHandle.debugMemoryDump(); if (Platform.isWindows()) { ((WinFbClientLibrary) clientLibrary).isc_que_events(statusVector, getJnaHandle(), jnaEventHandle.getJnaEventId(), (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(), Modified: client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java 2015-04-19 11:45:53 UTC (rev 61364) +++ client-java/trunk/src/jna-client/org/firebirdsql/gds/ng/jna/JnaEventHandle.java 2015-04-19 12:38:11 UTC (rev 61365) @@ -135,10 +135,12 @@ } void debugMemoryDump() { - System.out.println("Event Buffer"); - System.out.println(getEventBuffer().getValue().dump(0, size)); - System.out.println("Result Buffer"); - System.out.println(getResultBuffer().getValue().dump(0, size)); + synchronized (JnaEventHandle.class) { + System.out.println("Event Buffer " + getEventName()); + System.out.println(getEventBuffer().getValue().dump(0, size)); + System.out.println("Result Buffer " + getEventName()); + System.out.println(getResultBuffer().getValue().dump(0, size)); + } } private JnaEventCallback createEventCallback() { @@ -149,15 +151,14 @@ private class JnaEventCallback implements FbClientLibrary.IscEventCallback { @Override - public void apply(Pointer resultBuffer, short eventBufferLength, Pointer eventBuffer) { + public void apply(Pointer resultArgument, short eventBufferLength, Pointer eventsList) { synchronized (JnaEventHandle.this) { final int length = eventBufferLength & 0xFFFF; - if (length == 0 || eventBuffer == null) return; + System.out.println("Length for " + getEventName() + " " + length); + if (length == 0 || eventsList == null) return; byte[] tempBuffer = new byte[length]; - eventBuffer.read(0, tempBuffer, 0, length); - resultBuffer.write(0, tempBuffer, 0, length); - - debugMemoryDump(); + eventsList.read(0, tempBuffer, 0, length); + resultArgument.write(0, tempBuffer, 0, length); } // TODO Push to executor? Modified: client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java =================================================================== --- client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java 2015-04-19 11:45:53 UTC (rev 61364) +++ client-java/trunk/src/jna-client/org/firebirdsql/jna/fbclient/FbClientLibrary.java 2015-04-19 12:38:11 UTC (rev 61365) @@ -64,7 +64,7 @@ * </p> */ interface IscEventCallback extends Callback { - void apply(Pointer resultBuffer, short eventBufferLength, Pointer eventBuffer); + void apply(Pointer resultArgument, short eventBufferLength, Pointer eventsList); } /** * Original signature : <code>ISC_STATUS isc_attach_database(ISC_STATUS*, short, const ISC_SCHAR*, isc_db_handle*, short, const ISC_SCHAR*)</code><br> Modified: client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java =================================================================== --- client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-04-19 11:45:53 UTC (rev 61364) +++ client-java/trunk/src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java 2015-04-19 12:38:11 UTC (rev 61365) @@ -20,7 +20,10 @@ */ package org.firebirdsql.gds.ng.jna; -import com.sun.jna.Native; +import com.sun.jna.Memory; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; import org.firebirdsql.common.FBTestProperties; import org.firebirdsql.gds.EventHandle; import org.firebirdsql.gds.EventHandler; @@ -31,8 +34,11 @@ import org.firebirdsql.gds.ng.*; import org.firebirdsql.gds.ng.fields.RowValue; import org.firebirdsql.jdbc.FBSQLException; +import org.firebirdsql.jna.fbclient.FbClientLibrary; +import org.firebirdsql.jna.fbclient.ISC_STATUS; import org.firebirdsql.management.FBManager; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -344,19 +350,19 @@ SimpleEventHandler eventHandler = new SimpleEventHandler(); EventHandle eventHandleA = db.createEventHandle("TEST_EVENT_A", eventHandler); + EventHandle eventHandleB = db.createEventHandle("TEST_EVENT_B", eventHandler); + db.queueEvent(eventHandleA); - EventHandle eventHandleB = db.createEventHandle("TEST_EVENT_B", eventHandler); + //Thread.sleep(5); db.queueEvent(eventHandleB); Thread.sleep(50); eventHandler.clearEvents(); db.countEvents(eventHandleA); -// System.out.println("A"); -// ((JnaEventHandle) eventHandleA).debugMemoryDump(); + db.queueEvent(eventHandleA); db.countEvents(eventHandleB); -// System.out.println("B"); -// ((JnaEventHandle) eventHandleB).debugMemoryDump(); + db.queueEvent(eventHandleB); // assertTrue("Expected events to not have been triggered", eventHandler.getReceivedEventHandles().isEmpty()); @@ -393,7 +399,146 @@ } } + @Ignore @Test + public void testQueueEvent_andNotification_plainAPI() throws Exception { + FBManager fbManager = createFBManager(); + defaultDatabaseSetUp(fbManager); + try { + JnaDatabase db = factory.connect(connectionInfo); + try { + db.attach(); + final FbClientLibrary clientLibrary = db.getClientLibrary(); + + // Block for event A + byte[] eventNameA = db.getEncoding().encodeToCharset("TEST_EVENT_A"); + Memory eventNameMemoryA = new Memory(eventNameA.length + 1); + eventNameMemoryA.clear(); + eventNameMemoryA.write(0, eventNameA, 0, eventNameA.length); + PointerByReference eventBufferA = new PointerByReference(); + PointerByReference resultBufferA = new PointerByReference(); + int sizeA = clientLibrary.isc_event_block(eventBufferA, resultBufferA, + (short) 1, eventNameMemoryA); + + // Block for event B + byte[] eventNameB = db.getEncoding().encodeToCharset("TEST_EVENT_B"); + Memory eventNameMemoryB = new Memory(eventNameB.length + 1); + eventNameMemoryB.clear(); + eventNameMemoryB.write(0, eventNameB, 0, eventNameB.length); + PointerByReference eventBufferB = new PointerByReference(); + PointerByReference resultBufferB = new PointerByReference(); + int sizeB = clientLibrary.isc_event_block(eventBufferB, resultBufferB, + (short) 1, eventNameMemoryB); + + final FbClientLibrary.IscEventCallback callbackA = new FbClientLibrary.IscEventCallback() { + @Override + public void apply(Pointer resultArgument, short eventBufferLength, Pointer eventsList) { + System.out.println("Callback for A"); + if (eventBufferLength == 0) { + System.out.println("Zero"); + return; + } + byte[] tempBuffer = new byte[eventBufferLength]; + eventsList.read(0, tempBuffer, 0, eventBufferLength); + resultArgument.write(0, tempBuffer, 0, eventBufferLength); + } + }; + + final FbClientLibrary.IscEventCallback callbackB = new FbClientLibrary.IscEventCallback() { + @Override + public void apply(Pointer resultArgument, short eventBufferLength, Pointer eventsList) { + System.out.println("Callback for B"); + if (eventBufferLength == 0) { + System.out.println("Zero"); + return; + } + byte[] tempBuffer = new byte[eventBufferLength]; + eventsList.read(0, tempBuffer, 0, eventBufferLength); + resultArgument.write(0, tempBuffer, 0, eventBufferLength); + } + }; + + ISC_STATUS[] statusVector = new ISC_STATUS[20]; + + IntByReference eventAId = new IntByReference(); + clientLibrary.isc_que_events(statusVector, db.getJnaHandle(), eventAId, + (short) sizeA, eventBufferA.getValue(), + callbackA, resultBufferA.getValue()); + db.processStatusVector(statusVector, null); + + //Thread.sleep(5); + IntByReference eventBId = new IntByReference(); + clientLibrary.isc_que_events(statusVector, db.getJnaHandle(), eventBId, + (short) sizeB, eventBufferB.getValue(), + callbackB, resultBufferB.getValue()); + db.processStatusVector(statusVector, null); + + Thread.sleep(50); + System.out.println(eventBufferA.getValue().dump(0, sizeA)); + System.out.println(eventBufferB.getValue().dump(0, sizeB)); + + clientLibrary.isc_event_counts(statusVector, (short) sizeA, eventBufferA.getValue(), resultBufferA.getValue()); + db.processStatusVector(statusVector, null); + + clientLibrary.isc_que_events(statusVector, db.getJnaHandle(), eventAId, + (short) sizeA, eventBufferA.getValue(), + callbackA, resultBufferA.getValue()); + db.processStatusVector(statusVector, null); + + clientLibrary.isc_event_counts(statusVector, (short) sizeB, eventBufferA.getValue(), resultBufferB.getValue()); + db.processStatusVector(statusVector, null); + + clientLibrary.isc_que_events(statusVector, db.getJnaHandle(), eventBId, + (short) sizeB, eventBufferB.getValue(), + callbackB, resultBufferB.getValue()); + db.processStatusVector(statusVector, null); + + Thread.sleep(50); + System.out.println(eventBufferA.getValue().dump(0, sizeA)); + System.out.println(eventBufferB.getValue().dump(0, sizeB)); + +// assertTrue("Expected events to not have been triggered", eventHandler.getReceivedEventHandles().isEmpty()); +// +// transaction = getTransaction(db); +// statement.setTransaction(transaction); +// statement.prepare("INSERT INTO TEST VALUES (1)"); +// statement.execute(RowValue.EMPTY_ROW_VALUE); +// transaction.commit(); +// +// int retry = 0; +// while (!eventHandler.getReceivedEventHandles().contains(eventHandleA) && retry++ < 10) { +// Thread.sleep(50); +// } +// +// db.countEvents(eventHandleA); +// assertEquals(1, eventHandleA.getEventCount()); +// +// retry = 0; +// while (!eventHandler.getReceivedEventHandles().contains(eventHandleB) && retry++ < 10) { +// Thread.sleep(50); +// } +// +// db.countEvents(eventHandleB); +// assertEquals(1, eventHandleB.getEventCount()); + + Thread.sleep(100); + + System.out.println(eventAId.getValue()); + clientLibrary.isc_cancel_events(statusVector, db.getJnaHandle(), eventAId); + db.processStatusVector(statusVector, null); + Thread.sleep(100); + System.out.println(eventBId.getValue()); + clientLibrary.isc_cancel_events(statusVector, db.getJnaHandle(), eventBId); + db.processStatusVector(statusVector, null); + } finally { + safelyClose(db); + } + } finally { + defaultDatabaseTearDown(fbManager); + } + } + + @Test public void testExecuteImmediate_createDatabase() throws Exception { JnaDatabase db = factory.connect(connectionInfo); try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |