db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r631515 - in /db/derby/code/trunk/java/client/org/apache/derby/client/am: PreparedStatement.java Statement.java
Date Wed, 27 Feb 2008 08:45:00 GMT
Author: kristwaa
Date: Wed Feb 27 00:44:57 2008
New Revision: 631515

URL: http://svn.apache.org/viewvc?rev=631515&view=rev
Log:
DERBY-3441: Minor am.Statement and am.PreparedStatement refactorings.
Used Arrays.fill where appropriate, and removed some unnecessary throws clauses.
Patch file: derby-3441-2a-minor_am_refactoring.diff

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=631515&r1=631514&r2=631515&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Wed
Feb 27 00:44:57 2008
@@ -99,10 +99,7 @@
     protected void initResetPreparedStatement() {
         outputRegistered_ = false;
         isPreparedStatement_ = true;
-
-        if (parameterMetaData_ != null) {
-            resetParameters();
-        }
+        resetParameters();
     }
 
     public void reset(boolean fullReset) throws SqlException {
@@ -115,10 +112,10 @@
     }
 
     private void resetParameters() {
-        for (int i = 0; i < parameterMetaData_.columns_; i++) {
-            parameters_[i] = null;
-            parameterSet_[i] = false;
-            parameterRegistered_[i] = false;
+        if (parameterMetaData_ != null) {
+            Arrays.fill(parameters_, null);
+            Arrays.fill(parameterSet_, false);
+            Arrays.fill(parameterRegistered_, false);
         }
     }
 
@@ -1537,13 +1534,8 @@
                 }
                 checkForClosedStatement();
                 if (parameterMetaData_ != null) {
-                    for (int i = 0; i < parameters_.length; i++) {
-                        parameters_[i] = null;
-                    }
-
-                    for (int i = 0; i < parameterSet_.length; i++) {
-                        parameterSet_[i] = false;
-                    }
+                    Arrays.fill(parameters_, null);
+                    Arrays.fill(parameterSet_, false);
                 }
             }
         }
@@ -1835,9 +1827,8 @@
         // If CALLs are not describable then nothing gets clobbered because we won't
         // parse out extended describe, so again  no problem.
         if (sqlMode_ != isCall__ && parameterMetaData_ != null) {
-            for (int i = 0; i < parameterMetaData_.columns_; i++) {
-                parameterMetaData_.sqlxParmmode_[i] = 1;  // 1 means IN parameter
-            }
+            // 1 means IN parameter
+            Arrays.fill(parameterMetaData_.sqlxParmmode_, (short)1);
         }
 
         if (agent_.loggingEnabled()) {
@@ -2513,9 +2504,7 @@
         // Apparently, the JVM is not smart enough to traverse parameters_[] and null
         // out its members when the entire array is set to null (parameters_=null;).
         if (parameters_ != null) {
-            for (int i = 0; i < parameters_.length; i++) {
-                parameters_[i] = null;
-            }
+            Arrays.fill(parameters_, null);
         }
         parameters_ = null;
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=631515&r1=631514&r2=631515&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Wed Feb 27 00:44:57
2008
@@ -21,6 +21,7 @@
 package org.apache.derby.client.am;
 
 import java.sql.SQLException;
+import java.util.Arrays;
 
 import org.apache.derby.shared.common.reference.JDBC30Translation;
 import org.apache.derby.shared.common.reference.SQLState;
@@ -156,7 +157,7 @@
     // This collection is used for two different purposes:
     //   For statement batching it contains the batched SQL strings.
     //   For prepared statement batching it contains the batched input rows.
-    java.util.ArrayList batch_ = new java.util.ArrayList();
+    final java.util.ArrayList batch_ = new java.util.ArrayList();
 
 
     // Scrollable cursor attributes
@@ -200,15 +201,15 @@
 
     //---------------------constructors/finalizer/accessors--------------------
 
-    private Statement() throws SqlException {
+    private Statement() {
         initStatement();
     }
 
-    private void resetStatement() throws SqlException {
+    private void resetStatement() {
         initStatement();
     }
 
-    private void initStatement() throws SqlException {
+    private void initStatement() {
         materialStatement_ = null;
         connection_ = null;
         agent_ = null;
@@ -223,7 +224,7 @@
         initResetStatement();
     }
 
-    private void initResetStatement() throws SqlException {
+    private void initResetStatement() {
         initResetPreparedStatement();
 
         //section_ = null; // don't set section to null because write piggyback command require
a section
@@ -258,11 +259,7 @@
         isCatalogQuery_ = false;
         isAutoCommittableStatement_ = true;
 
-        if (batch_ == null) {
-            batch_ = new java.util.ArrayList();
-        } else {
-            batch_.clear();
-        }
+        batch_.clear();
         fetchSize_ = 0;
         fetchDirection_ = java.sql.ResultSet.FETCH_FORWARD;
         singletonRowData_ = null;
@@ -1074,9 +1071,7 @@
         // This is done to account for "chain-breaking" errors where we cannot
         // read any more replies
         int[] updateCounts = new int[batch_.size()];
-        for (int i = 0; i < batch_.size(); i++) {
-            updateCounts[i] = -3;
-        }
+        Arrays.fill(updateCounts, -3);
         flowExecuteBatch(updateCounts);
         return updateCounts;
     }



Mime
View raw message