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 fr...@apache.org on 2011/08/16 17:56:44 UTC
svn commit: r1158339 [3/5] - in /incubator/empire-db/trunk: ./
empire-db-codegen/src/main/java/org/apache/empire/db/codegen/
empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/
empire-db-examples/empire-db...
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java Tue Aug 16 15:56:41 2011
@@ -18,25 +18,26 @@
*/
package org.apache.empire.db;
-import org.apache.empire.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,9 +172,7 @@ public abstract class DBCommand extends
int index = cmdParams.indexOf(param);
if (index < paramUsageCount)
{ // Error: parameter probably used twice in statement!
- String msg = "A parameter may only be used once in a command.";
- error(Errors.Internal, msg);
- throw new EmpireException(this);
+ throw new MiscellaneousErrorException("A parameter may only be used once in a command.");
}
if (index > paramUsageCount)
{ // Correct parameter order
@@ -674,9 +673,9 @@ public abstract class DBCommand extends
*
* @return true if the database supports a limit or false otherwise
*/
- public boolean limitRows(int numRows)
+ public void limitRows(int numRows)
{
- return error(Errors.NotSupported, "limitRows");
+ throw new NotSupportedException(this, "limitRows");
}
/**
@@ -685,9 +684,9 @@ public abstract class DBCommand extends
*
* @return true if the database supports an offset or false otherwise
*/
- public boolean skipRows(int numRows)
+ public void skipRows(int numRows)
{
- return error(Errors.NotSupported, "skipRows");
+ throw new NotSupportedException(this, "skipRows");
}
/**
@@ -704,11 +703,11 @@ public abstract class DBCommand extends
}
@Override
- public synchronized boolean getSelect(StringBuilder buf)
+ public synchronized void getSelect(StringBuilder buf)
{
resetParamUsage();
if (select == null)
- return error(Errors.ObjectNotValid, getClass().getName()); // invalid!
+ throw new ObjectNotValidException(this); // invalid!
// Prepares statement
addSelect(buf);
// From clause
@@ -719,8 +718,6 @@ public abstract class DBCommand extends
addGrouping(buf);
// Add Order
addOrder(buf);
- // done
- return success();
}
/**
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java Tue Aug 16 15:56:41 2011
@@ -19,17 +19,19 @@
package org.apache.empire.db;
// java
-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.
@@ -107,8 +109,7 @@ public abstract class DBCommandExpr exte
@Override
public DBColumn[] getKeyColumns()
{
- error(Errors.NotSupported, "getKeyColumns");
- return null;
+ throw new NotSupportedException(this, "getKeyColumns");
}
/**
@@ -119,48 +120,47 @@ public abstract class DBCommandExpr exte
@Override
public Object[] getRecordKey(DBRecord rec)
{
- error(Errors.NotSupported, "getRecordKey");
- return null;
+ throw new NotSupportedException(this, "getRecordKey");
}
/** Returns the error message: ERR_NOTSUPPORTED */
@Override
- public boolean initRecord(DBRecord rec, Object[] keyValues)
+ public void initRecord(DBRecord rec, Object[] keyValues)
{
- return error(Errors.NotSupported, "initRecord");
+ throw new NotSupportedException(this, "initRecord");
}
/** Returns the error message: ERR_NOTSUPPORTED */
@Override
- public boolean createRecord(DBRecord rec, Connection conn)
+ public void createRecord(DBRecord rec, Connection conn)
{
- return error(Errors.NotSupported, "addRecord");
+ throw new NotSupportedException(this, "addRecord");
}
/** Returns the error message: ERR_NOTSUPPORTED */
@Override
- public boolean readRecord(DBRecord rec, Object[] keys, Connection conn)
+ public void readRecord(DBRecord rec, Object[] keys, Connection conn)
{
- return error(Errors.NotSupported, "getRecord");
+ throw new NotSupportedException(this, "getRecord");
}
/** Returns the error message: ERR_NOTSUPPORTED */
@Override
- public boolean updateRecord(DBRecord rec, Connection conn)
+ public void updateRecord(DBRecord rec, Connection conn)
{
- return error(Errors.NotSupported, "updateRecord");
+ throw new NotSupportedException(this, "updateRecord");
}
/** Returns the error message: ERR_NOTSUPPORTED */
@Override
- public boolean deleteRecord(Object[] keys, Connection conn)
+ public void deleteRecord(Object[] keys, Connection conn)
{
- return error(Errors.NotSupported, "deleteRecord");
+ throw new NotSupportedException(this, "deleteRecord");
}
}
/**
- * This class wrapps a column of sql command in a special command column object.
+ * This class wraps a column of sql command in a special command column object.
*/
protected static class DBCmdColumn extends DBColumn
{
@@ -275,9 +275,9 @@ public abstract class DBCommandExpr exte
* Not applicable - always returns true.
*/
@Override
- public boolean checkValue(Object value)
+ public void checkValue(Object value)
{
- return true;
+ // Nothing to check.
}
/**
@@ -304,7 +304,7 @@ public abstract class DBCommandExpr exte
// get Select SQL
public abstract boolean isValid();
- public abstract boolean getSelect(StringBuilder buf);
+ public abstract void getSelect(StringBuilder buf);
public abstract DBColumnExpr[] getSelectExprList();
@@ -340,15 +340,11 @@ public abstract class DBCommandExpr exte
* returns an SQL select command for querying records.
* @return the SQL-Command
*/
- public String getSelect()
+ public final String getSelect()
{
- StringBuilder buf = new StringBuilder();
- if (getSelect(buf) == false)
- {
- log.error(getErrorMessage());
- return null;
- }
- return buf.toString();
+ StringBuilder sql = new StringBuilder();
+ getSelect(sql);
+ return sql.toString();
}
/**
@@ -467,10 +463,8 @@ public abstract class DBCommandExpr exte
protected String getInsertInto(DBTable table, DBColumnExpr[] select, List<DBColumnExpr> columns)
{
if (select == null)
- { // invalid Object
- error(Errors.ObjectNotValid, getClass().getName());
- return null;
- }
+ throw new ObjectNotValidException(this);
+ // prepare buffer
StringBuilder buf = new StringBuilder("INSERT INTO ");
table.addSQL(buf, CTX_FULLNAME);
// destination columns
@@ -478,8 +472,7 @@ public abstract class DBCommandExpr exte
{ // Check Count
if (columns.size() != select.length)
{
- error(Errors.InvalidArg, columns, "columns");
- return null;
+ throw new InvalidArgumentException("columns", "size()!=select.length");
}
// Append Names
buf.append(" (");
@@ -519,10 +512,7 @@ public abstract class DBCommandExpr exte
{
DBColumnExpr[] select = getSelectExprList();
if (select == null || select.length < 1)
- {
- error(Errors.ObjectNotValid, getClass().getName());
- return null;
- }
+ 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/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java Tue Aug 16 15:56:41 2011
@@ -26,11 +26,20 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-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;
@@ -162,22 +171,20 @@ public abstract class DBDatabase extends
* Sets the database driver for this database. This will
* set up the connection for use.<br>
*
- * @param driver the databae driver
+ * @param driver the database driver
* @param conn the connection
*
- * @return true on succes
+ * @return true on success
*/
- public boolean open(DBDatabaseDriver driver, Connection conn)
+ public void open(DBDatabaseDriver driver, Connection conn)
{
// Close Database if already open
if (isOpen())
close(conn);
// Attach to driver
- if (driver.attachDatabase(this, conn)==false)
- return error(driver);
+ driver.attachDatabase(this, conn);
// set new driver
this.driver = driver;
- return success();
}
/**
@@ -207,24 +214,20 @@ public abstract class DBDatabase extends
*
* @return the DLL script for creating the entire database schema
*/
- public synchronized boolean getCreateDDLScript(DBDatabaseDriver driver, DBSQLScript script)
+ public synchronized void getCreateDDLScript(DBDatabaseDriver driver, DBSQLScript script)
{
DBDatabaseDriver prevDriver = this.driver;
try {
// Set driver
if (this.driver!=null && this.driver!=driver && driver!=null)
{ // The database belongs to a different driver
- return error(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)
this.driver = driver;
// Get DDL Command
- if (driver.getDDLScript(DBCmdType.CREATE, this, script)==false)
- { // DDL-creation failed
- return error(driver);
- }
- return success();
+ driver.getDDLScript(DBCmdType.CREATE, this, script);
} finally {
this.driver = prevDriver;
@@ -255,15 +258,14 @@ public abstract class DBDatabase extends
*
* @param schema the schema to set
*
- * @return true on succes
+ * @return true on success
*/
- public boolean setSchema(String schema)
+ public void setSchema(String schema)
{ // Database must not be open so far
if (driver != null)
- return error(Errors.NoAccess);
+ throw new PropertyReadOnlyException("schema");
// Set Schema
this.schema = schema;
- return success();
}
/**
@@ -296,15 +298,14 @@ public abstract class DBDatabase extends
*
* @param linkName the database link name
*
- * @return true on succes
+ * @return true on success
*/
- public boolean setLinkName(String linkName)
+ public void setLinkName(String linkName)
{ // Database must not be open so far
if (driver != null)
- return error(Errors.NoAccess);
+ throw new PropertyReadOnlyException(linkName);
// Set Link
this.linkName = linkName;
- return success();
}
/**
@@ -327,7 +328,7 @@ public abstract class DBDatabase extends
/**
* Adds a full qualified object name including schema prefix
* and database link postfix (if any).
- * to the string buffer suppield
+ * to the string buffer supplied
*
* @param buf the string buffer to which to append the qualified object name
* @param name the object's name
@@ -338,7 +339,7 @@ public abstract class DBDatabase extends
// Check driver
if (driver==null)
{ // No driver attached!
- error(Errors.ObjectNotValid, name);
+ log.warn("No driver attached for appending qualified name {0}.", name);
buf.append(name);
return;
}
@@ -433,24 +434,23 @@ public abstract class DBDatabase extends
* @param table the DBTable object
* @return true if successful
*/
- public boolean addTable(DBTable table)
+ public void addTable(DBTable table)
{ // find column by name
if (table == null || table.getDatabase() != this)
- return error(Errors.InvalidArg, table, "table");
+ throw new InvalidArgumentException("table", table);
if (tables.contains(table)==true)
- return error(Errors.ItemExists, table.getName());
+ throw new ItemExistsException(table.getName());
// Check for second instances
DBTable existing = getTable(table.getName());
if (existing!=null)
{ // Check classes
if (existing.getClass().equals(table.getClass()))
- return success(); // Ingore other instances
+ return; // Ignore other instances
// Table exists with different class
- return error(Errors.ItemExists, table.getName());
+ throw new ItemExistsException(table.getName());
}
// add now
tables.add(table);
- return true;
}
/**
@@ -486,14 +486,14 @@ public abstract class DBDatabase extends
* @param reference a reference for a source and target column pair
* @return true if the relations were successfully created.
*/
- public final boolean addRelation(DBRelation.DBReference reference)
+ public final void addRelation(DBRelation.DBReference reference)
{
String table = reference.getSourceColumn().getRowSet().getName();
String col1 = reference.getSourceColumn().getName();
// Create Relation Name
String name = table.substring(0, Math.min(table.length(), 14)) + "_" + col1.substring(0, Math.min(col1.length(), 12))
+ "_FK";
- return addRelation(name, new DBRelation.DBReference[] { reference });
+ addRelation(name, new DBRelation.DBReference[] { reference });
}
/**
@@ -503,7 +503,7 @@ public abstract class DBDatabase extends
* @param ref2 a reference for a source and target column pair
* @return true if the relations were successfully created.
*/
- public final boolean addRelation(DBRelation.DBReference ref1, DBRelation.DBReference ref2)
+ public final void addRelation(DBRelation.DBReference ref1, DBRelation.DBReference ref2)
{
String table = ref1.getSourceColumn().getRowSet().getName();
String col1 = ref1.getSourceColumn().getName();
@@ -512,7 +512,7 @@ public abstract class DBDatabase extends
String name = table.substring(0, Math.min(table.length(), 9))
+ "_" + col1.substring(0, Math.min(col1.length(), 9))
+ "_" + col2.substring(0, Math.min(col2.length(), 9)) + "_FK";
- return addRelation(name, new DBRelation.DBReference[] { ref1, ref2 });
+ addRelation(name, new DBRelation.DBReference[] { ref1, ref2 });
}
/**
@@ -523,12 +523,12 @@ public abstract class DBDatabase extends
*
* @return true if the relations were successfully created.
*/
- public boolean addRelation(String name, DBRelation.DBReference[] references)
+ public void addRelation(String name, DBRelation.DBReference[] references)
{
// Add a Relation
DBRelation relation = new DBRelation(this, name, references);
if (relations.contains(relation))
- return error(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
@@ -537,7 +537,6 @@ public abstract class DBDatabase extends
}
// OK
relations.add(relation);
- return true;
}
/**
@@ -558,15 +557,14 @@ public abstract class DBDatabase extends
* @param view the DBView object
* @return true if successful
*/
- public boolean addView(DBView view)
+ public void addView(DBView view)
{ // find column by name
if (view == null || view.getDatabase() != this)
- return error(Errors.InvalidArg, view, "view");
+ throw new InvalidArgumentException("view", view);
if (views.contains(view) == true)
- return error(Errors.ItemExists, view.getName());
+ throw new ItemExistsException(view.getName());
// add now
views.add(view);
- return true;
}
/**
@@ -609,11 +607,10 @@ public abstract class DBDatabase extends
/**
* @return true if the database has been opened or false otherwise
*/
- protected boolean checkOpen()
+ protected void checkOpen()
{
- if (driver == null)
- return error(DBErrors.DatabaseNotOpen);
- return success();
+ if (isOpen()==false)
+ throw new DatabaseNotOpenException(this);
}
/**
@@ -623,8 +620,7 @@ public abstract class DBDatabase extends
*/
public DBCommand createCommand()
{
- if (!checkOpen())
- return null;
+ checkOpen();
return driver.createCommand(this);
}
@@ -636,20 +632,16 @@ public abstract class DBDatabase extends
*/
public java.sql.Timestamp getUpdateTimestamp(Connection conn)
{
- // Default implementation
- if (checkOpen()==false)
- return null;
// Ask driver
+ checkOpen();
return driver.getUpdateTimestamp(conn);
}
// Sequences
public Object getNextSequenceValue(String seqName, Connection conn)
{
- // Default implementation
- if (checkOpen()==false)
- return null;
// Ask driver
+ checkOpen();
return driver.getNextSequenceValue(this, seqName, 1, conn);
}
@@ -665,42 +657,32 @@ public abstract class DBDatabase extends
public Object querySingleValue(String sqlCmd, Connection conn)
{
+ checkOpen();
ResultSet rs = null;
try
- { // Check Open
- if (checkOpen()==false)
- return null;
- // Debug
+ { // Debug
long start = System.currentTimeMillis();
if (log.isDebugEnabled())
log.debug("executing: " + sqlCmd);
// Get the next Value
rs = driver.executeQuery(sqlCmd, null, false, conn);
if (rs == null)
- { // Error
- error(driver);
- return null;
- }
+ throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
// Check Result
if (rs.next() == false)
- {
- //log.warn("querySingleValue returned no result : Stack", new Exception("Just to show the stack"));
+ { // no result
log.debug("querySingleValue returned no result");
- error(DBErrors.QueryNoResult, sqlCmd);
- return null;
+ throw new QueryNoResultException(sqlCmd);
}
// No Value
- clearError();
Object result = rs.getObject(1);
if (log.isDebugEnabled())
log.debug("querySingleValue complete in " + (System.currentTimeMillis() - start) + " ms -> value="
+ result);
return result;
- } catch (SQLException e)
- {
- log.error("querySingleValue exception: " + e.toString());
- error(DBErrors.QueryFailed, e);
- return null;
+ } catch (SQLException sqle)
+ { // Error
+ throw new QueryFailedException(this, sqlCmd, sqle);
} finally
{ // Cleanup
closeResultSet(rs);
@@ -825,10 +807,8 @@ public abstract class DBDatabase extends
* @return the number of elements that have been added to the collection or -1 if an error occurred
*/
public <T> int querySimpleList(Class<T> c, String sqlCmd, Connection conn, Collection<T> result)
- { // Check status
- if (checkOpen()==false)
- return -1;
- // Start query
+ { // Start query
+ checkOpen();
ResultSet rs = null;
try
{ // Log performance
@@ -838,10 +818,7 @@ public abstract class DBDatabase extends
// Get the next Value
rs = driver.executeQuery(sqlCmd, null, false, conn);
if (rs == null)
- { // Error
- error(driver);
- return -1;
- }
+ throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
// Check Result
int count=0;
while (rs.next())
@@ -853,18 +830,13 @@ public abstract class DBDatabase extends
// No Value
if (log.isInfoEnabled())
log.info("querySimpleList retured " + count + " items. Query completed in " + (System.currentTimeMillis() - start) + " ms");
- clearError();
return count;
} catch (ClassCastException e)
- {
- log.error("querySingleValue cast exception: ", e);
- error(Errors.Exception, e);
- return -1;
- } catch (SQLException e)
- {
- log.error("querySimpleList exception: ", e);
- error(DBErrors.QueryFailed, e);
- return -1;
+ { log.error("querySingleValue cast exception: ", e);
+ throw new InternalException(e);
+ } catch (SQLException sqle)
+ { // Error
+ throw new QueryFailedException(this, sqlCmd, sqle);
} finally
{ // Cleanup
closeResultSet(rs);
@@ -913,30 +885,19 @@ public abstract class DBDatabase extends
*/
public Options queryOptionList(String sqlCmd, Connection conn)
{ // Execute the Statement
- if (checkOpen()==false)
- return null;
- // Debug
+ checkOpen();
ResultSet rs = null;
try
- { // Check Open
- if (checkOpen()==false)
- return null;
- // Debug
+ { // Debug
long start = System.currentTimeMillis();
if (log.isInfoEnabled())
log.info("executing: " + sqlCmd);
// Get the next Value
rs = driver.executeQuery(sqlCmd, null, false, conn);
if (rs == null)
- { // Error
- error(driver);
- return null;
- }
+ throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
if (rs.getMetaData().getColumnCount()<2)
- { // Not enough columns
- error(Errors.InvalidArg, sqlCmd, "sqlCmd");
- return null;
- }
+ throw new InvalidArgumentException("sqlCmd", sqlCmd);
// Check Result
Options result = new Options();
while (rs.next())
@@ -948,12 +909,10 @@ public abstract class DBDatabase extends
// No Value
if (log.isInfoEnabled())
log.info("queryOptionList retured " + result.size() + " items. Query completed in " + (System.currentTimeMillis() - start) + " ms");
- clearError();
return result;
- } catch (SQLException e)
- {
- error(DBErrors.QueryFailed, e);
- return null;
+ } catch (SQLException sqle)
+ { // Error
+ throw new QueryFailedException(this, sqlCmd, sqle);
} finally
{ // Cleanup
closeResultSet(rs);
@@ -971,10 +930,8 @@ public abstract class DBDatabase extends
* @return a list of object arrays
*/
public int queryObjectList(String sqlCmd, Connection conn, Collection<Object[]> result)
- { // Check status
- if (checkOpen()==false)
- return -1;
- // Perform query
+ { // Perform query
+ checkOpen();
ResultSet rs = null;
try
{ // Log performance
@@ -984,10 +941,7 @@ public abstract class DBDatabase extends
// Get the next Value
rs = driver.executeQuery(sqlCmd, null, false, conn);
if (rs == null)
- { // Error
- error(driver);
- return -1;
- }
+ throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
// Read List
int colCount = rs.getMetaData().getColumnCount();
int count = 0;
@@ -1004,12 +958,10 @@ public abstract class DBDatabase extends
// No Value
if (log.isInfoEnabled())
log.info("queryObjectList retured " + count + " items. Query completed in " + (System.currentTimeMillis() - start) + " ms");
- clearError();
return count;
- } catch (SQLException e)
- {
- error(DBErrors.QueryFailed, e);
- return -1;
+ } catch (SQLException sqle)
+ { // Error
+ throw new QueryFailedException(this, sqlCmd, sqle);
} finally
{ // Cleanup
closeResultSet(rs);
@@ -1044,33 +996,26 @@ public abstract class DBDatabase extends
*/
public int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBDatabaseDriver.DBSetGenKeys setGenKeys)
{
+ checkOpen();
try
- {
- // check driver
- if (checkOpen()==false)
- return -1;
- // Debug
+ { // Debug
if (log.isInfoEnabled())
log.info("Executing: " + sqlCmd);
// execute SQL
long start = System.currentTimeMillis();
int affected = driver.executeSQL(sqlCmd, sqlParams, conn, setGenKeys);
+ // number of affected records
+ if (affected < 0)
+ throw new UnexpectedReturnValueException(affected, "driver.executeSQL()");
// Log
if (log.isInfoEnabled())
log.info("executeSQL affected " + affected + " Records / " + (System.currentTimeMillis() - start) + "ms");
- // number of affected records
- if (affected < 0)
- {
- error(driver);
- return -1;
- }
// Return number of affected records
return affected;
} catch (SQLException sqle)
{ // Error
- error(sqle);
- return -1;
+ throw new QueryFailedException(this, sqlCmd, sqle);
}
}
@@ -1093,9 +1038,9 @@ public abstract class DBDatabase extends
}
/**
- * Executes a select SQL-Statement and returns a resulset containing the query results.<BR>
+ * Executes a select SQL-Statement and returns a resultset containing the query results.<BR>
* This function returns a JDBC ResultSet.<BR>
- * Insteam of using this function directly you should use a DBReader object instead.<BR>
+ * Instead of using this function directly you should use a DBReader object instead.<BR>
* <P>
* @param sqlCmd the SQL-Command
* @param sqlParams a list of parameters for parameter queries (may depend on driver)
@@ -1105,33 +1050,26 @@ public abstract class DBDatabase extends
*/
public ResultSet executeQuery(String sqlCmd, Object[] sqlParams, boolean scrollable, Connection conn)
{
+ checkOpen();
try
- { // check driver
- if (checkOpen()==false)
- return null;
- // Debug
+ { // Debug
if (log.isDebugEnabled())
log.debug("Executing: " + sqlCmd);
// Execute the Statement
long start = System.currentTimeMillis();
ResultSet rs = driver.executeQuery(sqlCmd, sqlParams, scrollable, conn);
if (rs == null)
- { error(driver);
- return null;
- }
+ throw new UnexpectedReturnValueException(rs, "driver.executeQuery()");
// Debug
if (log.isDebugEnabled())
log.debug("executeQuery successful in " + (System.currentTimeMillis() - start) + " ms");
// Return number of affected records
- success();
return rs;
- } catch (SQLException e)
- { // SQL Query failed!
- log.error("execute query exception! sql = " + sqlCmd);
- error(DBErrors.QueryFailed, e);
- return null;
- }
+ } catch (SQLException sqle)
+ { // Error
+ throw new QueryFailedException(this, sqlCmd, sqle);
+ }
}
/**
@@ -1143,20 +1081,20 @@ public abstract class DBDatabase extends
*
* @return true if successful
*/
- public boolean commit(Connection conn)
+ public void commit(Connection conn)
{
try
{ // Check argument
if (conn==null)
- return error(Errors.InvalidArg, null, "conn");
+ throw new InvalidArgumentException("conn", conn);
// Commit
if (conn.getAutoCommit()==false)
conn.commit();
- return true;
- } catch (SQLException sqle)
- {
+ // Done
+ return;
+ } catch (SQLException sqle) {
// Commit failed!
- return error(sqle);
+ throw new InternalSQLException(this, sqle);
}
}
@@ -1169,19 +1107,20 @@ public abstract class DBDatabase extends
*
* @return true if successful
*/
- public boolean rollback(Connection conn)
+ public void rollback(Connection conn)
{
try
- { // Check arguement
+ { // Check argument
if (conn==null)
- return error(Errors.InvalidArg, null, "conn");
- // Rollback
+ throw new InvalidArgumentException("conn", conn);
+ // rollback
log.info("Database rollback issued!");
conn.rollback();
- return success();
- } catch (SQLException sqle)
- {
- return error(sqle);
+ // Done
+ return;
+ } catch (SQLException sqle) {
+ // Commit failed!
+ throw new InternalSQLException(this, sqle);
}
}
@@ -1198,10 +1137,10 @@ public abstract class DBDatabase extends
if (stmt != null)
stmt.close();
// done
- success();
- } catch (SQLException sqle)
- {
- error(sqle);
+ return;
+ } catch (SQLException sqle) {
+ // Commit failed!
+ throw new InternalSQLException(this, sqle);
}
}
@@ -1217,7 +1156,7 @@ public abstract class DBDatabase extends
{ // check ResultSet
if (rset == null)
return; // nothing to do
- // close Resutlset
+ // close Resultset
Statement stmt = rset.getStatement();
rset.close();
// check Statement
@@ -1225,11 +1164,11 @@ public abstract class DBDatabase extends
return;
// close Statement
stmt.close();
- success();
-
- } catch (SQLException sqle)
- {
- error(sqle);
+ // done
+ return;
+ } catch (SQLException sqle) {
+ // Commit failed!
+ throw new InternalSQLException(this, sqle);
}
}
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Tue Aug 16 15:56:41 2011
@@ -34,13 +34,14 @@ import java.util.Set;
import java.util.UUID;
import org.apache.empire.commons.DateUtils;
-import org.apache.empire.commons.ErrorObject;
-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;
@@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory;
* The DBDatabaseDriver class is an abstract base class for all database drivers.
* Its purpose is to handle everything that is - or might be - database vendor specific.
*/
-public abstract class DBDatabaseDriver extends ErrorObject implements Serializable
+public abstract class DBDatabaseDriver implements Serializable
{
private final static long serialVersionUID = 1L;
@@ -223,11 +224,9 @@ public abstract class DBDatabaseDriver e
if (log.isInfoEnabled())
log.info("Sequence {} incremented to {}.", SeqName, seqValue);
return new Long(seqValue);
- } catch (Exception e)
- {
- log.error("getNextValue exception: " + e.toString());
- error(e);
- return null;
+ } catch (SQLException e) {
+ // throw exception
+ throw new InternalSQLException(this, e);
} finally
{ // Cleanup
db.closeStatement(stmt);
@@ -380,8 +379,7 @@ public abstract class DBDatabaseDriver e
return (type==DataType.DATE ? DateUtils.getDateOnly(ts) : ts);
}
// Other types
- error(Errors.NotSupported, "getColumnAutoValue() for "+type);
- return null;
+ throw new NotSupportedException(this, "getColumnAutoValue() for "+type);
}
/**
@@ -569,8 +567,7 @@ public abstract class DBDatabaseDriver e
stmt = conn.createStatement(type, ResultSet.CONCUR_READ_ONLY);
return stmt.executeQuery(sqlCmd);
}
- } catch(SQLException e)
- {
+ } catch(SQLException e) {
// close statement (if not null)
close(stmt);
throw e;
@@ -679,9 +676,9 @@ public abstract class DBDatabaseDriver e
/**
* Called when a database is opened
*/
- protected boolean attachDatabase(DBDatabase db, Connection conn)
+ protected void attachDatabase(DBDatabase db, Connection conn)
{
- return success();
+ // Override to implement attaching behaviour
}
/**
@@ -701,9 +698,9 @@ public abstract class DBDatabaseDriver e
*
* @return true if it is consistent with the description
*/
- public boolean checkDatabase(DBDatabase db, String owner, Connection conn)
+ public void checkDatabase(DBDatabase db, String owner, Connection conn)
{
- return error(Errors.NotImplemented, "checkDatabase");
+ throw new NotImplementedException(this, "checkDatabase");
}
/**
@@ -715,9 +712,9 @@ public abstract class DBDatabaseDriver e
*
* @return true on succes
*/
- public boolean getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
+ public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
{
- return error(Errors.NotSupported, "getDDLScript");
+ throw new NotImplementedException(this, "getDDLScript");
}
/**
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBObject.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBObject.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBObject.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBObject.java Tue Aug 16 15:56:41 2011
@@ -19,26 +19,19 @@
package org.apache.empire.db;
// java.sql
-import org.apache.empire.commons.ErrorObject;
-import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.Serializable;
-import java.sql.SQLException;
/**
- * 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 extends ErrorObject implements Serializable
+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.
@@ -48,35 +41,4 @@ public abstract class DBObject extends E
*/
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 boolean error(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 error(type, db.getDriver().extractErrorMessage(sqle));
- // Set the error Message
- return error(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 boolean error(SQLException sqle)
- { // converts a database error message to a human readable error message.
- return error(DBErrors.SQLException, sqle);
- }
-
}
\ No newline at end of file
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBQuery.java Tue Aug 16 15:56:41 2011
@@ -18,22 +18,31 @@
*/
package org.apache.empire.db;
-import org.apache.empire.commons.Errors;
+import java.sql.Connection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
+
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.InvalidKeyException;
+import org.apache.empire.db.exceptions.NoPrimaryKeyException;
+import org.apache.empire.db.exceptions.QueryNoResultException;
+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.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemNotFoundException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
import org.w3c.dom.Element;
-import java.sql.Connection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicInteger;
-
/**
* This class can be used to wrap a query from a DBCommand and use it like a DBRowSet.<BR>
@@ -42,7 +51,7 @@ import java.util.concurrent.atomic.Atomi
* <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>
*
@@ -112,12 +121,12 @@ public class DBQuery extends DBRowSet
}
@Override
- public boolean checkValue(Object value)
+ public void checkValue(Object value)
{
DBColumn column = expr.getUpdateColumn();
if (column==null)
- return true;
- return column.checkValue(value);
+ return;
+ column.checkValue(value);
}
@Override
@@ -270,10 +279,7 @@ public class DBQuery extends DBRowSet
public Object[] getRecordKey(DBRecord record)
{
if (record == null || record.getRowSet() != this)
- {
- error(Errors.InvalidArg, record, "record");
- return null; // Invalid Argument
- }
+ throw new InvalidArgumentException("record", record);
// get Key
return (Object[]) record.getRowSetData();
}
@@ -307,11 +313,10 @@ public class DBQuery extends DBRowSet
* @return true if successful
*/
@Override
- public boolean initRecord(DBRecord rec, Object[] keyValues)
+ public void initRecord(DBRecord rec, Object[] keyValues)
{
- // Inititialisierung
- if (!prepareInitRecord(rec, DBRecord.REC_EMTPY, keyValues))
- return false;
+ // Prepare
+ prepareInitRecord(rec, DBRecord.REC_EMTPY, keyValues);
// Initialize all Fields
Object[] fields = rec.getFields();
for (int i = 0; i < fields.length; i++)
@@ -325,38 +330,38 @@ public class DBQuery extends DBRowSet
fields[columns.indexOf(keyColumns[i])] = keyValues[i];
}
// Init
- return completeInitRecord(rec);
+ completeInitRecord(rec);
}
/**
- * Returns an error, because querys could't add new records to the database.
+ * Returns an error, because it is not possible to add a record to a query.
*
* @param rec the DBRecord object, contains all fields and the field properties
* @param conn a valid database connection
- * @return an error, because querys could't add new records to the database
+ * @return a not implemented error
*/
@Override
- public boolean createRecord(DBRecord rec, Connection conn)
+ public void createRecord(DBRecord rec, Connection conn)
{
- return error(Errors.NotImplemented, "addRecord");
+ throw new NotImplementedException(this, "createRecord");
}
/**
* Creates a select SQL-Command of the query call the InitRecord method to execute the SQL-Command.
*
- * @param rec rec the DBRecord object, contains all fields and the field properties
+ * @param rec the DBRecord object, contains all fields and the field properties
* @param key an array of the primary key columns
* @param conn a valid connection to the database.
* @return true if successful
*/
@Override
- public boolean readRecord(DBRecord rec, Object[] key, Connection conn)
+ public void readRecord(DBRecord rec, Object[] key, Connection conn)
{
if (conn == null || rec == null)
- return error(Errors.InvalidArg, null, "conn|rec");
+ throw new InvalidArgumentException("conn|rec", null);
DBColumn[] keyColumns = getKeyColumns();
if (key == null || keyColumns.length != key.length)
- return error(DBErrors.RecordInvalidKey, key);
+ throw new InvalidKeyException(this, key);
// Select
for (int i = 0; i < keyColumns.length; i++)
{ // Set key column constraint
@@ -366,16 +371,15 @@ public class DBQuery extends DBRowSet
cmd.where(keyColumns[i].is(value));
}
// Read Record
- if (!readRecord(rec, cmd, conn))
- { // Record not found
- if (getErrorType() == DBErrors.QueryNoResult)
- return error(DBErrors.RecordNotFound, key);
- // Return given error
- return false;
- }
- // Set RowSetData
- rec.changeState(DBRecord.REC_VALID, key.clone());
- return success();
+ try {
+ // Read Record
+ readRecord(rec, cmd, conn);
+ // Set RowSetData
+ rec.changeState(DBRecord.REC_VALID, key.clone());
+ } catch (QueryNoResultException e) {
+ // Record not found
+ throw new RecordNotFoundException(this, key);
+ }
}
/**
@@ -383,20 +387,20 @@ public class DBQuery extends DBRowSet
*
* @param rec the DBRecord object. contains all fields and the field properties
* @param conn a valid connection to the database.
- * @return true if succesfull
+ * @return true if successful
*/
@Override
- public boolean updateRecord(DBRecord rec, Connection conn)
+ public void updateRecord(DBRecord rec, Connection conn)
{
if (conn == null || rec == null)
- return error(Errors.InvalidArg, null, "conn|rec");
+ throw new InvalidArgumentException("conn|rec", null);
// Has record been modified?
if (rec.isModified() == false)
- return success(); // Nothing to update
+ return; // Nothing to update
// Must have key Columns
DBColumn[] keyColumns = getKeyColumns();
if (keyColumns==null)
- return error(DBErrors.NoPrimaryKey, getAlias());
+ throw new NoPrimaryKeyException(this);
// Get the fields and the flags
Object[] fields = rec.getFields();
// Get all Update Commands
@@ -423,8 +427,7 @@ public class DBQuery extends DBRowSet
if (col.isReadOnly() && log.isDebugEnabled())
log.debug("updateRecord: Read-only column '" + col.getName() + " has been modified!");
// Check the value
- if (!col.checkValue(fields[i]))
- return error(col);
+ col.checkValue(fields[i]);
// Set
updCmd.set(col.to(fields[i]));
}
@@ -450,10 +453,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))
- return error(Errors.ItemNotFound, left.getFullName());
+ throw new ItemNotFoundException(left.getFullName());
if (right.getRowSet()==table && table.isKeyColumn(right))
if (!addJoinRestriction(upd, right, left, keyColumns, rec))
- return error(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 +480,7 @@ public class DBQuery extends DBRowSet
}
else
{ // other constraints are not supported
- return error(Errors.NotSupported, "updateRecord");
+ throw new NotSupportedException(this, "updateRecord with "+cmp.getClass().getName());
}
}
// Add Restrictions
@@ -524,15 +527,15 @@ public class DBQuery extends DBRowSet
{ // Error
if (affected == 0)
{ // Record not found
- error(DBErrors.RecordUpdateFailed, table.getName());
+ throw new RecordUpdateFailedException(this, keys);
}
// Rollback
db.rollback(conn);
- return false;
+ return;
}
else if (affected > 1)
{ // More than one record
- error(DBErrors.RecordUpdateInvalid, table.getName());
+ throw new RecordUpdateInvalidException(this, keys);
}
else
{ // success
@@ -546,7 +549,6 @@ public class DBQuery extends DBRowSet
}
// success
rec.changeState(DBRecord.REC_VALID, keys);
- return success();
}
/**
@@ -584,9 +586,9 @@ public class DBQuery extends DBRowSet
* @return true if the record has been successfully deleted or false otherwise
*/
@Override
- public boolean deleteRecord(Object[] keys, Connection conn)
+ public void deleteRecord(Object[] keys, Connection conn)
{
- return error(Errors.NotImplemented, "deleteRecord");
+ throw new NotImplementedException(this, "deleteRecord()");
}
}
\ No newline at end of file
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java Tue Aug 16 15:56:41 2011
@@ -18,17 +18,6 @@
*/
package org.apache.empire.db;
-import org.apache.commons.beanutils.ConstructorUtils;
-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.xml.XMLUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectOutputStream;
@@ -43,6 +32,21 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.apache.commons.beanutils.ConstructorUtils;
+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;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
/**
* <P>
@@ -50,7 +54,7 @@ import java.util.Map;
* In oder to perform a query call the open() function or - for single row queries - call getRecordData();<BR>
* You can iterate through the rows using moveNext() or an iterator.<BR>
* <P>
- * However take care: A reader must always be explcitly closed using the close() method!<BR>
+ * However take care: A reader must always be explicitly closed using the close() method!<BR>
* Otherwise you may lock the JDBC connection and run out of resources.<BR>
* Use <PRE>try { ... } finally { reader.close(); } </PRE> to make sure the reader is closed.<BR>
* <P>
@@ -119,9 +123,7 @@ public class DBReader extends DBRecordDa
public boolean hasNext()
{
try
- { // clear previous error
- clearError();
- // Check position
+ { // Check position
if (curCount >= maxCount)
return false;
// Check Recordset
@@ -129,9 +131,9 @@ public class DBReader extends DBRecordDa
return false;
// there are more records
return true;
- } catch (SQLException e)
- {
- return error(e);
+ } catch (SQLException e) {
+ // Error
+ throw new InternalSQLException(getDatabase(), e);
}
}
@@ -187,7 +189,7 @@ public class DBReader extends DBRecordDa
if (curCount >= maxCount)
return false;
if (rset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Check next Record
if (getCurrent == true)
{
@@ -346,7 +348,6 @@ public class DBReader extends DBRecordDa
}
try
{ // Check Value on Resultset
- clearError();
rset.getObject(index + 1);
return rset.wasNull();
} catch (Exception e)
@@ -365,21 +366,17 @@ public class DBReader extends DBRecordDa
@Override
public Object getValue(int index)
{
+ // Check params
if (index < 0 || index >= colList.length)
- { // Index out of range
- error(Errors.OutOfRange, index);
- return null;
- }
+ throw new InvalidArgumentException("index", index);
try
- { // Get Value from Resultset
- clearError();
+ { // Get Value from Resultset
DataType dataType = colList[index].getDataType();
return db.driver.getResultValue(rset, index + 1, dataType);
- } catch (Exception e)
+ } catch (SQLException e)
{ // Operation failed
- error(e);
- return null;
+ throw new InternalSQLException(this, e);
}
}
@@ -407,7 +404,7 @@ public class DBReader extends DBRecordDa
* @param conn a valid JDBC connection.
* @return true if successful
*/
- public boolean open(DBCommandExpr cmd, boolean scrollable, Connection conn)
+ public void open(DBCommandExpr cmd, boolean scrollable, Connection conn)
{
if (isOpen())
close();
@@ -417,11 +414,10 @@ public class DBReader extends DBRecordDa
db = cmd.getDatabase();
rset = db.executeQuery(sqlCmd, cmd.getParamValues(), scrollable, conn);
if (rset==null)
- return error(db);
+ throw new QueryNoResultException(sqlCmd);
// successfully opened
colList = cmd.getSelectExprList();
addOpenResultSet();
- return success();
}
/**
@@ -433,9 +429,9 @@ public class DBReader extends DBRecordDa
* @param conn a valid JDBC connection.
* @return true if successful
*/
- public boolean open(DBCommandExpr cmd, Connection conn)
+ public final void open(DBCommandExpr cmd, Connection conn)
{
- return open(cmd, false, conn);
+ open(cmd, false, conn);
}
/**
@@ -452,16 +448,14 @@ public class DBReader extends DBRecordDa
* @param conn a valid JDBC connection.
* @return true if successful
*/
- public boolean getRecordData(DBCommandExpr cmd, Connection conn)
+ public void getRecordData(DBCommandExpr cmd, Connection conn)
{ // Open the record
- if (!open(cmd, conn))
- return false;
+ open(cmd, conn);
// Get First Record
if (!moveNext())
{ // Close
- return error(DBErrors.QueryNoResult, cmd.getSelect());
+ throw new QueryNoResultException(cmd.getSelect());
}
- return success();
}
/**
@@ -504,17 +498,15 @@ public class DBReader extends DBRecordDa
public boolean skipRows(int count)
{
try
- { // clear previous error
- clearError();
- // Check Recordset
+ { // Check Recordset
if (rset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Forward only cursor?
int type = rset.getType();
if (type == ResultSet.TYPE_FORWARD_ONLY)
{
if (count < 0)
- return error(Errors.InvalidArg, count, "count");
+ throw new InvalidArgumentException("count", count);
// Move
for (; count > 0; count--)
{
@@ -542,9 +534,9 @@ public class DBReader extends DBRecordDa
}
return true;
- } catch (SQLException e)
- { // an error ocurred
- return error(e);
+ } catch (SQLException e) {
+ // an error occurred
+ throw new InternalSQLException(this, e);
}
}
@@ -556,23 +548,20 @@ public class DBReader extends DBRecordDa
public boolean moveNext()
{
try
- { // clear previous error
- clearError();
- // Check Recordset
+ { // Check Recordset
if (rset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Move Next
if (rset.next() == false)
{ // Close recordset automatically after last record
close();
- clearError();
return false;
}
return true;
- } catch (SQLException e)
- { // an error ocurred
- return error(e);
+ } catch (SQLException e) {
+ // an error occurred
+ throw new InternalSQLException(this, e);
}
}
@@ -582,8 +571,8 @@ public class DBReader extends DBRecordDa
* Returns an row iterator for this reader.<BR>
* There can only be one iterator at a time.
* <P>
- * @param maxCount the maximum number of item that shold be returned by this iterator
- * @return the row interator
+ * @param maxCount the maximum number of item that should be returned by this iterator
+ * @return the row iterator
*/
public Iterator<DBRecordData> iterator(int maxCount)
{
@@ -602,7 +591,7 @@ public class DBReader extends DBRecordDa
* Returns an row iterator for this reader.
* There can only be one iterator at a time.
* </PRE>
- * @return the row interator
+ * @return the row iterator
*/
public final Iterator<DBRecordData> iterator()
{
@@ -618,15 +607,14 @@ public class DBReader extends DBRecordDa
* </PRE>
* @param rowset the rowset to which to attach
* @param rec the record which to initialize
- * @return true if the record has been initialized sucessfully or false otherwise
+ * @return true if the record has been initialized successfully or false otherwise
*/
- public boolean initRecord(DBRowSet rowset, DBRecord rec)
+ public void initRecord(DBRowSet rowset, DBRecord rec)
{
if (rowset==null)
- return error(Errors.InvalidArg, rowset, "rowset");
- if (rowset.initRecord(rec, this)==false)
- return error(rowset);
- return success();
+ throw new InvalidArgumentException("rowset", rowset);
+ // init Record
+ rowset.initRecord(rec, this);
}
/**
@@ -645,8 +633,7 @@ public class DBReader extends DBRecordDa
// Check Recordset
if (rset == null)
{ // Resultset not available
- error(Errors.ObjectNotValid, getClass().getName());
- return null;
+ throw new ObjectNotValidException(this);
}
// Query List
try
@@ -672,8 +659,7 @@ public class DBReader extends DBRecordDa
else
{ // Use Property Setters
T bean = t.newInstance();
- if (getBeanProperties(bean)==false)
- return null;
+ getBeanProperties(bean);
c.add(bean);
}
// Decrease count
@@ -682,18 +668,12 @@ public class DBReader extends DBRecordDa
}
// done
return c;
- } catch (InvocationTargetException e)
- {
- error(e);
- return null;
- } catch (IllegalAccessException e)
- {
- error(e);
- return null;
- } catch (InstantiationException e)
- {
- error(e);
- return null;
+ } catch (InvocationTargetException e) {
+ throw new BeanInstantiationException(t, e);
+ } catch (IllegalAccessException e) {
+ throw new BeanInstantiationException(t, e);
+ } catch (InstantiationException e) {
+ throw new BeanInstantiationException(t, e);
}
}
@@ -726,14 +706,15 @@ public class DBReader extends DBRecordDa
* @return true if successful
*/
@Override
- public boolean addColumnDesc(Element parent)
+ public int addColumnDesc(Element parent)
{
if (colList == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Add Field Description
for (int i = 0; i < colList.length; i++)
colList[i].addXml(parent, 0);
- return success();
+ // return count
+ return colList.length;
}
/**
@@ -743,10 +724,10 @@ public class DBReader extends DBRecordDa
* @return true if successful
*/
@Override
- public boolean addRowValues(Element parent)
+ public int addRowValues(Element parent)
{
if (rset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Add all children
for (int i = 0; i < colList.length; i++)
{ // Read all
@@ -764,7 +745,8 @@ public class DBReader extends DBRecordDa
elem.setAttribute("null", "yes"); // Null-Value
}
}
- return success();
+ // return count
+ return colList.length;
}
/**
@@ -798,7 +780,7 @@ public class DBReader extends DBRecordDa
}
/**
- * Returns a XML document with the field descriptiona an values of this record.
+ * Returns a XML document with the field description an values of this record.
*
* @return the new XML Document object
*/
@@ -811,8 +793,7 @@ public class DBReader extends DBRecordDa
String rowsetElementName = getXmlDictionary().getRowSetElementName();
Element root = XMLUtil.createDocument(rowsetElementName);
// Add Field Description
- if (!addColumnDesc(root))
- return null;
+ addColumnDesc(root);
// Add row rset
addRows(root);
// return Document
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java Tue Aug 16 15:56:41 2011
@@ -18,25 +18,28 @@
*/
package org.apache.empire.db;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.Connection;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;
-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;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import java.lang.reflect.InvocationTargetException;
-import java.sql.Connection;
-import java.util.Collection;
-import java.util.List;
-
/**
*
@@ -69,7 +72,7 @@ public class DBRecord extends DBRecordDa
/**
* Create a new DBRecord object.<BR>
- * The record is not attachted to a RowSet and the record's state is intitially set to REC_INVALID.
+ * The record is not attached to a RowSet and the record's state is initially set to REC_INVALID.
*
* Please derive your own Objects from this class.
*/
@@ -321,11 +324,10 @@ public class DBRecord extends DBRecordDa
public boolean wasModified(int index)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
if (index < 0 || index >= fields.length)
- return error(Errors.OutOfRange, index);
+ throw new InvalidArgumentException("index", index);
// Check modified
- clearError();
if (modified == null)
return false;
return modified[index];
@@ -406,17 +408,10 @@ public class DBRecord extends DBRecordDa
public Object getValue(int index)
{ // Check state
if (fields == null)
- { // Record not valid
- error(Errors.ObjectNotValid, getClass().getName());
- return null;
- }
+ throw new ObjectNotValidException(this);
// Check index
if (index < 0 || index>= fields.length)
- { // Index out of range
- error(Errors.OutOfRange, index);
- return null;
- }
- clearError();
+ throw new InvalidArgumentException("index", index);
// Special check for NO_VALUE
if (fields[index] == ObjectUtils.NO_VALUE)
return null;
@@ -426,7 +421,7 @@ public class DBRecord extends DBRecordDa
/**
* Returns whether a field value is provided i.e. the value is not DBRowSet.NO_VALUE<BR>
- * This function is only useful in cases where records are partically loaded.<BR>
+ * This function is only useful in cases where records are partially loaded.<BR>
*
* @param index the filed index
*
@@ -435,13 +430,12 @@ public class DBRecord extends DBRecordDa
public boolean isValueValid(int index)
{ // Check state
if (fields == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Check index
if (index < 0 || index>= fields.length)
{ // Index out of range
- return error(Errors.OutOfRange, index);
+ throw new InvalidArgumentException("index", index);
}
- clearError();
// Special check for NO_VALUE
return (fields[index] != ObjectUtils.NO_VALUE);
}
@@ -501,36 +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 boolean setValue(int i, Object value)
+ public void setValue(int index, Object value)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
- if (i < 0 || i >= fields.length)
- return error(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))
- return success(); // no change
+ 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
- return error(DBErrors.FieldIsReadOnly, column.getName());
+ throw new FieldIsReadOnlyException(column);
}
// Is Value valid
- if (column.checkValue(value) == false)
- { // Invalid Value for column
- return error(column);
- }
+ column.checkValue(value);
// Init original values
- modifyValue(i, value);
- return success();
+ modifyValue(index, value);
}
/**
@@ -542,12 +532,12 @@ public class DBRecord extends DBRecordDa
* @param value the value
* @return true if successful
*/
- public final boolean setValue(Column column, Object value)
+ public final void setValue(Column column, Object value)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Get Column Index
- return setValue(rowset.getColumnIndex(column), value);
+ setValue(rowset.getColumnIndex(column), value);
}
/**
@@ -560,9 +550,7 @@ public class DBRecord extends DBRecordDa
public boolean isFieldReadOnly(DBColumn column)
{
if (rowset==null)
- { error(Errors.ObjectNotValid, getClass().getName());
- return true;
- }
+ throw new ObjectNotValidException(this);
// Ask RowSet
return (rowset.isColumnReadOnly(column));
}
@@ -585,7 +573,7 @@ public class DBRecord extends DBRecordDa
public boolean isFieldVisible(DBColumn column)
{
if (rowset==null)
- return error(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));
@@ -609,36 +597,11 @@ public class DBRecord extends DBRecordDa
* @param insert if true change the state of this object to REC_NEW
* @return true if successful or false otherwise
*/
- public boolean init(DBRowSet table, Object[] keyValues, boolean insert)
+ public void init(DBRowSet table, Object[] keyValues, boolean insert)
{ // Init with keys
- if (table.initRecord(this, keyValues) == false)
- return error(table);
+ table.initRecord(this, keyValues);
if (insert)
state = DBRecord.REC_NEW;
- return success();
- }
-
- /**
- * @param table
- * @param conn
- * @return true on succes
- * @deprecated use {@link DBRecord#create(DBRowSet, Connection)}
- */
- @Deprecated
- public final boolean initNew(DBRowSet table, Connection conn)
- {
- return (table.createRecord(this, conn) == false) ? error(table) : success();
- }
-
- /**
- * @param table
- * @return true on succes
- * @deprecated use {@link DBRecord#create(DBRowSet)}
- */
- @Deprecated
- public final boolean initNew(DBRowSet table)
- {
- return initNew(table, null);
}
/**
@@ -653,9 +616,9 @@ public class DBRecord extends DBRecordDa
* @param conn a valid JDBC connection
* @return true if successful
*/
- public boolean create(DBRowSet table, Connection conn)
+ public void create(DBRowSet table, Connection conn)
{
- return (table.createRecord(this, conn) == false) ? error(table) : success();
+ table.createRecord(this, conn);
}
/**
@@ -666,44 +629,44 @@ public class DBRecord extends DBRecordDa
* @param table the table for which to create a record
* @return true if successful
*/
- public boolean create(DBRowSet table)
+ public void create(DBRowSet table)
{
- return create(table, null);
+ create(table, null);
}
/**
* Loads a record from the database identified by it's primary key.
- * After sucessful reading the record will be valid and all values will be accessible.
+ * After successful reading the record will be valid and all values will be accessible.
* @see org.apache.empire.db.DBTable#readRecord(DBRecord, Object[], Connection)
*
* @param table the rowset from which to read the record
* @param keys an array of the primary key values
* @param conn a valid connection to the database.
- * @return true if the record was sucessfully loaded or false if the record was not found or an error occurred.
+ * @return true if the record was successfully loaded or false if the record was not found or an error occurred.
*/
- public boolean read(DBRowSet table, Object[] keys, Connection conn)
+ public void read(DBRowSet table, Object[] keys, Connection conn)
{
- return (table.readRecord(this, keys, conn) == false) ? error(table) : success();
+ table.readRecord(this, keys, conn);
}
/**
* Loads a record from the database identified by it's primary key.
- * After sucessful reading the record will be valid and all values will be accessible.
+ * After successful reading the record will be valid and all values will be accessible.
* @see org.apache.empire.db.DBTable#readRecord(DBRecord, Object[], Connection)
*
* @param table the rowset from which to read the record
* @param id the primary key of the record to load.
* @param conn a valid connection to the database.
- * @return true if the record was sucessfully loaded or false if the record was not found or an error occurred.
+ * @return true if the record was successfully loaded or false if the record was not found or an error occurred.
*/
- public final boolean read(DBRowSet table, Object id, Connection conn)
+ public final void read(DBRowSet table, Object id, Connection conn)
{
if (id instanceof Collection<?>)
{ // If it's a collection then convert it to an array
- return read(table, ((Collection<?>)id).toArray(), conn);
+ read(table, ((Collection<?>)id).toArray(), conn);
}
// Simple One-Column key
- return read(table, new Object[] { id }, conn);
+ read(table, new Object[] { id }, conn);
}
/**
@@ -713,13 +676,12 @@ public class DBRecord extends DBRecordDa
* @param conn a valid connection to the database.
* @return true if successful
*/
- public boolean update(Connection conn)
+ public void update(Connection conn)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
- if (!rowset.updateRecord(this, conn))
- return error(rowset);
- return success();
+ throw new ObjectNotValidException(this);
+ // update
+ rowset.updateRecord(this, conn);
}
/**
@@ -733,19 +695,17 @@ public class DBRecord extends DBRecordDa
* @param conn a valid connection to the database.
* @return true if successful
*/
- public boolean delete(Connection conn)
+ public void delete(Connection conn)
{
if (isValid()==false)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Delete only if record is not new
if (!isNew())
{
Object[] keys = rowset.getRecordKey(this);
- if (rowset.deleteRecord(keys, conn)==false)
- return error(rowset);
+ rowset.deleteRecord(keys, conn);
}
close();
- return success();
}
/**
@@ -754,11 +714,12 @@ public class DBRecord extends DBRecordDa
* @return true if successful
*/
@Override
- public boolean addColumnDesc(Element parent)
+ public int addColumnDesc(Element parent)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Add Field Description
+ int count = 0;
List<DBColumn> columns = rowset.getColumns();
for (int i = 0; i < columns.size(); i++)
{ // Add Field
@@ -766,8 +727,9 @@ public class DBRecord extends DBRecordDa
if (isFieldVisible(column)==false)
continue;
column.addXml(parent, 0);
+ count++;
}
- return success();
+ return count;
}
/**
@@ -777,10 +739,10 @@ public class DBRecord extends DBRecordDa
* @return true if successful
*/
@Override
- public boolean addRowValues(Element parent)
+ public int addRowValues(Element parent)
{
if (rowset == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// set row key
DBColumn[] keyColumns = rowset.getKeyColumns();
if (keyColumns != null && keyColumns.length > 0)
@@ -803,6 +765,7 @@ public class DBRecord extends DBRecordDa
if (isNew())
parent.setAttribute("new", "1");
// Add all children
+ int count = 0;
List<DBColumn> columns = rowset.getColumns();
for (int i = 0; i < fields.length; i++)
{ // Read all
@@ -815,8 +778,10 @@ public class DBRecord extends DBRecordDa
XMLUtil.addElement(parent, name, getString(i));
else
XMLUtil.addElement(parent, name).setAttribute("null", "yes"); // Null-Value
+ // increase count
+ count++;
}
- return success();
+ return count;
}
/**
@@ -829,7 +794,7 @@ public class DBRecord extends DBRecordDa
}
/**
- * Returns a XML document with the field descriptiona an values of this record.
+ * Returns a XML document with the field description an values of this record.
*
* @return the new XML Document object
*/
@@ -837,22 +802,18 @@ public class DBRecord extends DBRecordDa
public Document getXmlDocument()
{
if (rowset == null)
- { error(Errors.ObjectNotValid, getClass().getName());
- return null;
- }
+ 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))
- return null;
- // Add row Values
- if (!addRowValues(XMLUtil.addElement(root, xmlDic.getRowElementName())))
- return null;
+ if (addColumnDesc(root)>0)
+ { // Add row Values
+ addRowValues(XMLUtil.addElement(root, xmlDic.getRowElementName()));
+ }
// return Document
- clearError();
return root.getOwnerDocument();
}
@@ -893,9 +854,9 @@ public class DBRecord extends DBRecordDa
* @param bean the Java Bean from which to read the value from
* @param property the name of the property
* @param column the column for which to set the record value
- * @return true if the value has been sucessfully set or false if not
+ * @return true if the value has been successfully set or false if not
*/
- protected boolean setBeanValue(Object bean, String property, Column column)
+ protected void setBeanValue(Object bean, String property, Column column)
{
try
{ /*
@@ -908,27 +869,26 @@ public class DBRecord extends DBRecordDa
Object value = pub.getSimpleProperty(bean, property);
// Now, set the record value
- return setValue( column, value );
+ setValue( column, value );
} catch (IllegalAccessException e)
{ log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
- return error(e);
+ throw new BeanPropertyGetException(bean, property, e);
} catch (InvocationTargetException e)
{ log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
- return error(e);
+ throw new BeanPropertyGetException(bean, property, e);
} catch (NoSuchMethodException e)
- {
- log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
- return error(e);
+ { log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
+ throw new BeanPropertyGetException(bean, property, e);
}
}
/**
- * Sets record values from the suppied java bean.
+ * Sets record values from the supplied java bean.
*
- * @return true if at least one value has been set sucessfully
+ * @return true if at least one value has been set successfully
*/
- public boolean setBeanValues(Object bean, Collection<Column> ignoreList)
+ public int setBeanValues(Object bean, Collection<Column> ignoreList)
{
// Add all Columns
int count = 0;
@@ -941,17 +901,17 @@ public class DBRecord extends DBRecordDa
continue; // ignore this property
// Get Property Name
String property = column.getBeanPropertyName();
- if (setBeanValue(bean, property, column))
- count++;
+ setBeanValue(bean, property, column);
+ count++;
}
- return (count > 0);
+ return count;
}
/**
* Sets record values from the suppied java bean.
* @return true if at least one value has been set sucessfully
*/
- public final boolean setBeanValues(Object bean)
+ public final int setBeanValues(Object bean)
{
return setBeanValues(bean, null);
}