empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1378894 - in /empire-db/trunk: empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/ empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/ empir...
Date Thu, 30 Aug 2012 11:56:01 GMT
Author: doebele
Date: Thu Aug 30 11:56:00 2012
New Revision: 1378894

URL: http://svn.apache.org/viewvc?rev=1378894&view=rev
Log:
EMPIREDB-167
Change record state property from int to enum (has been on the TODO)

Modified:
    empire-db/trunk/empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
    empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
    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
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/SerializeTest.java

Modified: empire-db/trunk/empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
Thu Aug 30 11:56:00 2012
@@ -21,13 +21,11 @@ package org.apache.empire.samples.cxf.ws
 
 import java.util.Date;
 
-import org.apache.empire.db.DBRecord;
-
 
 // Holds all the data represented by a department-record from the database
 public class Department {
 
-	private long departmentId = DBRecord.REC_NEW;
+	private long departmentId = 0;
 	private String name = "";
 	private String head = "";
 	private String businessUnit = "";

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
Thu Aug 30 11:56:00 2012
@@ -31,7 +31,7 @@ public abstract class SampleRecord<T ext
 	protected T T; // The table
 
 	public SampleRecord(T table) {
-		super.init(table, DBRecord.REC_INVALID, null);
+		super.init(table, DBRecord.State.Invalid, null);
 		this.T = table;
 	}
 

Modified: empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-struts2-cxf/src/main/java/org/apache/empire/samples/cxf/wssample/common/Department.java
Thu Aug 30 11:56:00 2012
@@ -21,13 +21,11 @@ package org.apache.empire.samples.cxf.ws
 
 import java.util.Date;
 
-import org.apache.empire.db.DBRecord;
-
 
 // Holds all the data represented by a department-record from the database
 public class Department {
 
-	private long departmentId = DBRecord.REC_NEW;
+	private long departmentId = 0;
 	private String name = "";
 	private String head = "";
 	private String businessUnit = "";

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java Thu Aug
30 11:56:00 2012
@@ -135,7 +135,7 @@ public abstract class DBCommandExpr exte
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
-        public void initRecord(DBRecord rec, int initialState, Object[] keyValues)
+        public void initRecord(DBRecord rec, DBRecord.State initialState, Object[] keyValues)
         {
             throw new NotSupportedException(this, "initRecord");
         }

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java Thu Aug 30 11:56:00
2012
@@ -343,7 +343,7 @@ public class DBQuery extends DBRowSet
      * @param keyValues an array of the primary key columns
      */
     @Override
-    public void initRecord(DBRecord rec, int initialState, Object[] keyValues)
+    public void initRecord(DBRecord rec, DBRecord.State initialState, Object[] keyValues)
     {
         // Prepare
         prepareInitRecord(rec, initialState, keyValues);
@@ -405,7 +405,7 @@ public class DBQuery extends DBRowSet
             // Read Record
             readRecord(rec, cmd, conn);
             // Set RowSetData
-            rec.changeState(DBRecord.REC_VALID, key.clone());
+            rec.changeState(DBRecord.State.Valid, key.clone());
         } catch (QueryNoResultException e) {
             // Record not found
             throw new RecordNotFoundException(this, key);
@@ -584,7 +584,7 @@ public class DBQuery extends DBRowSet
             }
         }
         // success
-        rec.changeState(DBRecord.REC_VALID, keys);
+        rec.changeState(DBRecord.State.Valid, keys);
     }
 
     /**

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=1378894&r1=1378893&r2=1378894&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 Thu Aug 30
11:56:00 2012
@@ -31,9 +31,9 @@ import org.apache.empire.data.Column;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.Record;
 import org.apache.empire.db.exceptions.FieldIsReadOnlyException;
+import org.apache.empire.exceptions.BeanPropertyGetException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
-import org.apache.empire.exceptions.BeanPropertyGetException;
 import org.apache.empire.xml.XMLUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,19 +50,30 @@ public class DBRecord extends DBRecordDa
 {
     private final static long serialVersionUID = 1L;
   
-    /*
-     * TODO convert to an enum?
-     */
-    public static final int REC_INVALID  = -1;
-    // public static final int REC_EMTPY    = 0;
-    public static final int REC_VALID    = 1;
-    public static final int REC_MODIFIED = 2;
-    public static final int REC_NEW      = 3;
+    /* Record state enum */
+    public enum State
+    {
+    	Invalid,
+    /*	Empty,  not used! */
+    	Valid,
+    	Modified,
+    	New;
+
+    	/* Accessors */
+    	boolean isLess(State other)
+    	{
+    		return this.ordinal()<other.ordinal();
+    	}
+    	boolean isEqualOrMore(State other)
+    	{
+    		return this.ordinal()>=other.ordinal();
+    	}
+    }
 
     protected static final Logger log    = LoggerFactory.getLogger(DBRecord.class);
 
     // This is the record data
-    private int             state;
+    private State           state;
     private DBRowSet        rowset;
     private Object[]        fields;
     private boolean[]       modified;
@@ -77,7 +88,7 @@ public class DBRecord extends DBRecordDa
      */
     public DBRecord()
     {
-        state = REC_INVALID;
+        state = State.Invalid;
         rowset = null;
         fields = null;
         modified = null;
@@ -90,7 +101,7 @@ public class DBRecord extends DBRecordDa
      * @param state the state of the record 
      * @param rowSetData any further RowSet specific data
      */
-    protected void init(DBRowSet rowset, int state, Object rowSetData)
+    protected void init(DBRowSet rowset, State state, Object rowSetData)
     {
         // Init
         if (this.rowset != rowset)
@@ -126,7 +137,7 @@ public class DBRecord extends DBRecordDa
      * @param state
      * @param rowSetData
      */
-    protected void changeState(int state, Object rowSetData)
+    protected void changeState(State state, Object rowSetData)
     {
         this.state = state;
         this.rowsetData = rowSetData;
@@ -139,7 +150,7 @@ public class DBRecord extends DBRecordDa
     @Override
     public void close()
     {
-        init(null, REC_INVALID, null);
+        init(null, State.Invalid, null);
     }
     
     /** {@inheritDoc} */
@@ -201,7 +212,7 @@ public class DBRecord extends DBRecordDa
      * 
      * @return the record state
      */
-    public int getState()
+    public State getState()
     {
         return state;
     }
@@ -213,7 +224,7 @@ public class DBRecord extends DBRecordDa
      */
     public boolean isValid()
     {
-        return (state >= DBRecord.REC_VALID);
+        return (state != State.Invalid);
     }
 
     /**
@@ -236,7 +247,7 @@ public class DBRecord extends DBRecordDa
      */
     public boolean isModified()
     {
-        return (state >= DBRecord.REC_MODIFIED);
+        return (state.isEqualOrMore(State.Modified));
     }
 
     /**
@@ -246,7 +257,7 @@ public class DBRecord extends DBRecordDa
      */
     public boolean isNew()
     {
-        return (state == DBRecord.REC_NEW);
+        return (state == State.New);
     }
 
     /**
@@ -335,7 +346,7 @@ public class DBRecord extends DBRecordDa
      */
     public boolean wasModified(int index)
     {
-        if (rowset == null)
+        if (!isValid())
             throw new ObjectNotValidException(this);
         if (index < 0 || index >= fields.length)
             throw new InvalidArgumentException("index", index);
@@ -363,9 +374,12 @@ public class DBRecord extends DBRecordDa
      * @param isModified modified or not
      */
     public void setModified(DBColumn column, boolean isModified)
-    {
+    {	// Check valid
+        if (state == State.Invalid)
+            throw new ObjectNotValidException(this);
+        // Check modified
         if (modified == null)
-        { // Save all original values
+        { 	// Init array
             modified = new boolean[fields.length];
             for (int j = 0; j < fields.length; j++)
                 modified[j] = false;
@@ -374,10 +388,10 @@ public class DBRecord extends DBRecordDa
         if (index >= 0)
             modified[index] = isModified;
         // Set State to modified, if not already at least modified and isModified is set
to true
-        if (state < REC_MODIFIED && isModified)
-            state = REC_MODIFIED;
+        if (state.isLess(State.Modified) && isModified)
+            state = State.Modified;
         // Reset state to unmodified, if currently modified and not modified anymore after
the change
-        if (state == REC_MODIFIED && !isModified)
+        if (state == State.Modified && !isModified)
         {
         	boolean recordNotModified = true;
             for (int j = 0; j < fields.length; j++)
@@ -389,7 +403,7 @@ public class DBRecord extends DBRecordDa
             }
             if (recordNotModified)
             {
-            	state = REC_VALID;
+            	state = State.Valid;
             }
         }
     }
@@ -483,7 +497,10 @@ public class DBRecord extends DBRecordDa
      * @param value the column value
      */
     public void modifyValue(int i, Object value)
-    { // Init original values
+    {	// Check valid
+        if (state == State.Invalid)
+            throw new ObjectNotValidException(this);
+        // Init original values
         if (modified == null)
         { // Save all original values
             modified = new boolean[fields.length];
@@ -496,8 +513,8 @@ public class DBRecord extends DBRecordDa
         // Set Value
         fields[i] = value;
         // Set State
-        if (state < REC_MODIFIED)
-            state = REC_MODIFIED;
+        if (state.isLess(State.Modified))
+            state = State.Modified;
         // field changed
         onFieldChanged(i);
     }
@@ -512,7 +529,7 @@ public class DBRecord extends DBRecordDa
      */
     public void setValue(int index, Object value)
     {
-        if (rowset == null)
+        if (state == State.Invalid)
             throw new ObjectNotValidException(this);
         if (index < 0 || index >= fields.length)
             throw new InvalidArgumentException("index", index);
@@ -528,6 +545,10 @@ public class DBRecord extends DBRecordDa
         {   // Read Only column may be set
             throw new FieldIsReadOnlyException(column);
         }
+        if (state!=State.New && rowset.isKeyColumn(column))
+        {   // Key columns cannot be changed
+            throw new FieldIsReadOnlyException(column);
+        }
         // Is Value valid
         column.validate(value);
         // Init original values
@@ -612,7 +633,7 @@ public class DBRecord extends DBRecordDa
      
     public void init(DBRowSet table, Object[] keyValues, boolean insert)
     { // Init with keys
-    	int initialState = (insert ? REC_NEW : REC_VALID);  
+    	State initialState = (insert ? State.New : State.Valid);  
         table.initRecord(this, initialState, keyValues);
     }
     

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=1378894&r1=1378893&r2=1378894&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 Thu Aug 30
11:56:00 2012
@@ -468,7 +468,7 @@ public abstract class DBRowSet extends D
      * @param rec the DBRecord object to initialize this DBRowSet object
      * @param state the state of this DBRowSet object
      */
-    protected void prepareInitRecord(DBRecord rec, int state, Object rowSetData)
+    protected void prepareInitRecord(DBRecord rec, DBRecord.State state, Object rowSetData)
     {
         if (rec==null)
             throw new InvalidArgumentException("rec", rec);
@@ -485,7 +485,7 @@ public abstract class DBRowSet extends D
      * @param rec the Record object
      * @param keyValues an array of the primary key columns
      */
-    public void initRecord(DBRecord rec, int initialState, Object[] keyValues)
+    public void initRecord(DBRecord rec, DBRecord.State initialState, Object[] keyValues)
     {
         // Prepare
         prepareInitRecord(rec, initialState, null);
@@ -521,7 +521,7 @@ public abstract class DBRowSet extends D
     public void initRecord(DBRecord rec, DBRecordData recData)
     {
         // Initialize the record
-        prepareInitRecord(rec, DBRecord.REC_VALID, null);
+        prepareInitRecord(rec, DBRecord.State.Valid, null);
         // Get Record Field Values
         Object[] fields = rec.getFields();
         for (int i = 0; i < fields.length; i++)
@@ -693,7 +693,8 @@ public abstract class DBRowSet extends D
         // Check Arguments
         if (rec == null)
             throw new InvalidArgumentException("record", rec);
-        // Check Arguments
+        if (rec.isValid()==false)
+            throw new ObjectNotValidException(rec);
         if (conn == null)
             throw new InvalidArgumentException("conn", conn);
         // Get the new Timestamp
@@ -706,106 +707,107 @@ public abstract class DBRowSet extends D
         DBCommand cmd = db.createCommand();
         String sql = null;
         int setCount = 0;
-        switch (rec.getState())
-        {
-            case DBRecord.REC_MODIFIED:
-                if (primaryKey == null)
-                { // Requires a primary key
-                    log.error("updateRecord: "  + name + " no primary key defined!");
-                    throw new NoPrimaryKeyException(this);
+        // Perform action
+        DBRecord.State recordState = rec.getState(); 
+        if (recordState==DBRecord.State.New)
+        {	// Insert Record
+            for (int i = 0; i < columns.size(); i++)
+            {   // search for the column
+            	Object value = fields[i];
+                DBTableColumn col = (DBTableColumn) columns.get(i);
+                if (timestampColumn == col)
+                {   // Make sure the update timestamp column is set
+                    cmd.set(col.to(timestamp));
+                    continue;
+                } 
+                boolean empty = ObjectUtils.isEmpty(value); 
+                if (empty && col.isAutoGenerated()) 
+                {   // Check for AutoInc data type
+                    if (col.getDataType()==DataType.AUTOINC && 
+                        db.getDriver().isSupported(DBDriverFeature.SEQUENCES)==false)
+                    {  // Obtain value via JDBC Statement.RETURN_GENERATED_KEYS
+                       setGenKey = new DBSetGenKey(fields, i);
+                       continue;
+                    }
+                    // get the auto-generated field value
+                    fields[i] = value = col.getRecordDefaultValue(conn);
+                    empty = ObjectUtils.isEmpty(value);
                 }
-                for (int i = 0; i < columns.size(); i++)
-                { // search for the column
-                	Object value = fields[i];
-                	boolean modified = rec.wasModified(i);
-                	boolean empty = ObjectUtils.isEmpty(value); 
-                    DBTableColumn col = (DBTableColumn) columns.get(i);
-                    if (primaryKey.contains(col))
-                    { // Check for Modification
-                        if (modified == true)
-                        { // Requires a primary key
-                            log.warn("updateRecord: " + name + " primary has been modified!");
-                        }
-                        // set pk constraint
-                        if (db.isPreparedStatementsEnabled())
-                            value = cmd.addParam(col, value);
-                        cmd.where(col.is(value));
-                    } 
-                    else if (timestampColumn == col)
-                    {   // Check the update-timestamp
-                    	if (empty==false) 
-                    	{   // set timestamp constraint
-                            if (db.isPreparedStatementsEnabled())
-                                value = cmd.addParam(col, value);
-	                        cmd.where(col.is(value));
-                    	}    
-                    	else if (log.isDebugEnabled()) {
-                    		log.debug("updateRecord has no value for timestamp column. Concurrent
changes will not be detected.");
-                    	}	
-                        cmd.set(col.to(timestamp));
-                    } 
-                    else if (modified && value!=ObjectUtils.NO_VALUE)
-                    { // Update a field
-                        if (col.isReadOnly())
-                            log.warn("updateRecord: Read-only column '" + col.getName() +
" has been modified!");
-                        // Check the value
+                // Add the value to the command
+                if (empty==false)
+                {   // Check the value
+                    if (col.isAutoGenerated()==false)
                         col.validate(value);
-                        // Set the column
-                        cmd.set(col.to(value));
-                        setCount++;
-                    }
+                    // Insert a field
+                    cmd.set(col.to(value));
+                    setCount++;
                 }
-                // Get the SQL statement
-                sql = cmd.getUpdate();
-                break;
-
-            case DBRecord.REC_NEW:
-                for (int i = 0; i < columns.size(); i++)
-                {   // search for the column
-                	Object value = fields[i];
-                    DBTableColumn col = (DBTableColumn) columns.get(i);
-                    if (timestampColumn == col)
-                    {   // Make sure the update timestamp column is set
-                        cmd.set(col.to(timestamp));
-                        continue;
-                    } 
-                    boolean empty = ObjectUtils.isEmpty(value); 
-                    if (empty && col.isAutoGenerated()) 
-                    {   // Check for AutoInc data type
-                        if (col.getDataType()==DataType.AUTOINC && 
-                            db.getDriver().isSupported(DBDriverFeature.SEQUENCES)==false)
-                        {  // Obtain value via JDBC Statement.RETURN_GENERATED_KEYS
-                           setGenKey = new DBSetGenKey(fields, i);
-                           continue;
-                        }
-                        // get the auto-generated field value
-                        fields[i] = value = col.getRecordDefaultValue(conn);
-                        empty = ObjectUtils.isEmpty(value);
-                    }
-                    // Add the value to the command
-                    if (empty==false)
-                    {   // Check the value
-                        if (col.isAutoGenerated()==false)
-                            col.validate(value);
-                        // Insert a field
-                        cmd.set(col.to(value));
-                        setCount++;
-                    }
-                    else if (primaryKey!=null && primaryKey.contains(col))
-                    {   // All primary key fields must be supplied
-                        throw new FieldNotNullException(col);
-                    }
-                    else if (col.isRequired())
-                    {   // Error Column is required!
-                        throw new FieldNotNullException(col);
+                else if (primaryKey!=null && primaryKey.contains(col))
+                {   // All primary key fields must be supplied
+                    throw new FieldNotNullException(col);
+                }
+                else if (col.isRequired())
+                {   // Error Column is required!
+                    throw new FieldNotNullException(col);
+                }
+            }
+            sql = cmd.getInsert();
+        }
+        else if (recordState==DBRecord.State.Modified)
+        {	// Update Record
+            if (primaryKey == null)
+            { // Requires a primary key
+                log.error("updateRecord: "  + name + " no primary key defined!");
+                throw new NoPrimaryKeyException(this);
+            }
+            for (int i = 0; i < columns.size(); i++)
+            { // search for the column
+            	Object value = fields[i];
+            	boolean modified = rec.wasModified(i);
+            	boolean empty = ObjectUtils.isEmpty(value); 
+                DBTableColumn col = (DBTableColumn) columns.get(i);
+                if (primaryKey.contains(col))
+                { // Check for Modification
+                    if (modified == true)
+                    { // Requires a primary key
+                        log.warn("updateRecord: " + name + " primary has been modified!");
                     }
+                    // set pk constraint
+                    if (db.isPreparedStatementsEnabled())
+                        value = cmd.addParam(col, value);
+                    cmd.where(col.is(value));
+                } 
+                else if (timestampColumn == col)
+                {   // Check the update-timestamp
+                	if (empty==false) 
+                	{   // set timestamp constraint
+                        if (db.isPreparedStatementsEnabled())
+                            value = cmd.addParam(col, value);
+                        cmd.where(col.is(value));
+                	}    
+                	else if (log.isDebugEnabled()) {
+                		log.debug("updateRecord has no value for timestamp column. Concurrent changes
will not be detected.");
+                	}	
+                    cmd.set(col.to(timestamp));
+                } 
+                else if (modified && value!=ObjectUtils.NO_VALUE)
+                { // Update a field
+                    if (col.isReadOnly())
+                        log.warn("updateRecord: Read-only column '" + col.getName() + " has
been modified!");
+                    // Check the value
+                    col.validate(value);
+                    // Set the column
+                    cmd.set(col.to(value));
+                    setCount++;
                 }
-                sql = cmd.getInsert();
-                break;
-
-            default:
-                log.info("updateRecord: " + name + " record has not been modified! ");
-                return;
+            }
+            // Get the SQL statement
+            sql = cmd.getUpdate();
+        }
+        else
+        {	// Not modified
+            log.info("updateRecord: " + name + " record has not been modified! ");
+            return;
         }
         if (setCount == 0)
         {   // Nothing to update
@@ -834,7 +836,7 @@ public abstract class DBRowSet extends D
                 fields[i] = timestamp;
         }
         // Change State
-        rec.changeState(DBRecord.REC_VALID, null);
+        rec.changeState(DBRecord.State.Valid, null);
     }
     
     /**

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java Thu Aug 30 11:56:00
2012
@@ -427,7 +427,7 @@ public class DBTable extends DBRowSet im
     public void createRecord(DBRecord rec, Connection conn)
     {
         // Prepare
-        prepareInitRecord(rec, DBRecord.REC_NEW, null);
+        prepareInitRecord(rec, DBRecord.State.New, null);
         // Set Defaults
         int count = columns.size();
         for (int i = 0; i < count; i++)

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/SerializeTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/SerializeTest.java?rev=1378894&r1=1378893&r2=1378894&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/SerializeTest.java (original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/SerializeTest.java Thu Aug
30 11:56:00 2012
@@ -57,7 +57,7 @@ public class SerializeTest {
   public DBObject[] getObjectsToSerialize() {
     final TestDatabase db = new TestDatabase();
     DBRecord rec = new DBRecord();
-    rec.init(db.T_TEST, DBRecord.REC_NEW, null);
+    rec.init(db.T_TEST, DBRecord.State.New, null);
     db.open(new MockDriver(), null);
     return new DBObject[] {
             db,



Mime
View raw message