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 6ce4768  EMPIREDB-362 RecordFactory fix
6ce4768 is described below

commit 6ce47689a23c8bcdcd32c3e6a065bfad14f0dd4e
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Feb 1 01:18:17 2022 +0100

    EMPIREDB-362 RecordFactory fix
---
 .../java/org/apache/empire/data/bean/BeanResult.java    |  5 +++--
 .../src/main/java/org/apache/empire/db/DBUtils.java     |  6 +++---
 .../apache/empire/db/list/DBRecordListFactoryImpl.java  | 17 ++++++++++-------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git 
a/empire-db/src/main/java/org/apache/empire/data/bean/BeanResult.java 
b/empire-db/src/main/java/org/apache/empire/data/bean/BeanResult.java
index 54e681d..519187a 100644
--- a/empire-db/src/main/java/org/apache/empire/data/bean/BeanResult.java
+++ b/empire-db/src/main/java/org/apache/empire/data/bean/BeanResult.java
@@ -21,6 +21,7 @@ package org.apache.empire.data.bean;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 
+import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBContext;
@@ -84,7 +85,7 @@ public class BeanResult<T> extends ArrayList<T>
         for (DBColumn col : rowset.getColumns())
         {   // obtain the bean property Name
             String property = col.getBeanPropertyName();
-            if (!isPropertyAcessible(methods, property)) {
+            if (!isPropertyAcessible(methods, property, col.getDataType())) {
                 // Property not found
                 log.debug("Unable to access the property {} on {}. Column will 
be ignored.", property, clazz.getName());
                 continue;
@@ -98,7 +99,7 @@ public class BeanResult<T> extends ArrayList<T>
             throw new BeanIncompatibleException(clazz, rowset);
     }
 
-    private boolean isPropertyAcessible(Method[] methods, String property)
+    protected boolean isPropertyAcessible(Method[] methods, String property, 
DataType dataType)
     {
         property = 
"et"+property.substring(0,1).toUpperCase()+property.substring(1);
         for (int i=0; i<methods.length; i++)
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 0fad0d8..c64d9cf 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
@@ -814,9 +814,9 @@ public class DBUtils implements DBContextAware
      * @param recordClass the recordClass for which to create the list head 
      * @return
      */
-    protected <T extends DBRecord> DBRecordListFactory<T> 
createDefaultRecordListFactory(DBContext context, DBRowSet rowset, Class<T> 
recordClass) 
+    protected <T extends DBRecord> DBRecordListFactory<T> 
createDefaultRecordListFactory(Class<T> recordClass, DBRowSet rowset) 
     {
-        return new DBRecordListFactoryImpl<T>(recordClass, context, rowset);
+        return new DBRecordListFactoryImpl<T>(recordClass, rowset);
     }
     
     /**
@@ -900,7 +900,7 @@ public class DBUtils implements DBContextAware
     public final <T extends DBRecord> List<T> queryRecordList(DBCommand cmd, 
DBRowSet rowset)
     {
         @SuppressWarnings("unchecked")
-        DBRecordListFactory<T> factory = 
(DBRecordListFactory<T>)createDefaultRecordListFactory(context, rowset, 
DBRecord.class);
+        DBRecordListFactory<T> factory = 
(DBRecordListFactory<T>)createDefaultRecordListFactory(DBRecord.class, rowset);
         return queryRecordList(cmd, factory, 0, -1);
     }
 
diff --git 
a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
 
b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
index 17ef6f6..a0e2b91 100644
--- 
a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
+++ 
b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
@@ -66,19 +66,19 @@ public class DBRecordListFactoryImpl<T extends DBRecord> 
implements DBRecordList
      * Members
      */
     protected final Constructor<T> constructor;
-    protected final DBContext context;
     protected final DBRowSet rowset;
 
+    protected DBContext context;
+    
     /**
      * Constructs a DBRecordListFactoryImpl based on an DBRecord constructor
      * @param constructor the DBRecord constructor
      * @param context the database context
      * @param rowset the rowset for the created records
      */
-    public DBRecordListFactoryImpl(Constructor<T> constructor, DBContext 
context, DBRowSet rowset) 
+    public DBRecordListFactoryImpl(Constructor<T> constructor, DBRowSet 
rowset) 
     {
         this.constructor = constructor;
-        this.context = context;
         this.rowset = rowset;
     }
     
@@ -88,14 +88,17 @@ public class DBRecordListFactoryImpl<T extends DBRecord> 
implements DBRecordList
      * @param context the database context
      * @param rowset the rowset for the created records
      */
-    public DBRecordListFactoryImpl(Class<T> recordClass, DBContext context, 
DBRowSet rowset) 
+    public DBRecordListFactoryImpl(Class<T> recordClass, DBRowSet rowset) 
     {
-        this(findRecordConstructor(recordClass, DBContext.class, 
DBRowSet.class), context, rowset);
+        this(findRecordConstructor(recordClass, DBContext.class, 
DBRowSet.class), rowset);
     }
     
     @Override
     public void prepareQuery(DBCommand cmd, DBContext context)
     {
+        // set context
+        this.context = context;
+        // complete select
         if (cmd.hasSelectExpr())
         {   // Already has select expressions. 
             // Check against Rowset
@@ -127,8 +130,8 @@ public class DBRecordListFactoryImpl<T extends DBRecord> 
implements DBRecordList
     
     @Override
     public void completeQuery(List<T> list)
-    {
-        
+    {   // set context
+        this.context = null;
     }
     
 }

Reply via email to