You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2007/05/11 18:07:22 UTC
svn commit: r537218 - in
/db/derby/code/trunk/java/client/org/apache/derby/client:
am/CallableLocatorProcedures.java am/Connection.java net/NetConnection40.java
Author: rhillegas
Date: Fri May 11 09:07:21 2007
New Revision: 537218
URL: http://svn.apache.org/viewvc?view=rev&rev=537218
Log:
DERBY-2587: Commit Narayanan's ConnectionLocatorWork_v3.diff patch, adding support for Clob locators.
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java?view=diff&rev=537218&r1=537217&r2=537218
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java Fri May 11 09:07:21 2007
@@ -21,6 +21,9 @@
package org.apache.derby.client.am;
+import org.apache.derby.shared.common.error.ExceptionUtil;
+import org.apache.derby.shared.common.reference.SQLState;
+
/**
* Contains the necessary methods to call the stored procedure that
* operate on LOBs identified by locators. An instance of this class
@@ -43,6 +46,11 @@
*/
class CallableLocatorProcedures
{
+ //caches the information from a Stored Procedure
+ //call as to whether locator support is available in
+ //the server or not.
+ boolean isLocatorSupportAvailable = true;
+
// One member variable for each stored procedure that can be called.
// Used to be able to only prepare each procedure call once per connection.
private CallableStatement blobCreateLocatorCall;
@@ -72,6 +80,8 @@
*/
private static final int VARCHAR_MAXWIDTH = 32672;
+ //Constant representing an invalid locator value
+ private static final int INVALID_LOCATOR = -1;
/**
* Create an instance to be used for calling locator-based stored
@@ -94,6 +104,14 @@
*/
int blobCreateLocator() throws SqlException
{
+ //The information on whether the locator support
+ //is available is cached in the boolean
+ //isLocatorSupportAvailable. If this is false
+ //we can return -1
+ if (!isLocatorSupportAvailable) {
+ return INVALID_LOCATOR;
+ }
+
if (blobCreateLocatorCall == null) {
blobCreateLocatorCall = connection.prepareCallX
("? = CALL SYSIBM.BLOBCREATELOCATOR()",
@@ -105,8 +123,37 @@
// Make sure this statement does not commit user transaction
blobCreateLocatorCall.isAutoCommittableStatement_ = false;
}
-
- blobCreateLocatorCall.executeX();
+
+ try {
+ blobCreateLocatorCall.executeX();
+ }
+ catch(SqlException sqle) {
+ //An exception has occurred while calling the stored procedure
+ //used to create the locator value.
+
+ //We verify to see if this SqlException has a SQLState of
+ //42Y03(SQLState.LANG_NO_SUCH_METHOD_ALIAS)
+ //(corresponding to the stored procedure not being found)
+
+ //This means that locator support is not available.
+
+ //This information is cached so that each time to determine
+ //if locator support is available we do not have to make a
+ //round trip to the server.
+ if (sqle.getSQLState().compareTo
+ (ExceptionUtil.getSQLStateFromIdentifier
+ (SQLState.LANG_NO_SUCH_METHOD_ALIAS)) == 0) {
+ isLocatorSupportAvailable = false;
+ return INVALID_LOCATOR;
+ }
+ else {
+ //The SqlException has not occurred because of the
+ //stored procedure not being found. Hence we simply throw
+ //it back.
+ throw sqle;
+ }
+ }
+
return blobCreateLocatorCall.getIntX(1);
}
@@ -500,6 +547,14 @@
*/
int clobCreateLocator() throws SqlException
{
+ //The information on whether the locator support
+ //is available is cached in the boolean
+ //isLocatorSupportAvailable. If this is false
+ //we can return -1
+ if (!isLocatorSupportAvailable) {
+ return INVALID_LOCATOR;
+ }
+
if (clobCreateLocatorCall == null) {
clobCreateLocatorCall = connection.prepareCallX
("? = CALL SYSIBM.CLOBCREATELOCATOR()",
@@ -512,7 +567,36 @@
clobCreateLocatorCall.isAutoCommittableStatement_ = false;
}
- clobCreateLocatorCall.executeX();
+ try {
+ clobCreateLocatorCall.executeX();
+ }
+ catch(SqlException sqle) {
+ //An exception has occurred while calling the stored procedure
+ //used to create the locator value.
+
+ //We verify to see if this SqlException has a SQLState of
+ //42Y03(SQLState.LANG_NO_SUCH_METHOD_ALIAS)
+ //(corresponding to the stored procedure not being found)
+
+ //This means that locator support is not available.
+
+ //This information is cached so that each time to determine
+ //if locator support is available we do not have to make a
+ //round trip to the server.
+ if (sqle.getSQLState().compareTo
+ (ExceptionUtil.getSQLStateFromIdentifier
+ (SQLState.LANG_NO_SUCH_METHOD_ALIAS)) == 0) {
+ isLocatorSupportAvailable = false;
+ return INVALID_LOCATOR;
+ }
+ else {
+ //The SqlException has not occurred because of the
+ //stored procedure not being found. Hence we simply throw
+ //it back.
+ throw sqle;
+ }
+ }
+
return clobCreateLocatorCall.getIntX(1);
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?view=diff&rev=537218&r1=537217&r2=537218
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Fri May 11 09:07:21 2007
@@ -54,6 +54,9 @@
// If they depend on both commit and rollback, they need to get on CommitAndRollbackListeners_.
final java.util.WeakHashMap CommitAndRollbackListeners_ = new java.util.WeakHashMap();
private SqlWarning warnings_ = null;
+
+ //Constant representing an invalid locator value
+ private static final int INVALID_LOCATOR = -1;
// ------------------------properties set for life of connection--------------
@@ -2136,5 +2139,97 @@
return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;
return holdability;
}
+
+
+ /**
+ * Constructs an object that implements the <code>Clob</code> interface.
+ * The object returned initially contains no data.
+ *
+ * @return An object that implements the <clob>Clob</clob> interface
+ * @throws java.sql.SQLException if an object that implements the
+ * <code>Clob</code> interface can not be constructed.
+ */
+
+ public Clob createClob() throws SQLException {
+ if (agent_.loggingEnabled()) {
+ agent_.logWriter_.traceEntry(this, "createClob");
+ }
+
+ try {
+ checkForClosedConnection();
+ } catch (SqlException se) {
+ throw se.getSQLException();
+ }
+ org.apache.derby.client.am.Clob clob = new
+ org.apache.derby.client.am.Clob(this.agent_,"");
+
+ if (agent_.loggingEnabled()) {
+ agent_.logWriter_.traceExit(this, "createClob", clob);
+ }
+
+ return clob;
+ }
+
+ /**
+ * Constructs an object that implements the <code>Blob</code> interface.
+ * The object returned initially contains no data.
+ *
+ * @return An object that implements the <code>Blob</code> interface
+ * @throws SQLException if an object that implements the
+ * </code>Blob</code> interface can not be constructed.
+ *
+ */
+
+ public Blob createBlob() throws SQLException {
+ if (agent_.loggingEnabled()) {
+ agent_.logWriter_.traceEntry(this, "createBlob");
+ }
+
+ try {
+ checkForClosedConnection();
+ } catch (SqlException se) {
+ throw se.getSQLException();
+ }
+
+ //Stores a locator value obtained by calling the
+ //stored procedure BLOBCREATELOCATOR.
+ int locator = INVALID_LOCATOR;
+
+ //Stores the Blob instance that is returned.
+ org.apache.derby.client.am.Blob blob = null;
+
+ //Call the BLOBCREATELOCATOR stored procedure
+ //that will return a locator value.
+ try {
+ locator = locatorProcedureCall().blobCreateLocator();
+ }
+ catch(SqlException sqle) {
+ throw sqle.getSQLException();
+ }
+
+ //If the locator value is -1 it means that we do not
+ //have locator support on the server.
+
+ //The code here has been disabled because the Lob implementations
+ //have still not been completely converted to use locators. Once
+ //the Lob implementations are completed then this code can be enabled.
+ if (locator != INVALID_LOCATOR && false) {
+ //A valid locator value has been obtained.
+ blob = new org.apache.derby.client.am.Blob(this.agent_, locator);
+ }
+ else {
+ //A valid locator value could not be obtained.
+ blob = new org.apache.derby.client.am.Blob
+ (new byte[0],this.agent_, 0);
+ }
+
+ if (agent_.loggingEnabled()) {
+ agent_.logWriter_.traceExit(this, "createBlob", blob);
+ }
+
+ return blob;
+ }
+
+
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?view=diff&rev=537218&r1=537217&r2=537218
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Fri May 11 09:07:21 2007
@@ -132,43 +132,6 @@
throw SQLExceptionFactory.notImplemented ("createArrayOf(String,Object[])");
}
- /**
- * Constructs an object that implements the Clob interface. The object
- * returned initially contains no data.
- * @return An object that implements the Clob interface
- * @throws SQLException if an object that implements the
- * Clob interface can not be constructed.
- *
- */
-
- public Clob createClob() throws SQLException {
- try {
- checkForClosedConnection();
- } catch (SqlException se) {
- throw se.getSQLException();
- }
- org.apache.derby.client.am.Clob clob = new org.apache.derby.client.am.Clob(this.agent_,"");
- return clob;
- }
-
- /**
- * Constructs an object that implements the Clob interface. The object
- * returned initially contains no data.
- * @return An object that implements the Clob interface
- * @throws SQLException if an object that implements the
- * Clob interface can not be constructed.
- *
- */
-
- public Blob createBlob() throws SQLException {
- try {
- checkForClosedConnection();
- } catch (SqlException se) {
- throw se.getSQLException();
- }
- org.apache.derby.client.am.Blob blob = new org.apache.derby.client.am.Blob(new byte[0],this.agent_, 0);
- return blob;
- }
public NClob createNClob() throws SQLException {
throw SQLExceptionFactory.notImplemented ("createNClob ()");