You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2012/08/31 13:42:30 UTC

svn commit: r1379422 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBRecord.java DBRowSet.java

Author: doebele
Date: Fri Aug 31 11:42:30 2012
New Revision: 1379422

URL: http://svn.apache.org/viewvc?rev=1379422&view=rev
Log:
EMPIREDB-167 
avoid function name clash in DBRecord -> rename init(..) to initData(...)

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java?rev=1379422&r1=1379421&r2=1379422&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java Fri Aug 31 11:42:30 2012
@@ -110,22 +110,24 @@ public class DBRecord extends DBRecordDa
      * @param state the state of the record 
      * @param rowSetData any further RowSet specific data
      */
-    protected void init(DBRowSet rowset, Object rowSetData, boolean newRecord)
+    protected void initData(DBRowSet rowset, Object rowSetData, boolean newRecord)
     {
-        // Init
-    	boolean rowsetChanged = (this.rowset != rowset); 
+        // Init rowset
+        boolean rowsetChanged = (this.rowset != rowset);
         if (rowsetChanged)
+            fields = null;
+        this.rowset = rowset;
+        // Init fields
+        if (rowset!=null)
         {   // Set Rowset
-            this.rowset = rowset;
-            if (rowset!=null)
-                fields = new Object[rowset.getColumns().size()];
+            int colCount = rowset.getColumns().size();
+            if (fields==null || fields.length!=colCount)
+                fields = new Object[colCount];
             else
-                fields = null;
-        }
-        else if (fields!=null)
-        {   // clear fields
-            for (int i=0; i<fields.length; i++)
-                fields[i]=null; // ObjectUtils.NO_VALUE -> works too (difference?);
+            {   // clear fields
+                for (int i=0; i<fields.length; i++)
+                    fields[i]=null; // ObjectUtils.NO_VALUE -> works too (difference?);
+            }
         }
         // Set State
         this.rowsetData = rowSetData;
@@ -133,9 +135,9 @@ public class DBRecord extends DBRecordDa
         changeState((rowset==null ? State.Invalid : (newRecord ? State.New : State.Valid)));
         // notify
         if (rowsetChanged)
-        	onRowSetChanged();
+            onRowSetChanged();
     }
-
+    
     /**
      * changes the state of the record
      * @param newState
@@ -161,7 +163,13 @@ public class DBRecord extends DBRecordDa
     @Override
     public void close()
     {
-        init(null, null, false);
+        // rowset = null; -- do not change this --
+        fields = null;
+        modified = null;
+        rowsetData = null;
+        // change state
+        if (state!=State.Invalid)
+            changeState(State.Invalid);
     }
     
     /** {@inheritDoc} */
@@ -575,7 +583,7 @@ public class DBRecord extends DBRecordDa
      */
     public final void setValue(Column column, Object value)
     {
-        if (rowset == null)
+        if (!isValid())
             throw new ObjectNotValidException(this);
         // Get Column Index
         setValue(rowset.getColumnIndex(column), value);
@@ -589,10 +597,13 @@ public class DBRecord extends DBRecordDa
      */
     protected boolean allowFieldChange(DBColumn column)
     {
-        if (column.isAutoGenerated())
+        // Check auto generated
+        if (column.isAutoGenerated() && (!isNew() || !isNull(column)))
         	return false;
-        if (state!=State.New && rowset.isKeyColumn(column))
+        // Check key Column
+        if (!isNew() && rowset.isKeyColumn(column))
         	return false;
+        // done
         return true;
     }
 
@@ -693,7 +704,10 @@ public class DBRecord extends DBRecordDa
      
     public void init(DBRowSet table, Object[] keyValues, boolean insert)
     { 	// Init with keys
-        table.initRecord(this, keyValues, insert);
+        if (table!=null)
+            table.initRecord(this, keyValues, insert);
+        else
+            initData(null, null, false);
     }
     
     /**
@@ -709,6 +723,9 @@ public class DBRecord extends DBRecordDa
      */
     public void create(DBRowSet table, Connection conn)
     {
+        if (table==null)
+            throw new InvalidArgumentException("table", table);
+        // create
         table.createRecord(this, conn);
     }
     
@@ -736,6 +753,9 @@ public class DBRecord extends DBRecordDa
      */
     public void read(DBRowSet table, Object[] keys, Connection conn)
     {
+        if (table==null)
+            throw new InvalidArgumentException("table", table);
+        // read
         table.readRecord(this, keys, conn);
     }
 
@@ -818,7 +838,7 @@ public class DBRecord extends DBRecordDa
     @Override
     public int addColumnDesc(Element parent)
     {
-        if (rowset == null)
+        if (!isValid())
             throw new ObjectNotValidException(this);
         // Add Field Description
         int count = 0;
@@ -843,7 +863,7 @@ public class DBRecord extends DBRecordDa
     @Override
     public int addRowValues(Element parent)
     {
-        if (rowset == null)
+        if (!isValid())
             throw new ObjectNotValidException(this);
         // set row key
         DBColumn[] keyColumns = rowset.getKeyColumns();
@@ -903,7 +923,7 @@ public class DBRecord extends DBRecordDa
     @Override
     public Document getXmlDocument()
     {
-        if (rowset == null)
+        if (!isValid())
             throw new ObjectNotValidException(this);
         // Create Document
         DBXmlDictionary xmlDic = getXmlDictionary();

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1379422&r1=1379421&r2=1379422&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Fri Aug 31 11:42:30 2012
@@ -475,7 +475,7 @@ public abstract class DBRowSet extends D
         if (columns.size() < 1)
             throw new ObjectNotValidException(this);
         // Init
-        rec.init(this, rowSetData, insert);
+        rec.initData(this, rowSetData, insert);
     }
 
     /**