Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 31755 invoked from network); 2 May 2005 06:26:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2005 06:26:50 -0000 Received: (qmail 82377 invoked by uid 500); 2 May 2005 06:28:13 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 82214 invoked by uid 500); 2 May 2005 06:28:08 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 82125 invoked by uid 500); 2 May 2005 06:28:06 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 82097 invoked by uid 99); 2 May 2005 06:28:06 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 01 May 2005 23:28:00 -0700 Received: (qmail 31502 invoked by uid 65534); 2 May 2005 06:26:35 -0000 Message-ID: <20050502062635.31500.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r165585 [2/42] - in /incubator/derby/code/trunk/java/client/org/apache/derby: client/ client/am/ client/net/ client/resources/ jdbc/ Date: Mon, 02 May 2005 06:26:03 -0000 To: derby-cvs@incubator.apache.org From: jboynes@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/Cl= ientDataSourceFactory.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/ClientDataSourceFactory.java?rev=3D165585&r1=3D16558= 4&r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDa= taSourceFactory.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientDa= taSourceFactory.java Sun May 1 23:25:59 2005 @@ -20,85 +20,74 @@ =20 package org.apache.derby.client; =20 +import org.apache.derby.jdbc.ClientConnectionPoolDataSource; import org.apache.derby.jdbc.ClientDataSource; import org.apache.derby.jdbc.ClientXADataSource; -import org.apache.derby.jdbc.ClientConnectionPoolDataSource; =20 /** - * The data source factory currrently for ClientDataSource only. - * This factory will support XA and pooling-enabled data sources in the fu= ture. - *

- * 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. - *

- * A JNDI administrator is responsible for making sure that both the objec= t factory and - * data source implementation classes provided by a JDBC driver vendor are= accessible to - * the JNDI service provider at runtime. - *

- * An object factory implements the javax.naming.spi.ObjectFactory interfa= ce. 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 JD= BC 2.0 product. + * The data source factory currrently for ClientDataSource only. This fact= ory will support XA and pooling-enabled data + * sources in the future. + *

+ * 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 o= bject is actually stored by the JNDI + * implementation, not the data source object itself. + *

+ * A JNDI administrator is responsible for making sure that both the objec= t factory and data source implementation + * classes provided by a JDBC driver vendor are accessible to the JNDI ser= vice provider at runtime. + *

+ * An object factory implements the javax.naming.spi.ObjectFactory interfa= ce. This interface contains a single method, + * getObjectInstance, which is called by a JNDI service provider to recons= truct an object when that object is retrieved + * from JNDI. A JDBC driver vendor should provide an object factory as par= t of their JDBC 2.0 product. * * @see ClientDataSource - **/ -public class ClientDataSourceFactory implements javax.naming.spi.ObjectFac= tory -{ - static final String className__ =3D "org.apache.derby.jdbc.ClientDataSou= rceFactory"; - - public ClientDataSourceFactory () - { } - - /** - * Reconstructs a ClientDataSource object from a JNDI data source refere= nce. - *

- * The getObjectInstance() method is passed a reference that corresponds= to the object - * being retrieved as its first parameter. The other parameters are opti= onal in the case of - * JDBC data source objects. The object factory should use the informati= on contained in - * the reference to reconstruct the data source. If for some reason, a d= ata 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 informati= on - * 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 =3D (javax.naming.Reference) refObj; - - // Create the proper data source object shell. - ClientDataSource ds =3D null; - if (ref.getClassName().equals (ClientDataSource.className__)) - ds =3D new ClientDataSource(); - else if (ref.getClassName().equals (ClientXADataSource.className__)) - ds =3D new ClientXADataSource(); - else if (ref.getClassName().equals (ClientConnectionPoolDataSource.cla= ssName__)) - ds =3D new ClientConnectionPoolDataSource(); - else - return null; + */ +public class ClientDataSourceFactory implements javax.naming.spi.ObjectFac= tory { + static final String className__ =3D "org.apache.derby.jdbc.ClientDataS= ourceFactory"; + + public ClientDataSourceFactory() { + } + + /** + * Reconstructs a ClientDataSource object from a JNDI data source refe= rence. + *

+ * The getObjectInstance() method is passed a reference that correspon= ds to the object being retrieved as its first + * parameter. The other parameters are optional in the case of JDBC da= ta source objects. The object factory should + * use the information contained in the reference to reconstruct the d= ata 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 excepti= on 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 creati= ng 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) throw= s java.lang.Exception { + javax.naming.Reference ref =3D (javax.naming.Reference) refObj; + + // Create the proper data source object shell. + ClientDataSource ds =3D null; + if (ref.getClassName().equals(ClientDataSource.className__)) { + ds =3D new ClientDataSource(); + } else if (ref.getClassName().equals(ClientXADataSource.className_= _)) { + ds =3D new ClientXADataSource(); + } else if (ref.getClassName().equals(ClientConnectionPoolDataSourc= e=2EclassName__)) { + ds =3D new ClientConnectionPoolDataSource(); + } else { + return null; + } =20 - // Fill in the data source object shell with values from the jndi refe= rence. - ds.hydrateFromReference (ref); + // Fill in the data source object shell with values from the jndi = reference. + ds.hydrateFromReference(ref); =20 - return ds; - } + return ds; + } } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/Cl= ientPooledConnection.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/ClientPooledConnection.java?rev=3D165585&r1=3D165584= &r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPo= oledConnection.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientPo= oledConnection.java Sun May 1 23:25:59 2005 @@ -19,189 +19,193 @@ */ package org.apache.derby.client; =20 -import org.apache.derby.client.net.NetLogWriter; import org.apache.derby.client.am.SqlException; +import org.apache.derby.client.net.NetLogWriter; import org.apache.derby.jdbc.ClientDataSource; =20 -public class ClientPooledConnection implements javax.sql.PooledConnection -{ - private boolean newPC_ =3D true; - - private java.util.Vector listeners_ =3D null; - org.apache.derby.client.am.Connection physicalConnection_ =3D null; - org.apache.derby.client.net.NetConnection netPhysicalConnection_ =3D nul= l; - org.apache.derby.client.net.NetXAConnection netXAPhysicalConnection_ =3D= null; - - org.apache.derby.client.am.LogicalConnection logicalConnection_ =3D null; - - protected org.apache.derby.client.am.LogWriter logWriter_ =3D null; - - protected int rmId_ =3D 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 logWrit= er, - String user, - String password) throws SqlException - { - logWriter_ =3D logWriter; - ds_ =3D ds; - user_ =3D user; - password_ =3D password; - listeners_ =3D new java.util.Vector(); - - netPhysicalConnection_ =3D new org.apache.derby.client.net.NetConnect= ion ((NetLogWriter) logWriter_, - user, - password, - ds, - -1, - false); - physicalConnection_ =3D 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 logWrit= er, - String user, - String password, - int rmId) throws SqlException - { - logWriter_ =3D logWriter; - ds_ =3D ds; - user_ =3D user; - password_ =3D password; - rmId_ =3D rmId; - listeners_ =3D new java.util.Vector(); - netXAPhysicalConnection_ =3D new org.apache.derby.client.net.NetXAConn= ection ((NetLogWriter) logWriter_, - user, - password, - ds, - rmId, - true); - physicalConnection_ =3D netXAPhysicalConnection_; - } - - public ClientPooledConnection (ClientDataSource ds, - org.apache.derby.client.am.LogWriter logWrit= er - ) throws SqlException - { - logWriter_ =3D logWriter; - ds_ =3D ds; - listeners_ =3D new java.util.Vector(); - netPhysicalConnection_ =3D new org.apache.derby.client.net.NetConnect= ion ((NetLogWriter) logWriter_, - null, - null, - ds, - -1, - false); - physicalConnection_ =3D netPhysicalConnection_; - } - - protected void finalize() throws java.lang.Throwable - { - if (logWriter_ !=3D null) logWriter_.traceEntry (this, "finalize"); - close(); - } - - public synchronized void close() throws SqlException - { - if (logWriter_ !=3D null) logWriter_.traceEntry (this, "close"); - - if ( logicalConnection_ !=3D null ) { - logicalConnection_.nullPhysicalConnection(); - logicalConnection_ =3D null; - } - - if (physicalConnection_ =3D=3D null) return; - try { - // Even if the physcial connection is marked closed (in the pool), - // this will close its underlying resources. - physicalConnection_.closeResources(); - } - finally { - physicalConnection_ =3D 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 oth= er properties may not change. - public synchronized java.sql.Connection getConnection() throws SqlExcept= ion - { - if (logWriter_ !=3D 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_ =3D false; - - if (logWriter_ !=3D null) logWriter_.traceExit (this, "getConnection",= logicalConnection_); - return logicalConnection_; - } - - private void createLogicalConnection () throws SqlException - { - if (physicalConnection_ =3D=3D 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_ !=3D null) logicalConnection_.closeWithoutRecyc= lingToPool(); - logicalConnection_ =3D new org.apache.derby.client.am.LogicalConnectio= n (physicalConnection_, this); - } - - public synchronized void addConnectionEventListener (javax.sql.Connectio= nEventListener listener) - { - if (logWriter_ !=3D null) logWriter_.traceEntry (this, "addConnectionE= ventListener", listener); - listeners_.addElement (listener); - } - - public synchronized void removeConnectionEventListener (javax.sql.Connec= tionEventListener listener ) - { - if (logWriter_ !=3D null) logWriter_.traceEntry (this, "removeConnecti= onEventListener", 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, "recycleConn= ection"); - - for (java.util.Enumeration e =3D listeners_.elements(); e.hasMoreEleme= nts(); ) { - javax.sql.ConnectionEventListener listener =3D (javax.sql.Connection= EventListener) e.nextElement(); - javax.sql.ConnectionEvent event =3D new javax.sql.ConnectionEvent (t= his); - listener.connectionClosed (event); - } - } - - // Not public, but needs to be visible to am.LogicalConnection - public void trashConnection (SqlException exception) - { - for (java.util.Enumeration e =3D listeners_.elements(); e.hasMoreEleme= nts(); ) { - javax.sql.ConnectionEventListener listener =3D (javax.sql.Connection= EventListener) e.nextElement(); - javax.sql.ConnectionEvent event =3D new javax.sql.ConnectionEvent (t= his, exception); - listener.connectionErrorOccurred (event); - } - } - - // Used by LogicalConnection close when it disassociates itself from the= ClientPooledConnection - public synchronized void nullLogicalConnection () - { - logicalConnection_ =3D null; - } +public class ClientPooledConnection implements javax.sql.PooledConnection { + private boolean newPC_ =3D true; + + private java.util.Vector listeners_ =3D null; + org.apache.derby.client.am.Connection physicalConnection_ =3D null; + org.apache.derby.client.net.NetConnection netPhysicalConnection_ =3D n= ull; + org.apache.derby.client.net.NetXAConnection netXAPhysicalConnection_ = =3D null; + + org.apache.derby.client.am.LogicalConnection logicalConnection_ =3D nu= ll; + + protected org.apache.derby.client.am.LogWriter logWriter_ =3D null; + + protected int rmId_ =3D 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 log= Writer, + String user, + String password) throws SqlException { + logWriter_ =3D logWriter; + ds_ =3D ds; + user_ =3D user; + password_ =3D password; + listeners_ =3D new java.util.Vector(); + + netPhysicalConnection_ =3D new org.apache.derby.client.net.NetConn= ection((NetLogWriter) logWriter_, + user, + password, + ds, + -1, + false); + physicalConnection_ =3D 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 log= Writer, + String user, + String password, + int rmId) throws SqlException { + logWriter_ =3D logWriter; + ds_ =3D ds; + user_ =3D user; + password_ =3D password; + rmId_ =3D rmId; + listeners_ =3D new java.util.Vector(); + netXAPhysicalConnection_ =3D new org.apache.derby.client.net.NetXA= Connection((NetLogWriter) logWriter_, + user, + password, + ds, + rmId, + true); + physicalConnection_ =3D netXAPhysicalConnection_; + } + + public ClientPooledConnection(ClientDataSource ds, + org.apache.derby.client.am.LogWriter log= Writer) throws SqlException { + logWriter_ =3D logWriter; + ds_ =3D ds; + listeners_ =3D new java.util.Vector(); + netPhysicalConnection_ =3D new org.apache.derby.client.net.NetConn= ection((NetLogWriter) logWriter_, + null, + null, + ds, + -1, + false); + physicalConnection_ =3D netPhysicalConnection_; + } + + protected void finalize() throws java.lang.Throwable { + if (logWriter_ !=3D null) { + logWriter_.traceEntry(this, "finalize"); + } + close(); + } + + public synchronized void close() throws SqlException { + if (logWriter_ !=3D null) { + logWriter_.traceEntry(this, "close"); + } + + if (logicalConnection_ !=3D null) { + logicalConnection_.nullPhysicalConnection(); + logicalConnection_ =3D null; + } + + if (physicalConnection_ =3D=3D null) { + return; + } + try { + // Even if the physcial connection is marked closed (in the po= ol), + // this will close its underlying resources. + physicalConnection_.closeResources(); + } finally { + physicalConnection_ =3D null; + } + } + + // This is the standard API for getting a logical connection handle fo= r a pooled connection. + // No "resettable" properties are passed, so user, password, and all o= ther properties may not change. + public synchronized java.sql.Connection getConnection() throws SqlExce= ption { + if (logWriter_ !=3D null) { + logWriter_.traceEntry(this, "getConnection"); + } + createLogicalConnection(); + + if (!newPC_) { + physicalConnection_.reset(logWriter_, user_, password_, ds_, f= alse); // false means do not recompute + } + // properties from the dataSource + // properties don't change + else { + physicalConnection_.lightReset(); //poolfix + } + newPC_ =3D false; + + if (logWriter_ !=3D null) { + logWriter_.traceExit(this, "getConnection", logicalConnection_= ); + } + return logicalConnection_; + } + + private void createLogicalConnection() throws SqlException { + if (physicalConnection_ =3D=3D null) { + throw new SqlException(logWriter_, "getConnection() is not val= id on a closed PooledConnection."); + } + // Not the usual case, but if we have an existing logical connecti= on, then we must close it by spec. + // We close the logical connection without notifying the pool mana= ger that this pooled connection is availabe for reuse. + if (logicalConnection_ !=3D null) { + logicalConnection_.closeWithoutRecyclingToPool(); + } + logicalConnection_ =3D new org.apache.derby.client.am.LogicalConne= ction(physicalConnection_, this); + } + + public synchronized void addConnectionEventListener(javax.sql.Connecti= onEventListener listener) { + if (logWriter_ !=3D null) { + logWriter_.traceEntry(this, "addConnectionEventListener", list= ener); + } + listeners_.addElement(listener); + } + + public synchronized void removeConnectionEventListener(javax.sql.Conne= ctionEventListener listener) { + if (logWriter_ !=3D null) { + logWriter_.traceEntry(this, "removeConnectionEventListener", l= istener); + } + 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, "recycl= eConnection"); + } + + for (java.util.Enumeration e =3D listeners_.elements(); e.hasMoreE= lements();) { + javax.sql.ConnectionEventListener listener =3D (javax.sql.Conn= ectionEventListener) e.nextElement(); + javax.sql.ConnectionEvent event =3D new javax.sql.ConnectionEv= ent(this); + listener.connectionClosed(event); + } + } + + // Not public, but needs to be visible to am.LogicalConnection + public void trashConnection(SqlException exception) { + for (java.util.Enumeration e =3D listeners_.elements(); e.hasMoreE= lements();) { + javax.sql.ConnectionEventListener listener =3D (javax.sql.Conn= ectionEventListener) e.nextElement(); + javax.sql.ConnectionEvent event =3D new javax.sql.ConnectionEv= ent(this, exception); + listener.connectionErrorOccurred(event); + } + } + + // Used by LogicalConnection close when it disassociates itself from t= he ClientPooledConnection + public synchronized void nullLogicalConnection() { + logicalConnection_ =3D null; + } } =20 =20 Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/Cl= ientXAConnection.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/ClientXAConnection.java?rev=3D165585&r1=3D165584&r2= =3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXA= Connection.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXA= Connection.java Sun May 1 23:25:59 2005 @@ -19,120 +19,112 @@ */ package org.apache.derby.client; =20 +import java.sql.Connection; +import javax.sql.XAConnection; +import javax.transaction.xa.XAResource; + 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_ =3D 95688932; // semi-random starting value= for rmId - - private ClientXADataSource derbyds_ =3D null; - private XAResource xares_ =3D null; - private org.apache.derby.client.net.NetXAResource netXares_ =3D null; - private boolean fFirstGetConnection_ =3D true; - private Connection logicalCon_; // logicalConnection_ is inherited from = ClientPooledConnection=20 - // This connection is used to access the indoubt table - private NetXAConnection controlCon_ =3D 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_ =3D 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_ =3D super.getConnection(); - - netXares_ =3D new org.apache.derby.client.net.NetXAResource( this, - rmId_, userId, password, netXAPhysicalConnection_ ); - xares_ =3D 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_ =3D false; - } - else - { - // A new connection object is required - logicalCon_ =3D super.getConnection(); - if( this.physicalConnection_ !=3D null ) - { // have a physical connection, check if a NetXAResource - if( netXAPhysicalConnection_ !=3D null ) - { // the XAResource is a NetXAResource, re-initialize it - netXares_.initForReuse(); +import org.apache.derby.client.net.NetXAConnection; +import org.apache.derby.jdbc.ClientXADataSource; + +public class ClientXAConnection extends ClientPooledConnection implements = XAConnection { + private static int rmIdSeed_ =3D 95688932; // semi-random starting val= ue for rmId + + private ClientXADataSource derbyds_ =3D null; + private XAResource xares_ =3D null; + private org.apache.derby.client.net.NetXAResource netXares_ =3D null; + private boolean fFirstGetConnection_ =3D true; + private Connection logicalCon_; // logicalConnection_ is inherited fro= m ClientPooledConnection + // This connection is used to access the indoubt table + private NetXAConnection controlCon_ =3D null; + + public ClientXAConnection(ClientXADataSource ds, + org.apache.derby.client.net.NetLogWriter log= Wtr, + String userId, + String password) throws SqlException { + super(ds, logWtr, userId, password, getUnigueRmId()); + derbyds_ =3D 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_ =3D super.getConnection(); + + netXares_ =3D new org.apache.derby.client.net.NetXAResource(this, + rmId_, userId, password, netXAPhysicalConnection_); + xares_ =3D 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_ =3D false; + } else { + // A new connection object is required + logicalCon_ =3D super.getConnection(); + if (this.physicalConnection_ !=3D null) { // have a physical c= onnection, check if a NetXAResource + if (netXAPhysicalConnection_ !=3D null) { // the XAResourc= e is a NetXAResource, re-initialize it + netXares_.initForReuse(); + } + } + } + return logicalCon_; + } + + private static synchronized int getUnigueRmId() { + rmIdSeed_ +=3D 1; + return rmIdSeed_; + } + + public int getRmId() { + return rmId_; + } + + public XAResource getXAResource() throws SqlException { + if (logWriter_ !=3D null) { + logWriter_.traceExit(this, "getXAResource", xares_); + } + + return xares_; + } + + public ClientXADataSource getDataSource() throws SqlException { + if (logWriter_ !=3D null) { + logWriter_.traceExit(this, "getDataSource", derbyds_); + } + + return derbyds_; + } + + public NetXAConnection createControlConnection(NetLogWriter logWriter, + String user, + String password, + org.apache.derby.jdbc.C= lientDataSource dataSource, + int rmId, + boolean isXAConn) throw= s SqlException { + + controlCon_ =3D new NetXAConnection(logWriter, + user, + password, + dataSource, + rmId, + isXAConn); + controlCon_.setTransactionIsolation(Connection.TRANSACTION_READ_UN= COMMITTED); + + if (logWriter_ !=3D null) { + logWriter_.traceExit(this, "createControlConnection", controlC= on_); } - } + + return controlCon_; } - return logicalCon_; - } =20 - private static synchronized int getUnigueRmId() - { - rmIdSeed_ +=3D 1; - return rmIdSeed_; - } - - public int getRmId() - { - return rmId_; - } - - public XAResource getXAResource() throws SqlException - { - if (logWriter_ !=3D null) logWriter_.traceExit (this, "getXAResource",= xares_); - - return xares_; - } - - public ClientXADataSource getDataSource() throws SqlException - { - if (logWriter_ !=3D 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_ =3D new NetXAConnection ( - logWriter, - user, - password, - dataSource, - rmId, - isXAConn); - controlCon_.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMM= ITTED); - - if (logWriter_ !=3D null) logWriter_.traceExit (this, "createControlCo= nnection", controlCon_); - - return controlCon_; - } - - - public synchronized void close() throws SqlException - { - super.close(); - } + + public synchronized void close() throws SqlException { + super.close(); + } } =20 Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/Cl= ientXid.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/ClientXid.java?rev=3D165585&r1=3D165584&r2=3D165585&= view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXi= d=2Ejava (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/ClientXi= d=2Ejava Sun May 1 23:25:59 2005 @@ -19,202 +19,187 @@ */ package org.apache.derby.client; =20 -import javax.transaction.xa.*; +import javax.transaction.xa.Xid; =20 -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. - //

The Xid is made up of two contiguous parts. The first (of size - // gtrid_length) is the global transaction identfier and the seco= nd - // (of size bqual_length) is the branch qualifier. - //

If the formatID is -1, indicating the NULLXid, the data is - // ignored. - // - private byte data_[]; - - // - // The size of data. - // - static private final int XidDATASIZE =3D 128; - - // - // The maximum size of the global transaction identifier. - // - static public final int MAXGTRIDSIZE=3D 64; - - // - // The maximum size of the branch qualifier. - // - static public final int MAXBQUALSIZE=3D 64; - - static private final String hextab_=3D "0123456789ABCDEF"; - - - // - // Constructs a new null Xid. - //

After construction the data within the Xid should be initialized. - // - public ClientXid() - { - data_ =3D new byte[XidDATASIZE]; - gtrid_length_ =3D 0; - bqual_length_ =3D 0; - formatID_ =3D -1; - } - - // - // another contructor - // - public ClientXid( int formatID, byte[] gtrid, byte[] bqual ) - { - - formatID_ =3D formatID; - gtrid_length_ =3D gtrid.length; - bqual_length_ =3D bqual.length; - data_ =3D 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 =3D gtrid_length_ + bqual_length_; - d =3D new StringBuffer(L+L); - - for( i =3D 0; i < L; i++ ) - { - // Convert data string to hex - v =3D data_[i] & 0xff; - d.append(hextab_.charAt(v/16)); - d.append(hextab_.charAt(v&15)); - if ( (i+1)%4 =3D=3D 0 && (i+1) < L ) - d.append(" "); - } - - s =3D "{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 =3D 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 MAXBQUALSI= ZE - // elements of qual will be used. - // - public void setBranchQualifier( byte[] qual ) - { - bqual_length_ =3D 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_ =3D formatID; - return; - } - - // - // Returns the global transaction identifier for this Xid. - // - // @return the global transaction identifier - // - public byte[] getGlobalTransactionId() - { - byte[] gtrid =3D 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_ =3D=3D (-1) ) - { - return (-1); - } - return formatID_ + gtrid_length_ - bqual_length_; - } - - public boolean equals(Object obj) - { - return org.apache.derby.client.net.NetXAResource.xidsEqual(this, (java= x=2Etransaction.xa.Xid)obj); - } +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. + //

The Xid is made up of two contiguous parts. The first (of size + // gtrid_length) is the global transaction identfier and the se= cond + // (of size bqual_length) is the branch qualifier. + //

If the formatID is -1, indicating the NULLXid, the data is + // ignored. + // + private byte data_[]; + + // + // The size of data. + // + static private final int XidDATASIZE =3D 128; + + // + // The maximum size of the global transaction identifier. + // + static public final int MAXGTRIDSIZE =3D 64; + + // + // The maximum size of the branch qualifier. + // + static public final int MAXBQUALSIZE =3D 64; + + static private final String hextab_ =3D "0123456789ABCDEF"; + + + // + // Constructs a new null Xid. + //

After construction the data within the Xid should be initialized. + // + public ClientXid() { + data_ =3D new byte[XidDATASIZE]; + gtrid_length_ =3D 0; + bqual_length_ =3D 0; + formatID_ =3D -1; + } + + // + // another contructor + // + public ClientXid(int formatID, byte[] gtrid, byte[] bqual) { + + formatID_ =3D formatID; + gtrid_length_ =3D gtrid.length; + bqual_length_ =3D bqual.length; + data_ =3D 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 =3D gtrid_length_ + bqual_length_; + d =3D new StringBuffer(L + L); + + for (i =3D 0; i < L; i++) { + // Convert data string to hex + v =3D data_[i] & 0xff; + d.append(hextab_.charAt(v / 16)); + d.append(hextab_.charAt(v & 15)); + if ((i + 1) % 4 =3D=3D 0 && (i + 1) < L) { + d.append(" "); + } + } + + s =3D "{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 =3D 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 MAXBQUAL= SIZE + // elements of qual will be used. + // + public void setBranchQualifier(byte[] qual) { + bqual_length_ =3D 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_ =3D formatID; + return; + } + + // + // Returns the global transaction identifier for this Xid. + // + // @return the global transaction identifier + // + public byte[] getGlobalTransactionId() { + byte[] gtrid =3D 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_ =3D=3D (-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 Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am= /Agent.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/am/Agent.java?rev=3D165585&r1=3D165584&r2=3D165585&v= iew=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Agent= .java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Agent= .java Sun May 1 23:25:59 2005 @@ -20,275 +20,260 @@ =20 package org.apache.derby.client.am; =20 -public abstract class Agent -{ - public SqlException accumulatedReadExceptions_ =3D null; - - private boolean enableBatchedExceptionTracking_; - private int batchedExceptionLabelIndex_; - private boolean[] batchedExceptionGenerated_; - - Connection connection_; // made friendly for lobs only, refactor !! - public SectionManager sectionManager_ =3D null; // temporarily public, m= ake friendly at least !! - - public LogWriter logWriter_ =3D null; - - final CrossConverters crossConverters_; - - // Exceptions that occur on dnc's implementation of SqlException.getMess= age() via stored proc - // cannot be thrown on the getMessage() invocation because the signature= of getMessage() does not - // allow for throwing an exception. - // Therefore, we must save the exception and throw it at our very first = opportunity. - SqlException deferredException_; - void checkForDeferredExceptions() throws SqlException - { - if (deferredException_ !=3D null) { - SqlException temp =3D deferredException_; - deferredException_ =3D null; - throw temp; - } - } - public void accumulateDeferredException (SqlException e) - { - if (deferredException_ =3D=3D null) - deferredException_ =3D e; - else - deferredException_.setNextException (e); - } - - protected Agent (Connection connection, LogWriter logWriter) - { - connection_ =3D connection; - logWriter_ =3D logWriter; - crossConverters_ =3D new CrossConverters (this); - } - - protected void resetAgent ( LogWriter logWriter) - { - // sectionManager_ is set elsewhere - accumulatedReadExceptions_ =3D null; - enableBatchedExceptionTracking_ =3D false; - batchedExceptionLabelIndex_ =3D 0; - batchedExceptionGenerated_ =3D null; - logWriter_ =3D logWriter; - deferredException_ =3D null; - } - - public void resetAgent (Connection connection, LogWriter logWriter, int = loginTimeout, String server,int port) throws SqlException - { - resetAgent (logWriter); - resetAgent_ (logWriter, loginTimeout, server, port); - } - - abstract protected void resetAgent_(LogWriter logWriter, int loginTimeou= t, String server,int port) throws SqlException; - - //-------------------- entry points ------------------------------------= ------ - - public final boolean loggingEnabled () { return !org.apache.derby.client= .am.Configuration.traceSuspended__ && logWriter_ !=3D null; } - - public final void setLogWriter (LogWriter logWriter) - { - synchronized (connection_) { - if (logWriter_ !=3D null) logWriter_.close(); - logWriter_ =3D logWriter; - } - } - - public final java.io.PrintWriter getLogWriter () - { return (logWriter_ =3D=3D null) ? null : logWriter_.printWriter_; } - - abstract public LogWriter newLogWriter_ (java.io.PrintWriter printWriter= , int traceLevel); - - //----------------------------------------------------------------------= ------ - - - public final void accumulateReadException (SqlException e) - { - if (enableBatchedExceptionTracking_) { - batchedExceptionGenerated_ [batchedExceptionLabelIndex_] =3D true; - labelAsBatchedException (e, batchedExceptionLabelIndex_); - } - if (accumulatedReadExceptions_ =3D=3D null) - accumulatedReadExceptions_ =3D e; - else - accumulatedReadExceptions_.setNextException (e); - } - - // Called only for disconnect event - public final void accumulateDisconnectException (DisconnectException e) - { - if (enableBatchedExceptionTracking_) { - batchedExceptionGenerated_ [batchedExceptionLabelIndex_] =3D true; - labelAsBatchedException (e, batchedExceptionLabelIndex_); - } - if (accumulatedReadExceptions_ !=3D null) - e.setNextException (accumulatedReadExceptions_); - - accumulatedReadExceptions_ =3D null; - } - - // For now, it looks like the only time we accumulate chain breaking exc= eptions - // is for disconnect exceptions. - public final void accumulateChainBreakingReadExceptionAndThrow (Disconne= ctException e) throws DisconnectException - { - accumulateDisconnectException (e); // tacks disconnect exc to end of c= hain - markChainBreakingException_(); // sets a severity code in the NET agent - throw e; // disconnect will be caught in Reply classes, and front of o= riginal chain thrown - } - - abstract protected void markChainBreakingException_ ();=20 - abstract public void checkForChainBreakingException_ () throws SqlExcept= ion; - - private final void enableBatchedExceptionTracking (int batchSize) - { - enableBatchedExceptionTracking_ =3D true; - batchedExceptionGenerated_ =3D new boolean[batchSize]; - batchedExceptionLabelIndex_ =3D 0; - } - - final void disableBatchedExceptionTracking() - { - enableBatchedExceptionTracking_ =3D false; - } - - public final void setBatchedExceptionLabelIndex (int index) - { - batchedExceptionLabelIndex_ =3D index; - } - - private final SqlException labelAsBatchedException (SqlException e, int = index) - { - SqlException firstInChain =3D e; - while (e !=3D null) { - e.setBatchPositionLabel (index); - e =3D (SqlException) e.getNextException(); - } - return firstInChain; - } - - protected final void checkForExceptions () throws SqlException - { - if (accumulatedReadExceptions_ !=3D null) { - SqlException e =3D accumulatedReadExceptions_; - accumulatedReadExceptions_ =3D null; - throw e; - } - } - - // precondition: all batch execute reads have occurred - final boolean batchUpdateExceptionGenerated () - { - return batchedExceptionGenerated_ [batchedExceptionLabelIndex_]; - } - - public final void flow (Statement statement) throws SqlException - { - endWriteChain(); - flush_(); - beginReadChain (statement); - } - - public final void flowBatch (Statement statement, int batchSize) throws = SqlException - { - endBatchedWriteChain(); - flush_(); - beginBatchedReadChain (statement, batchSize); - } - - public final void flowOutsideUOW () throws SqlException - { - endWriteChain(); - flush_(); - beginReadChainOutsideUOW (); - } - - // flush() means to send all chained requests. - abstract public void flush_() throws DisconnectException; - - // Close client resources associated with this agent, such as socket and= streams for the net. - abstract public void close_ () throws SqlException; - - public void close () throws SqlException - { - close_(); - if (logWriter_ !=3D null) logWriter_.close(); - } - - public final void disconnectEvent () - { - // closes client-side resources associated with database connection - try { close(); } catch (SqlException doNothing) {} - connection_.completeChainBreakingDisconnect (); - } - - public void beginWriteChainOutsideUOW () throws SqlException - { - } - - public void beginWriteChain (Statement statement) throws SqlException - { - connection_.writeTransactionStart(statement); - } - - public final void beginBatchedWriteChain (Statement statement) throws Sq= lException - { - beginWriteChain (statement); - } - - protected void endWriteChain () - { - } - - protected final void endBatchedWriteChain () - { - } - - protected void beginReadChain (Statement statement) throws SqlException - { - connection_.readTransactionStart(); - } - - protected final void beginBatchedReadChain (Statement statement, int bat= chSize) throws SqlException - { - enableBatchedExceptionTracking (batchSize); - beginReadChain (statement); - } - - protected void beginReadChainOutsideUOW () throws SqlException - { - } - - public void endReadChain () throws SqlException - { - checkForExceptions(); - } - - public final void endBatchedReadChain (int[] updateCounts, SqlException = accumulatedExceptions) throws BatchUpdateException - { - disableBatchedExceptionTracking(); - for (int i=3D0; i < batchedExceptionGenerated_.length; i++) { - if (batchedExceptionGenerated_[i]) - updateCounts[i] =3D -3; - } - if (accumulatedExceptions =3D=3D null) { - try { - endReadChain(); - } - catch (SqlException e) { - accumulatedExceptions =3D e; - } - } - if (accumulatedExceptions !=3D null) { - BatchUpdateException bue =3D - new BatchUpdateException (logWriter_, - "Non-atomic batch failure. The batch was submitted, but " + - "at least one exception occurred on an individual member of the = batch. " + - "Use getNextException() to retrieve the exceptions for specific = batched elements.", - updateCounts); - bue.setNextException (accumulatedExceptions); - throw bue; +public abstract class Agent { + public SqlException accumulatedReadExceptions_ =3D null; + + private boolean enableBatchedExceptionTracking_; + private int batchedExceptionLabelIndex_; + private boolean[] batchedExceptionGenerated_; + + Connection connection_; // made friendly for lobs only, refactor !! + public SectionManager sectionManager_ =3D null; // temporarily public,= make friendly at least !! + + public LogWriter logWriter_ =3D null; + + final CrossConverters crossConverters_; + + // Exceptions that occur on dnc's implementation of SqlException.getMe= ssage() via stored proc + // cannot be thrown on the getMessage() invocation because the signatu= re of getMessage() does not + // allow for throwing an exception. + // Therefore, we must save the exception and throw it at our very firs= t opportunity. + SqlException deferredException_; + + void checkForDeferredExceptions() throws SqlException { + if (deferredException_ !=3D null) { + SqlException temp =3D deferredException_; + deferredException_ =3D null; + throw temp; + } + } + + public void accumulateDeferredException(SqlException e) { + if (deferredException_ =3D=3D null) { + deferredException_ =3D e; + } else { + deferredException_.setNextException(e); + } + } + + protected Agent(Connection connection, LogWriter logWriter) { + connection_ =3D connection; + logWriter_ =3D logWriter; + crossConverters_ =3D new CrossConverters(this); + } + + protected void resetAgent(LogWriter logWriter) { + // sectionManager_ is set elsewhere + accumulatedReadExceptions_ =3D null; + enableBatchedExceptionTracking_ =3D false; + batchedExceptionLabelIndex_ =3D 0; + batchedExceptionGenerated_ =3D null; + logWriter_ =3D logWriter; + deferredException_ =3D null; + } + + public void resetAgent(Connection connection, LogWriter logWriter, int= loginTimeout, String server, int port) throws SqlException { + resetAgent(logWriter); + resetAgent_(logWriter, loginTimeout, server, port); + } + + abstract protected void resetAgent_(LogWriter logWriter, int loginTime= out, String server, int port) throws SqlException; + + //-------------------- entry points ----------------------------------= -------- + + public final boolean loggingEnabled() { + return !org.apache.derby.client.am.Configuration.traceSuspended__ = && logWriter_ !=3D null; + } + + public final void setLogWriter(LogWriter logWriter) { + synchronized (connection_) { + if (logWriter_ !=3D null) { + logWriter_.close(); + } + logWriter_ =3D logWriter; + } + } + + public final java.io.PrintWriter getLogWriter() { + return (logWriter_ =3D=3D null) ? null : logWriter_.printWriter_; + } + + abstract public LogWriter newLogWriter_(java.io.PrintWriter printWrite= r, int traceLevel); + + //--------------------------------------------------------------------= -------- + + + public final void accumulateReadException(SqlException e) { + if (enableBatchedExceptionTracking_) { + batchedExceptionGenerated_[batchedExceptionLabelIndex_] =3D tr= ue; + labelAsBatchedException(e, batchedExceptionLabelIndex_); + } + if (accumulatedReadExceptions_ =3D=3D null) { + accumulatedReadExceptions_ =3D e; + } else { + accumulatedReadExceptions_.setNextException(e); + } + } + + // Called only for disconnect event + public final void accumulateDisconnectException(DisconnectException e)= { + if (enableBatchedExceptionTracking_) { + batchedExceptionGenerated_[batchedExceptionLabelIndex_] =3D tr= ue; + labelAsBatchedException(e, batchedExceptionLabelIndex_); + } + if (accumulatedReadExceptions_ !=3D null) { + e.setNextException(accumulatedReadExceptions_); + } + + accumulatedReadExceptions_ =3D null; + } + + // For now, it looks like the only time we accumulate chain breaking e= xceptions + // is for disconnect exceptions. + public final void accumulateChainBreakingReadExceptionAndThrow(Disconn= ectException e) throws DisconnectException { + accumulateDisconnectException(e); // tacks disconnect exc to end o= f chain + markChainBreakingException_(); // sets a severity code in the NET = agent + throw e; // disconnect will be caught in Reply classes, and front = of original chain thrown + } + + abstract protected void markChainBreakingException_(); + + abstract public void checkForChainBreakingException_() throws SqlExcep= tion; + + private final void enableBatchedExceptionTracking(int batchSize) { + enableBatchedExceptionTracking_ =3D true; + batchedExceptionGenerated_ =3D new boolean[batchSize]; + batchedExceptionLabelIndex_ =3D 0; + } + + final void disableBatchedExceptionTracking() { + enableBatchedExceptionTracking_ =3D false; + } + + public final void setBatchedExceptionLabelIndex(int index) { + batchedExceptionLabelIndex_ =3D index; + } + + private final SqlException labelAsBatchedException(SqlException e, int= index) { + SqlException firstInChain =3D e; + while (e !=3D null) { + e.setBatchPositionLabel(index); + e =3D (SqlException) e.getNextException(); + } + return firstInChain; + } + + protected final void checkForExceptions() throws SqlException { + if (accumulatedReadExceptions_ !=3D null) { + SqlException e =3D accumulatedReadExceptions_; + accumulatedReadExceptions_ =3D null; + throw e; + } + } + + // precondition: all batch execute reads have occurred + final boolean batchUpdateExceptionGenerated() { + return batchedExceptionGenerated_[batchedExceptionLabelIndex_]; + } + + public final void flow(Statement statement) throws SqlException { + endWriteChain(); + flush_(); + beginReadChain(statement); + } + + public final void flowBatch(Statement statement, int batchSize) throws= SqlException { + endBatchedWriteChain(); + flush_(); + beginBatchedReadChain(statement, batchSize); + } + + public final void flowOutsideUOW() throws SqlException { + endWriteChain(); + flush_(); + beginReadChainOutsideUOW(); + } + + // flush() means to send all chained requests. + abstract public void flush_() throws DisconnectException; + + // Close client resources associated with this agent, such as socket a= nd streams for the net. + abstract public void close_() throws SqlException; + + public void close() throws SqlException { + close_(); + if (logWriter_ !=3D null) { + logWriter_.close(); + } + } + + public final void disconnectEvent() { + // closes client-side resources associated with database connection + try { + close(); + } catch (SqlException doNothing) { + } + connection_.completeChainBreakingDisconnect(); + } + + public void beginWriteChainOutsideUOW() throws SqlException { + } + + public void beginWriteChain(Statement statement) throws SqlException { + connection_.writeTransactionStart(statement); + } + + public final void beginBatchedWriteChain(Statement statement) throws S= qlException { + beginWriteChain(statement); + } + + protected void endWriteChain() { + } + + protected final void endBatchedWriteChain() { + } + + protected void beginReadChain(Statement statement) throws SqlException= { + connection_.readTransactionStart(); + } + + protected final void beginBatchedReadChain(Statement statement, int ba= tchSize) throws SqlException { + enableBatchedExceptionTracking(batchSize); + beginReadChain(statement); + } + + protected void beginReadChainOutsideUOW() throws SqlException { + } + + public void endReadChain() throws SqlException { + checkForExceptions(); + } + + public final void endBatchedReadChain(int[] updateCounts, SqlException= accumulatedExceptions) throws BatchUpdateException { + disableBatchedExceptionTracking(); + for (int i =3D 0; i < batchedExceptionGenerated_.length; i++) { + if (batchedExceptionGenerated_[i]) { + updateCounts[i] =3D -3; + } + } + if (accumulatedExceptions =3D=3D null) { + try { + endReadChain(); + } catch (SqlException e) { + accumulatedExceptions =3D e; + } + } + if (accumulatedExceptions !=3D null) { + BatchUpdateException bue =3D + new BatchUpdateException(logWriter_, + "Non-atomic batch failure. The batch was subm= itted, but " + + "at least one exception occurred on an individual memb= er of the batch. " + + "Use getNextException() to retrieve the exceptions for= specific batched elements.", + updateCounts); + bue.setNextException(accumulatedExceptions); + throw bue; + } } - } } =20 =20 Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am= /AsciiStream.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/am/AsciiStream.java?rev=3D165585&r1=3D165584&r2=3D16= 5585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Ascii= Stream.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Ascii= Stream.java Sun May 1 23:25:59 2005 @@ -19,30 +19,28 @@ */ package org.apache.derby.client.am; =20 -public class AsciiStream extends java.io.InputStream -{ - private java.io.Reader reader_; - private String materializedString_;=20 - private int charsRead_ =3D 0; +public class AsciiStream extends java.io.InputStream { + private java.io.Reader reader_; + private String materializedString_; + private int charsRead_ =3D 0; =20 - public AsciiStream (String materializedString, java.io.Reader reader) - { - reader_ =3D reader; - materializedString_ =3D materializedString; - } + public AsciiStream(String materializedString, java.io.Reader reader) { + reader_ =3D reader; + materializedString_ =3D materializedString; + } =20 - public int read () throws java.io.IOException - { - int oneChar =3D reader_.read(); - ++charsRead_; - if (oneChar !=3D -1) // if not eos - return 0x00ff & oneChar; - else - return -1; // end of stream - } + public int read() throws java.io.IOException { + int oneChar =3D reader_.read(); + ++charsRead_; + if (oneChar !=3D -1) // if not eos + { + return 0x00ff & oneChar; + } else { + return -1; // end of stream + } + } =20 - public int available() - { - return materializedString_.length() - charsRead_; - } + public int available() { + return materializedString_.length() - charsRead_; + } } Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am= /BatchUpdateException.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/am/BatchUpdateException.java?rev=3D165585&r1=3D16558= 4&r2=3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Batch= UpdateException.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Batch= UpdateException.java Sun May 1 23:25:59 2005 @@ -23,69 +23,74 @@ import org.apache.derby.client.resources.ResourceKeys; =20 =20 -public class BatchUpdateException extends java.sql.BatchUpdateException -{ +public class BatchUpdateException extends java.sql.BatchUpdateException { =20 - //-----------------constructors------------------------------------------= ----- + //-----------------constructors---------------------------------------= -------- =20 - public BatchUpdateException (LogWriter logWriter, ErrorKey errorKey, int= [] updateCounts) - { - super (ResourceUtilities.getResource (ResourceKeys.driverOriginationIn= dicator) + - ResourceUtilities.getResource (errorKey.getResourceKey()), - errorKey.getSQLState(), - errorKey.getErrorCode(), - updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - public BatchUpdateException (LogWriter logWriter, ErrorKey errorKey, Obj= ect[] args, int[] updateCounts) - { - super (ResourceUtilities.getResource (ResourceKeys.driverOriginationIn= dicator) + - ResourceUtilities.getResource (errorKey.getResourceKey(), args), - errorKey.getSQLState(), - errorKey.getErrorCode(), - updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - public BatchUpdateException (LogWriter logWriter, ErrorKey errorKey, Obj= ect arg, int[] updateCounts) - { - this (logWriter, errorKey, new Object[] {arg}, updateCounts); - } - - // Temporary constructor until all error keys are defined. - public BatchUpdateException (LogWriter logWriter) - { - super (null, null, -99999, null); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - // Temporary constructor until all error keys are defined. - public BatchUpdateException (LogWriter logWriter, int[] updateCounts) - { - super (null, null, -99999, updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - // Temporary constructor until all error keys are defined. - public BatchUpdateException (LogWriter logWriter, String reason, int[] u= pdateCounts) - { - super (reason, null, -99999, updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - // Temporary constructor until all error keys are defined. - public BatchUpdateException (LogWriter logWriter, String reason, String = sqlState, int[] updateCounts) - { - super (reason, sqlState, -99999, updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } - - // Temporary constructor until all error keys are defined. - public BatchUpdateException (LogWriter logWriter, String reason, String = sqlState, int errorCode, int[] updateCounts) - { - super (reason, sqlState, errorCode, updateCounts); - if (logWriter !=3D null) logWriter.traceDiagnosable (this); - } + public BatchUpdateException(LogWriter logWriter, ErrorKey errorKey, in= t[] updateCounts) { + super(ResourceUtilities.getResource(ResourceKeys.driverOrigination= Indicator) + + ResourceUtilities.getResource(errorKey.getResourceKey()), + errorKey.getSQLState(), + errorKey.getErrorCode(), + updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + public BatchUpdateException(LogWriter logWriter, ErrorKey errorKey, Ob= ject[] args, int[] updateCounts) { + super(ResourceUtilities.getResource(ResourceKeys.driverOrigination= Indicator) + + ResourceUtilities.getResource(errorKey.getResourceKey(), a= rgs), + errorKey.getSQLState(), + errorKey.getErrorCode(), + updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + public BatchUpdateException(LogWriter logWriter, ErrorKey errorKey, Ob= ject arg, int[] updateCounts) { + this(logWriter, errorKey, new Object[]{arg}, updateCounts); + } + + // Temporary constructor until all error keys are defined. + public BatchUpdateException(LogWriter logWriter) { + super(null, null, -99999, null); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + // Temporary constructor until all error keys are defined. + public BatchUpdateException(LogWriter logWriter, int[] updateCounts) { + super(null, null, -99999, updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + // Temporary constructor until all error keys are defined. + public BatchUpdateException(LogWriter logWriter, String reason, int[] = updateCounts) { + super(reason, null, -99999, updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + // Temporary constructor until all error keys are defined. + public BatchUpdateException(LogWriter logWriter, String reason, String= sqlState, int[] updateCounts) { + super(reason, sqlState, -99999, updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } + + // Temporary constructor until all error keys are defined. + public BatchUpdateException(LogWriter logWriter, String reason, String= sqlState, int errorCode, int[] updateCounts) { + super(reason, sqlState, errorCode, updateCounts); + if (logWriter !=3D null) { + logWriter.traceDiagnosable(this); + } + } } =20 Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am= /Blob.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/am/Blob.java?rev=3D165585&r1=3D165584&r2=3D165585&vi= ew=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.= java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.= java Sun May 1 23:25:59 2005 @@ -20,257 +20,283 @@ =20 package org.apache.derby.client.am; =20 -public class Blob extends Lob implements java.sql.Blob -{ - //-----------------------------state------------------------------------= ------ - - byte[] binaryString_ =3D null; - - // Only used for input purposes. For output, each getBinaryStream call - // must generate an independent stream. - java.io.InputStream binaryStream_ =3D null; - int dataOffset_; - - //---------------------constructors/finalizer---------------------------= ------ - - public Blob (byte[] binaryString, - Agent agent, - int dataOffset) - { - super (agent); - binaryString_ =3D binaryString; - dataType_ |=3D BINARY_STRING; - sqlLength_ =3D binaryString.length - dataOffset; - lengthObtained_ =3D true; - dataOffset_ =3D dataOffset; - } - - // CTOR for input: - public Blob (Agent agent, - java.io.InputStream binaryStream, - int length) - { - super (agent); - binaryStream_ =3D binaryStream; - dataType_ |=3D BINARY_STREAM; - sqlLength_ =3D length; - lengthObtained_ =3D true; - } - - // ---------------------------jdbc 2------------------------------------= ------ - - public long length () throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "le= ngth"); - long retVal =3D super.sqlLength(); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "len= gth", retVal); - return retVal; - } - } - - // can return an array that may be have a length shorter than the suppli= ed - // length (no padding occurs) - public byte[] getBytes (long pos, int length) throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "ge= tBytes", (int) pos, length); - if ((pos <=3D 0) || (length < 0)) - throw new SqlException (agent_.logWriter_, "Invalid position " + p= os +" or length " + length); - byte[] retVal =3D getBytesX (pos, length); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "get= Bytes", retVal); - return retVal; - } - } - - private byte[] getBytesX (long pos, int length) throws SqlException - { - checkForClosedConnection (); - - // we may need to check for overflow on this cast - long actualLength =3D Math.min (this.length() - pos + 1, (long) length= ); - - byte[] retVal =3D new byte[(int) actualLength]; - System.arraycopy (binaryString_, (int) pos + dataOffset_ - 1, retVal, = 0, (int) actualLength); - return retVal; - } - - - public java.io.InputStream getBinaryStream () throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "ge= tBinaryStream"); - java.io.InputStream retVal =3D getBinaryStreamX(); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "get= BinaryStream", retVal); - return retVal; - } - } - - private java.io.InputStream getBinaryStreamX () throws SqlException - { - checkForClosedConnection (); - - if (isBinaryStream ()) // this Lob is used for input - return binaryStream_; - - return new java.io.ByteArrayInputStream (binaryString_, dataOffset_, = binaryString_.length - dataOffset_); - } - - public long position (byte[] pattern, long start) throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "po= sition(byte[], long)", pattern, start); - if (pattern =3D=3D null) throw new SqlException (agent_.logWriter_, = "Search pattern cannot be null."); - long pos =3D positionX (pattern, start); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "pos= ition(byte[], long)", pos); - return pos; - } - } - - private long positionX (byte[] pattern, long start) throws SqlException - { - checkForClosedConnection (); - - return binaryStringPosition(pattern, start); - } - - public long position (java.sql.Blob pattern, long start) throws SqlExcep= tion - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "po= sition(Blob, long)", pattern, start); - if (pattern =3D=3D null) throw new SqlException (agent_.logWriter_, = "Search pattern cannot be null."); - long pos =3D positionX (pattern, start); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "pos= ition(Blob, long)", pos); - return pos; - } - } - - private long positionX (java.sql.Blob pattern, long start) throws SqlExc= eption - { - checkForClosedConnection (); +public class Blob extends Lob implements java.sql.Blob { + //-----------------------------state----------------------------------= -------- =20 - try { - return binaryStringPosition(pattern.getBytes(1L, (int)pattern.length= ()) , start); - } - catch (java.sql.SQLException e) { - throw new SqlException (agent_.logWriter_, e.getMessage()); + byte[] binaryString_ =3D null; + + // Only used for input purposes. For output, each getBinaryStream call + // must generate an independent stream. + java.io.InputStream binaryStream_ =3D null; + int dataOffset_; + + //---------------------constructors/finalizer-------------------------= -------- + + public Blob(byte[] binaryString, + Agent agent, + int dataOffset) { + super(agent); + binaryString_ =3D binaryString; + dataType_ |=3D BINARY_STRING; + sqlLength_ =3D binaryString.length - dataOffset; + lengthObtained_ =3D true; + dataOffset_ =3D dataOffset; + } + + // CTOR for input: + public Blob(Agent agent, + java.io.InputStream binaryStream, + int length) { + super(agent); + binaryStream_ =3D binaryStream; + dataType_ |=3D BINARY_STREAM; + sqlLength_ =3D length; + lengthObtained_ =3D true; + } + + // ---------------------------jdbc 2----------------------------------= -------- + + public long length() throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "length"); + } + long retVal =3D super.sqlLength(); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "length", retVal); + } + return retVal; + } + } + + // can return an array that may be have a length shorter than the supp= lied + // length (no padding occurs) + public byte[] getBytes(long pos, int length) throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "getBytes", (int) pos, = length); + } + if ((pos <=3D 0) || (length < 0)) { + throw new SqlException(agent_.logWriter_, "Invalid positio= n " + pos + " or length " + length); + } + byte[] retVal =3D getBytesX(pos, length); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "getBytes", retVal); + } + return retVal; + } + } + + private byte[] getBytesX(long pos, int length) throws SqlException { + checkForClosedConnection(); + + // we may need to check for overflow on this cast + long actualLength =3D Math.min(this.length() - pos + 1, (long) len= gth); + + byte[] retVal =3D new byte[(int) actualLength]; + System.arraycopy(binaryString_, (int) pos + dataOffset_ - 1, retVa= l, 0, (int) actualLength); + return retVal; + } + + + public java.io.InputStream getBinaryStream() throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "getBinaryStream"); + } + java.io.InputStream retVal =3D getBinaryStreamX(); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "getBinaryStream", retVa= l); + } + return retVal; + } + } + + private java.io.InputStream getBinaryStreamX() throws SqlException { + checkForClosedConnection(); + + if (isBinaryStream()) // this Lob is used for input + { + return binaryStream_; + } + + return new java.io.ByteArrayInputStream(binaryString_, dataOffset_= , binaryString_.length - dataOffset_); + } + + public long position(byte[] pattern, long start) throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "position(byte[], long)= ", pattern, start); + } + if (pattern =3D=3D null) { + throw new SqlException(agent_.logWriter_, "Search pattern = cannot be null."); + } + long pos =3D positionX(pattern, start); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "position(byte[], long)"= , pos); + } + return pos; + } + } + + private long positionX(byte[] pattern, long start) throws SqlException= { + checkForClosedConnection(); + + return binaryStringPosition(pattern, start); + } + + public long position(java.sql.Blob pattern, long start) throws SqlExce= ption { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "position(Blob, long)",= pattern, start); + } + if (pattern =3D=3D null) { + throw new SqlException(agent_.logWriter_, "Search pattern = cannot be null."); + } + long pos =3D positionX(pattern, start); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "position(Blob, long)", = pos); + } + return pos; + } + } + + private long positionX(java.sql.Blob pattern, long start) throws SqlEx= ception { + checkForClosedConnection(); + + try { + return binaryStringPosition(pattern.getBytes(1L, (int) pattern= .length()), start); + } catch (java.sql.SQLException e) { + throw new SqlException(agent_.logWriter_, e.getMessage()); + } } - } =20 // -------------------------- JDBC 3.0 -------------------------------= ---- =20 =20 - public int setBytes (long pos, byte[] bytes) throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "= setBytes", (int) pos, bytes); - int length =3D setBytesX (pos, bytes, 0, bytes.length); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "s= etBytes", length); - return length; - } - } - - public int setBytes (long pos, byte[] bytes, int offset, int len) thro= ws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "= setBytes", (int) pos, bytes, offset, len); - int length =3D setBytesX (pos, bytes, offset, len); - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, "s= etBytes", length); - return length; - } - } + public int setBytes(long pos, byte[] bytes) throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "setBytes", (int) pos, = bytes); + } + int length =3D setBytesX(pos, bytes, 0, bytes.length); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "setBytes", length); + } + return length; + } + } + + public int setBytes(long pos, byte[] bytes, int offset, int len) throw= s SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "setBytes", (int) pos, = bytes, offset, len); + } + int length =3D setBytesX(pos, bytes, offset, len); + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "setBytes", length); + } + return length; + } + } + + public int setBytesX(long pos, byte[] bytes, int offset, int len) thro= ws SqlException { + int length =3D 0; + if ((int) pos <=3D 0 || pos > binaryString_.length - dataOffset_) { + throw new SqlException(agent_.logWriter_, "Invalid position " = + pos + + " , offset " + offset + " or length " + len); + } + if ((offset < 0) || offset > bytes.length || len < 0) { + throw new SqlException(agent_.logWriter_, "Invalid position " = + pos + + " , offset " + offset + " or length " + len); + } + if (len =3D=3D 0) { + return 0; + } + length =3D Math.min((bytes.length - offset), len); + if ((binaryString_.length - dataOffset_ - (int) pos + 1) < length)= { + byte newbuf[] =3D new byte[(int) pos + length + dataOffset_ - = 1]; + System.arraycopy(binaryString_, 0, newbuf, 0, binaryString_.le= ngth); + binaryString_ =3D newbuf; + } =20 - public int setBytesX (long pos, byte[] bytes, int offset, int len) thr= ows SqlException - { - int length =3D 0; - if ( (int) pos <=3D 0 || pos > binaryString_.length - dataOffset_) - throw new SqlException(agent_.logWriter_, "Invalid position " + po= s=20 - + " , offset " + offset + " or length " + len); - if ( (offset < 0) || offset > bytes.length || len < 0 ) - throw new SqlException(agent_.logWriter_, "Invalid position " + po= s=20 - + " , offset " + offset + " or length " + len= ); - if (len =3D=3D 0) - return 0; - length =3D Math.min((bytes.length - offset ),len); - if ((binaryString_.length - dataOffset_ - (int) pos + 1) < length) { - byte newbuf[] =3D new byte[(int)pos + length + dataOffset_-1]; - System.arraycopy(binaryString_,0,newbuf,0,binaryString_.length); - binaryString_ =3D newbuf; - } - - System.arraycopy(bytes,offset, binaryString_, (int)pos + dataOffset_= -1, length); - binaryStream_ =3D new java.io.ByteArrayInputStream(binaryString_); - sqlLength_ =3D binaryString_.length - dataOffset_; - return length; - } - - public java.io.OutputStream setBinaryStream (long pos) throws SqlExcep= tion - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this,= "setBinaryStream", (int) pos); - BlobOutputStream outStream =3D new BlobOutputStream (this,pos); - - if (agent_.loggingEnabled()) agent_.logWriter_.traceExit (this, = "setBinaryStream", outStream); - return outStream; - } - } - - public void truncate (long len) throws SqlException - { - synchronized (agent_.connection_) { - if (agent_.loggingEnabled()) agent_.logWriter_.traceEntry (this, "= truncate", (int) len); - if (len < 0 || len > this.length()) - throw new SqlException (agent_.logWriter_, "Invalid length " + l= en); - if (len =3D=3D this.length()) - return; - long newLength =3D (int)len + dataOffset_; - byte newbuf[] =3D new byte[(int)len + dataOffset_]; - System.arraycopy(binaryString_,0,newbuf,0,(int)newLength); - binaryString_ =3D newbuf; + System.arraycopy(bytes, offset, binaryString_, (int) pos + dataOff= set_ - 1, length); binaryStream_ =3D new java.io.ByteArrayInputStream(binaryString_); sqlLength_ =3D binaryString_.length - dataOffset_; - } + return length; } =20 - //------------------ Material layer event callback methods -------------= ------ + public java.io.OutputStream setBinaryStream(long pos) throws SqlExcept= ion { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, "setBinaryStream", (int= ) pos); + } + BlobOutputStream outStream =3D new BlobOutputStream(this, pos); + + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceExit(this, "setBinaryStream", outSt= ream); + } + return outStream; + } + } + + public void truncate(long len) throws SqlException { + synchronized (agent_.connection_) { + if (agent_.loggingEnabled()) { + agent_.logWriter_.traceEntry(this, " truncate", (int) len); + } + if (len < 0 || len > this.length()) { + throw new SqlException(agent_.logWriter_, "Invalid length = " + len); + } + if (len =3D=3D this.length()) { + return; + } + long newLength =3D (int) len + dataOffset_; + byte newbuf[] =3D new byte[(int) len + dataOffset_]; + System.arraycopy(binaryString_, 0, newbuf, 0, (int) newLength); + binaryString_ =3D newbuf; + binaryStream_ =3D new java.io.ByteArrayInputStream(binaryStrin= g_); + sqlLength_ =3D binaryString_.length - dataOffset_; + } + } + + //------------------ Material layer event callback methods -----------= -------- + + //---------------------------- helper methods ------------------------= -------- + public boolean isBinaryString() { + return ((dataType_ & BINARY_STRING) =3D=3D BINARY_STRING); + } + + public boolean isBinaryStream() { + return ((dataType_ & BINARY_STREAM) =3D=3D BINARY_STREAM); + } + + public byte[] getBinaryString() { + return binaryString_; + } + + protected long binaryStringPosition(byte[] pattern, long start) { + // perform a local byte string search, starting at start + // check that the range of comparison is valid + int index =3D (int) start + dataOffset_ - 1; // api start begins a= t 1 + + while (index + pattern.length <=3D binaryString_.length) { + if (isSubString(pattern, index)) { + return (long) (index - dataOffset_ + 1); // readjust for a= pi indexing + } + index++; + } + return -1L; // not found + } + + // precondition: binaryString_ is long enough for the comparison + protected boolean isSubString(byte[] pattern, int index) { + for (int i =3D 0; i < pattern.length; i++, index++) { + if (pattern[i] !=3D binaryString_[index]) { + return false; + } + } =20 - //---------------------------- helper methods --------------------------= ------ - public boolean isBinaryString () - { - return ((dataType_ & BINARY_STRING) =3D=3D BINARY_STRING); - } - - public boolean isBinaryStream () - { - return ((dataType_ & BINARY_STREAM) =3D=3D BINARY_STREAM); - } - - public byte[] getBinaryString () - { - return binaryString_; - } - - protected long binaryStringPosition (byte[] pattern, long start) - { - // perform a local byte string search, starting at start - // check that the range of comparison is valid - int index =3D (int) start + dataOffset_ - 1; // api start begins at 1 - - while (index + pattern.length <=3D binaryString_.length) { - if (isSubString (pattern, index)) - return (long)(index - dataOffset_ + 1); // readjust for api indexi= ng - index++; - } - return -1L; // not found - } - - // precondition: binaryString_ is long enough for the comparison - protected boolean isSubString (byte[] pattern, int index) - { - for (int i =3D 0; i < pattern.length; i++, index++) - if (pattern[i] !=3D binaryString_[index]) - return false; - - return true; - } + return true; + } }