You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/03/01 14:22:42 UTC

[empire-db] branch master updated: EMPIREDB-362 DBTable Do not set modified for defaultValues

This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ca9ca6  EMPIREDB-362 DBTable Do not set modified for defaultValues
8ca9ca6 is described below

commit 8ca9ca6901b9b0bd50e69f4cd3b704c15bb301f9
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Tue Mar 1 15:22:39 2022 +0100

    EMPIREDB-362 DBTable Do not set modified for defaultValues
---
 .../src/main/java/org/apache/empire/db/DBCombinedCmd.java   | 10 ++++++++++
 empire-db/src/main/java/org/apache/empire/db/DBCommand.java | 11 +++++++++++
 .../src/main/java/org/apache/empire/db/DBCommandExpr.java   |  7 +++++++
 empire-db/src/main/java/org/apache/empire/db/DBTable.java   | 13 ++-----------
 empire-db/src/main/java/org/apache/empire/db/DBUtils.java   |  8 +++-----
 5 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java b/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
index 8825bc4..3037b46 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.empire.data.DataType;
 import org.apache.empire.db.expr.order.DBOrderByExpr;
 
 /**
@@ -152,6 +153,15 @@ public class DBCombinedCmd extends DBCommandExpr
     }
 
     /**
+    * @return the DataType of the selected expression or DataType.UNKNOWN
+    */
+    @Override
+    public DataType getDataType()
+    {
+        return left.getDataType();
+    }
+    
+    /**
      * Creates the SQL-Command.
      * 
      * @param buf the SQL-Command
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index c978813..67f6a7e 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -294,6 +294,17 @@ public abstract class DBCommand extends DBCommandExpr
     {
         return (select!=null ? (select.indexOf(expr)>=0) : false);
     }
+
+    /**
+    * @return the DataType of the selected expression or DataType.UNKNOWN
+    */
+    @Override
+    public DataType getDataType()
+    {
+        if (select==null || select.size()!=1)
+            return DataType.UNKNOWN;
+        return select.get(0).getDataType(); 
+    }
     
     /**
      * Adds a DBColumnExpr object to the Select collection
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java b/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
index 096533d..2db0887 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
@@ -340,6 +340,13 @@ public abstract class DBCommandExpr extends DBExpr
     public abstract Object[] getParamValues();
 
     /**
+     * Returns the DataType selected by this command if only one column is returned
+     * If the command has more than one select expression DataType.UNKNOWN will be returned
+     * @return the DataType of the selected expression or DataType.UNKNOWN
+     */
+    public abstract DataType getDataType();
+    
+    /**
      * Creates the SQL-Command.
      * 
      * @param buf the SQL-Command
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBTable.java b/empire-db/src/main/java/org/apache/empire/db/DBTable.java
index 1b565cd..556fa1d 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBTable.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBTable.java
@@ -821,16 +821,6 @@ public class DBTable extends DBRowSet implements Cloneable
             throw new InvalidArgumentException("fieldInitMode", fieldInitMode);
         // Use connection if not deferred
         Connection conn = (fieldInitMode==FieldInitMode.SET_DEFAULTS_DEFERRED ? null : record.getContext().getConnection());
-        /*
-         *  Connection Auto-Detect (disabled!)
-         *  Use derived class to add connection if necessary
-         *         
-        DBColumn pkColumn = (primaryKey!=null ? primaryKey.getColumn(0) : null);
-        if (conn==null && pkColumn!=null && pkColumn.isAutoGenerated() && fields[getColumnIndex(pkColumn)]==null)
-        {   // Init AutoGenerated Key
-            conn = rec.getContext().getConnection();
-        }
-        */
         Object[] fields = record.getFields();
         // Set Default values
         // ATTENTION: Do not set to ObjectUtils.NO_VALUE
@@ -845,7 +835,8 @@ public class DBTable extends DBRowSet implements Cloneable
             if (ObjectUtils.isEmpty(value))
                 continue;
             // Initial value
-            record.modifyValue(i, value, false);
+            // Don't set to modified: record.modifyValue(i, value, false); 
+            fields[i] = value;
         }
     }
     
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
index 35c01c0..e65651b 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
@@ -197,7 +197,7 @@ public class DBUtils implements DBContextAware
      */
     public final <T> T querySingleValue(DBCommandExpr cmd, Class<T> resultType, boolean failOnNoResult)
     {
-        Object value = querySingleValue(cmd.getSelect(), cmd.getParamValues(), DataType.fromJavaType(resultType), failOnNoResult); 
+        Object value = querySingleValue(cmd.getSelect(), cmd.getParamValues(), cmd.getDataType(), failOnNoResult); 
         return ObjectUtils.convert(resultType, value);
     }
     
@@ -211,9 +211,7 @@ public class DBUtils implements DBContextAware
      */
     public final Object querySingleValue(DBCommandExpr cmd, boolean failOnNoResult)
     {
-        DBColumnExpr[] selExpr = cmd.getSelectExprList();
-        DataType dataType = (selExpr!=null && selExpr.length>0 ? selExpr[0].getDataType() : DataType.UNKNOWN); 
-        return querySingleValue(cmd.getSelect(), cmd.getParamValues(), dataType, failOnNoResult);  
+        return querySingleValue(cmd.getSelect(), cmd.getParamValues(), cmd.getDataType(), failOnNoResult);  
     }
     
     /**
@@ -449,7 +447,7 @@ public class DBUtils implements DBContextAware
      */
     public final <T> int querySimpleList(Class<T> c, DBCommandExpr cmd, Collection<T> result)
     {
-        return querySimpleList(c, cmd.getSelect(), cmd.getParamValues(), DataType.UNKNOWN, result, MAX_QUERY_ROWS); 
+        return querySimpleList(c, cmd.getSelect(), cmd.getParamValues(), cmd.getDataType(), result, MAX_QUERY_ROWS); 
     }
 
     /**