empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1244408 - in /empire-db/trunk: empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/ empire-db/src/main/java/org/apache/empire/db/ empire-db/src/test/java/org/apache/empire/db/
Date Wed, 15 Feb 2012 09:16:54 GMT
Author: doebele
Date: Wed Feb 15 09:16:53 2012
New Revision: 1244408

URL: http://svn.apache.org/viewvc?rev=1244408&view=rev
Log:
EMPIREDB-133

Added:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java   (with props)
Modified:
    empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java

Modified: empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java?rev=1244408&r1=1244407&r2=1244408&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
Wed Feb 15 09:16:53 2012
@@ -28,6 +28,7 @@ import org.apache.empire.commons.Options
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBCmdParam;
 import org.apache.empire.db.DBCmdType;
 import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBCommand;
@@ -37,7 +38,6 @@ import org.apache.empire.db.DBReader;
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.DBTableColumn;
-import org.apache.empire.db.DBCommand.DBCommandParam;
 import org.apache.empire.db.h2.DBDatabaseDriverH2;
 import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
 import org.slf4j.Logger;
@@ -375,8 +375,8 @@ public class SampleAdvApp 
         // create a command
         DBCommand cmd = db.createCommand();
         // Create cmd parameters
-        DBCommandParam curDepParam = cmd.addParam(); // Current Department
-        DBCommandParam genderParam = cmd.addParam(); // Gender ('M' or 'F')
+        DBCmdParam curDepParam = cmd.addParam(); // Current Department
+        DBCmdParam genderParam = cmd.addParam(); // Gender ('M' or 'F')
         // Define the query
         cmd.select(T_EMP.C_FULLNAME);
         cmd.join  (T_EMP.C_EMPLOYEE_ID, db.V_EMPLOYEE_INFO.C_EMPLOYEE_ID);

Added: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java?rev=1244408&view=auto
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java (added)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java Wed Feb 15
09:16:53 2012
@@ -0,0 +1,86 @@
+/*
+ * ESTEAM Software GmbH, 15.02.2012
+ */
+package org.apache.empire.db;
+
+import java.util.Set;
+
+import org.apache.empire.data.DataType;
+
+public class DBCmdParam extends DBExpr
+{
+    private final static long serialVersionUID = 1L;
+    protected DBCommand cmd;
+    protected DataType  type;
+    protected Object    value;
+    
+    protected DBCmdParam(DBCommand cmd, DataType type, Object value)
+    {
+        this.cmd = cmd;
+        this.type = type;
+        this.value = getCmdParamValue(value);
+    }
+    
+    protected Object getCmdParamValue(Object value)
+    {        
+        switch (type)
+        {
+            case BLOB:
+                if (value == null)
+                    return null;
+                if (value instanceof DBBlobData)
+                    return value;
+                if (value instanceof byte[])
+                    return new DBBlobData((byte[])value);
+                // create a blob data
+                return new DBBlobData(value.toString());
+            case CLOB:
+                if (value == null)
+                    return null;
+                if (value instanceof DBClobData)
+                    return value;
+                // create a clob data
+                return new DBClobData(value.toString());
+            default:
+                return value;
+        }
+    }
+    
+    @Override
+    public void addSQL(StringBuilder buf, long context)
+    {
+        buf.append("?"); //$NON-NLS-1$
+        // Move to current usage position
+        cmd.notifyParamUsage(this);
+    }
+    
+    /**
+     * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
+     */
+    @Override
+    public void addReferencedColumns(Set<DBColumn> list)
+    {
+        // Nothing to add
+    }
+    
+    @Override
+    public DBDatabase getDatabase()
+    {
+        return cmd.getDatabase();
+    }
+    
+    public DataType getDataType()
+    {
+        return type;
+    }
+    
+    public Object getValue()
+    {
+        return value;
+    }
+    
+    public void setValue(Object value)
+    {
+        this.value = getCmdParamValue(value);
+    }
+}

Propchange: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1244408&r1=1244407&r2=1244408&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java Wed Feb 15
09:16:53 2012
@@ -48,84 +48,6 @@ public abstract class DBCommand extends 
 {
     private final static long serialVersionUID = 1L;
 
-    public static final class DBCommandParam extends DBExpr
-    {
-        private final static long serialVersionUID = 1L;
-        protected DBCommand cmd;
-        protected DataType  type;
-        protected Object    value;
-        
-        protected DBCommandParam(DBCommand cmd, DataType type, Object value)
-        {
-            this.cmd = cmd;
-            this.type = type;
-            this.value = getCmdParamValue(value);
-        }
-        
-        protected Object getCmdParamValue(Object value)
-        {        
-            switch (type)
-            {
-                case BLOB:
-                    if (value == null)
-                        return null;
-                    if (value instanceof DBBlobData)
-                        return value;
-                    if (value instanceof byte[])
-                        return new DBBlobData((byte[])value);
-                    // create a blob data
-                    return new DBBlobData(value.toString());
-                case CLOB:
-                    if (value == null)
-                        return null;
-                    if (value instanceof DBClobData)
-                        return value;
-                    // create a clob data
-                    return new DBClobData(value.toString());
-                default:
-                    return value;
-            }
-        }
-        
-        @Override
-        public void addSQL(StringBuilder buf, long context)
-        {
-            buf.append("?"); //$NON-NLS-1$
-            // Move to current usage position
-            cmd.notifyParamUsage(this);
-        }
-        
-        /**
-         * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
-         */
-        @Override
-        public void addReferencedColumns(Set<DBColumn> list)
-        {
-            // Nothing to add
-        }
-        
-        @Override
-        public DBDatabase getDatabase()
-        {
-            return cmd.getDatabase();
-        }
-        
-        public DataType getDataType()
-        {
-        	return type;
-        }
-        
-        public Object getValue()
-        {
-            return value;
-        }
-        
-        public void setValue(Object value)
-        {
-            this.value = getCmdParamValue(value);
-        }
-    }
-
     // Logger
     protected static final Logger log = LoggerFactory.getLogger(DBCommand.class);
     // Distinct Select
@@ -138,7 +60,7 @@ public abstract class DBCommand extends 
     protected List<DBCompareExpr>    having         = null;
     protected List<DBColumnExpr>     groupBy        = null;
     // Parameters for prepared Statements
-    protected Vector<DBCommandParam> cmdParams      = null;
+    protected Vector<DBCmdParam> cmdParams      = null;
     private int                      paramUsageCount= 0;
     // Database
     private DBDatabase               db;
@@ -165,7 +87,7 @@ public abstract class DBCommand extends 
     /**
      * internally used to reorder the command params to match their order of occurance
      */
-    private synchronized void notifyParamUsage(DBCommandParam param)
+    protected synchronized void notifyParamUsage(DBCmdParam param)
     {
         int index = cmdParams.indexOf(param);
         if (index < paramUsageCount)
@@ -185,7 +107,7 @@ public abstract class DBCommand extends 
      */
    	private void removeCommandParam(DBCompareColExpr cmp) 
    	{
-        if (cmdParams!=null && (cmp.getValue() instanceof DBCommandParam))
+        if (cmdParams!=null && (cmp.getValue() instanceof DBCmdParam))
    			cmdParams.remove(cmp.getValue());
    	}
 
@@ -344,11 +266,11 @@ 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) && chk.value instanceof
DBCommandParam)
+                if (useCmdParam(expr.column, expr.value) && chk.value instanceof
DBCmdParam)
                 {   // replace parameter value
                     // int index = ((DBCommandParam) chk.value).index;
                     // this.setCmdParam(index, getCmdParamValue(expr.column, expr.value));
-                    ((DBCommandParam)chk.value).setValue(expr.value);
+                    ((DBCmdParam)chk.value).setValue(expr.value);
                 } 
                 else
                 { // replace value
@@ -392,12 +314,12 @@ public abstract class DBCommand extends 
      * 
      * @return the command parameter object 
      */
-    public DBCommandParam addParam(DataType type, Object value)
+    public DBCmdParam addParam(DataType type, Object value)
     {
         if (cmdParams==null)
-            cmdParams= new Vector<DBCommandParam>();
+            cmdParams= new Vector<DBCmdParam>();
         // Adds the parameter 
-        DBCommandParam param = new DBCommandParam(this, type, value);
+        DBCmdParam param = new DBCmdParam(this, type, value);
         if (cmdParams.add(param)==false)
             return null; // unknown error
         // Creates a Parameter expression
@@ -413,7 +335,7 @@ public abstract class DBCommand extends 
      * 
      * @return the command parameter object 
      */
-    public final DBCommandParam addParam(DBColumnExpr colExpr, Object value)
+    public final DBCmdParam addParam(DBColumnExpr colExpr, Object value)
     {
         return addParam(colExpr.getDataType(), value);
     }
@@ -424,7 +346,7 @@ public abstract class DBCommand extends 
      *  
      * @return the command parameter object
      */
-    public final DBCommandParam addParam(Object value)
+    public final DBCmdParam addParam(Object value)
     {
         return addParam(DataType.UNKNOWN, value);
     }
@@ -435,7 +357,7 @@ public abstract class DBCommand extends 
      *  
      * @return the command parameter object
      */
-    public final DBCommandParam addParam()
+    public final DBCmdParam addParam()
     {
         return addParam(DataType.UNKNOWN, null);
     }

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1244408&r1=1244407&r2=1244408&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Wed
Feb 15 09:16:53 2012
@@ -38,7 +38,7 @@ import org.apache.empire.commons.ObjectU
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
-import org.apache.empire.db.DBCommand.DBCommandParam;
+import org.apache.empire.db.DBCmdParam;
 import org.apache.empire.db.exceptions.InternalSQLException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
@@ -167,7 +167,7 @@ public abstract class DBDatabaseDriver i
             try
             {   // The select Statement
                 DBCommand cmd = driver.createCommand(db);
-                DBCommandParam nameParam = cmd.addParam(SeqName);
+                DBCmdParam nameParam = cmd.addParam(SeqName);
                 cmd.select(C_SEQVALUE);
                 cmd.select(C_TIMESTAMP);
                 cmd.where (C_SEQNAME.is(nameParam));
@@ -188,8 +188,8 @@ public abstract class DBDatabaseDriver i
                         db.closeResultSet(rs);
                         // Update existing Record
                         cmd.clear();
-                        DBCommandParam name = cmd.addParam(SeqName);
-                        DBCommandParam time = cmd.addParam(current);
+                        DBCmdParam name = cmd.addParam(SeqName);
+                        DBCmdParam time = cmd.addParam(current);
                         cmd.set(C_SEQVALUE.to(seqValue));
                         cmd.set(C_TIMESTAMP.to(DBDatabase.SYSDATE));
                         cmd.where(C_SEQNAME.is(name));

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java?rev=1244408&r1=1244407&r2=1244408&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java Wed Feb 15 09:16:53
2012
@@ -27,7 +27,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.DataType;
-import org.apache.empire.db.DBCommand.DBCommandParam;
+import org.apache.empire.db.DBCmdParam;
 import org.apache.empire.db.exceptions.InvalidKeyException;
 import org.apache.empire.db.exceptions.NoPrimaryKeyException;
 import org.apache.empire.db.exceptions.QueryNoResultException;
@@ -468,11 +468,11 @@ public class DBQuery extends DBRowSet
                     DBColumn col = cmpExpr.getColumnExpr().getUpdateColumn();
                     if (col!=null && col.getRowSet() == table)
                     {	// add the constraint
-                    	if (cmpExpr.getValue() instanceof DBCommandParam)
+                    	if (cmpExpr.getValue() instanceof DBCmdParam)
                     	{	// Create a new command param
                     		DBColumnExpr colExpr = cmpExpr.getColumnExpr();
-                    		DBCommandParam param =(DBCommandParam)cmpExpr.getValue(); 
-                    		DBCommandParam value = upd.addParam(colExpr, param.getValue());
+                    		DBCmdParam param =(DBCmdParam)cmpExpr.getValue(); 
+                    		DBCmdParam value = upd.addParam(colExpr, param.getValue());
                     		cmp = new DBCompareColExpr(colExpr, cmpExpr.getCmpop(), value);
                     	}
                         upd.where(cmp);

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java?rev=1244408&r1=1244407&r2=1244408&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java
(original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java
Wed Feb 15 09:16:53 2012
@@ -26,7 +26,7 @@ import java.sql.Connection;
 
 import org.apache.empire.DBResource;
 import org.apache.empire.DBResource.DB;
-import org.apache.empire.db.DBCommand.DBCommandParam;
+import org.apache.empire.db.DBCmdParam;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -63,7 +63,7 @@ public class PreparedStatementTest{
         // Define the query
         DBCommand cmd = db.createCommand();
         // Create parameters
-        DBCommandParam empIdParam  = cmd.addParam(null);
+        DBCmdParam empIdParam  = cmd.addParam(null);
         // the previous line could be shorter
         // DBCommandParam empIdParam  = cmd.addCmdParam(id);
         // create statement



Mime
View raw message