You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ba...@apache.org on 2005/04/28 21:05:45 UTC
svn commit: r165178 [1/26] - in /incubator/derby/code/trunk: ./ java/client/
java/client/org/ java/client/org/apache/ java/client/org/apache/derby/
java/client/org/apache/derby/client/ java/client/org/apache/derby/client/am/
java/client/org/apache/derby/client/net/
java/client/org/apache/derby/client/resources/
java/client/org/apache/derby/jdbc/ tools/ant/properties/
Author: bandaram
Date: Thu Apr 28 12:05:42 2005
New Revision: 165178
URL: http://svn.apache.org/viewcvs?rev=165178&view=rev
Log:
Submitting Derby client. Derby client is a type 4 JDBC client driver, designed to work with Derby network server.
Added:
incubator/derby/code/trunk/java/client/
incubator/derby/code/trunk/java/client/build.xml (with props)
incubator/derby/code/trunk/java/client/org/
incubator/derby/code/trunk/java/client/org/apache/
incubator/derby/code/trunk/java/client/org/apache/derby/
incubator/derby/code/trunk/java/client/org/apache/derby/client/
incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/AsciiStream.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/BlobOutputStream.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ClobOutputStream.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ClobWriter.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ColumnMetaData.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ConnectionCallbackInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ConversionException.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/DisconnectException.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ErrorKey.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/FloatingPoint.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/GetFileInputStreamAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/GetResourceBundleAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/GetResourceInputStreamAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/GetSystemPropertiesAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/LogWriter.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialPreparedStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ParameterMetaData.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatementCallbackInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ProductLevel.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/QueryTimerTask.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResourceUtilities.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCallbackInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/UnitOfWorkListener.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Version.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/CcsidManager.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/CodePoint.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/CodePointNameTable.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ConnectionReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ConnectionReplyInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ConnectionRequestInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/DssConstants.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/EbcdicCcsidManager.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/FdocaConstants.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/FdocaSimpleDataArray.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetAgent.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetCallableStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetConfiguration.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionRequest.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetIndoubtTransaction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetLogWriter.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetPreparedStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSetReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSetRequest.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqldta.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatement.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnectionReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnectionRequest.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/OpenSocketAction.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ResultSetReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ResultSetReplyInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/ResultSetRequestInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/StatementReply.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/StatementReplyInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/StatementRequestInterface.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/resources/
incubator/derby/code/trunk/java/client/org/apache/derby/client/resources/ResourceKeys.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/client/resources/Resources.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/
incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java (with props)
incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java (with props)
Modified:
incubator/derby/code/trunk/BUILDING.txt
incubator/derby/code/trunk/build.xml
incubator/derby/code/trunk/tools/ant/properties/dirs.properties
Modified: incubator/derby/code/trunk/BUILDING.txt
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/BUILDING.txt?rev=165178&r1=165177&r2=165178&view=diff
==============================================================================
--- incubator/derby/code/trunk/BUILDING.txt (original)
+++ incubator/derby/code/trunk/BUILDING.txt Thu Apr 28 12:05:42 2005
@@ -367,6 +367,7 @@
- derbytools.jar (utilities: sysinfo, dblook, ij)
- derbynet.jar (network server).
- derbyLocale_*.jar (9 jar files with locale support).
+ - derbyclient.jar (derby network client)
If the tests were built, the following jar file will also be built:
- derbyTesting.jar (the test framework and related files)
@@ -377,6 +378,7 @@
- command "ant derbynetjar" to build derbynet.jar
- command "ant derbylocalejars" to build the derby locale jar files.
- command "ant derbytestingjar" to build derbyTesting.jar
+ - command "ant derbyclientjar" to build derbyclient.jar
Notes:
(1) The estimated total time for build completion is ~5-10 minutes.
Modified: incubator/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/build.xml?rev=165178&r1=165177&r2=165178&view=diff
==============================================================================
--- incubator/derby/code/trunk/build.xml (original)
+++ incubator/derby/code/trunk/build.xml Thu Apr 28 12:05:42 2005
@@ -21,7 +21,7 @@
<!-- Targets -->
- <target name="buildsource" depends="init,engine,tools,drda,build,versioninfo,localeinfo"/>
+ <target name="buildsource" depends="init,engine,tools,drda,client,build,versioninfo,localeinfo"/>
<target name="all" depends="buildsource,demo,testing"/>
<!-- ==================================================================== -->
@@ -74,6 +74,7 @@
<available file="${out.dir}/org/apache/derby/info/DBMS.properties"/>
<available file="${out.dir}/org/apache/derby/info/tools.properties"/>
<available file="${out.dir}/org/apache/derby/info/net.properties"/>
+ <available file="${out.dir}/org/apache/derby/info/dnc.properties"/>
</and>
</condition>
</target>
@@ -102,12 +103,20 @@
<param name="info.productfile" value="codeline"/>
<param name="info.file" value="${out.dir}/org/apache/derby/info/net.properties"/>
</antcall>
+ <antcall target="infowriter">
+ <param name="info.buildnumber" value="1"/>
+ <param name="info.iname" value="Apache Derby Network Client"/>
+ <param name="info.ename" value="Apache Derby"/>
+ <param name="info.productfile" value="codeline"/>
+ <param name="info.file" value="${out.dir}/org/apache/derby/info/dnc.properties"/>
+ </antcall>
</target>
<target name="cleanversion">
<delete file="${out.dir}/org/apache/derby/info/DBMS.properties"/>
<delete file="${out.dir}/org/apache/derby/info/tools.properties"/>
<delete file="${out.dir}/org/apache/derby/info/net.properties"/>
+ <delete file="${out.dir}/org/apache/derby/info/dnc.properties"/>
</target>
<!-- ==================================================================== -->
<!-- Info writer build target -->
@@ -267,6 +276,10 @@
<ant dir="${derby.drda.src.dir}"/>
</target>
+ <target name="client" depends="engine,init">
+ <ant dir="${derby.client.src.dir}"/>
+ </target>
+
<target name="build">
<ant dir="${derby.build.src.dir}"/>
</target>
@@ -493,6 +506,7 @@
<fileset dir="${derby.drda.src.dir}"
includesfile="${javadoctools.dir}/publishedapi.ant"/>
</copy>
+
<!-- engine files -->
<copy todir="${out.javadoc.dir}/sourcedir">
@@ -634,8 +648,8 @@
<!-- Jar targets -->
<!-- =================================================================== -->
- <target name="buildjarsclean" depends="cleanjars,initjars,derbyjar,derbytoolsjar,derbynetjar,derbywar,derbylocalejars,derbytestingjar"/>
- <target name="buildjars" depends="initjars,derbyjar,derbytoolsjar,derbynetjar,derbywar,derbylocalejars,derbytestingjar"/>
+ <target name="buildjarsclean" depends="cleanjars,initjars,derbyjar,derbytoolsjar,derbynetjar,derbyclientjar,derbywar,derbylocalejars,derbytestingjar"/>
+ <target name="buildjars" depends="initjars,derbyjar,derbytoolsjar,derbynetjar,derbyclientjar,derbywar,derbylocalejars,derbytestingjar"/>
<target name="initjars" depends="setsanityname,getsvnversion">
<property name="derby.jar.dir" value="${basedir}/jars/${sanity.name}"/>
@@ -884,6 +898,45 @@
includes="META-INF/**"/>
</jar>
+ </target>
+
+<!-- - - - - - - - - - - - - - derbyclient.jar target - - - - - - - - -->
+
+ <target name="derbyclientjar" depends="setsanityname,initjars">
+
+ <echo message="Beginning derbyclient.jar ${sanity.name} build"/>
+
+ <echo message=" creating new dnc.properties file "/>
+
+ <mkdir dir="${out.dir}/org/apache/derby/info/"/>
+ <antcall target="infowriter">
+ <param name="info.buildnumber" value="${changenumber}"/>
+ <param name="info.iname" value="Apache Derby Network Client"/>
+ <param name="info.ename" value="Apache Derby"/>
+ <param name="info.productfile" value="codeline"/>
+ <param name="info.file" value="${out.dir}/org/apache/derby/info/dnc.properties"/>
+ </antcall>
+
+ <!-- copy license file to lists dir for inclusion in derbyclient.jar -->
+
+ <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
+ <copy todir="${derby.jar.dir}/lists/META-INF">
+ <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
+ </copy>
+
+ <delete file="${derby.jar.dir}/derbyclient.jar"/>
+
+ <jar destfile="${derby.jar.dir}/derbyclient.jar"
+ compress="true"
+ filesonly="true"
+ update="true">
+ <fileset dir="${out.dir}"
+ includes="org/apache/derby/client/**,
+ org/apache/derby/client/jdbc/Client**,org/apache/derby/jdbc/Client**,org/apache/derby/iapi/services/info/**
+ org/apache/derby/info/dnc.properties"/>
+ <fileset dir="${derby.jar.dir}/lists"
+ includes="META-INF/**"/>
+ </jar>
</target>
<!-- - - - - - - - - - - - - - derby.war target - - - - - - - - - - - -->
Added: incubator/derby/code/trunk/java/client/build.xml
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/build.xml?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/build.xml (added)
+++ incubator/derby/code/trunk/java/client/build.xml Thu Apr 28 12:05:42 2005
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!-- ==================================================================== -->
+<!-- Derby Client build file -->
+<!-- ==================================================================== -->
+<project default="client" basedir="../..">
+
+<!-- ==================================================================== -->
+<!-- Set properties -->
+<!-- ==================================================================== -->
+
+
+ <!-- User settings -->
+ <property file="${user.home}/ant.properties"/>
+
+ <!-- Set property lib dir -->
+ <property name="properties.dir" value="tools/ant/properties"/>
+
+ <!-- Significant dirs -->
+ <property file="${properties.dir}/dirs.properties"/>
+
+ <!-- Compiler settings -->
+ <property file="${properties.dir}/defaultcompiler.properties"/>
+ <property file="${properties.dir}/${build.compiler}.properties"/>
+
+
+ <!-- Compile-time classpath properties files -->
+ <property file="${properties.dir}/extrapath.properties"/>
+ <property file="${properties.dir}/compilepath.properties"/>
+
+ <!-- Release and Version info -->
+ <property file="${properties.dir}/release.properties"/>
+
+
+<!-- Targets -->
+
+<!-- compile classes -->
+ <target name="compile">
+ <javac
+ bootclasspath="${empty}"
+ nowarn="on"
+ debug="${debug}"
+ depend="${depend}"
+ deprecation="${deprecation}"
+ optimize="${optimize}"
+ proceed="${proceed}"
+ verbose="${verbose}"
+ srcdir="${derby.client.src.dir}"
+ includes="org/apache/derby/**"
+ destdir="${out.dir}">
+ <classpath>
+ <pathelement path="${jce1_2_1}"/>
+ <pathelement path="${java14compile.classpath}"/>
+ </classpath>
+ </javac>
+</target>
+
+
+<!-- default target -->
+ <target name="client" depends="compile"/>
+</project>
+
Propchange: incubator/derby/code/trunk/java/client/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java Thu Apr 28 12:05:42 2005
@@ -0,0 +1,781 @@
+/*
+
+ Derby - Class org.apache.derby.client.ClientBaseDataSource
+
+ Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+package org.apache.derby.client;
+
+import org.apache.derby.client.am.Configuration;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.am.LogWriter;
+import org.apache.derby.client.net.NetConfiguration;
+
+import java.util.Properties;
+
+public abstract class ClientBaseDataSource implements java.io.Serializable
+{
+ private static final long serialVersionUID = -7660172643035173692L;
+
+ // The loginTimeout jdbc 2 data source property is not supported as a jdbc 1 connection property,
+ // because loginTimeout is set by the jdbc 1 api via java.sql.DriverManager.setLoginTimeout().
+ // The databaseName, serverName, and portNumber data source properties are also not supported as connection properties
+ // because they are extracted from the jdbc 1 database url passed on the connection request.
+ // However, all other data source properties should probably also be supported as connection properties.
+
+ //---------------------contructors/finalizers---------------------------------
+
+ // This class is abstract, hide the default constructor
+ protected ClientBaseDataSource () {}
+
+ // ---------------------------- loginTimeout -----------------------------------
+ //
+ // was serialized in 1.0 release
+ /**
+ * The time in seconds to wait for a connection request on this data source.
+ * The default value of zero indicates that either the system time out be used or no timeout limit.
+ *
+ * @serial
+ **/
+ protected int loginTimeout = propertyDefault_loginTimeout;
+ public final static String propertyKey_loginTimeout = "loginTimeout";
+ public static final int propertyDefault_loginTimeout = 0;
+ public synchronized void setLoginTimeout (int seconds) { this.loginTimeout = seconds; }
+ public int getLoginTimeout () { return this.loginTimeout; }
+
+ // ---------------------------- logWriter -----------------------------------
+ //
+ /**
+ * The log writer is declared transient, and is not serialized or stored under JNDI.
+ *
+ * @see #traceLevel
+ */
+ protected transient java.io.PrintWriter logWriter = null;
+ public synchronized void setLogWriter (java.io.PrintWriter logWriter) { this.logWriter = logWriter; }
+ public java.io.PrintWriter getLogWriter() { return this.logWriter; }
+
+ // ---------------------------- databaseName -----------------------------------
+ //
+ // Stores the relational database name, RDBNAME.
+ // The length of the database name may be limited to 18 bytes
+ // and therefore may throw an SQLException.
+ //
+ //
+ protected String databaseName = null;
+ public final static String propertyKey_databaseName = "databaseName";
+
+ // databaseName is not permitted in a properties object
+
+
+ // ---------------------------- description ------------------------------
+ // A description of this data source.
+ protected String description = null;
+ public final static String propertyKey_description = "description";
+
+ // ---------------------------- dataSourceName -----------------------------------
+ //
+ // A data source name;
+ // used to name an underlying XADataSource,
+ // or ConnectionPoolDataSource when pooling of connections is done.
+ //
+ protected String dataSourceName = null;
+ public final static String propertyKey_dataSourceName = "dataSourceName";
+
+ // ---------------------------- portNumber -----------------------------------
+ //
+ protected int portNumber = propertyDefault_portNumber;
+ public final static int propertyDefault_portNumber = 1527;
+ public final static String propertyKey_portNumber = "portNumber";
+
+ // ---------------------------- serverName -----------------------------------
+ //
+ //
+ protected String serverName = null;
+ public final static String propertyKey_serverName = "serverName";
+
+ // serverName is not permitted in a properties object
+
+ // ---------------------------- user -----------------------------------
+ //
+ // This property can be overwritten by specifing the
+ // username parameter on the DataSource.getConnection() method
+ // call. If user is specified, then password must also be
+ // specified, either in the data source object or provided on
+ // the DataSource.getConnection() call.
+ //
+ // Each data source implementation subclass will maintain it's own <code>password</code> property.
+ // This password property may or may not be declared transient, and therefore may be serialized
+ // to a file in clear-text, care must taken by the user to prevent security breaches.
+ protected String user = null;
+ public final static String propertyKey_user = "user";
+ public final static String propertyDefault_user = "APP";
+
+ public static String getUser (java.util.Properties properties) {
+ String userString= properties.getProperty (propertyKey_user);
+ return parseString(userString,propertyDefault_user);
+ }
+
+ /**
+ * To Derby, the default is HOLD_CURSORS_OVER_COMMIT
+ */
+ protected int resultSetHoldability = propertyNotSet_resultSetHoldability; // 0 means not set.
+ public final static int HOLD_CURSORS_OVER_COMMIT = 1; // this matches jdbc 3 ResultSet.HOLD_CURSORS_OVER_COMMIT
+ public final static int CLOSE_CURSORS_AT_COMMIT = 2; // this matches jdbc 3 ResultSet.CLOSE_CURSORS_AT_COMMIT
+ public final static int propertyNotSet_resultSetHoldability = 0;
+ synchronized public void setResultSetHoldability (int resultSetHoldability) { this.resultSetHoldability = resultSetHoldability; }
+ public int getResultSetHoldability () { return this.resultSetHoldability; }
+
+ public final static int NOT_SET = 0; // 0 means not set.
+ public final static int YES = 1; // ="yes" as property string
+ public final static int NO = 2; // ="no" as property string
+
+
+ // ---------------------------- securityMechanism -----------------------------------
+ //
+ // The source security mechanism to use when connecting to this data source.
+ // <p>
+ // Security mechanism options are:
+ // <ul>
+ // <li> USER_ONLY_SECURITY
+ // <li> CLEAR_TEXT_PASSWORD_SECURITY
+ // <li> ENCRYPTED_PASSWORD_SECURITY
+ // <li> ENCRYPTED_USER_AND_PASSWORD_SECURITY - both password and user are encrypted
+ // </ul>
+ // The default security mechanism is USER_ONLY_SECURITY.
+ // <p>
+ // If the application specifies a security
+ // mechanism then it will be the only one attempted.
+ // If the specified security mechanism is not supported by the conversation
+ // then an exception will be thrown and there will be no additional retries.
+ // <p>
+ // This property is currently only available for the DNC driver.
+ // <p>
+ // Both user and password need to be set for all security mechanism except USER_ONLY_SECURITY
+ // When using USER_ONLY_SECURITY, only the user property needs to be specified.
+ //
+ protected short securityMechanism = propertyDefault_securityMechanism;
+ // TODO default should be USER_ONLY_SECURITY. Change when working on
+ // Network Server
+ // public final static short propertyDefault_securityMechanism = (short)
+ // org.apache.derby.client.net.NetConfiguration.SECMEC_USRIDONL;
+ public final static short propertyDefault_securityMechanism = (short)
+ org.apache.derby.client.net.NetConfiguration.SECMEC_USRIDONL;
+ public final static String propertyKey_securityMechanism = "securityMechanism";
+
+
+ // We use the NET layer constants to avoid a mapping for the NET driver.
+ public static short getSecurityMechanism (java.util.Properties properties)
+ {
+ String securityMechanismString = properties.getProperty (propertyKey_securityMechanism);
+ String passwordString = properties.getProperty (propertyKey_password);
+ short setSecurityMechanism = parseShort (securityMechanismString, propertyDefault_securityMechanism);
+ return getUpgradedSecurityMechanism(setSecurityMechanism,passwordString);
+ }
+
+
+ /**
+ * Upgrade the security mechansim to USRIDPWD if it is set to USRIDONL but
+ * we have a password.
+ */
+ public static short getUpgradedSecurityMechanism(short securityMechanism,
+ String password)
+ {
+ // if securityMechanism is USER_ONLY (the default) we may need
+ // to change it to CLEAR_TEXT_PASSWORD in order to send the password.
+ if ((password != null) &&
+ (securityMechanism == NetConfiguration.SECMEC_USRIDONL))
+
+ return (short) NetConfiguration.SECMEC_USRIDPWD;
+ else
+ return securityMechanism;
+ }
+ // ---------------------------- getServerMessageTextOnGetMessage -----------------------------------
+ //
+ protected boolean retrieveMessageText = propertyDefault_retrieveMessageText;
+ public final static boolean propertyDefault_retrieveMessageText = true;
+ public final static String propertyKey_retrieveMessageText = "retrieveMessageText";
+
+
+ public static boolean getRetrieveMessageText (java.util.Properties properties)
+ {
+ String retrieveMessageTextString = properties.getProperty (propertyKey_retrieveMessageText);
+ return parseBoolean (retrieveMessageTextString, propertyDefault_retrieveMessageText);
+ }
+
+ // ---------------------------- traceLevel -----------------------------------
+ //
+
+ public final static int TRACE_NONE = 0x0;
+ public final static int TRACE_ALL = 0xFFFFFFFF;
+ public final static int propertyDefault_traceLevel = TRACE_ALL;
+ public final static String propertyKey_traceLevel = "traceLevel";
+
+ protected int traceLevel = propertyDefault_traceLevel;
+ public static int getTraceLevel (java.util.Properties properties)
+ {
+ String traceLevelString = properties.getProperty (propertyKey_traceLevel);
+ return parseInt (traceLevelString, propertyDefault_traceLevel);
+ }
+
+ // ---------------------------- traceFile -----------------------------------
+ //
+ protected String traceFile = null;
+ public final static String propertyKey_traceFile = "traceFile";
+ public static String getTraceFile (java.util.Properties properties)
+ { return properties.getProperty (propertyKey_traceFile); }
+
+ // ---------------------------- traceDirectory -----------------------------------
+ // For the suffix of the trace file when traceDirectory is enabled.
+ private transient int traceFileSuffixIndex_ = 0;
+ //
+ protected String traceDirectory = null;
+ public final static String propertyKey_traceDirectory = "traceDirectory";
+
+ public static String getTraceDirectory (java.util.Properties properties)
+ { return properties.getProperty (propertyKey_traceDirectory); }
+
+ // ---------------------------- traceFileAppend -----------------------------------
+ //
+ protected boolean traceFileAppend = propertyDefault_traceFileAppend;
+ public final static boolean propertyDefault_traceFileAppend = false;
+ public final static String propertyKey_traceFileAppend = "traceFileAppend";
+ public static boolean getTraceFileAppend (java.util.Properties properties)
+ {
+ String traceFileAppendString = properties.getProperty (propertyKey_traceFileAppend);
+ return parseBoolean (traceFileAppendString, propertyDefault_traceFileAppend);
+ }
+
+ // ---------------------------- password -----------------------------------
+ //
+ // The password property is defined in subclasses, but the method
+ // getPassword (java.util.Properties properties) is in this class to eliminate
+ // dependencies on j2ee for connections that go thru the driver manager.
+ public final static String propertyKey_password = "password";
+
+ public static String getPassword (java.util.Properties properties) { return properties.getProperty ("password"); }
+
+ //------------------------ interface methods ---------------------------------
+
+ public javax.naming.Reference getReference () throws javax.naming.NamingException
+ {
+ // This method creates a new Reference object to represent this data source.
+ // The class name of the data source object is saved in the Reference,
+ // so that an object factory will know that it should create an instance
+ // of that class when a lookup operation is performed. The class
+ // name of the object factory, org.apache.derby.client.ClientBaseDataSourceFactory,
+ // is also stored in the reference.
+ // This is not required by JNDI, but is recommend in practice.
+ // JNDI will always use the object factory class specified in the reference when
+ // reconstructing an object, if a class name has been specified.
+ // See the JNDI SPI documentation
+ // for further details on this topic, and for a complete description of the Reference
+ // and StringRefAddr classes.
+ //
+ // This ClientBaseDataSource class provides several standard JDBC properties.
+ // The names and values of the data source properties are also stored
+ // in the reference using the StringRefAddr class.
+ // This is all the information needed to reconstruct a ClientBaseDataSource object.
+
+ javax.naming.Reference ref =
+ new javax.naming.Reference (this.getClass().getName(),
+ ClientDataSourceFactory.className__,
+ null);
+
+ Class clz = getClass();
+ java.lang.reflect.Field[] fields = clz.getFields();
+ for (int i=0; i<fields.length; i++) {
+ String name = fields[i].getName();
+ if (name.startsWith ("propertyKey_")) {
+ if (java.lang.reflect.Modifier.isTransient (fields[i].getModifiers()))
+ continue; // if it is transient, then skip this propertyKey.
+ try {
+ String propertyKey = fields[i].get (this).toString();
+ // search for property field.
+ java.lang.reflect.Field propertyField;
+ clz = getClass(); // start from current class.
+ while (true) {
+ try {
+ propertyField = clz.getDeclaredField (name.substring (12));
+ break; // found the property field, so break the while loop.
+ }
+ catch (java.lang.NoSuchFieldException nsfe) {
+ // property field is not found at current level of class, so continue to super class.
+ clz = clz.getSuperclass();
+ if (clz == Object.class)
+ throw new javax.naming.NamingException ("bug check: corresponding property field does not exist");
+ continue;
+ }
+ }
+
+ if (!java.lang.reflect.Modifier.isTransient (propertyField.getModifiers())) {
+ // if the property is not transient:
+ // get the property.
+ java.security.AccessController.doPrivileged (new org.apache.derby.client.am.SetAccessibleAction (
+ propertyField, true));
+ //propertyField.setAccessible (true);
+ Object propertyObj = propertyField.get (this);
+ String property = (propertyObj == null) ? null : String.valueOf (propertyObj);
+ // add into reference.
+ ref.add (new javax.naming.StringRefAddr (propertyKey, property));
+ }
+ }
+ catch (java.lang.IllegalAccessException e) {
+ throw new javax.naming.NamingException ("bug check: property cannot be accessed");
+ }
+ catch (java.security.PrivilegedActionException e) {
+ throw new javax.naming.NamingException ("Privileged action exception occurred.");
+ }
+ }
+ }
+ return ref;
+ }
+
+ /**
+ * Not an external. Do not document in pubs.
+ * Populates member data for this data source given a JNDI reference.
+ */
+ public void hydrateFromReference (javax.naming.Reference ref) throws java.sql.SQLException
+ {
+ javax.naming.RefAddr address;
+
+ Class clz = getClass();
+ java.lang.reflect.Field[] fields = clz.getFields();
+ for (int i=0; i<fields.length; i++) {
+ String name = fields[i].getName();
+ if (name.startsWith ("propertyKey_")) {
+ if (java.lang.reflect.Modifier.isTransient (fields[i].getModifiers()))
+ continue; // if it is transient, then skip this propertyKey.
+ try {
+ String propertyKey = fields[i].get (this).toString();
+ // search for property field.
+ java.lang.reflect.Field propertyField;
+ clz = getClass(); // start from current class.
+ while (true) {
+ try {
+ propertyField = clz.getDeclaredField (name.substring (12));
+ break; // found the property field, so break the while loop.
+ }
+ catch (java.lang.NoSuchFieldException nsfe) {
+ // property field is not found at current level of class, so continue to super class.
+ clz = clz.getSuperclass();
+ if (clz == Object.class)
+ throw new org.apache.derby.client.am.SqlException (
+ new org.apache.derby.client.am.LogWriter (this.logWriter, this.traceLevel),
+ "bug check: corresponding property field does not exist"
+ );
+ continue;
+ }
+ }
+
+ if (!java.lang.reflect.Modifier.isTransient (propertyField.getModifiers())) {
+ // if the property is not transient:
+ // set the property.
+ address = ref.get (propertyKey);
+ if (address != null) {
+ propertyField.setAccessible (true);
+ String type = propertyField.getType().toString();
+ if (type.equals ("boolean")) {
+ boolean value = ((String) address.getContent()).equalsIgnoreCase("true");
+ propertyField.setBoolean (this, value);
+ }
+ else if (type.equals ("byte")) {
+ byte value = Byte.parseByte ((String)address.getContent());
+ propertyField.setByte (this, value);
+ }
+ else if (type.equals ("short")) {
+ short value = Short.parseShort ((String)address.getContent());
+ propertyField.setShort (this, value);
+ }
+ else if (type.equals ("int")) {
+ int value = Integer.parseInt ((String)address.getContent());
+ propertyField.setInt (this, value);
+ }
+ else if (type.equals ("long")) {
+ long value = Long.parseLong ((String)address.getContent());
+ propertyField.setLong (this, value);
+ }
+ else if (type.equals ("float")) {
+ float value = Float.parseFloat ((String)address.getContent());
+ propertyField.setFloat (this, value);
+ }
+ else if (type.equals ("double")) {
+ double value = Double.parseDouble ((String)address.getContent());
+ propertyField.setDouble (this, value);
+ }
+ else if (type.equals ("char")) {
+ char value = ((String)address.getContent()).charAt(0);
+ propertyField.setChar (this, value);
+ }
+ else {
+ propertyField.set (this, address.getContent());
+ }
+ }
+ }
+ }
+ catch (java.lang.IllegalAccessException e) {
+ throw new org.apache.derby.client.am.SqlException (
+ new org.apache.derby.client.am.LogWriter (this.logWriter, this.traceLevel),
+ "bug check: property cannot be accessed"
+ );
+ }
+ }
+ }
+ }
+
+ // ----------------------supplemental methods---------------------------------
+ /**
+ * Not an external. Do not document in pubs.
+ * Returns all non-transient properties of a ClientBaseDataSource.
+ */
+ public java.util.Properties getProperties () throws java.sql.SQLException
+ {
+ java.util.Properties properties = new java.util.Properties();
+
+ Class clz = getClass();
+ java.lang.reflect.Field[] fields = clz.getFields();
+ for (int i=0; i<fields.length; i++) {
+ String name = fields[i].getName();
+ if (name.startsWith ("propertyKey_")) {
+ if (java.lang.reflect.Modifier.isTransient (fields[i].getModifiers()))
+ continue; // if it is transient, then skip this propertyKey.
+ try {
+ String propertyKey = fields[i].get (this).toString();
+ // search for property field.
+ java.lang.reflect.Field propertyField;
+ clz = getClass(); // start from current class.
+ while (true) {
+ try {
+ propertyField = clz.getDeclaredField (name.substring (12));
+ break; // found the property field, so break the while loop.
+ }
+ catch (java.lang.NoSuchFieldException nsfe) {
+ // property field is not found at current level of class, so continue to super class.
+ clz = clz.getSuperclass();
+ if (clz == Object.class)
+ throw new org.apache.derby.client.am.SqlException (
+ new org.apache.derby.client.am.LogWriter (this.logWriter, this.traceLevel),
+ "bug check: corresponding property field does not exist"
+ );
+ continue;
+ }
+ }
+
+ if (!java.lang.reflect.Modifier.isTransient (propertyField.getModifiers())) {
+ // if the property is not transient:
+ // get the property.
+ propertyField.setAccessible (true);
+ Object propertyObj = propertyField.get (this);
+ String property = String.valueOf (propertyObj); // don't use toString becuase it may be null.
+ if ("password".equals(propertyKey)) {
+ StringBuffer sb = new StringBuffer (property);
+ for (int j = 0; j< property.length(); j++) {
+ sb.setCharAt(j,'*');
+ }
+ property = sb.toString();
+ }
+ // add into prperties.
+ properties.setProperty (propertyKey, property);
+ }
+ }
+ catch (java.lang.IllegalAccessException e) {
+ throw new org.apache.derby.client.am.SqlException (
+ new org.apache.derby.client.am.LogWriter (this.logWriter, this.traceLevel),
+ "bug check: property cannot be accessed"
+ );
+ }
+ }
+ }
+
+ return properties;
+ }
+
+ //---------------------- helper methods --------------------------------------
+
+ // The java.io.PrintWriter overrides the traceFile setting.
+ // If neither traceFile nor jdbc logWriter are set, then null is returned.
+ public org.apache.derby.client.am.LogWriter computeDncLogWriterForNewConnection (
+ String logWriterInUseSuffix) // used only for trace directories to indicate whether
+ // log writer is use is from xads, cpds, sds, ds, driver, config, reset.
+ throws org.apache.derby.client.am.SqlException
+ {
+ return computeDncLogWriterForNewConnection (
+ this.logWriter,
+ this.traceDirectory,
+ this.traceFile,
+ this.traceFileAppend,
+ this.traceLevel,
+ logWriterInUseSuffix,
+ this.traceFileSuffixIndex_++);
+ }
+
+ // Called on for connection requests.
+ // The java.io.PrintWriter overrides the traceFile setting.
+ // If neither traceFile, nor logWriter, nor traceDirectory are set, then null is returned.
+ static public org.apache.derby.client.am.LogWriter computeDncLogWriterForNewConnection (
+ java.io.PrintWriter logWriter,
+ String traceDirectory,
+ String traceFile,
+ boolean traceFileAppend,
+ int traceLevel,
+ String logWriterInUseSuffix, // used only for trace directories to indicate whether
+ // log writer is use is from xads, cpds, sds, ds, driver, config.
+ int traceFileSuffixIndex) throws org.apache.derby.client.am.SqlException
+ {
+ int globaltraceFileSuffixIndex = Configuration.traceFileSuffixIndex__++;
+
+ org.apache.derby.client.am.LogWriter dncLogWriter;
+ // compute regular dnc log writer if there is any
+ dncLogWriter =
+ computeDncLogWriter (
+ logWriter,
+ traceDirectory,
+ traceFile,
+ traceFileAppend,
+ logWriterInUseSuffix,
+ traceFileSuffixIndex,
+ traceLevel);
+ if (dncLogWriter != null) return dncLogWriter;
+ // compute global default dnc log writer if there is any
+ dncLogWriter =
+ computeDncLogWriter (
+ null,
+ Configuration.traceDirectory__,
+ Configuration.traceFile__,
+ Configuration.traceFileAppend__,
+ "_global",
+ globaltraceFileSuffixIndex,
+ Configuration.traceLevel__);
+ return dncLogWriter;
+ }
+
+ // Compute a DNC log writer before a connection is created.
+ static org.apache.derby.client.am.LogWriter computeDncLogWriter (
+ java.io.PrintWriter logWriter,
+ String traceDirectory,
+ String traceFile,
+ boolean traceFileAppend,
+ String logWriterInUseSuffix,
+ int traceFileSuffixIndex,
+ int traceLevel) throws org.apache.derby.client.am.SqlException
+ {
+ // Otherwise, the trace file will still be created even TRACE_NONE.
+ if (traceLevel == TRACE_NONE) return null;
+
+ java.io.PrintWriter printWriter =
+ computePrintWriter (
+ logWriter,
+ traceDirectory,
+ traceFile,
+ traceFileAppend,
+ logWriterInUseSuffix,
+ traceFileSuffixIndex);
+ if (printWriter == null) return null;
+
+ org.apache.derby.client.am.LogWriter dncLogWriter;
+ dncLogWriter = new org.apache.derby.client.net.NetLogWriter (printWriter, traceLevel);
+ if (printWriter != logWriter && traceDirectory != null)
+ // When printWriter is an internal trace file and
+ // traceDirectory is not null, each connection has
+ // its own trace file and the trace file is not cached,
+ // so we can close it when DNC log writer is closed.
+ dncLogWriter.printWriterNeedsToBeClosed_ = true;
+ return dncLogWriter;
+ }
+
+ // Compute a DNC log writer after a connection is created.
+ // Declared public for use by am.Connection. Not a public external.
+ public static org.apache.derby.client.am.LogWriter computeDncLogWriter (
+ org.apache.derby.client.am.Connection connection,
+ java.io.PrintWriter logWriter,
+ String traceDirectory,
+ String traceFile,
+ boolean traceFileAppend,
+ String logWriterInUseSuffix,
+ int traceFileSuffixIndex,
+ int traceLevel) throws org.apache.derby.client.am.SqlException
+ {
+ // Otherwise, the trace file will still be created even TRACE_NONE.
+ if (traceLevel == TRACE_NONE) return null;
+
+ java.io.PrintWriter printWriter =
+ computePrintWriter (
+ logWriter,
+ traceDirectory,
+ traceFile,
+ traceFileAppend,
+ logWriterInUseSuffix,
+ traceFileSuffixIndex);
+ if (printWriter == null) return null;
+
+ org.apache.derby.client.am.LogWriter dncLogWriter =
+ connection.agent_.newLogWriter_ (printWriter, traceLevel);
+ if (printWriter != logWriter && traceDirectory != null)
+ // When printWriter is an internal trace file and
+ // traceDirectory is not null, each connection has
+ // its own trace file and the trace file is not cached,
+ // so we can close it when DNC log writer is closed.
+ dncLogWriter.printWriterNeedsToBeClosed_ = true;
+ return dncLogWriter;
+ }
+
+ // This method handles all the override semantics.
+ // The logWriter overrides the traceFile, and traceDirectory settings.
+ // If neither traceFile, nor logWriter, nor traceDirectory are set, then null is returned.
+ static java.io.PrintWriter computePrintWriter (
+ java.io.PrintWriter logWriter,
+ String traceDirectory,
+ String traceFile,
+ boolean traceFileAppend,
+ String logWriterInUseSuffix, // used only for trace directories to indicate whether
+ // log writer is use is from xads, cpds, sds, ds, driver, config.
+ int traceFileSuffixIndex) throws org.apache.derby.client.am.SqlException
+ {
+ if (logWriter != null) // java.io.PrintWriter is specified
+ return logWriter;
+ else { // check trace file setting.
+ if (traceDirectory != null) {
+ String fileName;
+ if (traceFile == null) fileName = traceDirectory + "/" + logWriterInUseSuffix + "_" + traceFileSuffixIndex;
+ else fileName = traceDirectory + "/" + traceFile + logWriterInUseSuffix + "_" + traceFileSuffixIndex;
+ return LogWriter.getPrintWriter (fileName, true); // no file append and not enable caching.
+ } else if (traceFile != null) {
+ return LogWriter.getPrintWriter (traceFile, traceFileAppend);
+ }
+ }
+ return null;
+ }
+
+ private static boolean parseBoolean (String boolString, boolean defaultBool)
+ {
+ if (boolString != null) return (boolString.equalsIgnoreCase ("true") || boolString.equalsIgnoreCase ("yes"));
+ return defaultBool;
+ }
+
+ private static String parseString (String string, String defaultString)
+ {
+ if (string != null) return string;
+ return defaultString;
+ }
+
+ private static short parseShort (String shortString, short defaultShort)
+ {
+ if (shortString != null) return Short.parseShort (shortString);
+ return defaultShort;
+ }
+
+ private static int parseInt (String intString, int defaultInt)
+ {
+ if (intString != null) return Integer.parseInt (intString);
+ return defaultInt;
+ }
+
+ private static long parseLong (String longString, long defaultLong)
+ {
+ if (longString != null) return Long.parseLong (longString);
+ return defaultLong;
+ }
+
+ private static int parseTernaryValue (String valueString, int defaultValue)
+ {
+ if ("true".equalsIgnoreCase (valueString) || "yes".equalsIgnoreCase (valueString)) return YES;
+ if ("false".equalsIgnoreCase (valueString) || "no".equalsIgnoreCase (valueString)) return NO;
+ if (valueString != null) {
+ int value = Integer.parseInt (valueString);
+ if (value < 0 || value > 2) throw new java.lang.NumberFormatException (valueString);
+ return value;
+ }
+ return defaultValue;
+ }
+
+ // tokenize "property=value;property=value..." and returns new properties object
+ //This method is used both by ClientDriver to parse the url and
+ // ClientDataSource.setConnectionAttributes
+ public static java.util.Properties tokenizeAttributes (String attributeString,
+ java.util.Properties properties) throws SqlException
+{
+ java.util.Properties augmentedProperties;
+
+ if (attributeString == null)
+ return properties;
+
+ if (properties != null)
+ augmentedProperties = (java.util.Properties) properties.clone();
+ else
+ augmentedProperties = new Properties();
+ try {
+ java.util.StringTokenizer attrTokenizer =
+ new java.util.StringTokenizer(attributeString,";");
+ while (attrTokenizer.hasMoreTokens()) {
+ String v = attrTokenizer.nextToken();
+
+ int eqPos = v.indexOf('=');
+ if (eqPos == -1)
+ throw new SqlException (null, "Invalid attribute syntax: " + attributeString);
+
+ augmentedProperties.setProperty((v.substring(0, eqPos)).trim(),
+ (v.substring(eqPos + 1)).trim()
+ );
+ }
+ }
+ catch (java.util.NoSuchElementException e) {
+ // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+ throw new SqlException (null, e, "Invalid attribute syntax: " + attributeString);
+ }
+ checkBoolean(augmentedProperties,propertyKey_retrieveMessageText);
+ return augmentedProperties;
+
+ }
+
+ private static void checkBoolean(Properties set, String attribute) throws SqlException
+ {
+ final String[] booleanChoices = {"true", "false"};
+ checkEnumeration( set, attribute, booleanChoices);
+ }
+
+
+ private static void checkEnumeration(Properties set, String attribute, String[] choices) throws SqlException
+ {
+ String value = set.getProperty(attribute);
+ if (value == null)
+ return;
+
+ for( int i = 0; i < choices.length; i++)
+ {
+ if( value.toUpperCase(java.util.Locale.ENGLISH).equals( choices[i].toUpperCase(java.util.Locale.ENGLISH)))
+ return;
+ }
+
+ // The attribute value is invalid. Construct a string giving the choices for
+ // display in the error message.
+ String choicesStr = "{";
+ for( int i = 0; i < choices.length; i++)
+ {
+ if( i > 0)
+ choicesStr += "|";
+ choicesStr += choices[i];
+ }
+
+ throw new SqlException (null, "JDBC attribute " + attribute +
+ "has an invalid value " + value +
+ " Valid values are " + choicesStr);
+ }
+
+
+
+}
+
+
Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientBaseDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java Thu Apr 28 12:05:42 2005
@@ -0,0 +1,104 @@
+/*
+
+ Derby - Class org.apache.derby.client.ClientDataSourceFactory
+
+ Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+package org.apache.derby.client;
+
+import org.apache.derby.jdbc.ClientDataSource;
+import org.apache.derby.jdbc.ClientXADataSource;
+import org.apache.derby.jdbc.ClientConnectionPoolDataSource;
+
+/**
+ * The data source factory currrently for ClientDataSource only.
+ * This factory will support XA and pooling-enabled data sources in the future.
+ * <p>
+ * This factory reconstructs a DERBY simple data source object
+ * when it is retrieved from JNDI.
+ * References are needed since many naming services
+ * don't have the ability to store Java objects in their serialized form.
+ * When a data source object is bound in this type of naming service the
+ * Reference for that object is actually stored by the JNDI implementation,
+ * not the data source object itself.
+ * <p>
+ * A JNDI administrator is responsible for making sure that both the object factory and
+ * data source implementation classes provided by a JDBC driver vendor are accessible to
+ * the JNDI service provider at runtime.
+ * <p>
+ * An object factory implements the javax.naming.spi.ObjectFactory interface. This
+ * interface contains a single method, getObjectInstance, which is called by a JNDI
+ * service provider to reconstruct an object when that object is retrieved from JNDI. A
+ * JDBC driver vendor should provide an object factory as part of their JDBC 2.0 product.
+ *
+ * @see ClientDataSource
+ **/
+public class ClientDataSourceFactory implements javax.naming.spi.ObjectFactory
+{
+ static final String className__ = "org.apache.derby.jdbc.ClientDataSourceFactory";
+
+ public ClientDataSourceFactory ()
+ { }
+
+ /**
+ * Reconstructs a ClientDataSource object from a JNDI data source reference.
+ * <p>
+ * The getObjectInstance() method is passed a reference that corresponds to the object
+ * being retrieved as its first parameter. The other parameters are optional in the case of
+ * JDBC data source objects. The object factory should use the information contained in
+ * the reference to reconstruct the data source. If for some reason, a data source object cannot
+ * be reconstructed from the reference, a value of null may be returned. This allows
+ * other object factories that may be registered in JNDI to be tried. If an exception is
+ * thrown then no other object factories are tried.
+ *
+ * @param refObj
+ * The possibly null object containing location or reference information
+ * that can be used in creating an object.
+ * @param name
+ * The name of this object relative to nameContext, or null if no name is specified.
+ * @param nameContext
+ * Context relative to which the name parameter is specified,
+ * or null if name is relative to the default initial context.
+ * @param environment
+ * Possibly null environment that is used in creating the object.
+ * @return
+ * object created; null if an object cannot be created
+ */
+ public Object getObjectInstance (Object refObj,
+ javax.naming.Name name,
+ javax.naming.Context nameContext,
+ java.util.Hashtable environment) throws java.lang.Exception
+ {
+ javax.naming.Reference ref = (javax.naming.Reference) refObj;
+
+ // Create the proper data source object shell.
+ ClientDataSource ds = null;
+ if (ref.getClassName().equals (ClientDataSource.className__))
+ ds = new ClientDataSource();
+ else if (ref.getClassName().equals (ClientXADataSource.className__))
+ ds = new ClientXADataSource();
+ else if (ref.getClassName().equals (ClientConnectionPoolDataSource.className__))
+ ds = new ClientConnectionPoolDataSource();
+ else
+ return null;
+
+ // Fill in the data source object shell with values from the jndi reference.
+ ds.hydrateFromReference (ref);
+
+ return ds;
+ }
+}
Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDataSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java Thu Apr 28 12:05:42 2005
@@ -0,0 +1,208 @@
+/*
+
+ Derby - Class org.apache.derby.client.ClientPooledConnection
+
+ Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+package org.apache.derby.client;
+
+import org.apache.derby.client.net.NetLogWriter;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.jdbc.ClientDataSource;
+
+public class ClientPooledConnection implements javax.sql.PooledConnection
+{
+ private boolean newPC_ = true;
+
+ private java.util.Vector listeners_ = null;
+ org.apache.derby.client.am.Connection physicalConnection_ = null;
+ org.apache.derby.client.net.NetConnection netPhysicalConnection_ = null;
+ org.apache.derby.client.net.NetXAConnection netXAPhysicalConnection_ = null;
+
+ org.apache.derby.client.am.LogicalConnection logicalConnection_ = null;
+
+ protected org.apache.derby.client.am.LogWriter logWriter_ = null;
+
+ protected int rmId_ = 0;
+
+ // Cached stuff from constructor
+ private ClientDataSource ds_;
+ private String user_;
+ private String password_;
+
+ // Constructor for Non-XA pooled connections.
+ // Using standard Java APIs, a CPDS is passed in.
+ // user/password overrides anything on the ds.
+ public ClientPooledConnection (ClientDataSource ds,
+ org.apache.derby.client.am.LogWriter logWriter,
+ String user,
+ String password) throws SqlException
+ {
+ logWriter_ = logWriter;
+ ds_ = ds;
+ user_ = user;
+ password_ = password;
+ listeners_ = new java.util.Vector();
+
+ netPhysicalConnection_ = new org.apache.derby.client.net.NetConnection ((NetLogWriter) logWriter_,
+ user,
+ password,
+ ds,
+ -1,
+ false);
+ physicalConnection_ = netPhysicalConnection_;
+ }
+
+ // Constructor for XA pooled connections only.
+ // Using standard Java APIs, a CPDS is passed in.
+ // user/password overrides anything on the ds.
+ public ClientPooledConnection (ClientDataSource ds,
+ org.apache.derby.client.am.LogWriter logWriter,
+ String user,
+ String password,
+ int rmId) throws SqlException
+ {
+ logWriter_ = logWriter;
+ ds_ = ds;
+ user_ = user;
+ password_ = password;
+ rmId_ = rmId;
+ listeners_ = new java.util.Vector();
+ netXAPhysicalConnection_ = new org.apache.derby.client.net.NetXAConnection ((NetLogWriter) logWriter_,
+ user,
+ password,
+ ds,
+ rmId,
+ true);
+ physicalConnection_ = netXAPhysicalConnection_;
+ }
+
+ public ClientPooledConnection (ClientDataSource ds,
+ org.apache.derby.client.am.LogWriter logWriter
+ ) throws SqlException
+ {
+ logWriter_ = logWriter;
+ ds_ = ds;
+ listeners_ = new java.util.Vector();
+ netPhysicalConnection_ = new org.apache.derby.client.net.NetConnection ((NetLogWriter) logWriter_,
+ null,
+ null,
+ ds,
+ -1,
+ false);
+ physicalConnection_ = netPhysicalConnection_;
+ }
+
+ protected void finalize() throws java.lang.Throwable
+ {
+ if (logWriter_ != null) logWriter_.traceEntry (this, "finalize");
+ close();
+ }
+
+ public synchronized void close() throws SqlException
+ {
+ if (logWriter_ != null) logWriter_.traceEntry (this, "close");
+
+ if ( logicalConnection_ != null ) {
+ logicalConnection_.nullPhysicalConnection();
+ logicalConnection_ = null;
+ }
+
+ if (physicalConnection_ == null) return;
+ try {
+ // Even if the physcial connection is marked closed (in the pool),
+ // this will close its underlying resources.
+ physicalConnection_.closeResources();
+ }
+ finally {
+ physicalConnection_ = null;
+ }
+ }
+
+ // This is the standard API for getting a logical connection handle for a pooled connection.
+ // No "resettable" properties are passed, so user, password, and all other properties may not change.
+ public synchronized java.sql.Connection getConnection() throws SqlException
+ {
+ if (logWriter_ != null) logWriter_.traceEntry (this, "getConnection");
+ createLogicalConnection ();
+
+ if (!newPC_)
+ physicalConnection_.reset (logWriter_, user_, password_, ds_, false); // false means do not recompute
+ // properties from the dataSource
+ // properties don't change
+ else {
+ physicalConnection_.lightReset(); //poolfix
+ }
+ newPC_ = false;
+
+ if (logWriter_ != null) logWriter_.traceExit (this, "getConnection", logicalConnection_);
+ return logicalConnection_;
+ }
+
+ private void createLogicalConnection () throws SqlException
+ {
+ if (physicalConnection_ == null)
+ throw new SqlException (logWriter_, "getConnection() is not valid on a closed PooledConnection.");
+ // Not the usual case, but if we have an existing logical connection, then we must close it by spec.
+ // We close the logical connection without notifying the pool manager that this pooled connection is availabe for reuse.
+ if (logicalConnection_ != null) logicalConnection_.closeWithoutRecyclingToPool();
+ logicalConnection_ = new org.apache.derby.client.am.LogicalConnection (physicalConnection_, this);
+ }
+
+ public synchronized void addConnectionEventListener (javax.sql.ConnectionEventListener listener)
+ {
+ if (logWriter_ != null) logWriter_.traceEntry (this, "addConnectionEventListener", listener);
+ listeners_.addElement (listener);
+ }
+
+ public synchronized void removeConnectionEventListener (javax.sql.ConnectionEventListener listener )
+ {
+ if (logWriter_ != null) logWriter_.traceEntry (this, "removeConnectionEventListener", listener);
+ listeners_.removeElement( listener );
+ }
+
+ // Not public, but needs to be visible to am.LogicalConnection
+ public void recycleConnection ()
+ {
+ if (physicalConnection_.agent_.loggingEnabled())
+ physicalConnection_.agent_.logWriter_.traceEntry (this, "recycleConnection");
+
+ for (java.util.Enumeration e = listeners_.elements(); e.hasMoreElements(); ) {
+ javax.sql.ConnectionEventListener listener = (javax.sql.ConnectionEventListener) e.nextElement();
+ javax.sql.ConnectionEvent event = new javax.sql.ConnectionEvent (this);
+ listener.connectionClosed (event);
+ }
+ }
+
+ // Not public, but needs to be visible to am.LogicalConnection
+ public void trashConnection (SqlException exception)
+ {
+ for (java.util.Enumeration e = listeners_.elements(); e.hasMoreElements(); ) {
+ javax.sql.ConnectionEventListener listener = (javax.sql.ConnectionEventListener) e.nextElement();
+ javax.sql.ConnectionEvent event = new javax.sql.ConnectionEvent (this, exception);
+ listener.connectionErrorOccurred (event);
+ }
+ }
+
+ // Used by LogicalConnection close when it disassociates itself from the ClientPooledConnection
+ public synchronized void nullLogicalConnection ()
+ {
+ logicalConnection_ = null;
+ }
+}
+
+
+
Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java Thu Apr 28 12:05:42 2005
@@ -0,0 +1,138 @@
+/*
+
+ Derby - Class org.apache.derby.client.ClientXAConnection
+
+ Copyright (c) 2003, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+package org.apache.derby.client;
+
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.jdbc.ClientXADataSource;
+import org.apache.derby.client.net.NetXAConnection;
+import org.apache.derby.client.net.NetLogWriter;
+import java.sql.*;
+import javax.sql.*;
+import javax.transaction.xa.*;
+
+public class ClientXAConnection extends ClientPooledConnection implements XAConnection
+{
+ private static int rmIdSeed_ = 95688932; // semi-random starting value for rmId
+
+ private ClientXADataSource derbyds_ = null;
+ private XAResource xares_ = null;
+ private org.apache.derby.client.net.NetXAResource netXares_ = null;
+ private boolean fFirstGetConnection_ = true;
+ private Connection logicalCon_; // logicalConnection_ is inherited from ClientPooledConnection
+ // This connection is used to access the indoubt table
+ private NetXAConnection controlCon_ = null;
+
+ public ClientXAConnection (ClientXADataSource ds,
+ org.apache.derby.client.net.NetLogWriter logWtr,
+ String userId,
+ String password) throws SqlException
+ {
+ super (ds,logWtr,userId, password, getUnigueRmId());
+ derbyds_ = ds;
+
+ // Have to instantiate a real connection here,
+ // otherwise if XA function is called before the connect happens,
+ // an error will be returned
+ // Note: conApp will be set after this call
+ logicalCon_ = super.getConnection();
+
+ netXares_ = new org.apache.derby.client.net.NetXAResource( this,
+ rmId_, userId, password, netXAPhysicalConnection_ );
+ xares_ = netXares_;
+ }
+
+ public Connection getConnection() throws SqlException
+ {
+ if ( fFirstGetConnection_ )
+ {
+ // Since super.getConnection() has already been called once
+ // in the constructor, we don't need to call it again for the
+ // call of this method.
+ fFirstGetConnection_ = false;
+ }
+ else
+ {
+ // A new connection object is required
+ logicalCon_ = super.getConnection();
+ if( this.physicalConnection_ != null )
+ { // have a physical connection, check if a NetXAResource
+ if( netXAPhysicalConnection_ != null )
+ { // the XAResource is a NetXAResource, re-initialize it
+ netXares_.initForReuse();
+ }
+ }
+ }
+ return logicalCon_;
+ }
+
+ private static synchronized int getUnigueRmId()
+ {
+ rmIdSeed_ += 1;
+ return rmIdSeed_;
+ }
+
+ public int getRmId()
+ {
+ return rmId_;
+ }
+
+ public XAResource getXAResource() throws SqlException
+ {
+ if (logWriter_ != null) logWriter_.traceExit (this, "getXAResource", xares_);
+
+ return xares_;
+ }
+
+ public ClientXADataSource getDataSource() throws SqlException
+ {
+ if (logWriter_ != null) logWriter_.traceExit (this, "getDataSource", derbyds_);
+
+ return derbyds_;
+ }
+
+ public NetXAConnection createControlConnection(NetLogWriter logWriter,
+ String user,
+ String password,
+ org.apache.derby.jdbc.ClientDataSource dataSource,
+ int rmId,
+ boolean isXAConn) throws SqlException
+ {
+
+ controlCon_ = new NetXAConnection (
+ logWriter,
+ user,
+ password,
+ dataSource,
+ rmId,
+ isXAConn);
+ controlCon_.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+
+ if (logWriter_ != null) logWriter_.traceExit (this, "createControlConnection", controlCon_);
+
+ return controlCon_;
+ }
+
+
+ public synchronized void close() throws SqlException
+ {
+ super.close();
+ }
+}
+
Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java Thu Apr 28 12:05:42 2005
@@ -0,0 +1,220 @@
+/*
+
+ Derby - Class org.apache.derby.client.ClientXid
+
+ Copyright (c) 2003, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+package org.apache.derby.client;
+
+import javax.transaction.xa.*;
+
+public class ClientXid implements Xid
+{
+ //
+ // The format identifier for the Xid. A value of -1 indicates
+ // that the NULLXid
+ //
+ private int formatID_;
+
+ //
+ // The number of bytes in the global transaction identfier
+ //
+ private int gtrid_length_;
+
+ //
+ // The number of bytes in the branch qualifier
+ //
+ private int bqual_length_;
+
+ //
+ // The data for the Xid.
+ // <p> The Xid is made up of two contiguous parts. The first (of size
+ // <b>gtrid_length</b>) is the global transaction identfier and the second
+ // (of size <b>bqual_length</b>) is the branch qualifier.
+ // <p>If the <b>formatID</b> is -1, indicating the NULLXid, the data is
+ // ignored.
+ //
+ private byte data_[];
+
+ //
+ // The size of <b>data</b>.
+ //
+ static private final int XidDATASIZE = 128;
+
+ //
+ // The maximum size of the global transaction identifier.
+ //
+ static public final int MAXGTRIDSIZE= 64;
+
+ //
+ // The maximum size of the branch qualifier.
+ //
+ static public final int MAXBQUALSIZE= 64;
+
+ static private final String hextab_= "0123456789ABCDEF";
+
+
+ //
+ // Constructs a new null Xid.
+ // <p>After construction the data within the Xid should be initialized.
+ //
+ public ClientXid()
+ {
+ data_ = new byte[XidDATASIZE];
+ gtrid_length_ = 0;
+ bqual_length_ = 0;
+ formatID_ = -1;
+ }
+
+ //
+ // another contructor
+ //
+ public ClientXid( int formatID, byte[] gtrid, byte[] bqual )
+ {
+
+ formatID_ = formatID;
+ gtrid_length_ = gtrid.length;
+ bqual_length_ = bqual.length;
+ data_ = new byte[XidDATASIZE];
+ System.arraycopy(gtrid, 0, data_, 0, gtrid_length_);
+ System.arraycopy(bqual, 0, data_, gtrid_length_, bqual_length_);
+ }
+
+ //
+ // Return a string representing this Xid for debuging
+ //
+ // @return the string representation of this Xid
+ //
+ public String toString()
+ {
+ StringBuffer d; // Data String, in HeXidecimal
+ String s; // Resultant String
+ int i;
+ int v;
+ int L;
+
+ L = gtrid_length_ + bqual_length_;
+ d = new StringBuffer(L+L);
+
+ for( i = 0; i < L; i++ )
+ {
+ // Convert data string to hex
+ v = data_[i] & 0xff;
+ d.append(hextab_.charAt(v/16));
+ d.append(hextab_.charAt(v&15));
+ if ( (i+1)%4 == 0 && (i+1) < L )
+ d.append(" ");
+ }
+
+ s = "{ClientXid: " +
+ "formatID(" + formatID_ + "), " +
+ "gtrid_length(" + gtrid_length_ + "), " +
+ "bqual_length(" + bqual_length_ + "), " +
+ "data(" + d.toString() + ")" +
+ "}" ;
+ return s;
+ }
+
+ //
+ // Returns the branch qualifier for this Xid.
+ //
+ // @return the branch qualifier
+ //
+ public byte[] getBranchQualifier()
+ {
+ byte[] bqual = new byte[bqual_length_];
+ System.arraycopy(data_,gtrid_length_,bqual,0,bqual_length_);
+ return bqual;
+ }
+
+ //
+ // Set the branch qualifier for this Xid.
+ //
+ // @param qual a Byte array containing the branch qualifier to be set. If
+ // the size of the array exceeds MAXBQUALSIZE, only the first MAXBQUALSIZE
+ // elements of qual will be used.
+ //
+ public void setBranchQualifier( byte[] qual )
+ {
+ bqual_length_ = qual.length > MAXBQUALSIZE?MAXBQUALSIZE:qual.length;
+ System.arraycopy(qual, 0, data_, gtrid_length_, bqual_length_);
+ }
+
+ //
+ // Obtain the format identifier part of the Xid.
+ //
+ // @return Format identifier. -1 indicates a null Xid
+ //
+ public int getFormatId()
+ {
+ return formatID_;
+ }
+
+ //
+ // Set the format identifier part of the Xid.
+ //
+ // @param Format identifier. -1 indicates a null Xid.
+ //
+ public void setFormatID(int formatID)
+ {
+ formatID_ = formatID;
+ return;
+ }
+
+ //
+ // Returns the global transaction identifier for this Xid.
+ //
+ // @return the global transaction identifier
+ //
+ public byte[] getGlobalTransactionId()
+ {
+ byte[] gtrid = new byte[gtrid_length_];
+ System.arraycopy(data_, 0, gtrid, 0, gtrid_length_);
+ return gtrid;
+ }
+
+ //
+ // return fields of Xid
+ //
+ public byte[] getData()
+ {
+ return data_;
+ }
+
+ public int getGtridLength()
+ {
+ return gtrid_length_;
+ }
+
+ public int getBqualLength()
+ {
+ return bqual_length_;
+ }
+
+ public int hashCode()
+ {
+ if ( formatID_ == (-1) )
+ {
+ return (-1);
+ }
+ return formatID_ + gtrid_length_ - bqual_length_;
+ }
+
+ public boolean equals(Object obj)
+ {
+ return org.apache.derby.client.net.NetXAResource.xidsEqual(this, (javax.transaction.xa.Xid)obj);
+ }
+} // class Xid
Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXid.java
------------------------------------------------------------------------------
svn:eol-style = native