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 2011/07/23 18:09:43 UTC

svn commit: r1150139 [1/3] - in /incubator/empire-db/branches/EMPIREDB-99: empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/ empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/sam...

Author: doebele
Date: Sat Jul 23 16:09:27 2011
New Revision: 1150139

URL: http://svn.apache.org/viewvc?rev=1150139&view=rev
Log:
EMPIREDB-99 exception classes created.

Added:
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/DatabaseNotOpenException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldIllegalValueException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldIsReadOnlyException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldNotNullException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldValueException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/FieldValueTooLongException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/InternalSQLException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/InvalidKeyException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/NoPrimaryKeyException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/QueryFailedException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/QueryNoResultException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/RecordDeleteFailedException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/RecordNotFoundException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/RecordUpdateFailedException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/RecordUpdateInvalidException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/exceptions/package.html   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertyGetException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/EmpireException.java   (contents, props changed)
      - copied, changed from r1149172, incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/EmpireException.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/EmpireFileException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/FileParseException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/FileReadException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/FileWriteException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/InternalException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/InvalidArgumentException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/InvalidPropertyException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/ItemExistsException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/ItemNotFoundException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/MiscellaneousErrorException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/NotImplementedException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/ObjectNotValidException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/PropertyReadOnlyException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/UnexpectedReturnValueException.java   (with props)
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/exceptions/package.html   (with props)
Removed:
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/EmpireException.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/EmpireExceptionTest.java
Modified:
    incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/Errors.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBObject.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBReader.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBTable.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBView.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
    incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvConfig.java Sat Jul 23 16:09:27 2011
@@ -18,8 +18,8 @@
  */
 package org.apache.empire.samples.db.advanced;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.xml.XMLConfiguration;
 import org.apache.empire.xml.XMLUtil;
 import org.apache.log4j.xml.DOMConfigurator;
@@ -80,13 +80,13 @@ public class SampleAdvConfig extends XML
         // Get configuration root node
         Element rootNode = getRootNode();
         if (rootNode == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Find log configuration node
         Element loggingNode = XMLUtil.findFirstChild(rootNode, loggingNodeName);
         if (loggingNode == null)
         {   // log configuration node not found
             log.error("Log configuration node {} has not been found. Logging has not been configured.", loggingNodeName);
-            throw new EmpireException(Errors.ItemNotFound, loggingNodeName);
+            throw new ItemNotFoundException(loggingNodeName);
         }
         // Init Log4J
         DOMConfigurator.configure(loggingNode);

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleConfig.java Sat Jul 23 16:09:27 2011
@@ -18,8 +18,8 @@
  */
 package org.apache.empire.samples.db;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.xml.XMLConfiguration;
 import org.apache.empire.xml.XMLUtil;
 import org.apache.log4j.xml.DOMConfigurator;
@@ -79,13 +79,13 @@ public class SampleConfig extends XMLCon
         // Get configuration root node
         Element rootNode = getRootNode();
         if (rootNode == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Find log configuration node
         Element loggingNode = XMLUtil.findFirstChild(rootNode, loggingNodeName);
         if (loggingNode == null)
         {   // log configuration node not found
             log.error("Log configuration node {} has not been found. Logging has not been configured.", loggingNodeName);
-            throw new EmpireException(Errors.ItemNotFound, loggingNodeName);
+            throw new ItemNotFoundException(loggingNodeName);
         }
         // Init Log4J
         DOMConfigurator.configure(loggingNode);

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/Errors.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/Errors.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/Errors.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/Errors.java Sat Jul 23 16:09:27 2011
@@ -18,7 +18,6 @@
  */
 package org.apache.empire.commons;
 
-import java.text.MessageFormat;
 
 /**
  * This class holds the definition of common error types.
@@ -32,6 +31,7 @@ import java.text.MessageFormat;
 public class Errors
 {
     // No Error
+/*    
     public static final ErrorType None            = new ErrorType("error.none", "");
     public static final ErrorType Cancelled       = new ErrorType("error.cancelled", "The action has been cancelled by the user");
     // Code Errors
@@ -63,6 +63,7 @@ public class Errors
     public static final ErrorType FileWriteError  = new ErrorType("error.filewriteerror", "Error creating or writing file {0}");
     public static final ErrorType PathNotFound    = new ErrorType("error.pathnotfound", "The directory {0} does not exists.");
     public static final ErrorType PathCreateFailed= new ErrorType("error.pathcreatefailed", "Error creating the directory {0}");
+*/    
 
     /**
      *  No instances of this class can be created.
@@ -78,6 +79,7 @@ public class Errors
      * @param info the ErrorInfo to get the message for
      * @return the message string for this info
      */
+    /*
     public static String getErrorMessage(ErrorType type, Object[] msgParams)
     {
         // Get Error Type
@@ -91,4 +93,5 @@ public class Errors
         String msg = MessageFormat.format(msgPattern, msgParams);
         return msg;
     }
+    */
 }

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java Sat Jul 23 16:09:27 2011
@@ -88,7 +88,7 @@ public class StringUtils
      */
     public static String valueOf(Object value)
     {
-        return toString(value, "");
+        return toString(value, "null");
     }
 
     /**
@@ -99,7 +99,7 @@ public class StringUtils
      */
     public static String valueOf(Object[] array)
     {
-        return toString(array, "");
+        return toString(array, "null");
     }
     
     /**

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/data/bean/BeanRecordProxy.java Sat Jul 23 16:09:27 2011
@@ -25,13 +25,16 @@ import java.util.List;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.beanutils.BeanUtilsBean;
 import org.apache.commons.beanutils.PropertyUtilsBean;
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 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.exceptions.BeanPropertyGetException;
+import org.apache.empire.exceptions.BeanPropertySetException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -173,7 +176,7 @@ public class BeanRecordProxy<T> implemen
     public boolean isNew()
     {
         if (!isValid())
-            throw new EmpireException(Errors.InvalidProperty, "bean");
+            throw new ObjectNotValidException(this);
         // Record is new until all key fields have been supplied
         if (keyColumns!=null)
         {   // Check all Key Columns
@@ -198,7 +201,7 @@ public class BeanRecordProxy<T> implemen
     public Object getValue(ColumnExpr column)
     {
         if (!isValid())
-            throw new EmpireException(Errors.InvalidProperty, "bean");
+            throw new ObjectNotValidException(this);
         // getBeanPropertyValue 
         return getBeanPropertyValue(data, column);
     }
@@ -224,7 +227,7 @@ public class BeanRecordProxy<T> implemen
     public void setValue(Column column, Object value)
     {
         if (!isValid())
-            throw new EmpireException(Errors.InvalidProperty, "bean");
+            throw new ObjectNotValidException(this);
         // Track modification status
         if (ObjectUtils.compareEqual(getValue(column), value)==false)
         {
@@ -251,7 +254,7 @@ public class BeanRecordProxy<T> implemen
     {
         int index = getFieldIndex(column);
         if (index<0)
-            throw new EmpireException(Errors.ItemNotFound, column.getName());
+            throw new ItemNotFoundException(column.getName());
         // check modified
         return (modified!=null && modified[index]);
     }
@@ -318,8 +321,10 @@ public class BeanRecordProxy<T> implemen
     protected Object getBeanPropertyValue(Object bean, ColumnExpr column)
     {
         // Check Params
+        if (bean==null)
+            throw new InvalidArgumentException("bean", bean);
         if (column==null)
-            throw new EmpireException(Errors.InvalidArg, "column");
+            throw new InvalidArgumentException("column", column);
         // getBeanPropertyValue 
         return getBeanPropertyValue(bean, column.getBeanPropertyName()); 
     }
@@ -327,8 +332,10 @@ public class BeanRecordProxy<T> implemen
     protected Object getBeanPropertyValue(Object bean, String property)
     {
         // Check Params
-        if (bean==null || property==null)
-            throw new EmpireException(Errors.InvalidArg, "property");
+        if (bean==null)
+            throw new InvalidArgumentException("bean", bean);
+        if (property==null)
+            throw new InvalidArgumentException("property", property);
         try
         {   // Get Property Value
             PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
@@ -336,21 +343,23 @@ public class BeanRecordProxy<T> implemen
 
         } catch (IllegalAccessException e)
         {   log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         } catch (InvocationTargetException e)
         {   log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         } catch (NoSuchMethodException e)
         {   log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         }
     }
 
     protected void setBeanPropertyValue(Object bean, Column column, Object value)
     {
         // Check Params
-        if (bean==null || column==null)
-            throw new EmpireException(Errors.InvalidArg, "column");
+        if (bean==null)
+            throw new InvalidArgumentException("bean", bean);
+        if (column==null)
+            throw new InvalidArgumentException("column", column);
         // Get Property Name
         String property = column.getBeanPropertyName(); 
         try
@@ -362,13 +371,13 @@ public class BeanRecordProxy<T> implemen
             // pub.setSimpleProperty(data, property, value);
         } catch (IllegalArgumentException e) {
             log.error(bean.getClass().getName() + ": invalid argument for property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertySetException(bean, property, e);
         } catch (IllegalAccessException e)
         {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertySetException(bean, property, e);
         } catch (InvocationTargetException e)
         {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertySetException(bean, property, e);
         }    
     }
     

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommand.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommand.java Sat Jul 23 16:09:27 2011
@@ -18,25 +18,26 @@
  */
 package org.apache.empire.db;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
 import org.apache.empire.db.expr.join.DBJoinExpr;
 import org.apache.empire.db.expr.join.DBJoinExprEx;
 import org.apache.empire.db.expr.set.DBSetExpr;
+import org.apache.empire.exceptions.MiscellaneousErrorException;
+import org.apache.empire.exceptions.NotSupportedException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
 
 /**
  * This abstract class handles the creation of the SQL-Commands. 
@@ -171,7 +172,7 @@ public abstract class DBCommand extends 
         int index = cmdParams.indexOf(param);
         if (index < paramUsageCount)
         {   // Error: parameter probably used twice in statement!
-            throw new EmpireException(Errors.Internal, "A parameter may only be used once in a command.");
+            throw new MiscellaneousErrorException("A parameter may only be used once in a command.");
         }
         if (index > paramUsageCount)
         {   // Correct parameter order
@@ -674,7 +675,7 @@ public abstract class DBCommand extends 
      */
     public void limitRows(int numRows)
     {
-        throw new EmpireException(Errors.NotSupported, "limitRows");
+        throw new NotSupportedException(this, "limitRows");
     }
 
     /**
@@ -685,7 +686,7 @@ public abstract class DBCommand extends 
      */
     public void skipRows(int numRows)
     {
-        throw new EmpireException(Errors.NotSupported, "skipRows");
+        throw new NotSupportedException(this, "skipRows");
     }
     
     /**
@@ -706,7 +707,7 @@ public abstract class DBCommand extends 
     {
         resetParamUsage();
         if (select == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName()); // invalid!
+            throw new ObjectNotValidException(this); // invalid!
         // Prepares statement
         addSelect(buf);
         // From clause

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java Sat Jul 23 16:09:27 2011
@@ -19,18 +19,19 @@
 package org.apache.empire.db;
 
 // java
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
-import org.apache.empire.commons.Options;
-import org.apache.empire.data.DataType;
-import org.apache.empire.db.expr.order.DBOrderByExpr;
-import org.w3c.dom.Element;
-
 import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.expr.order.DBOrderByExpr;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotSupportedException;
+import org.apache.empire.exceptions.ObjectNotValidException;
+import org.w3c.dom.Element;
+
 
 /**
  * This abstract class handles the creation of the SQL-Commands.
@@ -108,7 +109,7 @@ public abstract class DBCommandExpr exte
         @Override
         public DBColumn[] getKeyColumns()
         {
-            throw new EmpireException(Errors.NotSupported, "getKeyColumns");
+            throw new NotSupportedException(this, "getKeyColumns");
         }
 
         /**
@@ -119,42 +120,42 @@ public abstract class DBCommandExpr exte
         @Override
         public Object[] getRecordKey(DBRecord rec)
         {
-            throw new EmpireException(Errors.NotSupported, "getRecordKey");
+            throw new NotSupportedException(this, "getRecordKey");
         }
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
         public void initRecord(DBRecord rec, Object[] keyValues)
         {
-            throw new EmpireException(Errors.NotSupported, "initRecord");
+            throw new NotSupportedException(this, "initRecord");
         }
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
         public void createRecord(DBRecord rec, Connection conn)
         {
-            throw new EmpireException(Errors.NotSupported, "addRecord");
+            throw new NotSupportedException(this, "addRecord");
         }
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
         public void readRecord(DBRecord rec, Object[] keys, Connection conn)
         {
-            throw new EmpireException(Errors.NotSupported, "getRecord");
+            throw new NotSupportedException(this, "getRecord");
         }
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
         public void updateRecord(DBRecord rec, Connection conn)
         {
-            throw new EmpireException(Errors.NotSupported, "updateRecord");
+            throw new NotSupportedException(this, "updateRecord");
         }
 
         /** Returns the error message: ERR_NOTSUPPORTED */
         @Override
         public void deleteRecord(Object[] keys, Connection conn)
         {
-            throw new EmpireException(Errors.NotSupported, "deleteRecord");
+            throw new NotSupportedException(this, "deleteRecord");
         }
     }
 
@@ -462,7 +463,7 @@ public abstract class DBCommandExpr exte
     protected String getInsertInto(DBTable table, DBColumnExpr[] select, List<DBColumnExpr> columns)
     {
         if (select == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // prepare buffer
         StringBuilder buf = new StringBuilder("INSERT INTO ");
         table.addSQL(buf, CTX_FULLNAME);
@@ -471,7 +472,7 @@ public abstract class DBCommandExpr exte
         { // Check Count
             if (columns.size() != select.length)
             {
-                throw new EmpireException(Errors.InvalidArg, columns, "columns");
+                throw new InvalidArgumentException("columns", "size()!=select.length");
             }
             // Append Names
             buf.append(" (");
@@ -511,7 +512,7 @@ public abstract class DBCommandExpr exte
     {
         DBColumnExpr[] select = getSelectExprList();
         if (select == null || select.length < 1)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Match Columns
         List<DBColumnExpr> inscols = new ArrayList<DBColumnExpr>(select.length);
         for (int i = 0; i < select.length; i++)

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java Sat Jul 23 16:09:27 2011
@@ -26,12 +26,20 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.exceptions.DatabaseNotOpenException;
+import org.apache.empire.db.exceptions.InternalSQLException;
+import org.apache.empire.db.exceptions.QueryFailedException;
+import org.apache.empire.db.exceptions.QueryNoResultException;
 import org.apache.empire.db.expr.column.DBValueExpr;
+import org.apache.empire.exceptions.MiscellaneousErrorException;
+import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemExistsException;
+import org.apache.empire.exceptions.PropertyReadOnlyException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -213,7 +221,7 @@ public abstract class DBDatabase extends
             // Set driver
             if (this.driver!=null && this.driver!=driver && driver!=null)
             {   // The database belongs to a different driver
-                throw new EmpireException(Errors.Internal, "The database is attached to a different driver.");
+                throw new MiscellaneousErrorException("The database is attached to a different driver.");
             }
             // Temporarily change driver
             if (this.driver== null)
@@ -255,7 +263,7 @@ public abstract class DBDatabase extends
     public void setSchema(String schema)
     {   // Database must not be open so far
         if (driver != null)
-            throw new EmpireException(Errors.NoAccess);
+            throw new PropertyReadOnlyException("schema");
         // Set Schema 
         this.schema = schema;
     }
@@ -295,7 +303,7 @@ public abstract class DBDatabase extends
     public void setLinkName(String linkName)
     {   // Database must not be open so far
         if (driver != null)
-            throw new EmpireException(Errors.NoAccess);
+            throw new PropertyReadOnlyException(linkName);
         // Set Link 
         this.linkName = linkName;
     }
@@ -429,9 +437,9 @@ public abstract class DBDatabase extends
     public void addTable(DBTable table)
     { // find column by name
         if (table == null || table.getDatabase() != this)
-            throw new EmpireException(Errors.InvalidArg, table, "table");
+            throw new InvalidArgumentException("table", table);
         if (tables.contains(table)==true)
-            throw new EmpireException(Errors.ItemExists, table.getName());
+            throw new ItemExistsException(table.getName());
         // Check for second instances
         DBTable existing = getTable(table.getName()); 
         if (existing!=null)
@@ -439,7 +447,7 @@ public abstract class DBDatabase extends
             if (existing.getClass().equals(table.getClass()))
                 return; // Ignore other instances 
             // Table exists with different class
-            throw new EmpireException(Errors.ItemExists, table.getName());
+            throw new ItemExistsException(table.getName());
         }
         // add now
         tables.add(table);
@@ -520,7 +528,7 @@ public abstract class DBDatabase extends
         // Add a Relation
         DBRelation relation = new DBRelation(this, name, references);
         if (relations.contains(relation))
-            throw new EmpireException(Errors.ItemExists, name); // Itemn already exists
+            throw new ItemExistsException(name); // Itemn already exists
         // Add Reference column to table
         for (DBRelation.DBReference ref : references)
         {   // add the reference column
@@ -552,9 +560,9 @@ public abstract class DBDatabase extends
     public void addView(DBView view)
     { // find column by name
         if (view == null || view.getDatabase() != this)
-            throw new EmpireException(Errors.InvalidArg, view, "view");
+            throw new InvalidArgumentException("view", view);
         if (views.contains(view) == true)
-            throw new EmpireException(Errors.ItemExists, view.getName());
+            throw new ItemExistsException(view.getName());
         // add now
         views.add(view);
     }
@@ -602,7 +610,7 @@ public abstract class DBDatabase extends
     protected void checkOpen()
     {
         if (isOpen()==false)
-            throw new EmpireException(DBErrors.DatabaseNotOpen);
+            throw new DatabaseNotOpenException(this);
     }
     
     /**
@@ -659,12 +667,12 @@ public abstract class DBDatabase extends
             // Get the next Value
             rs = driver.executeQuery(sqlCmd, null, false, conn);
             if (rs == null)
-                throw new EmpireException(Errors.UnexpectedValue, rs, "driver.executeQuery()");
+                throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
             // Check Result
             if (rs.next() == false)
             {   // no result
                 log.debug("querySingleValue returned no result");
-                throw new EmpireException(DBErrors.QueryNoResult, sqlCmd);
+                throw new QueryNoResultException(sqlCmd);
             }
             // No Value
             Object result = rs.getObject(1);
@@ -674,9 +682,7 @@ public abstract class DBDatabase extends
             return result;
         } catch (SQLException sqle) 
         {   // Error
-            EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing query {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
         } finally
         { // Cleanup
             closeResultSet(rs);
@@ -812,7 +818,7 @@ public abstract class DBDatabase extends
             // Get the next Value
             rs = driver.executeQuery(sqlCmd, null, false, conn);
             if (rs == null)
-                throw new EmpireException(Errors.UnexpectedValue, rs, "driver.executeQuery()");
+                throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
             // Check Result
             int count=0;
             while (rs.next())
@@ -827,12 +833,10 @@ public abstract class DBDatabase extends
             return count;
         } catch (ClassCastException e) 
         {   log.error("querySingleValue cast exception: ", e);
-            throw new EmpireException(e);
+            throw new InternalException(e);
         } catch (SQLException sqle) 
         {   // Error
-            EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing query {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
         } finally
         { // Cleanup
             closeResultSet(rs);
@@ -891,9 +895,9 @@ public abstract class DBDatabase extends
             // Get the next Value
             rs = driver.executeQuery(sqlCmd, null, false, conn);
             if (rs == null)
-                throw new EmpireException(Errors.UnexpectedValue, rs, "driver.executeQuery()");
+                throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
             if (rs.getMetaData().getColumnCount()<2)
-                throw new EmpireException(Errors.InvalidArg, sqlCmd, "sqlCmd");
+                throw new InvalidArgumentException("sqlCmd", sqlCmd);
             // Check Result
             Options result = new Options();
             while (rs.next())
@@ -908,9 +912,7 @@ public abstract class DBDatabase extends
             return result;
         } catch (SQLException sqle) 
         {   // Error
-            EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing query {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
         } finally
         { // Cleanup
             closeResultSet(rs);
@@ -939,7 +941,7 @@ public abstract class DBDatabase extends
             // Get the next Value
             rs = driver.executeQuery(sqlCmd, null, false, conn);
             if (rs == null)
-                throw new EmpireException(Errors.UnexpectedValue, rs, "driver.executeQuery()");
+                throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
             // Read List
             int colCount = rs.getMetaData().getColumnCount();
             int count = 0;
@@ -959,9 +961,7 @@ public abstract class DBDatabase extends
             return count;
         } catch (SQLException sqle) 
         {   // Error
-            EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing query {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
         } finally
         { // Cleanup
             closeResultSet(rs);
@@ -1006,7 +1006,7 @@ public abstract class DBDatabase extends
             int affected = driver.executeSQL(sqlCmd, sqlParams, conn, setGenKeys);
             // number of affected records
             if (affected < 0)
-                throw new EmpireException(Errors.UnexpectedValue, affected, "driver.executeSQL()");
+                throw new UnexpectedReturnValueException(affected, "driver.executeSQL()");
             // Log
             if (log.isInfoEnabled())
 	            log.info("executeSQL affected " + affected + " Records / " + (System.currentTimeMillis() - start) + "ms");
@@ -1015,9 +1015,7 @@ public abstract class DBDatabase extends
             
 	    } catch (SQLException sqle) 
         { 	// Error
-	        EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing statement {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
 	    }    
     }
 
@@ -1061,7 +1059,7 @@ public abstract class DBDatabase extends
             long start = System.currentTimeMillis();
             ResultSet rs = driver.executeQuery(sqlCmd, sqlParams, scrollable, conn);
             if (rs == null)
-                throw new EmpireException(Errors.UnexpectedValue, rs, "driver.executeQuery()");
+                throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
             // Debug
             if (log.isDebugEnabled())
                 log.debug("executeQuery successful in " + (System.currentTimeMillis() - start) + " ms");
@@ -1070,9 +1068,7 @@ public abstract class DBDatabase extends
 
         } catch (SQLException sqle) 
         {   // Error
-            EmpireException exptn = SQL2EmpireException(DBErrors.QueryFailed, sqle); 
-            log.error("Error executing query {0}. Message is {0}", sqlCmd, exptn.getMessage());
-            throw exptn;
+            throw new QueryFailedException(this, sqlCmd, sqle);
         } 
     }
 
@@ -1090,7 +1086,7 @@ public abstract class DBDatabase extends
         try
         {   // Check argument
             if (conn==null)
-                throw new EmpireException(Errors.InvalidArg, null, "conn");
+                throw new InvalidArgumentException("conn", conn);
             // Commit
             if (conn.getAutoCommit()==false)
                 conn.commit();
@@ -1098,7 +1094,7 @@ public abstract class DBDatabase extends
             return;
         } catch (SQLException sqle) { 
             // Commit failed!
-            throw new EmpireException(sqle);
+            throw new InternalSQLException(this, sqle);
         }
     }
 
@@ -1116,7 +1112,7 @@ public abstract class DBDatabase extends
         try
         {   // Check argument
             if (conn==null)
-                throw new EmpireException(Errors.InvalidArg, null, "conn");
+                throw new InvalidArgumentException("conn", conn);
             // rollback
             log.info("Database rollback issued!");
             conn.rollback();
@@ -1124,7 +1120,7 @@ public abstract class DBDatabase extends
             return;
         } catch (SQLException sqle) { 
             // Commit failed!
-            throw new EmpireException(sqle);
+            throw new InternalSQLException(this, sqle);
         }
     }
 
@@ -1144,7 +1140,7 @@ public abstract class DBDatabase extends
             return;
         } catch (SQLException sqle) { 
             // Commit failed!
-            throw new EmpireException(sqle);
+            throw new InternalSQLException(this, sqle);
         }
     }
 
@@ -1172,7 +1168,7 @@ public abstract class DBDatabase extends
             return;
         } catch (SQLException sqle) { 
             // Commit failed!
-            throw new EmpireException(sqle);
+            throw new InternalSQLException(this, sqle);
         }
     }
 

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Sat Jul 23 16:09:27 2011
@@ -34,13 +34,14 @@ import java.util.Set;
 import java.util.UUID;
 
 import org.apache.empire.commons.DateUtils;
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCommand.DBCommandParam;
+import org.apache.empire.db.exceptions.InternalSQLException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -225,7 +226,7 @@ public abstract class DBDatabaseDriver i
                 return new Long(seqValue);
             } catch (SQLException e) {
                 // throw exception
-                throw SQL2EmpireException(e);
+                throw new InternalSQLException(this, e);
             } finally
             { // Cleanup
                 db.closeStatement(stmt);
@@ -378,7 +379,7 @@ public abstract class DBDatabaseDriver i
             return (type==DataType.DATE ? DateUtils.getDateOnly(ts) : ts);
         }
         // Other types
-        throw new EmpireException(Errors.NotSupported, "getColumnAutoValue() for "+type);
+        throw new NotSupportedException(this, "getColumnAutoValue() for "+type);
     }
 
     /**
@@ -699,7 +700,7 @@ public abstract class DBDatabaseDriver i
      */
     public void checkDatabase(DBDatabase db, String owner, Connection conn)
     {
-        throw new EmpireException(Errors.NotImplemented, "checkDatabase");
+        throw new NotImplementedException(this, "checkDatabase");
     }
     
     /**
@@ -713,7 +714,7 @@ public abstract class DBDatabaseDriver i
      */
     public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
     {
-        throw new EmpireException(Errors.NotSupported, "getDDLScript");
+        throw new NotImplementedException(this, "getDDLScript");
     }
     
     /**

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBObject.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBObject.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBObject.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBObject.java Sat Jul 23 16:09:27 2011
@@ -20,25 +20,18 @@ package org.apache.empire.db;
 
 // java.sql
 import java.io.Serializable;
-import java.sql.SQLException;
-
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
- * Base class for all database related objects.
- * Every object is attached to a DBDatabase object.
- * 
- *
+ * Base class for all objects that directly or indirectly belong to a database including the database object itself.
+ * Examples are: tables, views, columns, indexes, relations etc.
+ * Not included are: drivers, helper classes
  */
 public abstract class DBObject implements Serializable
 {
     private static final long serialVersionUID = 1L;
     // Logger
-    private static final Logger log = LoggerFactory.getLogger(DBObject.class);
+    // private static final Logger log = LoggerFactory.getLogger(DBObject.class);
 
     /**
      * Returns the database object to which this object belongs to.
@@ -47,36 +40,5 @@ public abstract class DBObject implement
      * @return the database object
      */
     public abstract DBDatabase getDatabase();
-    
-    /**
-     * Sets the current error from an SQL Exception.
-     * 
-     * @param type the error type
-     * @param sqle the SQL error message
-     *            
-     * @return the return value is always false
-     */
-    protected EmpireException SQL2EmpireException(ErrorType type, SQLException sqle)
-    {
-        log.error("Database operation failed.", sqle);
-        // converts a database error message to a human readable error message.
-        DBDatabase db = getDatabase();
-        if (db!=null && db.getDriver()!=null)
-            return new EmpireException(type, new Object[] { db.getDriver().extractErrorMessage(sqle) }, sqle);
-        // Set the error Message
-        return new EmpireException(type, sqle.getMessage());
-    }
-
-    /**
-     * Sets the current error from an SQL Exception.
-     * 
-     * @param sqle the SQL error message
-     *            
-     * @return the return value is always false
-     */
-    protected EmpireException SQL2EmpireException(SQLException sqle)
-    {   // converts a database error message to a human readable error message.
-        return SQL2EmpireException(DBErrors.SQLException, sqle);
-    }
 
 }
\ No newline at end of file

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBQuery.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBQuery.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBQuery.java Sat Jul 23 16:09:27 2011
@@ -24,15 +24,23 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCommand.DBCommandParam;
+import org.apache.empire.db.exceptions.NoPrimaryKeyException;
+import org.apache.empire.db.exceptions.InvalidKeyException;
+import org.apache.empire.db.exceptions.RecordNotFoundException;
+import org.apache.empire.db.exceptions.RecordUpdateFailedException;
+import org.apache.empire.db.exceptions.RecordUpdateInvalidException;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
 import org.apache.empire.db.expr.join.DBJoinExpr;
+import org.apache.empire.exceptions.EmpireException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
 import org.w3c.dom.Element;
 
 
@@ -43,7 +51,7 @@ import org.w3c.dom.Element;
  *  <LI>In oder to define subqueries simply define a command object with the subquery and wrap it inside a DBQuery.
  *    Then in a second command object you can reference this Query to join with your other tables and views.
  *    In order to join other columns with your query use findQueryColumn(DBColumnExpr expr) to get the 
- *    query column object for a given column expression in the orignial select clause.</LI> 
+ *    query column object for a given column expression in the original select clause.</LI> 
  *  <LI>With a key supplied you can have an updateable query that will update several records at once.</LI>
  * </UL>
  *
@@ -271,7 +279,7 @@ public class DBQuery extends DBRowSet
     public Object[] getRecordKey(DBRecord record)
     {
         if (record == null || record.getRowSet() != this)
-            throw new EmpireException(Errors.InvalidArg, record, "record");
+            throw new InvalidArgumentException("record", record);
         // get Key
         return (Object[]) record.getRowSetData();
     }
@@ -335,7 +343,7 @@ public class DBQuery extends DBRowSet
     @Override
     public void createRecord(DBRecord rec, Connection conn)
     {
-        throw new EmpireException(Errors.NotImplemented, "createRecord");
+        throw new NotImplementedException(this, "createRecord");
     }
 
     /**
@@ -350,10 +358,10 @@ public class DBQuery extends DBRowSet
     public void readRecord(DBRecord rec, Object[] key, Connection conn)
     {
         if (conn == null || rec == null)
-            throw new EmpireException(Errors.InvalidArg, null, "conn|rec");
+            throw new InvalidArgumentException("conn|rec", null);
         DBColumn[] keyColumns = getKeyColumns();
         if (key == null || keyColumns.length != key.length)
-            throw new EmpireException(DBErrors.RecordInvalidKey, key);
+            throw new InvalidKeyException(this, key);
         // Select
         for (int i = 0; i < keyColumns.length; i++)
         {   // Set key column constraint
@@ -372,7 +380,7 @@ public class DBQuery extends DBRowSet
             // Translate exception
             if (e.getErrorType()==DBErrors.QueryNoResult)
                 // Record not found
-                throw new EmpireException(DBErrors.RecordNotFound, key);
+                throw new RecordNotFoundException(this, key);
             else
                 // Other error
                 throw e;
@@ -390,14 +398,14 @@ public class DBQuery extends DBRowSet
     public void updateRecord(DBRecord rec, Connection conn)
     {
         if (conn == null || rec == null)
-            throw new EmpireException(Errors.InvalidArg, null, "conn|rec");
+            throw new InvalidArgumentException("conn|rec", null);
         // Has record been modified?
         if (rec.isModified() == false)
             return; // Nothing to update
         // Must have key Columns
         DBColumn[] keyColumns = getKeyColumns();
         if (keyColumns==null)
-            throw new EmpireException(DBErrors.NoPrimaryKey, getAlias());
+            throw new NoPrimaryKeyException(this);
         // Get the fields and the flags
         Object[] fields = rec.getFields();
         // Get all Update Commands
@@ -450,10 +458,10 @@ public class DBQuery extends DBRowSet
                 DBColumn right = join.getRight().getUpdateColumn();
                 if (left.getRowSet()==table && table.isKeyColumn(left))
                     if (!addJoinRestriction(upd, left, right, keyColumns, rec))
-                        throw new EmpireException(Errors.ItemNotFound, left.getFullName());
+                        throw new ItemNotFoundException(left.getFullName());
                 if (right.getRowSet()==table && table.isKeyColumn(right))
                     if (!addJoinRestriction(upd, right, left, keyColumns, rec))
-                        throw new EmpireException(Errors.ItemNotFound, right.getFullName());
+                        throw new ItemNotFoundException(right.getFullName());
             }
             // Evaluate Existing restrictions
             for (i = 0; cmd.where != null && i < cmd.where.size(); i++)
@@ -477,7 +485,7 @@ public class DBQuery extends DBRowSet
                 } 
                 else
                 {	// other constraints are not supported
-                    throw new EmpireException(Errors.NotSupported, "updateRecord");
+                    throw new NotSupportedException(this, "updateRecord with "+cmp.getClass().getName());
                 }
             }
             // Add Restrictions
@@ -524,7 +532,7 @@ public class DBQuery extends DBRowSet
             {   // Error
                 if (affected == 0)
                 { // Record not found
-                    throw new EmpireException(DBErrors.RecordUpdateFailed, table.getName());
+                    throw new RecordUpdateFailedException(this, keys);
                 }
                 // Rollback
                 db.rollback(conn);
@@ -532,7 +540,7 @@ public class DBQuery extends DBRowSet
             } 
             else if (affected > 1)
             { // More than one record
-                throw new EmpireException(DBErrors.RecordUpdateInvalid, table.getName());
+                throw new RecordUpdateInvalidException(this, keys);
             } 
             else
             { // success
@@ -585,7 +593,7 @@ public class DBQuery extends DBRowSet
     @Override
     public void deleteRecord(Object[] keys, Connection conn)
     {
-        throw new EmpireException(Errors.NotImplemented, "deleteRecord");
+        throw new NotImplementedException(this, "deleteRecord()");
     }
 
 }
\ No newline at end of file

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBReader.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBReader.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBReader.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBReader.java Sat Jul 23 16:09:27 2011
@@ -33,11 +33,14 @@ import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.exceptions.InternalSQLException;
+import org.apache.empire.db.exceptions.QueryNoResultException;
+import org.apache.empire.exceptions.BeanInstantiationException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.xml.XMLUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -129,7 +132,8 @@ public class DBReader extends DBRecordDa
                 // there are more records
                 return true;
             } catch (SQLException e) {
-                throw SQL2EmpireException(e);
+                // Error
+                throw new InternalSQLException(getDatabase(), e);
             }
         }
 
@@ -185,7 +189,7 @@ public class DBReader extends DBRecordDa
             if (curCount >= maxCount)
                 return false;
             if (rset == null)
-                throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+                throw new ObjectNotValidException(this);
             // Check next Record
             if (getCurrent == true)
             {
@@ -364,7 +368,7 @@ public class DBReader extends DBRecordDa
     {
         // Check params
         if (index < 0 || index >= colList.length)
-            throw new EmpireException(Errors.OutOfRange, index);
+            throw new InvalidArgumentException("index", index);
         try
         {   // Get Value from Resultset
             DataType dataType = colList[index].getDataType();
@@ -372,7 +376,7 @@ public class DBReader extends DBRecordDa
 
         } catch (SQLException e)
         { // Operation failed
-            throw SQL2EmpireException(e);
+            throw new InternalSQLException(this, e);
         }
     }
 
@@ -410,7 +414,7 @@ public class DBReader extends DBRecordDa
         db = cmd.getDatabase();
         rset = db.executeQuery(sqlCmd, cmd.getParamValues(), scrollable, conn);
         if (rset==null)
-            throw new EmpireException(DBErrors.QueryNoResult, sqlCmd);
+            throw new QueryNoResultException(sqlCmd);
         // successfully opened
         colList = cmd.getSelectExprList();
         addOpenResultSet();
@@ -450,7 +454,7 @@ public class DBReader extends DBRecordDa
         // Get First Record
         if (!moveNext())
         { // Close
-            throw new EmpireException(DBErrors.QueryNoResult, cmd.getSelect());
+            throw new QueryNoResultException(cmd.getSelect());
         }
     }
 
@@ -496,13 +500,13 @@ public class DBReader extends DBRecordDa
         try
         {   // Check Recordset
             if (rset == null)
-                throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+                throw new ObjectNotValidException(this);
             // Forward only cursor?
             int type = rset.getType();
             if (type == ResultSet.TYPE_FORWARD_ONLY)
             {
                 if (count < 0)
-                    throw new EmpireException(Errors.InvalidArg, count, "count");
+                    throw new InvalidArgumentException("count", count);
                 // Move
                 for (; count > 0; count--)
                 {
@@ -532,7 +536,7 @@ public class DBReader extends DBRecordDa
 
         } catch (SQLException e) {
             // an error occurred
-            throw new EmpireException(e);
+            throw new InternalSQLException(this, e);
         }
     }
 
@@ -546,7 +550,7 @@ public class DBReader extends DBRecordDa
         try
         {   // Check Recordset
             if (rset == null)
-                throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+                throw new ObjectNotValidException(this);
             // Move Next
             if (rset.next() == false)
             { // Close recordset automatically after last record
@@ -557,7 +561,7 @@ public class DBReader extends DBRecordDa
 
         } catch (SQLException e) {
             // an error occurred
-            throw SQL2EmpireException(e);
+            throw new InternalSQLException(this, e);
         }
     }
 
@@ -608,7 +612,7 @@ public class DBReader extends DBRecordDa
     public void initRecord(DBRowSet rowset, DBRecord rec)
     {
     	if (rowset==null)
-    	    throw new EmpireException(Errors.InvalidArg, rowset, "rowset");
+    	    throw new InvalidArgumentException("rowset", rowset);
     	// init Record
     	rowset.initRecord(rec, this);
     }
@@ -629,7 +633,7 @@ public class DBReader extends DBRecordDa
         // Check Recordset
         if (rset == null)
         {   // Resultset not available
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         }
         // Query List
         try
@@ -665,11 +669,11 @@ public class DBReader extends DBRecordDa
             // done
             return c;
         } catch (InvocationTargetException e) {
-            throw new EmpireException(e);
+            throw new BeanInstantiationException(t, e);
         } catch (IllegalAccessException e) {
-            throw new EmpireException(e);
+            throw new BeanInstantiationException(t, e);
         } catch (InstantiationException e) {
-            throw new EmpireException(e);
+            throw new BeanInstantiationException(t, e);
         }
     }
     
@@ -705,7 +709,7 @@ public class DBReader extends DBRecordDa
     public int addColumnDesc(Element parent)
     {
         if (colList == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Add Field Description
         for (int i = 0; i < colList.length; i++)
             colList[i].addXml(parent, 0);
@@ -723,7 +727,7 @@ public class DBReader extends DBRecordDa
     public int addRowValues(Element parent)
     {
         if (rset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Add all children
         for (int i = 0; i < colList.length; i++)
         { // Read all

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecord.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecord.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecord.java Sat Jul 23 16:09:27 2011
@@ -25,13 +25,15 @@ import java.util.List;
 
 import org.apache.commons.beanutils.BeanUtilsBean;
 import org.apache.commons.beanutils.PropertyUtilsBean;
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 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.exceptions.FieldIsReadOnlyException;
+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;
@@ -322,9 +324,9 @@ public class DBRecord extends DBRecordDa
     public boolean wasModified(int index)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         if (index < 0 || index >= fields.length)
-            throw new EmpireException(Errors.OutOfRange, index);
+            throw new InvalidArgumentException("index", index);
         // Check modified
         if (modified == null)
             return false;
@@ -406,10 +408,10 @@ public class DBRecord extends DBRecordDa
     public Object getValue(int index)
     {   // Check state
         if (fields == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Check index
         if (index < 0 || index>= fields.length)
-            throw new EmpireException(Errors.OutOfRange, index);
+            throw new InvalidArgumentException("index", index);
         // Special check for NO_VALUE 
         if (fields[index] == ObjectUtils.NO_VALUE)
             return null;
@@ -428,11 +430,11 @@ public class DBRecord extends DBRecordDa
     public boolean isValueValid(int index)
     {   // Check state
         if (fields == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Check index
         if (index < 0 || index>= fields.length)
         {   // Index out of range
-            throw new EmpireException(Errors.OutOfRange, index);
+            throw new InvalidArgumentException("index", index);
         }
         // Special check for NO_VALUE
         return (fields[index] != ObjectUtils.NO_VALUE);
@@ -493,32 +495,32 @@ public class DBRecord extends DBRecordDa
      * The functions checks if the column and the value are valid and whether the
      * value has changed.
      * 
-     * @param i the index of the column
+     * @param index the index of the column
      * @param value the value
      * @return true if successful
      */
-    public void setValue(int i, Object value)
+    public void setValue(int index, Object value)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
-        if (i < 0 || i >= fields.length)
-            throw new EmpireException(Errors.OutOfRange, i);
+            throw new ObjectNotValidException(this);
+        if (index < 0 || index >= fields.length)
+            throw new InvalidArgumentException("index", index);
         // Strings special
         if ((value instanceof String) && ((String)value).length()==0)
             value = null;
         // Has Value changed?
-        if (ObjectUtils.compareEqual(fields[i], value))
+        if (ObjectUtils.compareEqual(fields[index], value))
             return; // no change
         // Field has changed
-        DBColumn column = rowset.getColumn(i);
+        DBColumn column = rowset.getColumn(index);
         if (column.isAutoGenerated())
         {   // Read Only column may be set
-            throw new EmpireException(DBErrors.FieldIsReadOnly, column.getName());
+            throw new FieldIsReadOnlyException(column);
         }
         // Is Value valid
         column.checkValue(value);
         // Init original values
-        modifyValue(i, value);
+        modifyValue(index, value);
     }
 
     /**
@@ -533,7 +535,7 @@ public class DBRecord extends DBRecordDa
     public final void setValue(Column column, Object value)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Get Column Index
         setValue(rowset.getColumnIndex(column), value);
     }
@@ -548,7 +550,7 @@ public class DBRecord extends DBRecordDa
     public boolean isFieldReadOnly(DBColumn column)
     {
         if (rowset==null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Ask RowSet
         return (rowset.isColumnReadOnly(column));
     }
@@ -571,7 +573,7 @@ public class DBRecord extends DBRecordDa
     public boolean isFieldVisible(DBColumn column)
     {
         if (rowset==null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Check if field is present and the value is valid 
         int index = rowset.getColumnIndex(column);
         return (index>=0 && isValueValid(index));
@@ -677,7 +679,7 @@ public class DBRecord extends DBRecordDa
     public void update(Connection conn)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // update
         rowset.updateRecord(this, conn);
     }
@@ -696,7 +698,7 @@ public class DBRecord extends DBRecordDa
     public void delete(Connection conn)
     {
         if (isValid()==false)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Delete only if record is not new
         if (!isNew())
         {
@@ -715,7 +717,7 @@ public class DBRecord extends DBRecordDa
     public int addColumnDesc(Element parent)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Add Field Description
         int count = 0;
         List<DBColumn> columns = rowset.getColumns();
@@ -740,7 +742,7 @@ public class DBRecord extends DBRecordDa
     public int addRowValues(Element parent)
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // set row key
         DBColumn[] keyColumns = rowset.getKeyColumns();
         if (keyColumns != null && keyColumns.length > 0)
@@ -800,17 +802,17 @@ public class DBRecord extends DBRecordDa
     public Document getXmlDocument()
     {
         if (rowset == null)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Create Document
         DBXmlDictionary xmlDic = getXmlDictionary();
         Element root = XMLUtil.createDocument(xmlDic.getRowSetElementName());
         if (rowset.getName() != null)
             root.setAttribute("name", rowset.getName());
         // Add Field Description
-        if (addColumnDesc(root)==0)
-            throw new EmpireException(Errors.NoResult, rowset.getName());
-        // Add row Values
-        addRowValues(XMLUtil.addElement(root, xmlDic.getRowElementName()));
+        if (addColumnDesc(root)>0)
+        {   // Add row Values
+            addRowValues(XMLUtil.addElement(root, xmlDic.getRowElementName()));
+        }
         // return Document
         return root.getOwnerDocument();
     }
@@ -871,13 +873,13 @@ public class DBRecord extends DBRecordDa
 
         } catch (IllegalAccessException e)
         {   log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         } catch (InvocationTargetException e)
         {   log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         } catch (NoSuchMethodException e)
         {   log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
-            throw new EmpireException(e);
+            throw new BeanPropertyGetException(bean, property, e);
         }
     }
     

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java Sat Jul 23 16:09:27 2011
@@ -24,11 +24,11 @@ import java.util.Date;
 
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.empire.commons.DateUtils;
-import org.apache.empire.commons.EmpireException;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.RecordData;
+import org.apache.empire.exceptions.BeanPropertySetException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -282,13 +282,12 @@ public abstract class DBRecordData exten
             // done
 
         } catch (IllegalAccessException e)
-        {
-            log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
-            throw new EmpireException(e);
+        {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
+            throw new BeanPropertySetException(bean, property, e);
+            
         } catch (InvocationTargetException e)
-        {
-            log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
-            throw new EmpireException(e);
+        {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
+            throw new BeanPropertySetException(bean, property, e);
             /*
              * } catch(NoSuchMethodException e) { log.warn(bean.getClass().getName() + ": cannot check value of property '" +
              * property + "'"); return true;

Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1150139&r1=1150138&r2=1150139&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Sat Jul 23 16:09:27 2011
@@ -26,14 +26,23 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.empire.commons.EmpireException;
-import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBRelation.DBReference;
+import org.apache.empire.db.exceptions.FieldNotNullException;
+import org.apache.empire.db.exceptions.NoPrimaryKeyException;
+import org.apache.empire.db.exceptions.QueryNoResultException;
+import org.apache.empire.db.exceptions.InvalidKeyException;
+import org.apache.empire.db.exceptions.RecordNotFoundException;
+import org.apache.empire.db.exceptions.RecordUpdateFailedException;
+import org.apache.empire.db.exceptions.RecordUpdateInvalidException;
 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.ObjectNotValidException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -293,7 +302,7 @@ public abstract class DBRowSet extends D
     protected void addColumnReference(DBColumn source, DBColumn target)
     {
         if (source.getRowSet()!=this)
-            throw new EmpireException(Errors.InvalidArg, source.getFullName(), "column");
+            throw new InvalidArgumentException("column", source.getFullName());
         if (columnReferences== null)
             columnReferences = new HashMap<DBColumn, DBColumn>();
         // Check if column is already there
@@ -358,8 +367,10 @@ public abstract class DBRowSet extends D
      */
     protected void prepareInitRecord(DBRecord rec, int state, Object rowSetData)
     {
+        if (rec==null)
+            throw new InvalidArgumentException("rec", rec);
         if (columns.size() < 1)
-            throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
+            throw new ObjectNotValidException(this);
         // Init
         rec.init(this, state, rowSetData);
     }
@@ -414,34 +425,27 @@ public abstract class DBRowSet extends D
         Object[] fields = rec.getFields();
         for (int i = 0; i < fields.length; i++)
         {
-            try
-            {   // Read a value
-            	DBColumn column = columns.get(i);
-            	int rdi = recData.getFieldIndex(column);
-            	if (rdi<0)
-            	{	// Field not available in Record Data
-            		if (primaryKey!=null && primaryKey.contains(column))
-            		{	// Error: Primary Key not supplied
-            		    throw new EmpireException(DBErrors.RecordInvalidKey, column.toString());
-            		}
-                    if (timestampColumn == column)
-                    { // Check the update Time Stamp
-                    	if (log.isInfoEnabled())
-                    		log.info(getName() + "No record timestamp value has been provided. Hence concurrent changes will not be detected.");
-                    } 
-            		// Set to NO_VALUE
-                    fields[i] = ObjectUtils.NO_VALUE;
-            	}
-            	else
-            	{   // Get Field value
-                    fields[i] = recData.getValue(rdi);
-            	}
-            } catch (Exception e)
-            {   // Unknown exception
-                log.error("initRecord exception: " + e.toString());
-                rec.close();
-                throw new EmpireException(e);
-            }
+            // Read a value
+        	DBColumn column = columns.get(i);
+        	int rdi = recData.getFieldIndex(column);
+        	if (rdi<0)
+        	{	// Field not available in Record Data
+        		if (primaryKey!=null && primaryKey.contains(column))
+        		{	// Error: Primary Key not supplied
+        		    throw new ItemNotFoundException(column.getName());
+        		}
+                if (timestampColumn == column)
+                { // Check the update Time Stamp
+                	if (log.isInfoEnabled())
+                		log.info(getName() + "No record timestamp value has been provided. Hence concurrent changes will not be detected.");
+                } 
+        		// Set to NO_VALUE
+                fields[i] = ObjectUtils.NO_VALUE;
+        	}
+        	else
+        	{   // Get Field value
+                fields[i] = recData.getValue(rdi);
+        	}
         }
         // Done
         completeInitRecord(rec);
@@ -469,17 +473,18 @@ public abstract class DBRowSet extends D
     {
         // Check Primary key
         if (primaryKey == null ) 
-            throw new EmpireException(DBErrors.NoPrimaryKey, getName()); // Invalid Argument
+            throw new NoPrimaryKeyException(this); // Invalid Argument
         // Check Columns
         DBColumn[] keyColumns = primaryKey.getColumns();
         if (key == null || key.length != keyColumns.length)
-            throw new EmpireException(DBErrors.RecordInvalidKey, key); // Invalid Argument
+            throw new InvalidKeyException(this, key); // Invalid Argument
         // Add the key constraints
         for (int i = 0; i < key.length; i++)
-        {   // Set key column constraint
+        {   // prepare key value
             Object value = key[i];
             if (db.isPreparedStatementsEnabled())
                 value = cmd.addParam(keyColumns[i], value);
+            // set key column constraint
             cmd.where(keyColumns[i].is(value));
         }    
     }
@@ -509,6 +514,7 @@ public abstract class DBRowSet extends D
     
     /**
      * Reads the record with the given primary key from the database.
+     * If the record cannot be found, a RecordNotFoundException is thrown.
      * <P>
      * @param rec the DBRecord object which will hold the record data
      * @param key the primary key values
@@ -519,7 +525,7 @@ public abstract class DBRowSet extends D
     {
         // Check Arguments
         if (conn == null || rec == null)
-            throw new EmpireException(Errors.InvalidArg, null, "conn|rec");
+            throw new InvalidArgumentException("conn|rec", null);
         // Select
         DBCommand cmd = db.createCommand();
         cmd.select(columns);
@@ -528,14 +534,9 @@ public abstract class DBRowSet extends D
         try {
             // Read Record
             readRecord(rec, cmd, conn);
-        } catch (EmpireException e) {
+        } catch (QueryNoResultException e) {
             // Translate exception
-            if (e.getErrorType()==DBErrors.QueryNoResult)
-                // Record not found
-                throw new EmpireException(DBErrors.RecordNotFound, key);
-            else
-                // Other error
-                throw e;
+            throw new RecordNotFoundException(this, key);
         }
     }
 
@@ -550,7 +551,7 @@ public abstract class DBRowSet extends D
     {
         // Check Arguments
         if (conn == null)
-            throw new EmpireException(Errors.InvalidArg, conn, "conn");
+            throw new InvalidArgumentException("conn", conn);
         // Select
         DBCommand cmd = db.createCommand();
         cmd.select(count());
@@ -590,7 +591,7 @@ public abstract class DBRowSet extends D
     {
         // Check Arguments
         if (conn == null)
-            throw new EmpireException(Errors.InvalidArg, conn, "conn");
+            throw new InvalidArgumentException("conn", conn);
         // Get the new Timestamp
         String name = getName();
         Timestamp timestamp = (timestampColumn!=null) ? db.getUpdateTimestamp(conn) : null;
@@ -607,7 +608,7 @@ public abstract class DBRowSet extends D
                 if (primaryKey == null)
                 { // Requires a primary key
                     log.error("updateRecord: "  + name + " no primary key defined!");
-                    throw new EmpireException(DBErrors.NoPrimaryKey, name);
+                    throw new NoPrimaryKeyException(this);
                 }
                 for (int i = 0; i < columns.size(); i++)
                 { // search for the column
@@ -688,11 +689,11 @@ public abstract class DBRowSet extends D
                     }
                     else if (primaryKey!=null && primaryKey.contains(col))
                     {   // All primary key fields must be supplied
-                        throw new EmpireException(DBErrors.FieldNotNull, col.getName());
+                        throw new FieldNotNullException(col);
                     }
                     else if (col.isRequired())
                     {   // Error Column is required!
-                        throw new EmpireException(DBErrors.FieldNotNull, col.getName());
+                        throw new FieldNotNullException(col);
                     }
                 }
                 sql = cmd.getInsert();
@@ -711,15 +712,15 @@ public abstract class DBRowSet extends D
         int affected = db.executeSQL(sql, cmd.getParamValues(), conn, setGenKey);
         if (affected < 0)
         {   // Update Failed
-            throw new EmpireException(Errors.UnexpectedValue, affected, "db.executeSQL()");
+            throw new UnexpectedReturnValueException(affected, "db.executeSQL()");
         } 
         else if (affected == 0)
         { // Record not found
-            throw new EmpireException(DBErrors.RecordUpdateFailed, name);
+            throw new RecordUpdateFailedException(this, getRecordKey(rec));
         } 
         else if (affected > 1)
         { // Multiple Records affected
-            throw new EmpireException(DBErrors.RecordUpdateInvalid, name);
+            throw new RecordUpdateInvalidException(this, getRecordKey(rec));
         }
         // Correct Timestamp
         if (timestampColumn != null)
@@ -785,7 +786,7 @@ public abstract class DBRowSet extends D
     {
         // Key length and reference length must match
         if (refs.length!=parentKey.length)
-            throw new EmpireException(DBErrors.RecordInvalidKey);
+            throw new InvalidArgumentException("refs", refs);
         // Rowset
         DBColumn[] keyColumns = getKeyColumns();
         if (keyColumns==null || keyColumns.length==0)
@@ -794,7 +795,7 @@ public abstract class DBRowSet extends D
             for (int i=0; i<parentKey.length; i++)
                 cmd.where(refs[i].getSourceColumn().is(parentKey[i]));
             if (db.executeSQL(cmd.getDelete((DBTable)this), conn)<0)
-                throw new EmpireException(Errors.UnexpectedValue, -1, "db.executeSQL()");
+                throw new UnexpectedReturnValueException(-1, "db.executeSQL()");
         }
         else
         {   // Query all keys