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 03babba  EMPIREDB-362 small fix
03babba is described below

commit 03babbacb87143f6821ac9b3d48a209c2459f672
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Jan 31 18:04:36 2022 +0100

    EMPIREDB-362 small fix
---
 .../main/java/org/apache/empire/db/DBDatabase.java |  5 +-
 .../main/java/org/apache/empire/db/DBRecord.java   |  2 +-
 .../main/java/org/apache/empire/db/DBUtils.java    | 88 ++++++++++++++++++++++
 3 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java 
b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index 89f14ad..98bd1ba 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -290,9 +290,10 @@ public abstract class DBDatabase extends DBObject
      * 
      * @return Returns the DBMS Handler for this database
      */
-    public DBMSHandler getDbms()
+    @SuppressWarnings("unchecked")
+    public <T extends DBMSHandler> T getDbms()
     {
-        return dbms;
+        return (T)dbms;
     }
     
     /**
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java 
b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
index c8fb198..e7d37f7 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
@@ -525,7 +525,7 @@ public class DBRecord extends DBRecordData implements 
DBContextAware, Record, Cl
      * @return the Column at the specified index 
      */
     @Override
-    public final DBColumn getColumn(int index)
+    public DBColumn getColumn(int index)
     {
         return getRowSet().getColumn(index);
     }
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 c78d49c..a73fe83 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
@@ -881,11 +881,99 @@ public class DBUtils implements DBContextAware
         }
     }
 
+    /**
+     * Executes a query and returns a list of DBRecord items
+     * @param cmd the command holding the constraints and order or the query
+     * @param rowset the rowset for which to query the records
+     * @return the list of DBRecord items
+     */
     public final <T extends DBRecord> List<T> queryRecordList(DBCommand cmd, 
DBRowSet rowset)
     {
         @SuppressWarnings("unchecked")
         DBRecordListFactory<T> factory = 
(DBRecordListFactory<T>)createDefaultRecordListFactory(context, rowset, 
DBRecord.class);
         return queryRecordList(cmd, factory, 0, -1);
     }
+
+    /**#
+     * Query a list of simple Java objects (beans)
+     * @param cmd the comman
+     * @param type
+     * @param first
+     * @param pageSize
+     * @return
+     */
+    public <T> List<T> queryBeanList(DBCommand cmd, Class<T> type, int first, 
int pageSize)
+    {
+        DBReader r = new DBReader(context);
+        try
+        {   // check pageSize
+            if (pageSize==0)
+            {   log.warn("PageSize must not be 0. Setting to -1 for all 
records!");
+                pageSize = -1;
+            }
+            // set range
+            DBMSHandler dbms = cmd.getDatabase().getDbms();
+            if (pageSize>0 && dbms.isSupported(DBMSFeature.QUERY_LIMIT_ROWS))
+            {   // let the database limit the rows
+                if (first>0 && dbms.isSupported(DBMSFeature.QUERY_SKIP_ROWS))
+                {   // let the database skip the rows
+                    cmd.skipRows(first);
+                    // no need to skip rows ourself
+                    first = 0;
+                }
+                cmd.limitRows(first+pageSize);
+            }
+            // Runquery
+            r.open(cmd);
+            if (first>0) 
+            {   // skip rows
+                r.skipRows(first);
+            }
+            ArrayList<T> list = r.getBeanList(type, pageSize);
+            // check sortable
+            /*
+            if (EnumerableListEntry.class.isAssignableFrom(type))
+            {
+                int rownum = 0;
+                for (EnumerableListEntry sle : ((ArrayList<? extends 
EnumerableListEntry>)list))
+                {
+                    sle.setRownum(++rownum);
+                }
+            }
+            */
+            return list;
+        }
+        finally
+        {
+            r.close();
+        }
+    }
+
+    public <T> List<T> queryBeanList(DBCommand cmd, Class<T> type)
+    {
+        return queryBeanList(cmd, type, 0, -1);
+    }
+    
+    /**
+     * Query a single bean's properties
+     * @param cmd the bean query command
+     * @param bean the bean for which to set the properties
+    public int queryBeanProperties(DBCommand cmd, Object bean)
+    {
+        DBReader r = new DBReader(context);
+        try
+        {   // Runquery
+            r.getRecordData(cmd);
+            int count = r.setBeanProperties(bean);
+            if (count<= 0)
+                log.warn("No matching bean properties found!");
+           return count;
+        }
+        finally
+        {
+            r.close();
+        }
+    }
+     */
     
 }

Reply via email to