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 eb4192c  EMPIREDB-372 Allow method chaining for DBCommand and DBRecord
eb4192c is described below

commit eb4192cec395c4a8694939af0522d29925e710fa
Author: Rainer Döbele <[email protected]>
AuthorDate: Sat Feb 12 16:34:18 2022 +0100

    EMPIREDB-372 Allow method chaining for DBCommand and DBRecord
---
 .../empire/samples/db/advanced/SampleAdvApp.java   |   4 +-
 .../empire/samples/db/advanced/SampleAdvDB.java    |   3 +-
 .../org/apache/empire/samples/db/SampleApp.java    | 146 +++++-----
 .../java/org/apache/empire/db/DBColumnExpr.java    |  14 +-
 .../java/org/apache/empire/db/DBCombinedCmd.java   |   3 +-
 .../main/java/org/apache/empire/db/DBCommand.java  | 302 ++++++++++++---------
 .../java/org/apache/empire/db/DBCommandExpr.java   |  15 +-
 .../main/java/org/apache/empire/db/DBDatabase.java |   4 +-
 .../main/java/org/apache/empire/db/DBQuery.java    |  14 +-
 .../main/java/org/apache/empire/db/DBRecord.java   |  44 ++-
 .../java/org/apache/empire/db/DBRecordBase.java    |   4 +-
 .../java/org/apache/empire/db/DBRecordBean.java    |  44 ++-
 .../org/apache/empire/dbms/h2/DBMSHandlerH2.java   |   6 +-
 .../apache/empire/dbms/mysql/DBMSHandlerMySQL.java |  12 +-
 .../apache/empire/dbms/oracle/DBCommandOracle.java |   8 +-
 .../dbms/postgresql/DBMSHandlerPostgreSQL.java     |   6 +-
 .../empire/dbms/sqlite/DBMSHandlerSQLite.java      |   3 +-
 .../empire/dbms/sqlserver/DBMSHandlerMSSQL.java    |   3 +-
 18 files changed, 382 insertions(+), 253 deletions(-)

diff --git 
a/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
 
b/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
index 51b8208..6dda2d2 100644
--- 
a/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
+++ 
b/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
@@ -632,8 +632,8 @@ public class SampleAdvApp
         cmd.select(T_DEP.C_DEPARTMENT_ID, T_DEP.C_NAME, T_DEP.C_BUSINESS_UNIT);
         cmd.select(T_EMP.C_UPDATE_TIMESTAMP, T_DEP.C_UPDATE_TIMESTAMP);
         // Set Joins
-        cmd.join(T_EDH.C_EMPLOYEE_ID, 
Q_MAX_DATE.findQueryColumn(T_EDH.C_EMPLOYEE_ID))
-          
.where(T_EDH.C_DATE_FROM.is(Q_MAX_DATE.findQueryColumn(MAX_DATE_FROM)));
+        cmd.join(T_EDH.C_EMPLOYEE_ID, Q_MAX_DATE.column(T_EDH.C_EMPLOYEE_ID),
+                 T_EDH.C_DATE_FROM.is(Q_MAX_DATE.column(MAX_DATE_FROM)));
         cmd.join(T_EMP.C_EMPLOYEE_ID, T_EDH.C_EMPLOYEE_ID);
         cmd.join(T_DEP.C_DEPARTMENT_ID, T_EDH.C_DEPARTMENT_ID);
         // Set Constraints
diff --git 
a/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvDB.java
 
b/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvDB.java
index 81a15a4..64d84de 100644
--- 
a/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvDB.java
+++ 
b/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvDB.java
@@ -248,8 +248,7 @@ public class SampleAdvDB extends TDatabase<SampleAdvDB>
                        
.append(EMP.C_FIRSTNAME.coalesce(DBDatabase.EMPTY_STRING))
                        .append(" (").append(DEP.C_NAME).append(")"));
             // Set Joins
-            cmd.join(EDH.C_EMPLOYEE_ID, EDS.C_EMPLOYEE_ID)
-              .where(EDH.C_DATE_FROM.is(EDS.C_MAX_DATE_FROM));
+            cmd.join(EDH.C_EMPLOYEE_ID, EDS.C_EMPLOYEE_ID, 
EDH.C_DATE_FROM.is(EDS.C_MAX_DATE_FROM));
             cmd.join(EMP.C_EMPLOYEE_ID, EDH.C_EMPLOYEE_ID);
             cmd.join(DEP.C_DEPARTMENT_ID, EDH.C_DEPARTMENT_ID);
             // done
diff --git 
a/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
 
b/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
index 0c571b0..e9ef32b 100644
--- 
a/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
+++ 
b/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
@@ -373,10 +373,10 @@ public class SampleApp
         SampleDB.Departments DEP = db.DEPARTMENTS;
                // Insert a Department
                TRecord<SampleDB.Departments> rec = new 
TRecord<SampleDB.Departments>(context, DEP);
-               rec.create();
-               rec.setValue(DEP.NAME, departmentName);
-               rec.setValue(DEP.BUSINESS_UNIT, businessUnit);
-               rec.update();
+               rec.create()
+                  .set(DEP.NAME, departmentName)
+                  .set(DEP.BUSINESS_UNIT, businessUnit)
+                  .update();
                // Return Department ID
         return rec.getId();
        }
@@ -391,12 +391,12 @@ public class SampleApp
         SampleDB.Employees EMP = db.EMPLOYEES;
                // Insert an Employee
                DBRecord rec = new DBRecord(context, EMP);
-               rec.create(null);
-               rec.setValue(EMP.FIRST_NAME, firstName);
-               rec.setValue(EMP.LAST_NAME, lastName);
-               rec.setValue(EMP.GENDER, gender);
-               rec.setValue(EMP.DEPARTMENT_ID, departmentId);
-               rec.update();
+               rec.create(null)
+                  .set(EMP.FIRST_NAME, firstName)
+                  .set(EMP.LAST_NAME, lastName)
+                  .set(EMP.GENDER, gender)
+                  .set(EMP.DEPARTMENT_ID, departmentId)
+              .update();
                // Return Employee ID
                return rec.getId();
        }
@@ -420,7 +420,7 @@ public class SampleApp
             variation = variation.setScale(2, RoundingMode.HALF_UP);
             // insert
             rec.create(DBRecord.key(employeeId, month.getYear(), 
month.getMonth()));
-            rec.setValue(PAY.AMOUNT, monthlySalary.add(variation));
+            rec.set(PAY.AMOUNT, monthlySalary.add(variation));
             rec.update();
         }
     }
@@ -437,14 +437,14 @@ public class SampleApp
                DBRecord rec = new DBRecord(context, db.EMPLOYEES);
                rec.read(idEmp);
                // Set
-               rec.setValue(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+               rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
                rec.update();
                */
            
         DBRecordBean rec = new DBRecordBean();
         rec.read(context, db.EMPLOYEES, idEmp);
         // Set
-        rec.setValue(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+        rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
         rec.update(context);
            
        }
@@ -463,7 +463,7 @@ public class SampleApp
         DBRecord rec = new DBRecord(context, EMP);
         rec.read(DBRecord.key(idEmp), PartialMode.INCLUDE, EMP.PHONE_NUMBER);
         // Set
-        rec.setValue(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+        rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
         rec.update();
     }
 
@@ -488,8 +488,8 @@ public class SampleApp
         // Make employee Head of Department and update salary
         DBRecord rec = new DBRecord(context, query);
         rec.read(idEmp);
-        rec.setValue(EMP.SALARY, salary);
-        rec.setValue(DEP.HEAD, rec.getString(EMP.LAST_NAME));
+        rec.set(EMP.SALARY, salary);
+        rec.set(DEP.HEAD, rec.getString(EMP.LAST_NAME));
         rec.update();
     }
 
@@ -505,22 +505,22 @@ public class SampleApp
 
         DBRecord rec = new DBRecord(context, EMP);
         rec.create();
-        rec.setValue(EMP.FIRSTNAME, "Foo");
-        rec.setValue(EMP.LASTNAME, "Manchoo");
-        rec.setValue(EMP.GENDER, Gender.M);
-        rec.setValue(EMP.DEPARTMENT_ID, idDep);
+        rec.set(EMP.FIRSTNAME, "Foo");
+        rec.set(EMP.LASTNAME, "Manchoo");
+        rec.set(EMP.GENDER, Gender.M);
+        rec.set(EMP.DEPARTMENT_ID, idDep);
         rec.update();
         log.info("Timestamp {}", rec.getString(EMP.UPDATE_TIMESTAMP));
         
-        rec.setValue(EMP.FIRSTNAME, "Foo 2");
-        rec.setValue(EMP.LASTNAME, "Manchu");
-        rec.setValue(EMP.PHONE_NUMBER, "0815/4711");
+        rec.set(EMP.FIRSTNAME, "Foo 2");
+        rec.set(EMP.LASTNAME, "Manchu");
+        rec.set(EMP.PHONE_NUMBER, "0815/4711");
         rec.update();
         log.info("Timestamp {}", rec.getString(EMP.UPDATE_TIMESTAMP));
         
         context.rollback();
         
-        rec.setValue(EMP.FIRSTNAME, "Dr. Foo");
+        rec.set(EMP.FIRSTNAME, "Dr. Foo");
         rec.update();
         log.info("Timestamp {}", rec.getString(EMP.UPDATE_TIMESTAMP));
 
@@ -550,15 +550,15 @@ public class SampleApp
         
         DBRecord rec = new DBRecord(context, EMP);        
         rec.read(idEmp);
-        rec.setValue(EMP.PHONE_NUMBER, null);
-        rec.setValue(EMP.SALARY, "100.000");
+        rec.set(EMP.PHONE_NUMBER, null);
+        rec.set(EMP.SALARY, "100.000");
         rec.update();
 
         log.info("Timestamp {}", rec.getString(EMP.UPDATE_TIMESTAMP));
         
         context.rollback();
         
-        rec.setValue(EMP.PHONE_NUMBER, "07531-45716-0");
+        rec.set(EMP.PHONE_NUMBER, "07531-45716-0");
         rec.update();
 
         log.info("Timestamp {}", rec.getString(EMP.UPDATE_TIMESTAMP));
@@ -586,7 +586,7 @@ public class SampleApp
         rec.read(idEmp);
 
         // log.info("Timestamp {}", rec.getString(T.UPDATE_TIMESTAMP));
-        // rec.setValue(T.SALARY, "100.001");
+        // rec.set(T.SALARY, "100.001");
         // rec.update();
         // log.info("Timestamp {}", rec.getString(T.UPDATE_TIMESTAMP));
         
@@ -636,9 +636,6 @@ public class SampleApp
     {
         int lastYear = LocalDate.now().getYear()-1;
            
-           // Create a command
-           DBCommand cmd = db.createCommand();
-           
            // Define shortcuts for tables used - not necessary but convenient
            SampleDB.Employees   EMP = db.EMPLOYEES;
            SampleDB.Departments DEP = db.DEPARTMENTS;
@@ -663,22 +660,24 @@ public class SampleApp
         // DBColumnExpr genderExpr = 
cmd.select(EMP.GENDER.decode(EMP.GENDER.getOptions()).as(EMP.GENDER.getName()));
 
         // Select Employee and Department columns
-        cmd.select(EMP.ID.as("EMPLOYEE_ID"), EMPLOYEE_FULLNAME);
-        cmd.select(EMP.GENDER, EMP.PHONE_NUMBER, PHONE_EXT_NUMBER);
-        cmd.select(DEP.NAME.as("DEPARTMENT"));
-        cmd.select(DEP.BUSINESS_UNIT);
+        DBCommand cmd = db.createCommand()
+           .select(EMP.ID.as("EMPLOYEE_ID"), EMPLOYEE_FULLNAME)
+           .select(EMP.GENDER, EMP.PHONE_NUMBER, PHONE_EXT_NUMBER)
+           .select(DEP.NAME.as("DEPARTMENT"))
+           .select(DEP.BUSINESS_UNIT)
+           // Joins
+           .join(EMP.DEPARTMENT_ID, DEP.ID)
+           .joinLeft(EMP.ID, PAY.EMPLOYEE_ID, PAY.YEAR.is(lastYear))
+           // Where constraints
+           .where(EMP.LAST_NAME.length().isGreaterThan(0))
+           .where(EMP.GENDER.in(Gender.M, Gender.F))
+           .where(EMP.RETIRED.is(false))
+           // Order by
+           .orderBy(EMPLOYEE_FULLNAME);
+
         // Add payment of last year using a SUM aggregation
         cmd.groupBy(cmd.getSelectExpressions());
         cmd.select(PAYMENTS_LAST_YEAR);
-        // Joins
-        cmd.join(EMP.DEPARTMENT_ID, DEP.ID);
-        cmd.joinLeft(EMP.ID, PAY.EMPLOYEE_ID).where(PAY.YEAR.is(lastYear));
-        // Where constraints
-        cmd.where(EMP.LAST_NAME.length().isGreaterThan(0));
-        cmd.where(EMP.GENDER.in(Gender.M, Gender.F));
-        cmd.where(EMP.RETIRED.is(false));
-        // Order by
-        cmd.orderBy(EMPLOYEE_FULLNAME);
 
         /*
          * Example for limitRows() and skipRows()
@@ -783,35 +782,36 @@ public class SampleApp
 
         // Employee total query
         DBColumnExpr EMP_TOTAL = PAY.AMOUNT.sum().as("EMP_TOTAL");
-        DBCommand cmdEmpTotal = db.createCommand();
-        cmdEmpTotal.select(PAY.EMPLOYEE_ID, EMP_TOTAL);
-        cmdEmpTotal.where (PAY.YEAR.is(lastYear));
-        cmdEmpTotal.groupBy(PAY.EMPLOYEE_ID);
-        DBQuery qryEmpTotal = new DBQuery(cmdEmpTotal, "qet");
+        DBCommand cmdEmpTotal = db.createCommand()
+           .select(PAY.EMPLOYEE_ID, EMP_TOTAL)
+           .where (PAY.YEAR.is(lastYear))
+           .groupBy(PAY.EMPLOYEE_ID);
+        DBQuery Q_EMP_TOTAL = new DBQuery(cmdEmpTotal, "qet");
         
         // Department total query
         DBColumnExpr DEP_TOTAL = PAY.AMOUNT.sum().as("DEP_TOTAL");
-        DBCommand cmdDepTotal  = db.createCommand();
-        cmdDepTotal.select(EMP.DEPARTMENT_ID, DEP_TOTAL);
-        cmdDepTotal.join  (PAY.EMPLOYEE_ID, EMP.ID);
-        cmdDepTotal.where (PAY.YEAR.is(lastYear));
-        cmdDepTotal.groupBy(EMP.DEPARTMENT_ID);
-        DBQuery qryDepTotal = new DBQuery(cmdDepTotal, "qdt");
-
-        DBColumnExpr PCT_OF_DEPARTMENT_COST = 
qryEmpTotal.column(EMP_TOTAL).multiplyWith(100).divideBy(qryDepTotal.column(DEP_TOTAL));
+        DBCommand cmdDepTotal  = db.createCommand()
+           .select(EMP.DEPARTMENT_ID, DEP_TOTAL)
+           .join  (PAY.EMPLOYEE_ID, EMP.ID)
+           .where (PAY.YEAR.is(lastYear))
+           .groupBy(EMP.DEPARTMENT_ID);
+        DBQuery Q_DEP_TOTAL = new DBQuery(cmdDepTotal, "qdt");
+
+        // Percentage of department
+        DBColumnExpr PCT_OF_DEP_COST = 
Q_EMP_TOTAL.column(EMP_TOTAL).multiplyWith(100).divideBy(Q_DEP_TOTAL.column(DEP_TOTAL));
         // Create the employee query
-        DBCommand cmd = db.createCommand();
-        cmd.select(EMP.ID, EMP.FIRST_NAME, EMP.LAST_NAME, 
DEP.NAME.as("DEPARTMENT"));
-        cmd.select(qryEmpTotal.column(EMP_TOTAL));
-        cmd.select(PCT_OF_DEPARTMENT_COST.as("PCT_OF_DEPARTMENT_COST"));
-        // join Employee with Department
-        cmd.join  (EMP.DEPARTMENT_ID, DEP.ID);
-        // Join with Subqueries
-        cmd.joinLeft(EMP.ID, qryEmpTotal.column(PAY.EMPLOYEE_ID));
-        cmd.joinLeft(DEP.ID, qryDepTotal.column(EMP.DEPARTMENT_ID));
-        // Order by
-        cmd.orderBy(DEP.NAME.desc());
-        cmd.orderBy(EMP.LAST_NAME);
+        DBCommand cmd = db.createCommand()
+           .select(EMP.ID, EMP.FIRST_NAME, EMP.LAST_NAME, 
DEP.NAME.as("DEPARTMENT"))
+           .select(Q_EMP_TOTAL.column(EMP_TOTAL))
+           .select(PCT_OF_DEP_COST.as("PCT_OF_DEPARTMENT_COST"))
+           // join Employee with Department
+           .join(EMP.DEPARTMENT_ID, DEP.ID)
+           // Join with Subqueries
+           .joinLeft(EMP.ID, Q_EMP_TOTAL.column(PAY.EMPLOYEE_ID))
+           .joinLeft(DEP.ID, Q_DEP_TOTAL.column(EMP.DEPARTMENT_ID))
+           // Order by
+           .orderBy(DEP.NAME.desc())
+           .orderBy(EMP.LAST_NAME);
            
         List<DataListEntry> list = context.getUtils().queryDataList(cmd);
         /* uncomment this to print full list
@@ -824,11 +824,11 @@ public class SampleApp
             // int depId = dle.getId(DEP);
             String empName = StringUtils.concat(", ", 
dle.getString(EMP.LAST_NAME), dle.getString(EMP.FIRST_NAME));
             String depName = dle.getString(DEP.NAME);
-            boolean hasPayments =!dle.isNull(qryEmpTotal.column(EMP_TOTAL));
+            boolean hasPayments =!dle.isNull(Q_EMP_TOTAL.column(EMP_TOTAL));
             if (hasPayments)
             {   // report
-                BigDecimal empTotal = 
dle.getDecimal(qryEmpTotal.column(EMP_TOTAL));
-                BigDecimal pctOfDep = 
dle.getDecimal(PCT_OF_DEPARTMENT_COST).setScale(1, RoundingMode.HALF_UP);
+                BigDecimal empTotal = 
dle.getDecimal(Q_EMP_TOTAL.column(EMP_TOTAL));
+                BigDecimal pctOfDep = 
dle.getDecimal(PCT_OF_DEP_COST).setScale(1, RoundingMode.HALF_UP);
                 log.info("Eployee[{}]: {}\tDepartment: {}\tPayments: {} ({}% 
of Department)", empId, empName, depName, empTotal, pctOfDep);
             }
             else
@@ -869,7 +869,7 @@ public class SampleApp
             log.info("Eployee[{}]: {}\tPhone: {}\tSalary: {}", 
StringUtils.toString(key), empName, phone, salary);
             // modify salary
             BigDecimal newSalary = new BigDecimal(2000 + ((Math.random()*200) 
- 100.0));
-            record.setValue(EMP.SALARY, newSalary);
+            record.set(EMP.SALARY, newSalary);
             // check
             if (record.wasModified(EMP.SALARY))
             {   // Salary was modified
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java 
b/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
index 5c5c693..b0e97f6 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
@@ -1343,5 +1343,17 @@ public abstract class DBColumnExpr extends DBExpr
     {
         return this.getDatabase().getColumnJavaType(this);
     }
-    
+ 
+    /**
+     * For Debugging
+     */
+    @Override
+    public String toString()
+    {
+        String name = getName();
+        if (StringUtils.isNotEmpty(name))
+            return getClass().getSimpleName() + "[" + name + "]";
+        // default
+        return super.toString();
+    }
 }
\ No newline at end of file
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 d3ca978..10159b3 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
@@ -193,7 +193,7 @@ public class DBCombinedCmd extends DBCommandExpr
     }
 
     @Override
-    public void orderBy(DBOrderByExpr... exprs)
+    public DBCommandExpr orderBy(DBOrderByExpr... exprs)
     {
         if (orderBy == null)
             orderBy = new ArrayList<DBOrderByExpr>();
@@ -203,6 +203,7 @@ public class DBCombinedCmd extends DBCommandExpr
             DBColumnExpr c = getCmdColumn(obe.getColumnExpr());
             orderBy.add(new DBOrderByExpr(c, obe.isDescending()));
         }
+        return this;
     }
 
 }
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 d16fd0d..3dfed66 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
@@ -34,6 +34,7 @@ import org.apache.empire.db.expr.join.DBColumnJoinExpr;
 import org.apache.empire.db.expr.join.DBCompareJoinExpr;
 import org.apache.empire.db.expr.join.DBCrossJoinExpr;
 import org.apache.empire.db.expr.join.DBJoinExpr;
+import org.apache.empire.db.expr.order.DBOrderByExpr;
 import org.apache.empire.db.expr.set.DBSetExpr;
 import org.apache.empire.dbms.DBSqlPhrase;
 import org.apache.empire.exceptions.InternalException;
@@ -201,11 +202,6 @@ public abstract class DBCommand extends DBCommandExpr
         }
     }
 
-    /**
-     * Returns the current DBDatabase object.
-     * 
-     * @return the current DBDatabase object
-     */
     @SuppressWarnings("unchecked")
     @Override
     public final DBDatabase getDatabase()
@@ -213,49 +209,53 @@ public abstract class DBCommand extends DBCommandExpr
         return db;
     }
 
+    /**
+     * Returns true if the this command has either Select or Set expressions
+     */
     @Override
     public boolean isValid()
     {
-       return isValidQuery() || isValidUpdate();
+       return hasSelectExpr() || hasSetExpr();
     }
 
     /**
-     * Returns whether the command object can produce a select sql-statement.
-     * 
-     * @return true if at least one select expression has been set
+     * Sets whether or not the select statement should contain
+     * the distinct directive .
      */
-    public boolean isValidQuery()
+    public DBCommand selectDistinct()
     {
-       return (select != null);
+       this.selectDistinct = true;
+       return this;
     }
 
     /**
-     * Returns whether the command object can produce a update sql-statement.
-     * 
-     * @return true if a set expression has been set.
+     * Returns whether or not the select statement will be distinct or not.
+     *  
+     * @return true if the select will contain the distinct directive or false 
otherwise.
      */
-    public boolean isValidUpdate()
+    public boolean isSelectDistinct()
     {
-        return (set != null);
+       return selectDistinct;
     }
-
+    
     /**
-     * Sets whether or not the select statement should contain
-     * the distinct directive .
+     * returns whether or not the command has any select expression 
+     * @return true if the command has any select expression of false otherwise
      */
-    public void selectDistinct()
+    @Override
+    public boolean hasSelectExpr()
     {
-       this.selectDistinct = true;
+        return (select!=null && !select.isEmpty());
     }
 
     /**
-     * Returns whether or not the select statement will be distinct or not.
-     *  
-     * @return true if the select will contain the distinct directive or false 
otherwise.
+     * returns whether or not the command has a specific select expression 
+     * @return true if the command contains the given select expression of 
false otherwise
      */
-    public boolean isSelectDistinct()
+    @Override
+    public boolean hasSelectExpr(DBColumnExpr expr)
     {
-       return selectDistinct;
+        return (select!=null ? (select.indexOf(expr)>=0) : false);
     }
     
     /**
@@ -263,12 +263,13 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param expr the DBColumnExpr object
      */
-    public void select(DBColumnExpr expr)
+    public DBCommand select(DBColumnExpr expr)
     {   // Select this column
         if (select == null)
             select = new ArrayList<DBColumnExpr>();
         if (expr != null && select.contains(expr) == false)
             select.add(expr);
+        return this;
     }
 
     /**
@@ -276,12 +277,13 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param exprs an vararg of DBColumnExpr's to select
      */
-    public final void select(DBColumnExpr... exprs)
+    public final DBCommand select(DBColumnExpr... exprs)
     {
         for (DBColumnExpr expr : exprs)
         {
             select(expr);
         }
+        return this;
     }
 
     /**
@@ -289,12 +291,13 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param columns the column expressions to add
      */
-    public final void select(Collection<? extends DBColumnExpr> columns)
+    public final DBCommand select(Collection<? extends DBColumnExpr> columns)
     {
         for (DBColumnExpr expr : columns)
         {
             select(expr);
         }
+        return this;
     }
 
     /**
@@ -302,12 +305,13 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param exprs one or more columns to select
      */
-    public void selectQualified(DBColumn... columns)
+    public DBCommand selectQualified(DBColumn... columns)
     {
         for (DBColumn col : columns)
         {
             select(col.qualified());
         }
+        return this;
     }
 
     /**
@@ -315,22 +319,42 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param columns the column expressions to add
      */
-    public final void selectQualified(Collection<? extends DBColumn> columns)
+    public final DBCommand selectQualified(Collection<? extends DBColumn> 
columns)
     {
         for (DBColumn col : columns)
         {
             select(col.qualified());
         }
+        return this;
+    }
+    
+    /**
+     * Returns an array of all select expressions
+     * 
+     * @return an array of all DBColumnExpr objects or <code>null</code> if 
there is nothing to select
+     */
+    @Override
+    public DBColumnExpr[] getSelectExprList()
+    {
+        int count = (select != null) ? select.size() : 0;
+        if (count < 1)
+            return null;
+        // The List
+        DBColumnExpr[] exprList = new DBColumnExpr[count];
+        for (int i = 0; i < count; i++)
+            exprList[i] = select.get(i);
+        // The expression List
+        return exprList;
     }
 
     /**
-     * returns whether or not a command contains a select expression
-     * @return true if the expression is contained in the select 
+     * Returns all select expressions as unmodifiable list
+     * @return the list of DBColumnExpr used for select
      */
-    public boolean containsSelect(DBColumnExpr selExpr)
+    @Override
+    public List<DBColumnExpr> getSelectExpressions()
     {
-        int idx = (select != null ? select.indexOf(selExpr) : -1);
-        return (idx<0);
+        return (this.select!=null ? Collections.unmodifiableList(this.select) 
: null);
     }
 
     /**
@@ -383,35 +407,11 @@ public abstract class DBCommand extends DBCommandExpr
     }
     
     /**
-     * returns true if prepared statements are enabled for this database
-     */
-    protected boolean isPreparedStatementsEnabled()
-    {
-        return db.isPreparedStatementsEnabled();
-    }
-    
-    /**
-     * returns true if a cmdParam should be used for the given column or false 
otherwise
-     */
-    protected boolean useCmdParam(DBColumn col, Object value)
-    {
-        // Cannot wrap DBExpr or DBSystemDate
-        if (value==null || value instanceof DBExpr || value instanceof 
DBDatabase.DBSystemDate)
-            return false;
-        // Check if prepared statements are enabled
-        if (isPreparedStatementsEnabled())
-            return true;
-        // Only use a command param if column is of type BLOB or CLOB
-        DataType dt = col.getDataType();
-        return ( dt==DataType.BLOB || dt==DataType.CLOB );
-    }
-    
-    /**
      * Adds a single set expressions to this command
      * Use column.to(...) to create a set expression 
      * @param expr the DBSetExpr object(s)
      */
-    public void set(DBSetExpr expr)
+    public DBCommand set(DBSetExpr expr)
     {
         if (set == null)
             set = new ArrayList<DBSetExpr>();
@@ -436,7 +436,7 @@ public abstract class DBCommand extends DBCommandExpr
                     // replace value
                     chk.value = expr.value;
                 }
-                return;
+                return this;
             }
         }
         // Replace with parameter 
@@ -444,6 +444,7 @@ public abstract class DBCommand extends DBCommandExpr
             expr.value = addParam(expr.column.getDataType(), expr.value);
         // new Value!
         set.add(expr);
+        return this;
     }
     
     /**
@@ -451,10 +452,11 @@ public abstract class DBCommand extends DBCommandExpr
      * Use column.to(...) to create a set expression 
      * @param expr the DBSetExpr object(s)
      */
-    public final void set(DBSetExpr... exprs)
+    public final DBCommand set(DBSetExpr... exprs)
     {
         for (int i=0; i<exprs.length; i++)
             set(exprs[i]);
+        return this;
     }
     
     /**
@@ -554,7 +556,7 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param join the join expression
      */
-    public void join(DBJoinExpr join)
+    public DBCommand join(DBJoinExpr join)
     {
         // check tables
         if (join.getLeftTable().equals(join.getRightTable()))
@@ -567,9 +569,10 @@ public abstract class DBCommand extends DBCommandExpr
         { // Check whether join exists
             DBJoinExpr item = joins.get(i);
             if (item.equals(join))
-                return;
+                return this;
         }
         joins.add(join);
+        return this;
     }
 
     /**
@@ -580,9 +583,9 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @return the join expresion 
      */
-    public final DBColumnJoinExpr join(DBColumnExpr left, DBColumn right)
+    public final DBCommand join(DBColumnExpr left, DBColumn right, 
DBCompareExpr... addlConstraints)
     {
-        return join(left, right, DBJoinType.INNER);
+        return join(left, right, DBJoinType.INNER, addlConstraints);
     }
 
     /**
@@ -595,9 +598,9 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @return the join expresion 
      */
-    public final DBColumnJoinExpr joinLeft(DBColumnExpr left, DBColumn right)
+    public final DBCommand joinLeft(DBColumnExpr left, DBColumn right, 
DBCompareExpr... addlConstraints)
     {
-        return join(left, right, DBJoinType.LEFT);
+        return join(left, right, DBJoinType.LEFT, addlConstraints);
     }
 
     /**
@@ -610,25 +613,34 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @return the join expresion 
      */
-    public final DBColumnJoinExpr joinRight(DBColumnExpr left, DBColumn right)
+    public final DBCommand joinRight(DBColumnExpr left, DBColumn right, 
DBCompareExpr... addlConstraints)
     {
-        return join(left, right, DBJoinType.RIGHT);
+        return join(left, right, DBJoinType.RIGHT, addlConstraints);
     }
 
     /**
      * Adds a join based on two columns to the list of join expressions.
      * 
+     * Migration hint from 2.x -> replace ").where(" with just "," 
+     * 
      * @param left the left join value
      * @param right the right join
      * @param joinType type of join ({@link DBJoinType#INNER}, {@link 
DBJoinType#LEFT}, {@link DBJoinType#RIGHT})
      * 
      * @return the join expression 
      */
-    public final DBColumnJoinExpr join(DBColumnExpr left, DBColumnExpr right, 
DBJoinType joinType)
+    public final DBCommand join(DBColumnExpr left, DBColumnExpr right, 
DBJoinType joinType, DBCompareExpr... addlConstraints)
     {
         DBColumnJoinExpr join = new DBColumnJoinExpr(left, right, joinType);
         join(join);
-        return join;
+        // additional constraints
+        DBCompareExpr where = null;
+        for (int i=0; i<addlConstraints.length; i++)
+            where = (where!=null ? where.and(addlConstraints[i]) : 
addlConstraints[i]);
+        if (where!=null)
+            join.where(where);
+        // done
+        return this;
     }
     
     /**
@@ -637,11 +649,12 @@ public abstract class DBCommand extends DBCommandExpr
      * @param right the right RowSet
      * @return the join expression
      */
-    public final DBCrossJoinExpr join(DBRowSet left, DBRowSet right)
+    public final DBCommand join(DBRowSet left, DBRowSet right)
     {
         DBCrossJoinExpr join = new DBCrossJoinExpr(left, right);
         join(join);
-        return join;
+        // done
+        return this;
     }
 
     /**
@@ -653,11 +666,11 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @return the join expresion 
      */
-    public final DBCompareJoinExpr join(DBRowSet rowset, DBCompareExpr cmp, 
DBJoinType joinType)
+    public final DBCommand join(DBRowSet rowset, DBCompareExpr cmp, DBJoinType 
joinType)
     {
         DBCompareJoinExpr join = new DBCompareJoinExpr(rowset, cmp, joinType); 
         join(join);
-        return join;
+        return this;
     }
 
     /**
@@ -668,7 +681,7 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @return the join expresion 
      */
-    public final DBCompareJoinExpr join(DBRowSet rowset, DBCompareExpr cmp)
+    public final DBCommand join(DBRowSet rowset, DBCompareExpr cmp)
     {
         return join(rowset, cmp, DBJoinType.INNER);
     }
@@ -812,11 +825,12 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param expr the DBCompareExpr object
      */
-    public void where(DBCompareExpr expr)
+    public DBCommand where(DBCompareExpr expr)
     {
         if (where == null)
             where = new ArrayList<DBCompareExpr>();
         setConstraint(where, expr);
+        return this;
     }
     
     /**
@@ -825,10 +839,11 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param expr the DBCompareExpr object
      */
-    public final void where(DBCompareExpr... exprs)
+    public final DBCommand where(DBCompareExpr... exprs)
     {
         for (int i=0; i<exprs.length; i++)
             where(exprs[i]);
+        return this;
     }
 
     /**
@@ -889,11 +904,12 @@ public abstract class DBCommand extends DBCommandExpr
      * adds a constraint to the having clause.
      * @param expr the DBCompareExpr object
      */
-    public void having(DBCompareExpr expr)
+    public DBCommand having(DBCompareExpr expr)
     {
         if (having == null)
             having = new ArrayList<DBCompareExpr>();
         setConstraint(having, expr);
+        return this;
     }
 
     /**
@@ -950,7 +966,7 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param exprs vararg of columns by which to group the rows
      */
-    public void groupBy(DBColumnExpr...exprs)
+    public DBCommand groupBy(DBColumnExpr...exprs)
     {
         if (groupBy == null)
             groupBy = new ArrayList<DBColumnExpr>();
@@ -960,6 +976,7 @@ public abstract class DBCommand extends DBCommandExpr
             if (expr.isAggregate()==false && groupBy.contains(expr)==false)
                 groupBy.add(expr);
         }
+        return this;
     }
 
     /**
@@ -967,61 +984,13 @@ public abstract class DBCommand extends DBCommandExpr
      * 
      * @param columns the column expressions to add
      */
-    public final void groupBy(Collection<? extends DBColumnExpr> columns)
+    public final DBCommand groupBy(Collection<? extends DBColumnExpr> columns)
     {
         for (DBColumnExpr expr : columns)
         {
             groupBy(expr);
         }
-    }
-    
-    /**
-     * returns whether or not the command has any select expression 
-     * @return true if the command has any select expression of false otherwise
-     */
-    @Override
-    public boolean hasSelectExpr()
-    {
-        return (select!=null && !select.isEmpty());
-    }
-
-    /**
-     * returns whether or not the command has a specific select expression 
-     * @return true if the command contains the given select expression of 
false otherwise
-     */
-    @Override
-    public boolean hasSelectExpr(DBColumnExpr expr)
-    {
-        return (select!=null ? (select.indexOf(expr)>=0) : false);
-    }
-    
-    /**
-     * Returns an array of all select expressions
-     * 
-     * @return an array of all DBColumnExpr objects or <code>null</code> if 
there is nothing to select
-     */
-    @Override
-    public DBColumnExpr[] getSelectExprList()
-    {
-        int count = (select != null) ? select.size() : 0;
-        if (count < 1)
-            return null;
-        // The List
-        DBColumnExpr[] exprList = new DBColumnExpr[count];
-        for (int i = 0; i < count; i++)
-            exprList[i] = select.get(i);
-        // The expression List
-        return exprList;
-    }
-
-    /**
-     * Returns all select expressions as unmodifiable list
-     * @return the list of DBColumnExpr used for select
-     */
-    @Override
-    public List<DBColumnExpr> getSelectExpressions()
-    {
-        return (this.select!=null ? Collections.unmodifiableList(this.select) 
: null);
+        return this;
     }
 
     /**
@@ -1084,6 +1053,51 @@ public abstract class DBCommand extends DBCommandExpr
     }
 
     /**
+     * Overridden to change return type from DBCommandExpr to DBCommand
+     */
+    @Override
+    public DBCommand orderBy(DBOrderByExpr... exprs)
+    {
+        return (DBCommand)super.orderBy(exprs);
+    }
+
+    /**
+     * Overridden to change return type from DBCommandExpr to DBCommand
+     */
+    @Override
+    public DBCommand orderBy(DBColumnExpr... exprs)
+    {
+        return (DBCommand)super.orderBy(exprs);
+    }
+
+    /**
+     * Overridden to change return type from DBCommandExpr to DBCommand
+     */
+    @Override
+    public DBCommand orderBy(DBColumnExpr expr, boolean desc)
+    {
+        return (DBCommand)super.orderBy(expr, desc);
+    }
+
+    /**
+     * Overridden to change return type from DBCommandExpr to DBCommand
+     */
+    @Override
+    public DBCommand limitRows(int limitRows)
+    {
+        return (DBCommand)super.limitRows(limitRows);
+    }
+
+    /**
+     * Overridden to change return type from DBCommandExpr to DBCommand
+     */
+    @Override
+    public DBCommand skipRows(int skipRows)
+    {
+        return (DBCommand)super.skipRows(skipRows);
+    }
+    
+    /**
      * Clears the entire command object.
      */
     public void clear()
@@ -1100,6 +1114,30 @@ public abstract class DBCommand extends DBCommandExpr
         clearLimit();
         resetParamUsage();
     }
+    
+    /**
+     * returns true if prepared statements are enabled for this database
+     */
+    protected boolean isPreparedStatementsEnabled()
+    {
+        return db.isPreparedStatementsEnabled();
+    }
+    
+    /**
+     * returns true if a cmdParam should be used for the given column or false 
otherwise
+     */
+    protected boolean useCmdParam(DBColumn col, Object value)
+    {
+        // Cannot wrap DBExpr or DBSystemDate
+        if (value==null || value instanceof DBExpr || value instanceof 
DBDatabase.DBSystemDate)
+            return false;
+        // Check if prepared statements are enabled
+        if (isPreparedStatementsEnabled())
+            return true;
+        // Only use a command param if column is of type BLOB or CLOB
+        DataType dt = col.getDataType();
+        return ( dt==DataType.BLOB || dt==DataType.CLOB );
+    }
 
     /**
      * adds a constraint to the 'where' or 'having' collections 
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 f78ea46..0509aac 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
@@ -421,12 +421,11 @@ public abstract class DBCommandExpr extends DBExpr
 
     /**
      * Adds an order by expression the command
-     * 
      * @param exprs vararg of orderBy expressions
      * 
      * @see org.apache.empire.db.DBCommandExpr#orderBy(DBColumnExpr, boolean)
      */
-    public void orderBy(DBOrderByExpr... exprs)
+    public DBCommandExpr orderBy(DBOrderByExpr... exprs)
     {
         if (orderBy == null)
             orderBy = new ArrayList<DBOrderByExpr>();
@@ -448,6 +447,7 @@ public abstract class DBCommandExpr extends DBExpr
                 orderBy.add(expr);
             }
         }
+        return this;
     }
 
     /**
@@ -455,12 +455,13 @@ public abstract class DBCommandExpr extends DBExpr
      * 
      * @param exprs vararg of column expressions
      */
-    public final void orderBy(DBColumnExpr... exprs)
+    public DBCommandExpr orderBy(DBColumnExpr... exprs)
     {
         for (DBColumnExpr expr : exprs)
         {
             orderBy(new DBOrderByExpr(expr, false));
         }
+        return this;
     }
 
     /**
@@ -469,9 +470,9 @@ public abstract class DBCommandExpr extends DBExpr
      * @param expr the DBColumnExpr object
      * @param desc if true, the results from select statement will sort top 
down
      */
-    public final void orderBy(DBColumnExpr expr, boolean desc)
+    public DBCommandExpr orderBy(DBColumnExpr expr, boolean desc)
     {
-        orderBy(new DBOrderByExpr(expr, desc));
+        return orderBy(new DBOrderByExpr(expr, desc));
     }
 
     /**
@@ -479,7 +480,7 @@ public abstract class DBCommandExpr extends DBExpr
      * A negative value will remove the limit.
      *
      */
-    public void limitRows(int numRows)
+    public DBCommandExpr limitRows(int numRows)
     {
         throw new NotSupportedException(this, "limitRows");
     }
@@ -488,7 +489,7 @@ public abstract class DBCommandExpr extends DBExpr
      * sets the offset of the first row to return when executing a query 
command.
      * A negative value will remove the offset.
      */
-    public void skipRows(int numRows)
+    public DBCommandExpr skipRows(int numRows)
     {
         throw new NotSupportedException(this, "skipRows");
     }
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 9428007..e6e5ddc 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
@@ -646,7 +646,7 @@ public abstract class DBDatabase extends DBObject
      */
     protected void addTable(DBTable table)
     { // find column by name
-        if (table == null || table.getDatabase() != this)
+        if (table == null || table.db != this)
             throw new InvalidArgumentException("table", table);
         if (tables.contains(table)==true)
             throw new ItemExistsException(table.getName());
@@ -814,7 +814,7 @@ public abstract class DBDatabase extends DBObject
      */
     protected void addView(DBView view)
     { // find column by name
-        if (view == null || view.getDatabase() != this)
+        if (view == null || view.db != this)
             throw new InvalidArgumentException("view", view);
         if (views.contains(view) == true)
             throw new ItemExistsException(view.getName());
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBQuery.java 
b/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
index 166634b..c6bf2e4 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
@@ -240,7 +240,7 @@ public class DBQuery extends DBRowSet
      * @param expr the DBColumnExpr object
      * @return the query column
      */
-    public DBQueryColumn findQueryColumn(DBColumnExpr expr)
+    public DBQueryColumn findColumn(DBColumnExpr expr)
     {
         for (int i = 0; i < queryColumns.length; i++)
         {
@@ -257,7 +257,7 @@ public class DBQuery extends DBRowSet
      * @param the column name
      * @return the query column
      */
-    public DBQueryColumn findQueryColumn(String name)
+    public DBQueryColumn findColumn(String name)
     {
         for (int i = 0; i < queryColumns.length; i++)
         {
@@ -276,7 +276,10 @@ public class DBQuery extends DBRowSet
      */
     public DBQueryColumn column(DBColumnExpr expr)
     {
-        return findQueryColumn(expr);
+        DBQueryColumn col = findColumn(expr);
+        if (col==null)
+            throw new ItemNotFoundException(expr);
+        return col;
     }
     
     /**
@@ -287,7 +290,10 @@ public class DBQuery extends DBRowSet
      */
     public DBQueryColumn column(String name)
     {
-        return findQueryColumn(name);
+        DBQueryColumn col = findColumn(name);
+        if (col==null)
+            throw new ItemNotFoundException(name);
+        return col;
     }
     
     /**
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 0855195..3033b66 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
@@ -239,17 +239,19 @@ public class DBRecord extends DBRecordBase
     /**
      * Creates a new record
      */
-    public void create(Object[] initalKey)
+    public DBRecord create(Object[] initalKey)
     {
         getRowSet().createRecord(this, initalKey, true);
+        return this;
     }
 
     /**
      * Creates a new record
      */
-    public void create()
+    public DBRecord create()
     {
         getRowSet().createRecord(this, null, false);
+        return this;
     }
     
     /**
@@ -257,27 +259,29 @@ public class DBRecord extends DBRecordBase
      * Hint: variable args param (Object...) caused problems with migration
      * @param key an array of the primary key values
      */
-    public void read(Object[] key)
+    public DBRecord read(Object[] key)
     {   // read
         getRowSet().readRecord(this, key);
+        return this;
     }
 
     /**
      * Reads a record from the database
      * @param id the record id value
      */
-    public final void read(long id)
+    public final DBRecord read(long id)
     {
-        read(new Object[] {id});
+        return read(new Object[] {id});
     }
     
     /**
      * Reads a record from the database
      * @param key an array of the primary key values
      */
-    public void read(DBCompareExpr whereConstraints)
+    public DBRecord read(DBCompareExpr whereConstraints)
     {
         getRowSet().readRecord(this, whereConstraints);
+        return this;
     }
     
     /**
@@ -290,9 +294,35 @@ public class DBRecord extends DBRecordBase
      * @param mode flag whether to include only the given columns or whether 
to add all but the given columns
      * @param columns the columns to include or exclude (depending on mode)
      */
-    public void read(Object[] key, PartialMode mode, DBColumn... columns)
+    public DBRecord read(Object[] key, PartialMode mode, DBColumn... columns)
     {
         getRowSet().readRecord(this, key, mode, columns);
+        return this;
+    }
+
+    /**
+     * Sets the value of a column in the record.
+     * Same as getValue but provided in conjunction with set(...)
+
+     * @param column a DBColumn object
+     * @param value the value
+     */
+    public final Object get(Column column)
+    {   
+        return getValue(column);
+    }
+
+    /**
+     * Sets the value of a column in the record.
+     * Same as setValue but allows chaining as it returns itself
+
+     * @param column a DBColumn object
+     * @param value the value
+     */
+    public final DBRecord set(Column column, Object value)
+    {   
+        setValue(getFieldIndex(column), value);
+        return this;
     }
 
     /**
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java 
b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
index ea452a5..d9d5805 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
@@ -621,7 +621,7 @@ public abstract class DBRecordBase extends DBRecordData 
implements Record, Clone
     }
 
     /**
-     * Sets the value of the column in the record.
+     * Sets the value of a column in the record.
      * The functions checks if the column and the value are valid and whether 
the
      * value has changed.
      * 
@@ -680,7 +680,7 @@ public abstract class DBRecordBase extends DBRecordData 
implements Record, Clone
     }
 
     /**
-     * Sets the value of the column in the record.
+     * Sets the value of a column in the record.
      * The functions checks if the column and the value are valid and whether 
the
      * value has changed.
      * 
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordBean.java 
b/empire-db/src/main/java/org/apache/empire/db/DBRecordBean.java
index bdcb7ac..73638cb 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordBean.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordBean.java
@@ -161,11 +161,12 @@ public class DBRecordBean extends DBRecordBase
     /**
      * Creates a new record
      */
-    public void create(DBContext context, DBRowSet rowset, Object[] initalKey)
+    public DBRecordBean create(DBContext context, DBRowSet rowset, Object[] 
initalKey)
     {
         try {
             this.tempContext = context;
             rowset.createRecord(this, initalKey, true);
+            return this;
         } finally {
             this.tempContext = null;
         }
@@ -174,11 +175,12 @@ public class DBRecordBean extends DBRecordBase
     /**
      * Creates a new record
      */
-    public void create(DBContext context, DBRowSet rowset)
+    public DBRecordBean create(DBContext context, DBRowSet rowset)
     {
         try {
             this.tempContext = context;
             rowset.createRecord(this, null, false);
+            return this;
         } finally {
             this.tempContext = null;
         }
@@ -189,11 +191,12 @@ public class DBRecordBean extends DBRecordBase
      * Hint: variable args param (Object...) caused problems with migration
      * @param key an array of the primary key values
      */
-    public void read(DBContext context, DBRowSet rowset, Object[] key)
+    public DBRecordBean read(DBContext context, DBRowSet rowset, Object[] key)
     {   // read
         try {
             this.tempContext = context;
             rowset.readRecord(this, key);
+            return this;
         } finally {
             this.tempContext = null;
         }
@@ -203,20 +206,21 @@ public class DBRecordBean extends DBRecordBase
      * Reads a record from the database
      * @param id the record id value
      */
-    public final void read(DBContext context, DBRowSet rowset, long id)
+    public final DBRecordBean read(DBContext context, DBRowSet rowset, long id)
     {
-        read(context, rowset, new Object[] {id});
+        return read(context, rowset, new Object[] {id});
     }
     
     /**
      * Reads a record from the database
      * @param key an array of the primary key values
      */
-    public void read(DBContext context, DBRowSet rowset, DBCompareExpr 
whereConstraints)
+    public DBRecordBean read(DBContext context, DBRowSet rowset, DBCompareExpr 
whereConstraints)
     {   // read
         try {
             this.tempContext = context;
             rowset.readRecord(this, whereConstraints);
+            return this;
         } finally {
             this.tempContext = null;
         }
@@ -232,15 +236,41 @@ public class DBRecordBean extends DBRecordBase
      * @param mode flag whether to include only the given columns or whether 
to add all but the given columns
      * @param columns the columns to include or exclude (depending on mode)
      */
-    public void read(DBContext context, DBRowSet rowset, Object[] key, 
PartialMode mode, DBColumn... columns)
+    public DBRecordBean read(DBContext context, DBRowSet rowset, Object[] key, 
PartialMode mode, DBColumn... columns)
     {   // read
         try {
             this.tempContext = context;
             rowset.readRecord(this, key, mode, columns);
+            return this;
         } finally {
             this.tempContext = null;
         }
     }
+
+    /**
+     * Sets the value of a column in the record.
+     * Same as getValue but provided in conjunction with set(...)
+
+     * @param column a DBColumn object
+     * @param value the value
+     */
+    public final Object get(Column column)
+    {   
+        return getValue(column);
+    }
+
+    /**
+     * Sets the value of a column in the record.
+     * Same as setValue but allows chaining as it returns itself
+
+     * @param column a DBColumn object
+     * @param value the value
+     */
+    public final DBRecordBean set(Column column, Object value)
+    {   
+        setValue(getFieldIndex(column), value);
+        return this;
+    }
     
     /**
      * Updates the record in the database
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/h2/DBMSHandlerH2.java 
b/empire-db/src/main/java/org/apache/empire/dbms/h2/DBMSHandlerH2.java
index 3de0741..98dd19a 100644
--- a/empire-db/src/main/java/org/apache/empire/dbms/h2/DBMSHandlerH2.java
+++ b/empire-db/src/main/java/org/apache/empire/dbms/h2/DBMSHandlerH2.java
@@ -67,19 +67,21 @@ public class DBMSHandlerH2 extends DBMSHandlerBase
         }
     
            @Override
-           public void limitRows(int limitRows)
+           public DBCommand limitRows(int limitRows)
            {
                // set limit
                this.limitRows = limitRows;
+               return this;
            }
        
            @Override
-           public void skipRows(int skipRows)
+           public DBCommand skipRows(int skipRows)
            {
                if (skipRows<0)
                    throw new InvalidArgumentException("skipRows", skipRows);
                // set skip
                this.skipRows = skipRows; 
+            return this;
            }
             
            @Override
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/mysql/DBMSHandlerMySQL.java 
b/empire-db/src/main/java/org/apache/empire/dbms/mysql/DBMSHandlerMySQL.java
index 6037e6b..a53e41b 100644
--- a/empire-db/src/main/java/org/apache/empire/dbms/mysql/DBMSHandlerMySQL.java
+++ b/empire-db/src/main/java/org/apache/empire/dbms/mysql/DBMSHandlerMySQL.java
@@ -71,15 +71,17 @@ public class DBMSHandlerMySQL extends DBMSHandlerBase
         }
         
         @Override
-        public void limitRows(int numRows)
+        public DBCommand limitRows(int numRows)
         {
             limit = numRows;
+            return this;
         }
 
         @Override
-        public void skipRows(int numRows)
+        public DBCommand skipRows(int numRows)
         {
             skip = numRows;
+            return this;
         }
          
         @Override
@@ -926,14 +928,16 @@ public class DBMSHandlerMySQL extends DBMSHandlerBase
                        protected int limit = -1;
             protected int skip  = -1;
             @Override
-            public void limitRows(int numRows)
+            public DBCommandExpr limitRows(int numRows)
             {
                 limit = numRows;
+                return this;
             }
             @Override
-            public void skipRows(int numRows)
+            public DBCommandExpr skipRows(int numRows)
             {
                 skip = numRows;
+                return this;
             }
             @Override
             public void clearLimit()
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/oracle/DBCommandOracle.java 
b/empire-db/src/main/java/org/apache/empire/dbms/oracle/DBCommandOracle.java
index ad6b32a..58222c0 100644
--- a/empire-db/src/main/java/org/apache/empire/dbms/oracle/DBCommandOracle.java
+++ b/empire-db/src/main/java/org/apache/empire/dbms/oracle/DBCommandOracle.java
@@ -128,19 +128,21 @@ public class DBCommandOracle extends DBCommand
     }
     
     @Override
-    public void limitRows(int limitRows)
+    public DBCommandOracle limitRows(int limitRows)
     {
         // set limit
         this.limitRows = limitRows;
+        return this;
     }
 
     @Override
-    public void skipRows(int skipRows)
+    public DBCommandOracle skipRows(int skipRows)
     {
         if (skipRows<0)
             throw new InvalidArgumentException("skipRows", skipRows);
         // set skip
-        this.skipRows = skipRows; 
+        this.skipRows = skipRows;
+        return this;
     }
      
     @Override
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBMSHandlerPostgreSQL.java
 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBMSHandlerPostgreSQL.java
index 37e854b..04709c4 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBMSHandlerPostgreSQL.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/postgresql/DBMSHandlerPostgreSQL.java
@@ -92,15 +92,17 @@ public class DBMSHandlerPostgreSQL extends DBMSHandlerBase
         }
         
         @Override
-        public void limitRows(int numRows)
+        public DBCommand limitRows(int numRows)
         {
             limit = numRows;
+            return this;
         }
 
         @Override
-        public void skipRows(int numRows)
+        public DBCommand skipRows(int numRows)
         {
             skip = numRows;
+            return this;
         }
          
         @Override
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
index 2ca3cba..bd4f4af 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
@@ -79,13 +79,14 @@ public class DBMSHandlerSQLite extends DBMSHandlerBase
         }
         
         @Override
-               public void join(DBJoinExpr join)
+               public DBCommandSQLite join(DBJoinExpr join)
         {
             // http://www.sqlite.org/omitted.html
             if (join.getType() != DBJoinType.LEFT) {
                 throw new NotImplementedException(join.getType(), 
join.getLeftTable().getName() + " join " + join.getRightTable().getName()); 
             }
             super.join(join);
+            return this;
         }
         
         @Override
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlserver/DBMSHandlerMSSQL.java
 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlserver/DBMSHandlerMSSQL.java
index 6b7234b..ae442b9 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlserver/DBMSHandlerMSSQL.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlserver/DBMSHandlerMSSQL.java
@@ -70,9 +70,10 @@ public class DBMSHandlerMSSQL extends DBMSHandlerBase
        }
         
         @Override
-        public void limitRows(int numRows)
+        public DBCommand limitRows(int numRows)
         {
             limit = numRows;
+            return this;
         }
          
         @Override

Reply via email to