empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1241002 - /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
Date Mon, 06 Feb 2012 12:56:15 GMT
Author: doebele
Date: Mon Feb  6 12:56:15 2012
New Revision: 1241002

URL: http://svn.apache.org/viewvc?rev=1241002&view=rev
Log:
EMPIREDB-130
fixed according to description.

Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1241002&r1=1241001&r2=1241002&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
Mon Feb  6 12:56:15 2012
@@ -405,53 +405,66 @@ public abstract class DBDatabaseDriver i
         for (int i=0; i<sqlParams.length; i++)
         {
             Object value = sqlParams[i];
-            if (value instanceof DBBlobData)
-            {
-                // handling for blobs
-                DBBlobData blobData = (DBBlobData)value;
-                pstmt.setBinaryStream(i + 1, blobData.getInputStream(), blobData.getLength());
-                // log
-                if (log.isDebugEnabled())
-                    log.debug("Statement param {} set to BLOB data", i+1);
-            }
-            else if(value instanceof DBClobData)
-            {
-                // handling for clobs
-                DBClobData clobData = (DBClobData)value;
-                pstmt.setCharacterStream(i + 1, clobData.getReader(), clobData.getLength());
-                // log
-                if (log.isDebugEnabled())
-                    log.debug("Statement param {} set to CLOB data", i+1);
-            }
-            else if(value instanceof Character)
-            {
-                // handling for dates
-                String strval = value.toString();
-                pstmt.setObject(i + 1, strval);
-                // log
-                if (log.isDebugEnabled())
-                    log.debug("Statement param {} set to '{}'", i+1, strval);
-            }
-            else if(value instanceof Date && !(value instanceof Timestamp))
-            {
-                // handling for dates
-                Timestamp ts = new Timestamp(((Date)value).getTime());
-                pstmt.setObject(i + 1, ts);
-                // log
-                if (log.isDebugEnabled())
-                    log.debug("Statement param {} set to date '{}'", i+1, ts);
-            }
-            else
-            {   // simple parameter value 
-                pstmt.setObject(i + 1, value);
-                // log
-                if (log.isDebugEnabled())
-                    log.debug("Statement param {} set to '{}'", i+1, value);
-            }
+            addStatementParam(pstmt, i+1, value);
         }
 	}
 
     /**
+     * Adds a statement parameter to a prepared statement
+     * 
+     * @param pstmt the prepared statement
+     * @param sqlParams list of objects
+     */
+    protected void addStatementParam(PreparedStatement pstmt, int paramIndex, Object value)
+		throws SQLException
+	{
+        if (value instanceof DBBlobData)
+        {
+            // handling for blobs
+            DBBlobData blobData = (DBBlobData)value;
+            pstmt.setBinaryStream(paramIndex, blobData.getInputStream(), blobData.getLength());
+            // log
+            if (log.isDebugEnabled())
+                log.debug("Statement param {} set to BLOB data", paramIndex);
+        }
+        else if(value instanceof DBClobData)
+        {
+            // handling for clobs
+            DBClobData clobData = (DBClobData)value;
+            pstmt.setCharacterStream(paramIndex, clobData.getReader(), clobData.getLength());
+            // log
+            if (log.isDebugEnabled())
+                log.debug("Statement param {} set to CLOB data", paramIndex);
+        }
+        else if(value instanceof Date && !(value instanceof Timestamp))
+        {
+            // handling for dates
+            Timestamp ts = new Timestamp(((Date)value).getTime());
+            pstmt.setObject(paramIndex, ts);
+            // log
+            if (log.isDebugEnabled())
+                log.debug("Statement param {} set to date '{}'", paramIndex, ts);
+        }
+        else if((value instanceof Character) 
+        	 || (value instanceof Enum<?>))
+        {
+            // Objects that need String conversion
+            String strval = value.toString();
+            pstmt.setObject(paramIndex, strval);
+            // log
+            if (log.isDebugEnabled())
+                log.debug("Statement param {} set to '{}'", paramIndex, strval);
+        }
+        else
+        {   // simple parameter value 
+            pstmt.setObject(paramIndex, value);
+            // log
+            if (log.isDebugEnabled())
+                log.debug("Statement param {} set to '{}'", paramIndex, value);
+        }
+	}
+    
+    /**
      * Extracts native error message of an sqlExeption.
      * 
      * @param e the SQLException



Mime
View raw message