empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1301430 - in /empire-db/trunk: ./ empire-db/src/main/java/org/apache/empire/data/ empire-db/src/main/java/org/apache/empire/data/bean/ empire-db/src/main/java/org/apache/empire/db/ empire-db/src/main/java/org/apache/empire/db/exceptions/ e...
Date Fri, 16 Mar 2012 10:56:05 GMT
Author: doebele
Date: Fri Mar 16 10:56:04 2012
New Revision: 1301430

URL: http://svn.apache.org/viewvc?rev=1301430&view=rev
Log:
EMPIREDB-137
Record.isReadOnly() and Column.validate() methods added

Modified:
    empire-db/trunk/CHANGELOG.txt
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Column.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Record.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.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/main/java/org/apache/empire/db/DBTableColumn.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java

Modified: empire-db/trunk/CHANGELOG.txt
URL: http://svn.apache.org/viewvc/empire-db/trunk/CHANGELOG.txt?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/CHANGELOG.txt (original)
+++ empire-db/trunk/CHANGELOG.txt Fri Mar 16 10:56:04 2012
@@ -15,6 +15,7 @@ Release 2.2.1:
     * [EMPIREDB-79]  - Allow specification of delete action for each DBRelation (ON DELETE
CASCADE)
 
 ** Improvement
+    * [EMPIREDB-137] - Extend Record and Column interfaces by Record.isReadOnly() and Column.validate()
methods
     * [EMPIREDB-133] - Simplify use of DBCommand:DBCommandParam class
     * [EMPIREDB-129] - Allow expression based indexes
     * [EMPIREDB-126] - Various small improvements, like new method overloads, code and javadoc
cleanup, etc.

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Column.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Column.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Column.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Column.java Fri Mar 16
10:56:04 2012
@@ -19,9 +19,9 @@
 package org.apache.empire.data;
 
 /**
- * The column interface provides methods for accessing metadata that is only relevant for
updateing records.
+ * The column interface provides methods for accessing metadata that is only relevant for
updating records.
  * <P>
- * This interface inherits from ColumnExpr which provides futher metadata.
+ * This interface inherits from ColumnExpr which provides further metadata.
  * <P>
  */
 public interface Column extends ColumnExpr
@@ -59,4 +59,10 @@ public interface Column extends ColumnEx
      */
     boolean isReadOnly();
 
+    /**
+     * Checks if the given value is a valid value for this column 
+     * If not, an exception is thrown
+     */
+    void validate(Object value);
+
 }

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Record.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Record.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Record.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/Record.java Fri Mar 16
10:56:04 2012
@@ -43,6 +43,12 @@ public interface Record extends RecordDa
     boolean isValid();
 
     /**
+     * returns true if this record is readOnly.
+     * @return true if this record is readOnly
+     */
+    boolean isReadOnly();
+
+    /**
      * returns true if the record has been modified.
      * @return true if the record has been modified or false otherwise
      */
@@ -54,7 +60,6 @@ public interface Record extends RecordDa
      */
     boolean isNew();
 
-
     /**
      * returns the column at the specified index.
      * @param index index of a requested column

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanProperty.java
Fri Mar 16 10:56:04 2012
@@ -19,10 +19,12 @@
 package org.apache.empire.data.bean;
 
 import org.apache.empire.commons.Attributes;
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.exceptions.FieldNotNullException;
 
 /**
  * BeanObject
@@ -196,6 +198,12 @@ public class BeanProperty implements Col
         return (dataMode==DataMode.NotNull);
     }
 
+    public void validate(Object value)
+    {
+        if (ObjectUtils.isEmpty(value) && isRequired())
+            throw new FieldNotNullException(this);
+    }
+
     // --- others ---
 
     /**

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
Fri Mar 16 10:56:04 2012
@@ -30,6 +30,7 @@ import org.apache.empire.commons.Options
 import org.apache.empire.data.Column;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.Record;
+import org.apache.empire.db.DBRowSet;
 import org.apache.empire.exceptions.BeanPropertyGetException;
 import org.apache.empire.exceptions.BeanPropertySetException;
 import org.apache.empire.exceptions.InvalidArgumentException;
@@ -198,6 +199,11 @@ public class BeanRecordProxy<T> implemen
         return (data!=null);
     }
 
+    public boolean isReadOnly()
+    {
+        return (isValid() ? false : true);
+    }
+
     public Object getValue(ColumnExpr column)
     {
         if (!isValid())

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumn.java Fri Mar 16
10:56:04 2012
@@ -21,10 +21,12 @@ package org.apache.empire.db;
 // Java
 import java.util.Set;
 
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.exceptions.DatabaseNotOpenException;
+import org.apache.empire.db.exceptions.FieldNotNullException;
 import org.apache.empire.db.expr.set.DBSetExpr;
 import org.w3c.dom.Element;
 
@@ -121,7 +123,20 @@ public abstract class DBColumn extends D
      */
     public abstract boolean isReadOnly();
 
-    public abstract void checkValue(Object value);
+    /**
+     * Checks if the given value is a valid value for this column 
+     * If not, an exception is thrown
+     */
+    public abstract void validate(Object value);
+    
+    /**
+     * @deprecated use validate() instead 
+     */
+    @Deprecated
+    public final void checkValue(Object value)
+    {
+        validate(value);
+    }
 
     /**
      * Returns true if column the column is a character based column (char, text or clob)

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=1301430&r1=1301429&r2=1301430&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 Fri Mar
16 10:56:04 2012
@@ -80,6 +80,13 @@ public abstract class DBCommandExpr exte
         {
             return null;
         }
+        
+        /** Not applicable - returns false */
+        @Override
+        public boolean isUpdateable()
+        {
+            return false;
+        }
 
         /**
          * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
@@ -278,7 +285,7 @@ public abstract class DBCommandExpr exte
          * Not applicable - always returns true.
          */
         @Override
-        public void checkValue(Object value)
+        public void validate(Object value)
         {
             // Nothing to check.
         }

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=1301430&r1=1301429&r2=1301430&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 Fri Mar 16 10:56:04
2012
@@ -121,12 +121,12 @@ public class DBQuery extends DBRowSet
         }
 
         @Override
-        public void checkValue(Object value)
+        public void validate(Object value)
         {
             DBColumn column = expr.getUpdateColumn();
             if (column==null)
                 return;
-            column.checkValue(value);
+            column.validate(value);
         }
 
         @Override
@@ -231,6 +231,16 @@ public class DBQuery extends DBRowSet
     {
         return alias;
     }
+    
+    /**
+     * Returns whether or not the table supports record updates.
+     * @return true if the table allows record updates
+     */
+    @Override
+    public boolean isUpdateable()
+    {
+        return (getKeyColumns()!=null);
+    }
 
     /**
      * Gets all columns of this rowset (e.g. for cmd.select()).
@@ -389,8 +399,14 @@ public class DBQuery extends DBRowSet
     @Override
     public void updateRecord(DBRecord rec, Connection conn)
     {
-        if (conn == null || rec == null)
-            throw new InvalidArgumentException("conn|rec", null);
+        // check updateable
+        if (isUpdateable()==false)
+            throw new NotSupportedException(this, "updateRecord");
+        // check params
+        if (rec == null)
+            throw new InvalidArgumentException("record", null);
+        if (conn == null)
+            throw new InvalidArgumentException("conn", null);
         // Has record been modified?
         if (rec.isModified() == false)
             return; // Nothing to update

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=1301430&r1=1301429&r2=1301430&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 Mar 16
10:56:04 2012
@@ -217,6 +217,19 @@ public class DBRecord extends DBRecordDa
     }
 
     /**
+     * Returns true if the record is valid.
+     * 
+     * @return true if the record is valid
+     */
+    public boolean isReadOnly()
+    {
+        if (!isValid())
+            return true;
+        DBRowSet rowset = getRowSet();
+        return (rowset==null || !rowset.isUpdateable());
+    }
+
+    /**
      * Returns true if the record is modified.
      * 
      * @return true if the record is modified

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=1301430&r1=1301429&r2=1301430&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 Mar 16
10:56:04 2012
@@ -42,6 +42,7 @@ import org.apache.empire.db.exceptions.R
 import org.apache.empire.db.expr.column.DBCountExpr;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.NotSupportedException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
 import org.slf4j.Logger;
@@ -104,6 +105,8 @@ public abstract class DBRowSet extends D
     public abstract String getName();
     
     public abstract String getAlias();
+    
+    public abstract boolean isUpdateable();
 
     public abstract void createRecord(DBRecord rec, Connection conn);
 
@@ -583,6 +586,12 @@ public abstract class DBRowSet extends D
      */
     public void updateRecord(DBRecord rec, Connection conn)
     {
+        // check updateable
+        if (isUpdateable()==false)
+            throw new NotSupportedException(this, "updateRecord");
+        // Check Arguments
+        if (rec == null)
+            throw new InvalidArgumentException("record", rec);
         // Check Arguments
         if (conn == null)
             throw new InvalidArgumentException("conn", conn);

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=1301430&r1=1301429&r2=1301430&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 Fri Mar 16 10:56:04
2012
@@ -98,6 +98,16 @@ public class DBTable extends DBRowSet im
     {
         return alias;
     }
+    
+    /**
+     * Returns whether or not the table supports record updates. Default is true.
+     * @return true if the table allows record updates
+     */
+    @Override
+    public boolean isUpdateable()
+    {
+        return true;
+    }
 
     /**
      * Clones this table and assigns a new table alias.

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Fri Mar
16 10:56:04 2012
@@ -312,7 +312,7 @@ public class DBTableColumn extends DBCol
      * @return true if the value is valid or false otherwise.
      */
     @Override
-    public void checkValue(Object value)
+    public void validate(Object value)
     {
         // Check for NULL
         if (isRequired() && (value == null || value.toString().length() < 1))

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java Fri Mar 16 10:56:04
2012
@@ -122,11 +122,11 @@ public abstract class DBView extends DBR
         }    
 
         @Override
-        public void checkValue(Object value)
+        public void validate(Object value)
         {
             if (updateColumn==null)
                 return;
-            updateColumn.checkValue(value);
+            updateColumn.validate(value);
         }
 
         @Override
@@ -277,6 +277,7 @@ public abstract class DBView extends DBR
      * Returns whether or not the view is updateable
      * @return true if the view is updateable or false if not 
      */
+    @Override
     public boolean isUpdateable()
     {
         return this.updateable;
@@ -394,7 +395,7 @@ public abstract class DBView extends DBR
     @Override
     public void createRecord(DBRecord rec, Connection conn)
     {
-        throw new NotSupportedException(this, "addRecord");
+        throw new NotSupportedException(this, "createRecord");
     }
 
     /*

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java
Fri Mar 16 10:56:04 2012
@@ -19,6 +19,7 @@
 package org.apache.empire.db.exceptions;
 
 import org.apache.empire.commons.ErrorType;
+import org.apache.empire.data.Column;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.exceptions.EmpireException;
 
@@ -35,4 +36,9 @@ public class FieldNotNullException exten
     {
         super(errorType, new String[] { col.getFullName() });
     }
+    
+    public FieldNotNullException(Column col)
+    {
+        super(errorType, new String[] { col.getName() });
+    }
 }

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java?rev=1301430&r1=1301429&r2=1301430&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java (original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java Fri Mar
16 10:56:04 2012
@@ -85,7 +85,7 @@ public class DBCommandTest
         }
 
         @Override
-        public void checkValue(Object value)
+        public void validate(Object value)
         {
             return;
         }



Mime
View raw message