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 28fd063  EMPIREDB-362 Api-cleanup 2
28fd063 is described below

commit 28fd06338c53b3b1825a177522868d80d4468d5e
Author: Rainer Döbele <[email protected]>
AuthorDate: Sun Feb 6 18:39:55 2022 +0100

    EMPIREDB-362 Api-cleanup 2
---
 .../main/java/org/apache/empire/data/Record.java   |  7 +++--
 .../org/apache/empire/data/list/DataListEntry.java |  4 +--
 .../main/java/org/apache/empire/db/DBQuery.java    | 36 +++++++++++-----------
 .../main/java/org/apache/empire/db/DBRecord.java   |  8 +++--
 .../main/java/org/apache/empire/db/DBRowSet.java   | 16 +++++-----
 .../main/java/org/apache/empire/db/DBTable.java    | 16 ----------
 6 files changed, 39 insertions(+), 48 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/data/Record.java 
b/empire-db/src/main/java/org/apache/empire/data/Record.java
index a976318..ec8532b 100644
--- a/empire-db/src/main/java/org/apache/empire/data/Record.java
+++ b/empire-db/src/main/java/org/apache/empire/data/Record.java
@@ -21,6 +21,7 @@ package org.apache.empire.data;
 import java.util.Collection;
 
 import org.apache.empire.commons.Options;
+import org.apache.empire.exceptions.InvalidArgumentException;
 
 
 /**
@@ -39,9 +40,11 @@ public interface Record extends RecordData
      * @param parts
      * @return
      */
-    public static Object[] key(Object... parts)
+    public static Object[] key(Object... values)
     {
-        return parts;
+        if (values.length==0)
+            throw new InvalidArgumentException("values", values);
+        return values;
     }
 
     /**
diff --git 
a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java 
b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
index eb75585..c8cc276 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
@@ -76,7 +76,7 @@ public class DataListEntry implements RecordData, Serializable
         return ObjectUtils.getLong(getValue(keyColumns[0]));
     }
     
-    public boolean compareKey(Column[] keyColumns, Object[] keyValues)
+    public boolean compareKey(Column[] keyColumns, Object[] key)
     {
         for (int i=0; i<keyColumns.length; i++)
         {   // find field
@@ -84,7 +84,7 @@ public class DataListEntry implements RecordData, Serializable
             if (index<0)
                 throw new ItemNotFoundException(keyColumns[i].getName());
             // compare
-            if (!ObjectUtils.compareEqual(values[index], keyValues[i]))
+            if (!ObjectUtils.compareEqual(values[index], key[i]))
                 return false; // not equal
         }
         // found
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 67a92af..1fc514d 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
@@ -416,27 +416,27 @@ public class DBQuery extends DBRowSet
     /**
      * Updates a query record by creating individual update commands for each 
table.
      * 
-     * @param rec the DBRecord object. contains all fields and the field 
properties
+     * @param record the DBRecord object. contains all fields and the field 
properties
      * @param conn a valid connection to the database.
      */
     @Override
-    public void updateRecord(DBRecord rec)
+    public void updateRecord(DBRecord record)
     {
         // check updateable
         if (isUpdateable()==false)
             throw new NotSupportedException(this, "updateRecord");
         // check params
-        if (rec == null)
+        if (record == null)
             throw new InvalidArgumentException("record", null);
         // Has record been modified?
-        if (rec.isModified() == false)
+        if (record.isModified() == false)
             return; // Nothing to update
         // Must have key Columns
         DBColumn[] keyColumns = getKeyColumns();
         if (keyColumns==null)
             throw new NoPrimaryKeyException(this);
         // Get the fields and the flags
-        Object[] fields = rec.getFields();
+        Object[] fields = record.getFields();
         // Get all Update Commands
         Map<DBRowSet, DBCommand> updCmds = new HashMap<DBRowSet, DBCommand>(3);
         for (int i = 0; i < columns.size(); i++)
@@ -455,7 +455,7 @@ public class DBQuery extends DBRowSet
              * if (updateTimestampColumns.contains( col ) ) { // Check the 
update timestamp cmd.set( col.to( DBDatabase.SYSDATE ) ); }
              */
             // Set the field Value
-            boolean modified = rec.wasModified(i);
+            boolean modified = record.wasModified(i);
             if (modified == true)
             { // Update a field
                 if (col.isReadOnly() && log.isDebugEnabled())
@@ -467,11 +467,11 @@ public class DBQuery extends DBRowSet
             }
         }
         // the connection
-        DBContext context = rec.getContext();
+        DBContext context = record.getContext();
         Connection conn = context.getConnection();
         // the commands
         DBCommand cmd = getCommandFromExpression();
-        Object[] key  = getRecordKey(rec);
+        Object[] key  = getRecordKey(record);
         DBRowSet table= null;
         DBCommand upd = null;
         for(Entry<DBRowSet,DBCommand> entry:updCmds.entrySet())
@@ -493,10 +493,10 @@ public class DBQuery extends DBRowSet
                 DBColumn left  = join.getLeft() .getUpdateColumn();
                 DBColumn right = join.getRight().getUpdateColumn();
                 if (left.getRowSet()==table && table.isKeyColumn(left))
-                    if (!addJoinRestriction(upd, left, right, keyColumns, key, 
rec))
+                    if (!addJoinRestriction(upd, left, right, keyColumns, key, 
record))
                         throw new ItemNotFoundException(left.getFullName());
                 if (right.getRowSet()==table && table.isKeyColumn(right))
-                    if (!addJoinRestriction(upd, right, left, keyColumns, key, 
rec))
+                    if (!addJoinRestriction(upd, right, left, keyColumns, key, 
record))
                         throw new ItemNotFoundException(right.getFullName());
             }
             // Evaluate Existing restrictions
@@ -590,7 +590,7 @@ public class DBQuery extends DBRowSet
             }
         }
         // success
-        rec.updateComplete();
+        record.updateComplete();
     }
 
     /**
@@ -608,24 +608,24 @@ public class DBQuery extends DBRowSet
     /**
      * Adds join restrictions to the supplied command object.
      */
-    protected boolean addJoinRestriction(DBCommand upd, DBColumn updCol, 
DBColumn keyCol, DBColumn[] keyColumns, Object[] keyValues, DBRecord rec)
+    protected boolean addJoinRestriction(DBCommand cmd, DBColumn updCol, 
DBColumn joinCol, DBColumn[] keyColumns, Object[] key, DBRecord record)
     {   // Find key for foreign field
-        for (int i = 0; keyValues!=null && i < keyColumns.length; i++)
-            if (keyColumns[i]==keyCol)
+        for (int i = 0; key!=null && i < keyColumns.length; i++)
+            if (keyColumns[i]==joinCol)
             {   // Set Field from Key
-                upd.where(updCol.is(keyValues[i]));
+                cmd.where(updCol.is(key[i]));
                 return true;
             }
         // Not found, what about the record
         int index = this.getColumnIndex(updCol);
         if (index<0)
-            index = this.getColumnIndex(keyCol);
+            index = this.getColumnIndex(joinCol);
         if (index>=0)
         {   // Field Found
-            if (rec.wasModified(index))
+            if (record.wasModified(index))
                 return false; // Ooops, Key field has changed
             // Set Constraint
-            upd.where(updCol.is(rec.getValue(index)));
+            cmd.where(updCol.is(record.getValue(index)));
             return true;
         }
         return false;
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 e2af34b..708dce8 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
@@ -219,12 +219,14 @@ public class DBRecord extends DBRecordData implements 
Record, Cloneable, Seriali
 
     /**
      * varArgs to Array
-     * @param parts
+     * @param values
      * @return
      */
-    public static Object[] key(Object... parts)
+    public static Object[] key(Object... values)
     {
-        return parts;
+        if (values.length==0)
+            throw new InvalidArgumentException("values", values);
+        return values;
     }
 
     // Context and RowSet
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java 
b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
index a5f33dd..ad443dc 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
@@ -564,13 +564,15 @@ public abstract class DBRowSet extends DBExpr implements 
Entity
     }
 
     /**
-     * Initializes a DBRecord for this RowSet and sets primary key values (the 
Object[] keyValues).
+     * Initializes a DBRecord for this RowSet and sets primary key values.
      * The record may then be modified and updated.<BR>
      * <P>
      * @param record the Record object
-     * @param keyValues an array of the primary key columns
+     * @param key an array of the values for the primary key
+     * @param fieldInitMode indicates how to initializes the record fields
+     * @param newRecord true if the record is new or false if it is an 
existing record
      */
-    protected void initRecord(DBRecord record, Object[] keyValues, 
FieldInitMode fieldInitMode, boolean newRecord)
+    protected void initRecord(DBRecord record, Object[] key, FieldInitMode 
fieldInitMode, boolean newRecord)
     {
         // check param
         checkParamRecord("record", record, false);
@@ -583,13 +585,13 @@ public abstract class DBRowSet extends DBExpr implements 
Entity
          * ![fields[i] <> ObjectUtils.NO_VALUE];
          */    
         // Init Key Values
-        if (keyValues != null)
+        if (key != null)
         {   // Check Columns
             DBColumn[] keyColumns =(DBColumn[])getKeyColumns();
             if (keyColumns==null)
                 throw new NoPrimaryKeyException(this);
-            if (keyValues.length!=keyColumns.length)
-                throw new InvalidArgumentException("keyValues", keyValues);
+            if (key.length!=keyColumns.length)
+                throw new InvalidArgumentException("key", key);
             for (int i = 0; i < keyColumns.length; i++)
             {   // check
                 DBColumn keyColumn = keyColumns[i]; 
@@ -597,7 +599,7 @@ public abstract class DBRowSet extends DBExpr implements 
Entity
                     throw new FieldIsReadOnlyException(keyColumn);
                 // Ignore Validity Checks
                 int field = getColumnIndex(keyColumn);
-                fields[field] = keyValues[i];
+                fields[field] = key[i];
             }
         }
         // Set defaults (don't provide connection here)
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 d3a92c5..da73c36 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
@@ -645,22 +645,6 @@ public class DBTable extends DBRowSet implements Cloneable
     {
         this.cascadeDeleteAction = cascadeDeleteAction;
     }
-    
-    /**
-     * Creates a record key from a list of key values.
-     * The supplied values must be in the correct order. 
-     * @param keyValues
-     * @return the record key
-     */
-    public Object[] key(Object... keyValues)
-    {   // Check size
-        if (keyValues==null || keyValues.length==0)
-            throw new InvalidArgumentException("keyValues", keyValues);
-        if (this.primaryKey!=null && 
keyValues.length!=this.primaryKey.getColumnCount())
-            throw new InvalidArgumentException("keyValues:length", 
keyValues.length);
-        // Return the key
-        return keyValues;
-    }
 
     /**
      * Creates a delete SQL-Command by using the DBCommand getDelete method

Reply via email to