empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1072764 - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: ./ derby/ h2/ mysql/ oracle/ sqlserver/
Date Sun, 20 Feb 2011 22:05:51 GMT
Author: doebele
Date: Sun Feb 20 22:05:51 2011
New Revision: 1072764

URL: http://svn.apache.org/viewvc?rev=1072764&view=rev
Log:
EMPIREDB-81
corrections

Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
Sun Feb 20 22:05:51 2011
@@ -140,7 +140,7 @@ public abstract class DBCommand extends 
     protected List<DBColumnExpr>     groupBy        = null;
     // Parameters for prepared Statements
     protected Vector<DBCommandParam> cmdParams      = null;
-    protected int                    paramUsageCount= 0;
+    private int                      paramUsageCount= 0;
     // Database
     private DBDatabase               db;
 
@@ -158,7 +158,7 @@ public abstract class DBCommand extends 
      * internally used to reset the command param usage count.
      * Note: Only one thread my generate an SQL statement 
      */
-    private void resetParamUsage()
+    protected void resetParamUsage()
     {
         paramUsageCount = 0;
     }
@@ -320,8 +320,12 @@ public abstract class DBCommand extends 
         }
     }
     
-    protected boolean useCmdParam(DBColumn col)
+    protected boolean useCmdParam(DBColumn col, Object value)
     {
+        // Cannot wrap DBExpr or DBSystemDate
+        if (value instanceof DBExpr || value instanceof DBDatabase.DBSystemDate)
+            return false;
+        // Check if prepared statements are enabled
         if (db.isPreparedStatementsEnabled())
             return true;
         // Only use a command param if column is of type BLOB or CLOB
@@ -343,8 +347,7 @@ public abstract class DBCommand extends 
             DBSetExpr chk = set.get(i);
             if (chk.column.equals(expr.column))
             { // Overwrite existing value
-                if (useCmdParam(expr.column) && (expr.value instanceof DBExpr) ==
false
-                    && chk.value instanceof DBCommandParam)
+                if (useCmdParam(expr.column, expr.value) && chk.value instanceof
DBCommandParam)
                 {   // replace parameter value
                     // int index = ((DBCommandParam) chk.value).index;
                     // this.setCmdParam(index, getCmdParamValue(expr.column, expr.value));
@@ -358,7 +361,7 @@ public abstract class DBCommand extends 
             }
         }
         // Replace with parameter 
-        if (useCmdParam(expr.column) && (expr.value instanceof DBExpr)==false)
+        if (useCmdParam(expr.column, expr.value))
             expr.value = addParam(expr.column.getDataType(), expr.value);
         // new Value!
         set.add(expr);

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=1072764&r1=1072763&r2=1072764&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
Sun Feb 20 22:05:51 2011
@@ -24,6 +24,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -208,7 +209,7 @@ public abstract class DBDatabaseDriver e
                         cmd.set(C_SEQNAME.to(SeqName));
                         cmd.set(C_SEQVALUE.to(seqValue));
                         cmd.set(C_TIMESTAMP.to(DBDatabase.SYSDATE));
-                        if (driver.executeSQL(cmd.getInsert(), null, conn, null) < 1)
+                        if (driver.executeSQL(cmd.getInsert(), cmd.getParamValues(), conn,
null) < 1)
                             seqValue = 0; // Try again
                     }
                     // check for concurrency problem
@@ -402,7 +403,7 @@ public abstract class DBDatabaseDriver e
                 pstmt.setBinaryStream(i + 1, blobData.getInputStream(), blobData.getLength());
                 // log
                 if (log.isDebugEnabled())
-                    log.debug("Statement param " + (i+1) + " set to BLOB data");
+                    log.debug("Statement param {} set to BLOB data", i+1);
             }
             else if(value instanceof DBClobData)
             {
@@ -411,14 +412,32 @@ public abstract class DBDatabaseDriver e
                 pstmt.setCharacterStream(i + 1, clobData.getReader(), clobData.getLength());
                 // log
                 if (log.isDebugEnabled())
-                    log.debug("Statement param " + (i+1) + " set to CLOB data");
+                    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 " + (i+1) + " set to '" + value + "'");
+                    log.debug("Statement param {} set to '{}'", i+1, value);
             }
         }
 	}

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
Sun Feb 20 22:05:51 2011
@@ -446,7 +446,7 @@ public class DBDatabaseDriverDerby exten
         sql.append(")");
         // Comment?
         String comment = t.getComment();
-        if (StringUtils.isValid(comment))
+        if (StringUtils.isNotEmpty(comment))
         {   // Add the table comment
             sql.append(" COMMENT = '");
             sql.append(comment);

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
Sun Feb 20 22:05:51 2011
@@ -451,7 +451,7 @@ public class DBDatabaseDriverH2 extends 
         sql.append(")");
         // Comment?
         String comment = t.getComment();
-        if (StringUtils.isValid(comment))
+        if (StringUtils.isNotEmpty(comment))
         {   // Add the table comment
             sql.append(" COMMENT = '");
             sql.append(comment);

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
Sun Feb 20 22:05:51 2011
@@ -213,7 +213,7 @@ public class DBDatabaseDriverMySQL exten
         // Prepare
         try
         {   // Set Database
-            if (StringUtils.isValid(databaseName))
+            if (StringUtils.isNotEmpty(databaseName))
                 executeSQL("USE " + databaseName, null, conn, null);
             // Sequence Table
             if (useSequenceTable && db.getTable(sequenceTableName)==null)
@@ -463,7 +463,7 @@ public class DBDatabaseDriverMySQL exten
         // User Master to create Database
         if (createSchema)
         {   // check database Name
-            if (StringUtils.isValid(databaseName)==false)
+            if (StringUtils.isEmpty(databaseName))
                 return error(Errors.InvalidProperty, "databaseName");
             // Create Database
             script.addStmt("CREATE DATABASE IF NOT EXISTS " + databaseName + " CHARACTER
SET " + characterSet);
@@ -540,14 +540,14 @@ public class DBDatabaseDriverMySQL exten
         }
         sql.append(")");
         // Engine
-        if (StringUtils.isValid(engine)) 
+        if (StringUtils.isNotEmpty(engine)) 
         {   // Set the table engine
             sql.append(" ENGINE = ");
             sql.append(engine);
         }
         // Comment?
         String comment = t.getComment();
-        if (StringUtils.isValid(comment))
+        if (StringUtils.isNotEmpty(comment))
         {   // Add the table comment
             sql.append(" COMMENT = '");
             sql.append(comment);

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
Sun Feb 20 22:05:51 2011
@@ -120,8 +120,9 @@ public class DBCommandOracle extends DBC
      * @return true if the creation was successful
      */
     @Override
-    public boolean getSelect(StringBuilder buf)
+    public synchronized boolean getSelect(StringBuilder buf)
     {
+        resetParamUsage();
         if (select == null)
             return error(Errors.ObjectNotValid, getClass().getName()); // invalid!
         // Prepares statement
@@ -173,8 +174,9 @@ public class DBCommandOracle extends DBC
      * @return the delete SQL-Command
      */
     @Override
-    public String getDelete(DBTable table)
+    public synchronized String getDelete(DBTable table)
     {
+        resetParamUsage();
         StringBuilder buf = new StringBuilder("DELETE ");
         if (optimizerHint != null)
         {   // Append an optimizer hint to the select statement e.g. SELECT /*+ RULE */

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java?rev=1072764&r1=1072763&r2=1072764&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
Sun Feb 20 22:05:51 2011
@@ -180,7 +180,7 @@ public class DBDatabaseDriverMSSQL exten
         // Prepare
         try
         {   // Set Database
-            if (StringUtils.isValid(databaseName))
+            if (StringUtils.isNotEmpty(databaseName))
                 executeSQL("USE " + databaseName, null, conn, null);
             // Set Dateformat
             executeSQL("SET DATEFORMAT ymd", null, conn, null);
@@ -189,7 +189,7 @@ public class DBDatabaseDriverMSSQL exten
                 new DBSeqTable(sequenceTableName, db);
             // Check Schema
             String schema = db.getSchema();
-            if (StringUtils.isValid(schema) && schema.indexOf('.')<0 &&
StringUtils.isValid(objectOwner))
+            if (StringUtils.isNotEmpty(schema) && schema.indexOf('.')<0 &&
StringUtils.isNotEmpty(objectOwner))
             {   // append database owner
                 db.setSchema(schema + "." + objectOwner);
             }
@@ -462,7 +462,7 @@ public class DBDatabaseDriverMSSQL exten
         // User Master to create Database
         if (createSchema)
         {   // check database Name
-            if (StringUtils.isValid(databaseName)==false)
+            if (StringUtils.isEmpty(databaseName))
                 return error(Errors.InvalidProperty, "databaseName");
             // Create Database
             script.addStmt("USE master");



Mime
View raw message