Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,39 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.ResultSetCallbackInterface
+
+   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.am;
+
+// Methods implemented by the common ResultSet class to handle
+// certain events that may originate from the material or common layers.
+//
+// Reply implementations may update result set state via this interface.
+public interface ResultSetCallbackInterface
+{
+  // The query was ended at the server because all rows have been retrieved.
+  public void earlyCloseComplete (Sqlca sqlca);
+
+  public int completeSqlca (Sqlca sqlca);
+
+  // Chain a warning on the result set object.
+  public void accumulateWarning (SqlWarning e);
+
+  public StatementCallbackInterface getStatementCallbackInterface ();
+  public ConnectionCallbackInterface getConnectionCallbackInterface ();
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSetCallbackInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,64 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.Savepoint
+
+   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.am;
+
+public class Savepoint implements java.sql.Savepoint
+{
+  // ----------------- internals 
-----------------------------------------------
+
+  int savepointId_ = 0;
+  String savepointName_ = null;
+  Agent agent_;
+
+  
//---------------------constructors/finalizer---------------------------------
+
+  // create a named savepoint.
+  Savepoint (Agent agent, String savepointName)
+  {
+    agent_ = agent;
+    savepointName_ = savepointName;
+  }
+
+  // create an un-named savepoint.
+  Savepoint (Agent agent, int savepointId)
+  {
+    agent_ = agent;
+    savepointId_ = savepointId;
+  }
+
+  // ----------------- externals 
-----------------------------------------------
+
+  public int getSavepointId() throws SqlException
+  {
+    if (savepointId_ != 0)
+      return savepointId_;
+    else
+      throw new SqlException (agent_.logWriter_, "This is a named savepoint.");
+  }
+
+  public String getSavepointName() throws SqlException
+  {
+    if (savepointName_ != null)
+      return savepointName_;
+    else
+      throw new SqlException (agent_.logWriter_, "This is an un-named 
savepoint.");
+  }
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java 
(added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java 
Thu Apr 28 12:05:42 2005
@@ -0,0 +1,162 @@
+/*
+ *
+ * Derby - Class org.apache.derby.client.am.Section
+ *
+ * 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.am;
+
+public class Section
+{
+
+  protected int sectionNumber;
+  protected String packageName;
+  protected String serverCursorName; // As given by dnc package set
+  int resultSetHoldability_;
+  
+  // Stores the package name and consistency token  
+  byte[] PKGNAMCBytes; 
+  boolean isGenerated; // flag to identify server generated sections
+
+  public Section (Agent agent, String name, int sectionNumber, String 
cursorName, int resultSetHoldability)
+  {
+     // default for all sections except for generated section , isGenerated is 
set to false
+     init(agent,name,sectionNumber,cursorName,resultSetHoldability,false);
+  }
+
+  public Section (Agent agent, String name, int sectionNumber, String 
cursorName, int resultSetHoldability,boolean isGenerated)
+  {
+     
init(agent,name,sectionNumber,cursorName,resultSetHoldability,isGenerated);
+  }
+
+  private void init (Agent agent, String name, int sectionNumber, String 
cursorName, int resultSetHoldability,boolean isGenerated)
+  {
+    this.packageName = name;
+    this.sectionNumber = sectionNumber;
+    this.serverCursorName = cursorName;
+    resultSetHoldability_ = resultSetHoldability;
+    agent_ = agent;
+    this.isGenerated = isGenerated;
+
+    // Store the packagename and consistency token bytes depending on the 
holdability
+    // PKGNAMCBytes will point to the appropriate byte array in SectionManager
+    // that stores the PKGNAMCBytes for reuse
+    // There are 2 byte arrays in SectionManager
+    // 1. holdPKGNAMCBytes which stores the PKGNAMCBytes when holdability is 
set
+    // 2. noHoldPKGNAMCBytes which stores the PKGNAMCBytes when holdability is 
non hold
+    // Note for generated sections, PKGNAMCBytes is generated by the server.
+    if(!isGenerated)
+    {
+       if (resultSetHoldability_ == ResultSet.HOLD_CURSORS_OVER_COMMIT)
+         PKGNAMCBytes = agent_.sectionManager_.holdPKGNAMCBytes;
+       else if (resultSetHoldability_ == ResultSet.CLOSE_CURSORS_AT_COMMIT)
+         PKGNAMCBytes = agent_.sectionManager_.noHoldPKGNAMCBytes;
+    }
+  }
+
+  /**
+   *  Store the Packagename and consistency token information 
+   *  for reuse. 
+   *  Case 1: if it is generated section, just store the byte array in 
PKGNAMCBytes
+   *  Case 2: for not a generated section, information is stored in the 
correct byte array
+   *  depending on the holdability in SectionManager  
+   */
+  public void setPKGNAMCBytes(byte[] b)
+  {
+     if(isGenerated)
+        PKGNAMCBytes = b;
+     else 
+        agent_.sectionManager_.setPKGNAMCBytes(b,resultSetHoldability_);
+  }
+
+  /**
+   * retrieve the package name and consistency token information
+   */
+  public byte[] getPKGNAMCBytes()
+  {
+     return PKGNAMCBytes;
+  }
+
+  public String getPackageName() { return this.packageName; }
+
+
+  // Add a finalizer to free() the section, useful for Statement.executes that 
result in exceptions
+
+  public int getSectionNumber ()
+  {
+    return this.sectionNumber;
+  }
+
+  public String getPackage ()
+  {
+    return this.packageName;
+  }
+
+  public String getServerCursorName ()
+  {
+    return this.serverCursorName;
+  }
+
+  // ------------------------ transient members 
--------------------------------
+
+  public String serverCursorNameForPositionedUpdate_ = null; // member for 
positioned update sections only
+  transient protected String clientCursorName_; // As given by jdbc 
setCursorName(), this can change
+
+  public String getServerCursorNameForPositionedUpdate ()
+  {
+    return serverCursorNameForPositionedUpdate_;
+  }
+
+  public String getClientCursorName ()
+  {
+    return clientCursorName_;
+  }
+
+  public void setClientCursorName (String clientCursorName)
+  { //
+    //System.out.println("clientCursorName is set"+ clientCursorName);
+    this.clientCursorName_ = clientCursorName;
+  }
+
+  protected Agent agent_;
+
+
+  public void free ()
+  {
+    if (resultSetHoldability_ != -1)
+      this.agent_.sectionManager_.freeSection(this, resultSetHoldability_);
+  }
+
+  public boolean isReservedPositionedUpdate ()
+  {
+    return false;
+  }
+
+  public int getStaticStatementType ()
+  {
+    return 0;
+  }
+
+  public Section getPositionedUpdateSection () throws java.sql.SQLException
+  {
+    return agent_.sectionManager_.getPositionedUpdateSection (this);
+  }
+
+  public void setCursorName (String name)
+  {
+    serverCursorName = name;
+  }
+
+}
+

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,219 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SectionManager
+
+   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.am;
+
+
+public class SectionManager
+{
+  String collection_;
+  Agent agent_;
+
+  // Cursor holdability attributes used as package cluster indices.
+  // Not defined in PackageBindOptions because this attribute is part of the
+  // declare cursor [with hold] sql string based on section binds.
+  // By convention, we bind all sections in the same package with
+  // the same holdability.
+  final static int HOLD = 0;
+  final static int NO_HOLD = 1;
+
+  // The following stack of available sections is
+  // for pooling and recycling previously used sections.
+  // For performance, the section objects themselves are pooled,
+  // rather than just keeping track of free section numbers;
+  // this way, we don't have to new-up a section if one is available in the 
pool.
+  java.util.Stack freeSectionsNonHold_ = null;
+  java.util.Stack freeSectionsHold_ = null;
+
+  int nextAvailableSectionNumber_ = 1;
+
+  // store package consistency token information and initialized in
+  // setPKGNAMCBytes 
+  // holdPKGNAMCBytes stores PKGNAMCBytes when holdability is hold
+  // noHoldPKGNAMCBytes stores PKGNAMCBytes when holdability is no hold
+  public  static byte[] holdPKGNAMCBytes = null;
+  public  static byte[] noHoldPKGNAMCBytes = null;
+
+
+  final static String packageNameWithHold__ = "SYSLH000";
+  final static String packageNameWithNoHold__ = "SYSLN000";
+
+  final static String cursorNamePrefixWithHold__ = "SQL_CURLH000C";
+  final static String cursorNamePrefixWithNoHold__ = "SQL_CURLN000C";
+
+  // Jdbc 1 positioned updates are implemented via
+  // sql scan for "...where current of <users-cursor-name>",
+  // the addition of mappings from cursor names to query sections,
+  // and the subtitution of <users-cursor-name> with <canned-cursor-name> in 
the pass-thru sql string
+  // "...where current of <canned-cursor-name>" when user-defined cursor names 
are used.
+  // Both "canned" cursor names (from our jdbc package set) and user-defined 
cursor names are mapped.
+  // Statement.cursorName_ is initialized to null until the cursor name is 
requested or set.
+  // When set (s.setCursorName()) with a user-defined name, then it is added 
to the cursor map at that time;
+  // When requested (rs.getCursorName()), if the cursor name is still null,
+  // then is given the canned cursor name as defined by our jdbc package set 
and added to the cursor map.
+  // Still need to consider how positioned updates should interact with 
multiple result sets from a stored.
+  private java.util.Hashtable positionedUpdateCursorNameToQuerySection_ = new 
java.util.Hashtable();
+
+  // Cursor name to ResultSet mapping is needed for positioned updates to 
check whether
+  // a ResultSet is scrollable.  If so, exception is thrown.
+  private java.util.Hashtable positionedUpdateCursorNameToResultSet_ = new 
java.util.Hashtable();
+
+  String databaseName;
+
+  int maxNumSections_ = 32768;
+
+  public SectionManager (String collection, Agent agent, String databaseName)
+  {
+    collection_ = collection;
+    agent_ = agent;
+    this.databaseName = databaseName;
+    freeSectionsNonHold_ = new java.util.Stack();
+    freeSectionsHold_ = new java.util.Stack();
+  }
+
+  /**
+   *  Store the Packagename and consistency token information 
+   *  This is called from Section.setPKGNAMCBytes
+   *  @param b bytearray that has the PKGNAMC information to be stored
+   *  @param resultSetHoldability depending on the holdability store it in the 
correct 
+   *                             byte array
+   *  packagename and consistency token information for 
+   *  when holdability is set to HOLD_CURSORS_OVER_COMMIT is stored in 
holdPKGNAMCBytes
+   *  and in noHoldPKGNAMCBytes when holdability is set to 
CLOSE_CURSORS_AT_COMMIT  
+   *
+   */
+  public void setPKGNAMCBytes(byte[] b, int resultSetHoldability)
+  {
+    if(resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.HOLD_CURSORS_OVER_COMMIT)
+        agent_.sectionManager_.holdPKGNAMCBytes = b;
+    else if (resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.CLOSE_CURSORS_AT_COMMIT)
+       agent_.sectionManager_.noHoldPKGNAMCBytes = b;
+  }
+
+
+  //------------------------entry 
points----------------------------------------
+
+  // Get a section for either a jdbc update or query statement.
+  public Section getDynamicSection (
+                                int resultSetHoldability) throws SqlException
+  {
+    int cursorHoldIndex;
+    if (resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.HOLD_CURSORS_OVER_COMMIT) {
+      return getSection (freeSectionsHold_, packageNameWithHold__, 
cursorNamePrefixWithHold__, resultSetHoldability);
+    }
+    else if (resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.CLOSE_CURSORS_AT_COMMIT)
+      return getSection (freeSectionsNonHold_, packageNameWithNoHold__, 
cursorNamePrefixWithNoHold__, resultSetHoldability);
+    else
+      throw new SqlException (agent_.logWriter_, "resultSetHoldability 
property " + resultSetHoldability + " not supported");
+  }
+
+  protected Section getSection(java.util.Stack freeSections, String 
packageName, String cursorNamePrefix, int resultSetHoldability) throws 
SqlException
+ {
+   if (!freeSections.empty()) {
+     return (Section)freeSections.pop();
+   }
+   else if (nextAvailableSectionNumber_ < (maxNumSections_-1))  {
+     String cursorName = cursorNamePrefix + nextAvailableSectionNumber_;
+     Section section = new Section (agent_, packageName, 
nextAvailableSectionNumber_, cursorName, resultSetHoldability);
+     nextAvailableSectionNumber_++;
+     return section;
+   }
+  else
+  // unfortunately we have run out of sections
+  throw new SqlException(agent_.logWriter_, "Run out of sections to 
use,sections limited to 32k currently");
+ }
+
+  public void freeSection (Section section, int resultSetHoldability)
+  {
+    if (resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.HOLD_CURSORS_OVER_COMMIT)
+      this.freeSectionsHold_.push(section);
+    else if (resultSetHoldability == 
org.apache.derby.jdbc.ClientDataSource.CLOSE_CURSORS_AT_COMMIT)
+      this.freeSectionsNonHold_.push(section);
+  }
+  // Get a section for a jdbc 2 positioned update/delete for the corresponding 
query.
+  // A positioned update section must come from the same package as its query 
section.
+  Section getPositionedUpdateSection (Section querySection) throws SqlException
+  {
+    Connection connection = agent_.connection_;
+    return getDynamicSection (connection.resultSetHoldability_);
+  }
+
+  // Get a section for a jdbc 1 positioned update/delete for the corresponding 
query.
+  // A positioned update section must come from the same package as its query 
section.
+  Section getPositionedUpdateSection (String cursorName, boolean 
useExecuteImmediateSection) throws SqlException
+  {
+    Section querySection = (Section) 
positionedUpdateCursorNameToQuerySection_.get (cursorName);
+
+    // If querySection is null, then the user must have provided a bad cursor 
name.
+    // Otherwise, get a new section and save the client's cursor name and the 
server's
+    // cursor name to the new section.
+    if (querySection != null) {
+      Section section = getPositionedUpdateSection (querySection);
+      // getPositionedUpdateSection gets the next available section from the 
query
+      // package, and it has a different cursor name associated with the 
section.
+      // We need to save the client's cursor name and server's cursor name to 
the
+      // new section.
+      section.setClientCursorName (querySection.getClientCursorName());
+      section.serverCursorNameForPositionedUpdate_ = 
querySection.getServerCursorName();
+      return section;
+    }
+    else
+      return null;
+  }
+
+  void mapCursorNameToQuerySection (String cursorName, Section section)
+  {
+    positionedUpdateCursorNameToQuerySection_.put (cursorName, section);
+  }
+
+  void mapCursorNameToResultSet (String cursorName, ResultSet resultSet)
+  {
+    positionedUpdateCursorNameToResultSet_.put (cursorName, resultSet);
+  }
+
+  ResultSet getPositionedUpdateResultSet (String cursorName) throws 
SqlException
+  {
+    ResultSet rs = (ResultSet)positionedUpdateCursorNameToResultSet_.get 
(cursorName);
+    if (rs == null)
+      throw new SqlException (agent_.logWriter_, "ResultSet for cursor " +
+                              cursorName + " is closed.");
+    return (rs.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) ? null 
: rs;
+  }
+
+  void removeCursorNameToResultSetMapping (String clientCursorName,
+                                           String serverCursorName)
+  {
+    if (clientCursorName != null)
+      positionedUpdateCursorNameToResultSet_.remove (clientCursorName);
+    if (serverCursorName != null)
+      positionedUpdateCursorNameToResultSet_.remove (serverCursorName);
+  }
+
+  void removeCursorNameToQuerySectionMapping (String clientCursorName,
+                                              String serverCursorName)
+  {
+    if (clientCursorName != null)
+      positionedUpdateCursorNameToQuerySection_.remove (clientCursorName);
+    if (serverCursorName != null)
+      positionedUpdateCursorNameToQuerySection_.remove (serverCursorName);
+  }
+
+}
+

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,45 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SetAccessibleAction
+
+   Copyright (c) 2002, 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.am;
+
+// Java 2 PrivilegedExceptionAction encapsulation of the action to set 
accessible flag of an object
+public class SetAccessibleAction implements 
java.security.PrivilegedExceptionAction
+{
+  private boolean accessible_ = false;
+
+  // provides information about, and dynamic access to, a single field of a 
class or an interface
+  private java.lang.reflect.Field field_ = null;
+
+  public SetAccessibleAction (java.lang.reflect.Field field, boolean 
accessible)
+  {
+    field_ = field;
+    accessible_ = accessible;
+  }
+
+  public Object run ()
+  {
+    field_.setAccessible (accessible_);
+    return null;
+  }
+
+  public void setAccessible (boolean accessible) { accessible_ = accessible; }
+  public void setField (java.lang.reflect.Field field) { field_ = field; }
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SetAccessibleAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,114 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SignedBinary
+
+   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.am;
+
+public class SignedBinary
+{
+  // Hide the default constructor, this is a static class.
+  private SignedBinary () {}
+
+  /**
+   * Unix byte-order for signed binary representations.
+   */
+  public final static int BIG_ENDIAN = 1;
+
+  /**
+   * Intel 80/86 reversed byte-order for signed binary representations.
+   */
+  public final static int LITTLE_ENDIAN = 2;
+
+  /**
+   * Build a Java short from a 2-byte signed binary representation.
+   *
+   * @exception IllegalArgumentException if the specified byte order is not 
recognized.
+   */
+  public static final short getShort (byte[] buffer, int offset)
+  {
+    return (short) (((buffer[offset+0] & 0xff) << 8) +
+                    ((buffer[offset+1] & 0xff) << 0));
+  }
+
+  /**
+   * Build a Java int from a 4-byte signed binary representation.
+   *
+   * @exception IllegalArgumentException if the specified byte order is not 
recognized.
+   */
+  public static final int getInt (byte[] buffer, int offset)
+  {
+    return (int) (((buffer[offset+0] & 0xff) << 24) +
+                  ((buffer[offset+1] & 0xff) << 16) +
+                  ((buffer[offset+2] & 0xff) << 8) +
+                  ((buffer[offset+3] & 0xff) << 0));
+  }
+
+  /**
+   * Build a Java long from an 8-byte signed binary representation.
+   *
+   * @exception IllegalArgumentException if the specified byte order is not 
recognized.
+   */
+  public static final long getLong (byte[] buffer, int offset)
+  {
+    return (long) (((buffer[offset+0] & 0xffL) << 56) +
+                   ((buffer[offset+1] & 0xffL) << 48) +
+                   ((buffer[offset+2] & 0xffL) << 40) +
+                   ((buffer[offset+3] & 0xffL) << 32) +
+                   ((buffer[offset+4] & 0xffL) << 24) +
+                   ((buffer[offset+5] & 0xffL) << 16) +
+                   ((buffer[offset+6] & 0xffL) << 8) +
+                   ((buffer[offset+7] & 0xffL) << 0));
+  }
+
+  //--------------------- input converters 
-------------------------------------
+
+  /**
+   * Write a Java short to a 2-byte big endian signed binary representation.
+   */
+  public static final void shortToBigEndianBytes (byte[] buffer, int offset, 
short v)
+  {
+    buffer[offset++] = (byte) ((v >>> 8) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 0) & 0xFF);
+  }
+
+  /**
+   * Write a Java int to a 4-byte big endian signed binary representation.
+   */
+  public static final void intToBigEndianBytes (byte[] buffer, int offset, int 
v)
+  {
+    buffer[offset++] = (byte) ((v >>> 24) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 16) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 8) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 0) & 0xFF);
+  }
+
+  /**
+   * Write a Java long to an 8-byte big endian signed binary representation.
+   */
+  public static final void longToBigEndianBytes (byte[] buffer, int offset, 
long v)
+  {
+    buffer[offset++] = (byte) ((v >>> 56) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 48) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 40) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 32) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 24) & 0xFF);
+    buffer[offset++] = (byte) ((v >>> 16) & 0xFF);
+    buffer[offset++] = (byte) ((v >>>  8) & 0xFF);
+    buffer[offset++] = (byte) ((v >>>  0) & 0xFF);
+  }
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SignedBinary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java 
(added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java 
Thu Apr 28 12:05:42 2005
@@ -0,0 +1,47 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SqlCode
+
+   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.am;
+
+// This class is for strong-typing.
+//
+// Dnc architected codes in the range +/- 4200 to 4299, plus one additional 
code for -4499.
+//
+// SQL codes are architected by the product that issues them.
+//
+public class SqlCode
+{
+  private int code_;
+
+  private SqlCode (int code) { code_ = code; }
+
+  int getCode() { return code_; }
+
+  public final static SqlCode invalidCommitOrRollbackUnderXA = new SqlCode 
(-4200);
+
+  public final static SqlCode invalidSetAutoCommitUnderXA = new SqlCode 
(-4201);
+
+  public final static SqlCode queuedXAError = new SqlCode (-4203);
+
+  public final static SqlCode disconnectError = new SqlCode (-4499);
+
+  public final static SqlCode undefinedError = new SqlCode (-99999);
+
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlCode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,297 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SqlException
+
+   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.am;
+
+import org.apache.derby.client.resources.ResourceKeys;
+
+
+// The signature of the stored procedure SQLCAMessage I have come out so far 
is as follows:
+// SQLCAMessage (
+//     IN  SQLCode       INTEGER,
+//     IN  SQLErrml      SMALLINT,
+//     IN  SQLErrmc      VARCHAR(70),
+//     IN  SQLErrp       CHAR(8),
+//     IN  SQLErrd0      INTEGER,
+//     IN  SQLErrd1      INTEGER,
+//     IN  SQLErrd2      INTEGER,
+//     IN  SQLErrd3      INTEGER,
+//     IN  SQLErrd4      INTEGER,
+//     IN  SQLErrd5      INTEGER,
+//     IN  SQLWarn       CHAR(11),
+//     IN  SQLState      CHAR(5),
+//     IN  Locale        CHAR(5),
+//     IN  BufferSize    SMALLINT,
+//     IN  LineWidth     SMALLINT,
+//     OUT Message       VARCHAR(2400))
+//
+// Some issues have been identified:
+// 1. What would be the schema name of the stored procedue SQLCAMessage?
+// 2. What is the format and type of the Locale parameter? If there does, I 
would really like to know the format of the locale in order to decide the type 
of the Locale parameter. Even there does not either, the Locale parameter 
probably still needs to be kept there for future extension, and we need to 
figure out the format of the locale.
+// 3. What would be the format of the output message? Is this full message 
text ok or do we only need the explanation message corresponding to an SQL 
code. This somehow matters whether we need the Buffersize and Linewidth 
parameters for the stored procedure.
+// 4. What if the invocation of stored procedure failed (due to, eg, 
connection dropping)? In this case, we probably need to return some client-side 
message.
+public class SqlException extends java.sql.SQLException implements Diagnosable
+{
+  java.lang.Throwable throwable_ = null;
+  protected Sqlca sqlca_ = null; // for engine generated errors only
+  private String batchPositionLabel_; // for batched exceptions only
+
+  
//-----------------constructors-----------------------------------------------
+
+  public SqlException (LogWriter logWriter, ErrorKey errorKey)
+  {
+    super (ResourceUtilities.getResource 
(ResourceKeys.driverOriginationIndicator) +
+           ResourceUtilities.getResource (errorKey.getResourceKey()),
+           errorKey.getSQLState(),
+           errorKey.getErrorCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  public SqlException (LogWriter logWriter, ErrorKey errorKey, Object[] args)
+  {
+    super (ResourceUtilities.getResource 
(ResourceKeys.driverOriginationIndicator) +
+           ResourceUtilities.getResource (errorKey.getResourceKey(), args),
+           errorKey.getSQLState(),
+           errorKey.getErrorCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  public SqlException (LogWriter logWriter, ErrorKey errorKey, Object arg)
+  {
+    this (logWriter, errorKey, new Object[] {arg});
+  }
+
+  public SqlException (LogWriter logWriter, Sqlca sqlca)
+  {
+    super ();
+    sqlca_ = sqlca;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter)
+  {
+    super (null, null, -99999);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  /*
+  // Temporary constructor until all error keys are defined.
+  public SQLException (LogWriter logWriter, java.lang.Throwable throwable)
+  {
+    super ();
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+  */
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, String reason)
+  {
+    super (reason, null, -99999);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, java.lang.Throwable throwable, 
String reason)
+  {
+    super (reason, null, -99999);
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, java.lang.Throwable throwable, 
String reason, SqlState sqlstate)
+  {
+    super (reason, sqlstate.getState(), -99999);
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only.
+  public SqlException (LogWriter logWriter, java.lang.Throwable throwable, 
String reason, String sqlstate)
+  {
+    super (reason, sqlstate, -99999);
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, String reason, SqlState sqlState)
+  {
+    super (reason, sqlState.getState(), -99999);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only.
+  public SqlException (LogWriter logWriter, String reason, String sqlState)
+  {
+    super (reason, sqlState, -99999);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, String reason, SqlState sqlState, 
SqlCode errorCode)
+  {
+    super (reason, (sqlState == null) ? null : sqlState.getState(), 
errorCode.getCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only.
+  public SqlException (LogWriter logWriter, String reason, String sqlState, 
int errorCode)
+  {
+    super (reason, sqlState, errorCode);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlException (LogWriter logWriter, java.lang.Throwable throwable, 
String reason, SqlState sqlState, SqlCode errorCode)
+  {
+    super (reason, sqlState.getState(), errorCode.getCode());
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only.
+  public SqlException (LogWriter logWriter, java.lang.Throwable throwable, 
String reason, String sqlState, int errorCode)
+  {
+    super (reason, sqlState, errorCode);
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Label an exception element in a batched update exception chain.
+  // This text will be prepended onto the exceptions message text dynamically
+  // when getMessage() is called.
+  // Called by the Agent.
+  void setBatchPositionLabel (int index)
+  {
+    batchPositionLabel_ = "Error for batch element #" + index + ": ";
+  }
+
+  public Sqlca getSqlca ()
+  {
+    return sqlca_;
+  }
+
+  public java.lang.Throwable getThrowable ()
+  {
+    return throwable_;
+  }
+
+  public String getMessage ()
+  {
+    String message;
+
+    if (sqlca_ == null)
+      message = super.getMessage();
+    else
+      message = ((Sqlca) sqlca_).getJDBCMessage();
+
+    if (batchPositionLabel_ == null)
+      return message;
+
+    return batchPositionLabel_ + message;
+  }
+
+  public String getSQLState ()
+  {
+    if (sqlca_ == null)
+      return super.getSQLState();
+    else
+      return sqlca_.getSqlState();
+  }
+
+  public int getErrorCode ()
+  {
+    if (sqlca_ == null)
+      return super.getErrorCode();
+    else
+      return sqlca_.getSqlCode();
+  }
+
+  public void printTrace (java.io.PrintWriter printWriter, String header)
+  {
+    ExceptionFormatter.printTrace (this, printWriter, header);
+  }
+
+  // Return a single SQLException without the "next" pointing to another 
SQLException.
+  // Because the "next" is a private field in java.sql.SQLException,
+  // we have to create a new SqlException in order to break the chain with 
"next" as null.
+  SqlException copyAsUnchainedSQLException (LogWriter logWriter)
+  {
+    if (sqlca_ != null)
+      return new SqlException (logWriter, sqlca_); // server error
+    else
+      return new SqlException (logWriter, getMessage(), getSQLState(), 
getErrorCode()); // client error
+  }
+}
+
+// An intermediate exception encapsulation to provide code-reuse
+// for common ResultSet and ResultSetMetaData column access exceptions.
+class ColumnIndexOutOfBoundsException extends SqlException
+{
+  ColumnIndexOutOfBoundsException (LogWriter logWriter, Throwable throwable, 
int resultSetColumn)
+  {
+    super (logWriter, throwable,
+           "Invalid argument:" +
+           " Result column index " + resultSetColumn + " is out of range.");
+  }
+}
+
+// An intermediate exception encapsulation to provide code-reuse
+// for common ResultSet data conversion exceptions.
+class NumberFormatConversionException extends SqlException
+{
+  NumberFormatConversionException (LogWriter logWriter, String instance)
+  {
+    super (logWriter,
+            "Invalid data conversion:" +
+           " Result column instance " +
+           instance +
+           " is either an invalid numeric representation" +
+           " or is out of range.");
+  }
+}
+
+// An intermediate exception encapsulation to provide code-reuse
+// for common ResultSet data conversion exceptions.
+class ColumnTypeConversionException extends SqlException
+{
+  ColumnTypeConversionException (LogWriter logWriter)
+  {
+    super (logWriter,
+           "Invalid data conversion:" +
+           " Wrong result column type for requested conversion.");
+  }
+}
+
+// An intermediate exception encapsulation to provide code-reuse
+// for common CrossConverters data conversion exceptions.
+class LossOfPrecisionConversionException extends SqlException
+{
+  LossOfPrecisionConversionException (LogWriter logWriter, String instance)
+  {
+    super (logWriter,
+           "Invalid data conversion:" +
+           "Requested conversion would result in a loss of precision of " +
+           instance);
+  }
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java 
(added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java 
Thu Apr 28 12:05:42 2005
@@ -0,0 +1,58 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SqlState
+
+   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.am;
+
+// This class is for strong-typing.
+//
+// Unless otherwise architected by PROTOCOL, all client-side generated SQL 
States should be
+// Dnc architected codes in the range "46600" to "466ZZ".
+//
+// In general SQL states are architected by the product that issues them.
+// Therefore Dnc will not attempt to reuse pre-existing sql states 
+// Range for dnc architected sql codes is +/- 4400 to 4499.
+//
+public class SqlState
+{
+  private String state_;
+
+  private SqlState (String state) { state_ = state; }
+
+  String getState() { return state_; }
+
+  // The following codes are architected by PROTOCOL on page 331 of PROTOCOL 
V2 Volume 1.
+  // SQL States generated by Dnc should be Dnc-specific with the following 
specific exctpions.
+  //
+  public final static SqlState _08004 = new SqlState ("08004");
+  public final static SqlState _58009 = new SqlState ("58009");
+  public final static SqlState _58010 = new SqlState ("58010");
+  public final static SqlState _58014 = new SqlState ("58014");
+  public final static SqlState _58015 = new SqlState ("58015");
+  public final static SqlState _58016 = new SqlState ("58016");
+  public final static SqlState _58017 = new SqlState ("58017");
+  public final static SqlState _24501 = new SqlState ("24501");
+  public final static SqlState _58008 = new SqlState ("58008");
+  public final static SqlState _22021 = new SqlState ("22021");
+  public final static SqlState _2D521 = new SqlState ("2D521");
+
+  // Dnc-archited sql states follow
+  //
+  public final static SqlState undefined = new SqlState (null);
+}

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
 (added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
 Thu Apr 28 12:05:42 2005
@@ -0,0 +1,157 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SqlWarning
+
+   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.am;
+
+import org.apache.derby.client.resources.ResourceKeys;
+
+// Not yet done:
+//   Assign an ErrorKey, ResourceKey, and Resource for each throw statement.
+//   Save for future pass to avoid maintenance during development.
+
+// Until the "Error Cycle" pass is complete.
+// Use the temporary constructors at the bottom.
+public class SqlWarning extends java.sql.SQLWarning implements Diagnosable
+{
+  private java.lang.Throwable throwable_ = null;
+  protected Sqlca sqlca_ = null; // for engine generated errors only
+
+  
//-----------------constructors-----------------------------------------------
+
+  public SqlWarning (LogWriter logWriter, ErrorKey errorKey)
+  {
+    super (ResourceUtilities.getResource 
(ResourceKeys.driverOriginationIndicator) +
+           ResourceUtilities.getResource (errorKey.getResourceKey()),
+           errorKey.getSQLState(),
+           errorKey.getErrorCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  public SqlWarning (LogWriter logWriter, ErrorKey errorKey, Object[] args)
+  {
+    super (ResourceUtilities.getResource 
(ResourceKeys.driverOriginationIndicator) +
+           ResourceUtilities.getResource (errorKey.getResourceKey(), args),
+           errorKey.getSQLState(),
+           errorKey.getErrorCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  public SqlWarning (LogWriter logWriter, ErrorKey errorKey, Object arg)
+  {
+    this (logWriter, errorKey, new Object[] {arg});
+  }
+
+  public SqlWarning (LogWriter logWriter, Sqlca sqlca)
+  {
+    super ();
+    sqlca_ = sqlca;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlWarning (LogWriter logWriter)
+  {
+    super ();
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlWarning (LogWriter logWriter, String text)
+  {
+    super (text);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+    // Temporary constructor until all error keys are defined.
+  public SqlWarning (LogWriter logWriter, java.lang.Throwable throwable, 
String text)
+  {
+    super (text);
+    throwable_ = throwable;
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlWarning (LogWriter logWriter, String text, SqlState sqlState)
+  {
+    super (text, sqlState.getState());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only
+  public SqlWarning (LogWriter logWriter, String text, String sqlState)
+  {
+    super (text, sqlState);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined.
+  public SqlWarning (LogWriter logWriter, String text, SqlState sqlState, 
SqlCode errorCode)
+  {
+    super (text, sqlState.getState(), errorCode.getCode());
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  // Temporary constructor until all error keys are defined, for subsystem use 
only.
+  public SqlWarning (LogWriter logWriter, String text, String sqlState, int 
errorCode)
+  {
+    super (text, sqlState, errorCode);
+    if (logWriter != null) logWriter.traceDiagnosable (this);
+  }
+
+  public java.lang.Throwable getThrowable ()
+  {
+    return throwable_;
+  }
+
+  public Sqlca getSqlca ()
+  {
+    return sqlca_;
+  }
+
+  public String getMessage ()
+  {
+    if (sqlca_ == null)
+      return super.getMessage();
+    else
+      return ((Sqlca) sqlca_).getJDBCMessage();
+  }
+
+  public String getSQLState ()
+  {
+    if (sqlca_ == null)
+      return super.getSQLState();
+    else
+      return sqlca_.getSqlState();
+  }
+
+  public int getErrorCode ()
+  {
+    if (sqlca_ == null)
+      return super.getErrorCode();
+    else
+      return sqlca_.getSqlCode();
+  }
+
+  public void printTrace (java.io.PrintWriter printWriter, String header)
+  {
+    ExceptionFormatter.printTrace (this, printWriter, header);
+  }
+}
+

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: 
http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=165178&view=auto
==============================================================================
--- 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java 
(added)
+++ 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java 
Thu Apr 28 12:05:42 2005
@@ -0,0 +1,427 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.Sqlca
+
+   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.am;
+
+public abstract class Sqlca
+{
+  transient protected Connection connection_;
+  java.sql.SQLException exceptionThrownOnStoredProcInvocation_;
+  boolean messageTextRetrievedContainsTokensOnly_ = true;
+
+  // data corresponding to SQLCA fields
+  protected int      sqlCode_;        // SQLCODE
+  private String     sqlErrmc_;       // A string with all error tokens 
delimited by sqlErrmcDelimiter
+  protected String[] sqlErrmcTokens_; // A string array with each element
+  // contain an error token
+  protected String   sqlErrp_;        // function name issuing error
+  protected int[]    sqlErrd_;        // 6 diagnostic Information
+  protected char[]   sqlWarn_;        // 11 warning Flags
+  protected String   sqlState_;       // SQLSTATE
+
+  // raw sqlca data fields before unicode conversion
+  protected byte[] sqlErrmcBytes_;
+  protected byte[] sqlErrpBytes_;
+  protected byte[] sqlWarnBytes_;
+  protected byte[] sqlStateBytes_;
+
+  protected int ccsid_;
+  protected int sqlErrmcCcsid_;
+  protected boolean containsSqlcax_ = true;
+  protected long rowsetRowCount_;
+
+  //public static final String sqlErrmcDelimiter = "\u00FF";
+  private static final String sqlErrmcDelimiter__ = ";";
+
+  // JDK stack trace calls e.getMessage(), so we must set some state on the 
sqlca that says return tokens only.
+  private boolean returnTokensOnlyInMessageText_ = false;
+
+  transient private final Agent agent_;
+
+  private String cachedMessage;
+
+  protected Sqlca (org.apache.derby.client.am.Connection connection)
+  {
+    connection_ = connection;
+    agent_ = connection_ != null ? connection_.agent_ : null;
+  }
+
+  void returnTokensOnlyInMessageText (boolean returnTokensOnlyInMessageText)
+  {
+    returnTokensOnlyInMessageText_ = returnTokensOnlyInMessageText;
+  }
+
+  synchronized public int getSqlCode ()
+  {
+    return sqlCode_;
+  }
+
+  synchronized public String getSqlErrmc()
+  {
+    if (sqlErrmc_ != null)
+      return sqlErrmc_;
+
+    // sqlErrmc string is dependent on sqlErrmcTokens array having been built
+    if (sqlErrmcTokens_ == null)
+      getSqlErrmcTokens();
+
+    // sqlErrmc will be build only if sqlErrmcTokens has been build.
+    // Otherwise, a null string will be returned.
+    if (sqlErrmcTokens_ == null)
+      return null;
+
+    // create 0-length String if no tokens
+    if (sqlErrmcTokens_.length == 0) {
+      sqlErrmc_ = "";
+      return sqlErrmc_;
+    }
+
+    // concatenate tokens with sqlErrmcDelimiter delimiters into one String
+    StringBuffer buffer = new StringBuffer();
+    int indx;
+    for (indx=0; indx < sqlErrmcTokens_.length-1; indx++) {
+      buffer.append (sqlErrmcTokens_[indx]);
+      buffer.append (sqlErrmcDelimiter__);
+    }
+    // add the last token
+    buffer.append (sqlErrmcTokens_[indx]);
+
+    // save as a string
+    sqlErrmc_ = buffer.toString();
+    return sqlErrmc_;
+  }
+
+  synchronized public String[] getSqlErrmcTokens ()
+  {
+    if (sqlErrmcTokens_ != null)
+      return sqlErrmcTokens_;
+
+    // processSqlErrmcTokens handles null sqlErrmcBytes_ case
+    sqlErrmcTokens_ = processSqlErrmcTokens (sqlErrmcBytes_);
+    return sqlErrmcTokens_;
+  }
+
+  synchronized public String getSqlErrp()
+  {
+    if (sqlErrp_ != null)
+      return sqlErrp_;
+
+    if (sqlErrpBytes_ == null)
+      return null;
+
+    try {
+      sqlErrp_ = bytes2String (sqlErrpBytes_,
+                               0,
+                               sqlErrpBytes_.length
+                               );
+      return sqlErrp_;
+    }
+    catch (java.io.UnsupportedEncodingException e) {
+      // leave sqlErrp as null.
+      return null;
+    }
+  }
+
+  public int[] getSqlErrd()
+  {
+    if (sqlErrd_ != null)
+      return sqlErrd_;
+
+    sqlErrd_ = new int[6]; // create an int array.
+    return sqlErrd_;
+  }
+
+  synchronized public char[] getSqlWarn()
+  {
+    if (sqlWarn_ != null)
+      return sqlWarn_;
+
+    try {
+      if (sqlWarnBytes_ == null)
+        sqlWarn_ = new char[] {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' 
', ' '}; // 11 blank.
+      else
+        sqlWarn_ = bytes2String (sqlWarnBytes_, 0, sqlWarnBytes_.length 
).toCharArray();
+      return sqlWarn_;
+    }
+    catch (java.io.UnsupportedEncodingException e) {
+      sqlWarn_ = new char[] {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
' '}; // 11 blank.
+      return sqlWarn_;
+    }
+  }
+
+  synchronized public String getSqlState()
+  {
+    if (sqlState_ != null)
+      return sqlState_;
+
+    if (sqlStateBytes_ == null)
+      return null;
+
+    try {
+      sqlState_ = bytes2String (sqlStateBytes_,
+                                0,
+                                sqlStateBytes_.length
+                                );
+      return sqlState_;
+    }
+    catch (java.io.UnsupportedEncodingException e) {
+      // leave sqlState as null.
+      return null;
+    }
+  }
+
+  // Gets the formatted message, can throw an exception.
+  synchronized public String getMessage () throws SqlException
+  {
+    // should this be traced to see if we are calling a stored proc?
+    if (cachedMessage != null) return cachedMessage;
+
+      if (connection_ == null || connection_.isClosedX() || 
returnTokensOnlyInMessageText_)
+        return getUnformattedMessage();
+
+    CallableStatement cs = null;
+    synchronized (connection_) {
+      try {
+      cs = connection_.prepareMessageProc ("call 
SYSIBM.SQLCAMESSAGE(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+
+      // SQLCode: SQL return code.
+        cs.setIntX (1, getSqlCode());
+      // SQLErrml: Length of SQL error message tokens.
+        cs.setShortX (2, (short) ((getSqlErrmc() != 
null)?getSqlErrmc().length():0));
+      // SQLErrmc: SQL error message tokens as a String (delimited by 
semicolon ";").
+        cs.setStringX (3, getSqlErrmc());
+      // SQLErrp: Product signature.
+        cs.setStringX (4, getSqlErrp());
+      // SQLErrd: SQL internal error code.
+        cs.setIntX (5,  getSqlErrd()[0]);
+        cs.setIntX (6,  getSqlErrd()[1]);
+        cs.setIntX (7,  getSqlErrd()[2]);
+        cs.setIntX (8,  getSqlErrd()[3]);
+        cs.setIntX (9,  getSqlErrd()[4]);
+        cs.setIntX (10, getSqlErrd()[5]);
+      // SQLWarn: SQL warning flags.
+        cs.setStringX (11, new String (getSqlWarn()));
+      // SQLState: standard SQL state.
+        cs.setStringX (12, getSqlState());
+      // MessageFileName: Not used by our driver, so set to null.
+        cs.setStringX (13, null);
+      // Locale: language preference requested for the return error message.
+        cs.setStringX (14, java.util.Locale.getDefault().toString());
+        // server could return a locale different from what we requested
+        cs.registerOutParameterX (14, java.sql.Types.VARCHAR);
+      // Message: error message returned from SQLCAMessage stored procedure.
+        cs.registerOutParameterX (15, java.sql.Types.LONGVARCHAR);
+      // RCode: return code from SQLCAMessage stored procedure.
+        cs.registerOutParameterX (16, java.sql.Types.INTEGER);
+        cs.executeX();
+
+        if (cs.getIntX(16) == 0) {
+          // Return the message text.
+          messageTextRetrievedContainsTokensOnly_ = false;
+          String message = cs.getStringX (15);
+          cachedMessage = message;
+          return message;
+        } else {
+          // Stored procedure can't return a valid message text, so we return
+                 // unformated exception
+          return getUnformattedMessage();
+        }
+    }
+    finally {
+        if (cs != null) try { cs.closeX(); } catch (java.sql.SQLException 
doNothing) {}
+      }
+    }
+  }
+
+  // May or may not get the formatted message depending upon datasource 
directives.  cannot throw exeption.
+  public synchronized String getJDBCMessage ()
+  {
+    // The transient connection_ member will only be null if the Sqlca has 
been deserialized
+    if (connection_ != null && connection_.retrieveMessageText_) {
+      try {
+        return getMessage();
+      }
+      catch (SqlException e) { 
+        // Invocation of stored procedure fails, so we return error message 
tokens directly.
+        exceptionThrownOnStoredProcInvocation_ = e;
+        chainDeferredExceptionsToAgentOrAsConnectionWarnings ((SqlException) 
e);
+        return getUnformattedMessage ();
+      }
+    }
+    else
+      return getUnformattedMessage ();
+  }
+
+  private String getUnformattedMessage ()
+  { return "DERBY SQL error: SQLCODE: " + getSqlCode() + ", SQLSTATE: " + 
getSqlState() + ", SQLERRMC: " + getSqlErrmc(); }
+
+  private void chainDeferredExceptionsToAgentOrAsConnectionWarnings 
(SqlException e)
+  {
+    SqlException current = e;
+    while (current != null) {
+      SqlException next = (SqlException) current.getNextException();
+      current = current.copyAsUnchainedSQLException (agent_.logWriter_);
+      if (current.getErrorCode() == -440) {
+        SqlWarning warningForStoredProcFailure = new SqlWarning 
(agent_.logWriter_,
+          " Unable to obtain message text from server." +
+          " See chained exception." +
+          " The stored procedure SYSIBM.SQLCAMESSAGE is not installed on 
server." +
+          " Contact your DBA.");
+        warningForStoredProcFailure.setNextException (current);
+        connection_.accumulate440WarningForMessageProcFailure 
(warningForStoredProcFailure);
+      }
+      else if (current.getErrorCode() == -444) {
+        SqlWarning warningForStoredProcFailure = new SqlWarning 
(agent_.logWriter_,
+          " Unable to obtain message text from server." +
+          " See chained exception." +
+          " The stored procedure SYSIBM.SQLCAMESSAGE cannot be accessed on the 
server." +
+          " Contact your DBA.");
+        warningForStoredProcFailure.setNextException (current);
+        connection_.accumulate444WarningForMessageProcFailure 
(warningForStoredProcFailure);
+      }
+      else {
+        agent_.accumulateDeferredException (current);
+      }
+      current = next;
+    }
+  }
+
+  public boolean includesSqlCode (int[] codes)
+  {
+    for (int i=0; i<codes.length; i++) {
+      if (codes[i] == getSqlCode()) return true;
+    }
+    return false;
+  }
+  // ------------------- helper methods 
----------------------------------------
+
+  private String[] processSqlErrmcTokens (byte[] tokenBytes)
+  {
+    if (tokenBytes == null)
+      return null;
+
+    // create 0-length String tokens array if tokenBytes is 0-length
+    int length = tokenBytes.length;
+    if (length == 0)
+      return new String[0];
+
+    try {
+      // tokenize and convert tokenBytes
+      java.io.ByteArrayOutputStream buffer = new 
java.io.ByteArrayOutputStream();
+      java.util.LinkedList tokens = new java.util.LinkedList();
+
+      // parse the error message tokens
+      for (int index=0; index<length-1; index++) {
+
+       // non-delimiter - continue to write into buffer
+       if (tokenBytes[index] != -1)  // -1 is the delimiter '\xFF'
+         buffer.write (tokenBytes[index]);
+
+       // delimiter - convert current token and add to list
+       else {
+         tokens.add (bytes2String (buffer.toByteArray(), 0, buffer.size()));
+         buffer.reset();
+       }
+      }
+
+      int lastIndex = length-1;
+      // check for last byte not being a delimiter, i.e. part of last token
+      if (tokenBytes[lastIndex] != -1) {
+       // write the last byte
+       buffer.write (tokenBytes[lastIndex]);
+       // convert the last token and add to list
+       tokens.add (bytes2String (buffer.toByteArray(), 0, buffer.size()));
+      }
+
+      // last byte is delimiter implying an empty String for last token
+      else {
+       // convert current token, if one exists, and add to list
+       if (lastIndex != 0)
+         tokens.add (bytes2String (buffer.toByteArray(), 0, buffer.size()));
+       // last token is an empty String
+       tokens.add ("");
+      }
+
+      // create the String array and fill it with tokens.
+      String[] tokenStrings = new String[tokens.size()];
+
+      java.util.Iterator iterator = tokens.iterator();
+      for (int i = 0; iterator.hasNext(); i++)
+       tokenStrings[i] = (String) iterator.next();
+
+      return tokenStrings;
+    }
+    catch (java.io.UnsupportedEncodingException e) {
+      return null;
+    }
+  }
+
+  private String bytes2String (byte[] bytes, int offset, int length )
+    throws java.io.UnsupportedEncodingException
+  {
+      return new String (bytes, offset, length);
+  }
+
+  public int getUpdateCount ()
+  {
+    if (sqlErrd_ == null)
+      return 0;
+    return sqlErrd_[2];
+  }
+
+  public long getRowCount () throws 
org.apache.derby.client.am.DisconnectException
+  {
+    return ((long)sqlErrd_[0]<<32) + sqlErrd_[1];
+  }
+
+  public void setContainsSqlcax (boolean containsSqlcax)
+  {
+    containsSqlcax_ = containsSqlcax;
+  }
+
+  public boolean containsSqlcax ()
+  {
+    return containsSqlcax_;
+  }
+
+  public void resetRowsetSqlca (org.apache.derby.client.am.Connection 
connection,
+                                int sqlCode,
+                                byte[] sqlStateBytes,
+                                byte[] sqlErrpBytes,
+                                int ccsid)
+  {
+    connection_ = connection;
+    sqlCode_ = sqlCode;
+    sqlStateBytes_ = sqlStateBytes;
+    sqlErrpBytes_ = sqlErrpBytes;
+    ccsid_ = ccsid;
+  }
+
+  public void setRowsetRowCount (long rowCount)
+  {
+    rowsetRowCount_ = rowCount;
+  }
+
+  public long getRowsetRowCount ()
+  {
+    return rowsetRowCount_;
+  }
+}
+

Propchange: 
incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to