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

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


The following commit(s) were added to refs/heads/version3 by this push:
     new 18e03c3  EMPIREDB-368 small fix
18e03c3 is described below

commit 18e03c37d9aa76d22852799693c79c055503ce3b
Author: Rainer Döbele <[email protected]>
AuthorDate: Fri Feb 4 09:11:55 2022 +0100

    EMPIREDB-368 small fix
---
 empire-db/src/main/java/org/apache/empire/db/DBUtils.java        | 9 ++++++---
 .../main/java/org/apache/empire/db/list/DBBeanFactoryCache.java  | 4 +---
 .../java/org/apache/empire/db/list/DBBeanListFactoryImpl.java    | 9 +++++++--
 3 files changed, 14 insertions(+), 8 deletions(-)

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 2b074d1..890951e 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
@@ -22,6 +22,7 @@ import 
org.apache.empire.db.exceptions.ConstraintViolationException;
 import org.apache.empire.db.exceptions.QueryFailedException;
 import org.apache.empire.db.exceptions.QueryNoResultException;
 import org.apache.empire.db.exceptions.StatementFailedException;
+import org.apache.empire.db.exceptions.UnknownBeanTypeException;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
 import org.apache.empire.db.list.Bean;
 import org.apache.empire.db.list.DBBeanFactoryCache;
@@ -932,7 +933,7 @@ public class DBUtils implements DBContextAware
      */
     protected synchronized <T> DBBeanListFactory<T> 
getRowsetBeanListFactory(Class<T> beanType, DBRowSet rowset) 
     {
-        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType, false);
+        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType);
         if (factory==null)
         {   // Create default factory
             log.info("No factory found for bean type '{}' and rowset {}. 
Creating default", beanType.getName(), rowset.getName());
@@ -950,7 +951,7 @@ public class DBUtils implements DBContextAware
      */
     protected synchronized <T> DBBeanListFactory<T> 
getCommandBeanListFactory(Class<T> beanType, DBCommand cmd) 
     {
-        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType, false);
+        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType);
         if (factory==null) 
         {   // Check command: Must have select!
             if (!cmd.hasSelectExpr())
@@ -1145,7 +1146,9 @@ public class DBUtils implements DBContextAware
     {
         DBObject.checkParamNull("whereConstraints", whereConstraints);
         // must have a factory
-        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType, true);
+        DBBeanListFactory<T> factory = 
DBBeanFactoryCache.getFactoryForType(beanType);
+        if (factory==null)
+            throw new UnknownBeanTypeException(beanType);
         // add constraints
         DBDatabase db = whereConstraints.getDatabase();
         DBCommand cmd = db.createCommand();
diff --git 
a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanFactoryCache.java 
b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanFactoryCache.java
index 525ff9f..16f605f 100644
--- a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanFactoryCache.java
+++ b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanFactoryCache.java
@@ -54,12 +54,10 @@ public final class DBBeanFactoryCache
      * @param beanType the Java bean type
      * @return return the DBRowSet assigned to this type 
      */
-    public static synchronized <T> DBBeanListFactory<T> 
getFactoryForType(Class<T> beanType, boolean checkExists)
+    public static synchronized <T> DBBeanListFactory<T> 
getFactoryForType(Class<T> beanType)
     {
         @SuppressWarnings("unchecked")
         DBBeanListFactory<T> factory = 
(DBBeanListFactory<T>)beanFactoryMap.get(beanType); 
-        if (factory==null && checkExists)
-            throw new UnknownBeanTypeException(beanType);
         return factory;
     }
 
diff --git 
a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java 
b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
index 7da7872..4bdbbb0 100644
--- 
a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
+++ 
b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
@@ -31,6 +31,7 @@ import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBContext;
 import org.apache.empire.db.DBRecordData;
+import org.apache.empire.db.exceptions.CommandWithoutSelectException;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.UnsupportedTypeException;
@@ -161,6 +162,7 @@ public class DBBeanListFactoryImpl<T> implements 
DBBeanListFactory<T>
     @Override
     public void prepareQuery(DBCommand cmd, DBContext context)
     {
+        boolean hasSelect = cmd.hasSelectExpr();
         // check if constructor params are selected and add if appropriate
         if (constructorParams!=null)
         {   // select all columns which are not already selected
@@ -170,8 +172,8 @@ public class DBBeanListFactoryImpl<T> implements 
DBBeanListFactory<T>
                     cmd.select(expr);
             }
         }
-        // check the rest of the columns
-        if (setterColumns!=null)
+        // check the rest of the columns, but only if no select is present
+        if (setterColumns!=null && !hasSelect)
         {   // select all columns which are not already selected
             for (DBColumnExpr expr : setterColumns)
             {
@@ -181,6 +183,9 @@ public class DBBeanListFactoryImpl<T> implements 
DBBeanListFactory<T>
                     cmd.select(expr);
             }
         }
+        // still no select ?
+        if (!cmd.hasSelectExpr())
+            throw new CommandWithoutSelectException(cmd); 
     }
     
     @Override

Reply via email to