empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1342251 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire: commons/ObjectUtils.java db/DBCombinedCmd.java db/DBQuery.java db/DBReader.java
Date Thu, 24 May 2012 13:29:59 GMT
Author: doebele
Date: Thu May 24 13:29:58 2012
New Revision: 1342251

URL: http://svn.apache.org/viewvc?rev=1342251&view=rev
Log:
EMPIREDB-145
Modified constructors of DBQuery

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java?rev=1342251&r1=1342250&r2=1342251&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java Thu
May 24 13:29:58 2012
@@ -419,6 +419,11 @@ public final class ObjectUtils
     {
         if (v==null || c.isInstance(v))
             return (T)v;
+        // Get Class form Primitive Type
+        if (c.isPrimitive())
+        {   // Get's the Java Class representing the primitive type
+            c = MethodUtils.getPrimitiveWrapper(c);
+        }    
         // Convert
         if (c.isAssignableFrom(Boolean.class))
             return c.cast(getBoolean(v));
@@ -464,6 +469,11 @@ public final class ObjectUtils
         {   // Both are numeric
             return true;
         }
+        // Special case: Allow character to string assignment
+        if (source==Character.class && target==String.class)
+        {
+            return true;
+        }    
         // Not compatible
         return false;
     }

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java?rev=1342251&r1=1342250&r2=1342251&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java Thu May
24 13:29:58 2012
@@ -132,7 +132,7 @@ public class DBCombinedCmd extends DBCom
       buf.append( "(" );
       left.getSelect(buf);
       // concat keyword     
-      buf.append( ") " );
+      buf.append( ")\r\n" );
       buf.append( keyWord );
       buf.append( " (" );
       // the right part

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=1342251&r1=1342250&r2=1342251&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 Thu May 24 13:29:58
2012
@@ -162,7 +162,7 @@ public class DBQuery extends DBRowSet
 
     private static AtomicInteger queryCount = new AtomicInteger(0);
 
-    protected DBCommand       cmd;
+    protected DBCommandExpr   cmdExpr;
     protected DBColumn[]      keyColumns = null;
     protected DBQueryColumn[] queryColumns = null;
     protected String          alias;
@@ -174,10 +174,10 @@ public class DBQuery extends DBRowSet
      * @param cmd the SQL-Command
      * @param keyColumns an array of the primary key columns
      */
-    public DBQuery(DBCommand cmd, DBColumn[] keyColumns)
+    public DBQuery(DBCommandExpr cmd, DBColumn[] keyColumns)
     { // Set the column expressions
         super(cmd.getDatabase());
-        this.cmd = cmd;
+        this.cmdExpr = cmd;
         // Set Query Columns
         DBColumnExpr[] exprList = cmd.getSelectExprList();
         queryColumns = new DBQueryColumn[exprList.length];
@@ -199,7 +199,7 @@ public class DBQuery extends DBRowSet
      * @param cmd the SQL-Command
      * @param keyColumn the primary key column
      */
-    public DBQuery(DBCommand cmd, DBColumn keyColumn)
+    public DBQuery(DBCommandExpr cmd, DBColumn keyColumn)
     { // Set the column expressions
         this(cmd, new DBColumn[] { keyColumn });
     }
@@ -209,12 +209,33 @@ public class DBQuery extends DBRowSet
      * 
      * @param cmd the command object representing an SQL-Command.
      */
-    public DBQuery(DBCommand cmd)
+    public DBQuery(DBCommandExpr cmd)
     { // Set the column expressions
         this(cmd, (DBColumn[]) null);
     }
 
     /**
+     * returns the command from the underlying command expression or throws an exception
+     * @return the command used for this query
+     */
+    private DBCommand getCommandFromExpression()
+    {
+        if (cmdExpr instanceof DBCommand)
+            return ((DBCommand)cmdExpr);
+        // not supported
+        throw new NotSupportedException(this, "getCommand");
+    }
+
+    /**
+     * returns the underlying command expression
+     * @return the command used for this query
+     */
+    public DBCommandExpr getCommandExpr()
+    {
+        return cmdExpr;
+    }
+
+    /**
      * not applicable - returns null
      */
     @Override
@@ -304,7 +325,7 @@ public class DBQuery extends DBRowSet
     public void addSQL(StringBuilder buf, long context)
     {
         buf.append("(");
-        buf.append(cmd.getSelect());
+        buf.append(cmdExpr.getSelect());
         buf.append(")");
         // Add Alias
         if ((context & CTX_ALIAS) != 0 && alias != null)
@@ -371,6 +392,7 @@ public class DBQuery extends DBRowSet
         if (key == null || keyColumns.length != key.length)
             throw new InvalidKeyException(this, key);
         // Select
+        DBCommand cmd = getCommandFromExpression();
         for (int i = 0; i < keyColumns.length; i++)
         {   // Set key column constraint
             Object value = key[i];
@@ -440,15 +462,16 @@ public class DBQuery extends DBRowSet
                 if (col.isReadOnly() && log.isDebugEnabled())
                     log.debug("updateRecord: Read-only column '" + col.getName() + " has
been modified!");
                 // Check the value
-                col.checkValue(fields[i]);
+                col.validate(fields[i]);
                 // Set
                 updCmd.set(col.to(fields[i]));
             }
         }
         // the commands
+        DBCommand cmd = getCommandFromExpression();
         Object[] keys = (Object[]) rec.getRowSetData();
-        DBRowSet table;
-        DBCommand upd;
+        DBRowSet table= null;
+        DBCommand upd = null;
         for(Entry<DBRowSet,DBCommand> entry:updCmds.entrySet())
         {
             int i = 0;

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java?rev=1342251&r1=1342250&r2=1342251&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java Thu May 24
13:29:58 2012
@@ -647,8 +647,9 @@ public class DBReader extends DBRecordDa
             { // Create bean an init
                 if (ctor!=null)
                 {   // Use Constructor
+                    Class<?>[] ctorParamTypes = ctor.getParameterTypes();
                     for (int i = 0; i < getFieldCount(); i++)
-                        args[i] = getValue(i);
+                        args[i] = ObjectUtils.convert(ctorParamTypes[i], getValue(i));
                     T bean = (T)ctor.newInstance(args);
                     c.add(bean);
                 }



Mime
View raw message