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 [4/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/DBRecordData.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java Tue Aug 16 15:56:41 2011
@@ -18,21 +18,22 @@
*/
package org.apache.empire.db;
// XML
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Date;
+
import org.apache.commons.beanutils.BeanUtils;
import org.apache.empire.commons.DateUtils;
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;
import org.w3c.dom.Element;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collection;
-import java.util.Date;
-
/**
* This interface defines for the classes DDRecordSet and DBRecord.
@@ -55,8 +56,8 @@ public abstract class DBRecordData exten
// Column lookup
public abstract ColumnExpr getColumnExpr(int i);
// xml
- public abstract boolean addColumnDesc(Element parent);
- public abstract boolean addRowValues (Element parent);
+ public abstract int addColumnDesc(Element parent);
+ public abstract int addRowValues (Element parent);
public abstract Document getXmlDocument();
// others
public abstract void close();
@@ -95,7 +96,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to integer if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final int getInt(ColumnExpr column)
@@ -121,7 +122,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to a long if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final long getLong(ColumnExpr column)
@@ -147,7 +148,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to double if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final double getDouble(ColumnExpr column)
@@ -173,7 +174,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to boolean if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final boolean getBoolean(ColumnExpr column)
@@ -197,7 +198,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to a string if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final String getString(ColumnExpr column)
@@ -223,7 +224,7 @@ public abstract class DBRecordData exten
* Returns a data value for the desired column.
* The data value is converted to a Date if necessary.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return the value
*/
public final Date getDateTime(ColumnExpr column)
@@ -245,7 +246,7 @@ public abstract class DBRecordData exten
/**
* Checks whether or not the value for the given column is null.
*
- * @param column identifing the column
+ * @param column identifying the column
* @return true if the value is null or false otherwise
*/
public final boolean isNull(ColumnExpr column)
@@ -256,7 +257,7 @@ public abstract class DBRecordData exten
/**
* Set a single property value of a java bean object used by readProperties.
*/
- protected boolean getBeanProperty(Object bean, String property, Object value)
+ protected void getBeanProperty(Object bean, String property, Object value)
{
try
{ /*
@@ -264,7 +265,7 @@ public abstract class DBRecordData exten
log.trace(bean.getClass().getName() + ": setting property '" + property + "' to " + String.valueOf(value));
*/
if (value instanceof Date)
- { // Patch for Strage Date Bug in BeanUtils
+ { // Patch for Stage Date Bug in BeanUtils
value = DateUtils.addDate((Date)value, 0, 0, 0);
}
// Set Property Value
@@ -279,16 +280,14 @@ public abstract class DBRecordData exten
* res); }
*/
// done
- return success();
} catch (IllegalAccessException e)
- {
- log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
- return error(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 + "'");
- return error(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;
@@ -301,9 +300,10 @@ public abstract class DBRecordData exten
*
* @return true if successful
*/
- public boolean getBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
+ public int getBeanProperties(Object bean, Collection<ColumnExpr> ignoreList)
{
// Add all Columns
+ int count = 0;
for (int i = 0; i < getFieldCount(); i++)
{ // Check Property
ColumnExpr column = getColumnExpr(i);
@@ -311,13 +311,10 @@ public abstract class DBRecordData exten
continue; // ignore this property
// Get Property Name
String property = column.getBeanPropertyName();
- if (getBeanProperty(bean, property, this.getValue(i))==false)
- { // Error setting property.
- return false;
- }
+ getBeanProperty(bean, property, this.getValue(i));
+ count++;
}
- // Success, All Properties have been set
- return success();
+ return count;
}
/**
@@ -325,7 +322,7 @@ public abstract class DBRecordData exten
*
* @return true if successful
*/
- public final boolean getBeanProperties(Object bean)
+ public final int getBeanProperties(Object bean)
{
return getBeanProperties(bean, null);
}
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Tue Aug 16 15:56:41 2011
@@ -18,24 +18,34 @@
*/
package org.apache.empire.db;
-import org.apache.empire.commons.Errors;
+import java.sql.Connection;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
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;
-import java.sql.Connection;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* This class is the base class for all the DBTable,
@@ -95,9 +105,9 @@ public abstract class DBRowSet extends D
public abstract String getAlias();
- public abstract boolean createRecord(DBRecord rec, Connection conn);
+ public abstract void createRecord(DBRecord rec, Connection conn);
- public abstract boolean deleteRecord(Object[] keys, Connection conn);
+ public abstract void deleteRecord(Object[] keys, Connection conn);
/**
* Returns the full qualified name of the rowset.
@@ -283,21 +293,20 @@ public abstract class DBRowSet extends D
}
/**
- * Adds a column reference to the ist of table references.
- * This method ist internally called from DBDatabase.addReleation().
+ * Adds a column reference to the list of table references.
+ * This method is internally called from DBDatabase.addReleation().
*
* @param source a column reference for one of this table's column
* @param target the target column to which the source column references
*/
- protected boolean addColumnReference(DBColumn source, DBColumn target)
+ protected void addColumnReference(DBColumn source, DBColumn target)
{
if (source.getRowSet()!=this)
- return error(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
columnReferences.put(source, target);
- return success();
}
/**
@@ -350,19 +359,20 @@ public abstract class DBRowSet extends D
}
/**
- * Initialise this DBRowSet object and sets it's initial state.
+ * Initialize this DBRowSet object and sets it's initial state.
*
- * @param rec the DBRecord object to initialise this DBRowSet object
+ * @param rec the DBRecord object to initialize this DBRowSet object
* @param state the state of this DBRowSet object
* @return true if successful
*/
- protected boolean prepareInitRecord(DBRecord rec, int state, Object rowSetData)
+ protected void prepareInitRecord(DBRecord rec, int state, Object rowSetData)
{
+ if (rec==null)
+ throw new InvalidArgumentException("rec", rec);
if (columns.size() < 1)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new ObjectNotValidException(this);
// Init
rec.init(this, state, rowSetData);
- return success();
}
/**
@@ -373,11 +383,10 @@ public abstract class DBRowSet extends D
* @param keyValues an array of the primary key columns
* @return true if successful
*/
- public boolean initRecord(DBRecord rec, Object[] keyValues)
+ public void initRecord(DBRecord rec, Object[] keyValues)
{
- // Inititialisierung
- if (!prepareInitRecord(rec, DBRecord.REC_EMTPY, null))
- return false;
+ // Prepare
+ prepareInitRecord(rec, DBRecord.REC_EMTPY, null);
// Initialize all Fields
Object[] fields = rec.getFields();
for (int i = 0; i < fields.length; i++)
@@ -394,7 +403,7 @@ public abstract class DBRowSet extends D
}
}
// Init
- return completeInitRecord(rec);
+ completeInitRecord(rec);
}
/**
@@ -408,7 +417,7 @@ public abstract class DBRowSet extends D
* @param recData the record data from which to initialized the record
* @return true if successful
*/
- public boolean initRecord(DBRecord rec, DBRecordData recData)
+ public void initRecord(DBRecord rec, DBRecordData recData)
{
// Initialize the record
prepareInitRecord(rec, DBRecord.REC_VALID, null);
@@ -416,82 +425,42 @@ 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
- return error(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);
- // Check for error
- if (fields[i]==null && recData.hasError())
- return error(recData);
- }
- } catch (Exception e)
- { // Unknown exception
- log.error("initRecord exception: " + e.toString());
- rec.close();
- return error(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
- return completeInitRecord(rec);
+ completeInitRecord(rec);
}
/**
- * Reads a single record from the database using the given command object.<BR>
- * If a reocord is found the DBRecord object will hold all record data.
+ * Completes the record initialization.<BR>
+ * Override this function to do post initialization processing.
* <P>
- * @param rec the DBRecord object which holds the record data
- * @param cmd the SQL-Command used to query the record
- * @param conn a valid JDBC connection.
+ * @param rec the DBRecord object to initialize
* @return true if successful
*/
- protected boolean readRecord(DBRecord rec, DBCommand cmd, Connection conn)
- {
- DBReader reader = null;
- try
- {
- clearError();
- reader = new DBReader();
- if (reader.getRecordData(cmd, conn)==false)
- return error(reader);
- if (initRecord(rec, reader)==false)
- return false;
- // Done
- return success();
-
- } finally
- {
- reader.close();
- }
- }
-
- /**
- * Completes the record initialisation.<BR>
- * Override this function to do post initialisation processing.
- * <P>
- * @param rec the DBRecord object to initialise
- * @return true if successful
- */
- protected boolean completeInitRecord(DBRecord rec)
+ protected void completeInitRecord(DBRecord rec)
{
rec.onRecordChanged();
- return success();
}
/**
@@ -500,55 +469,75 @@ public abstract class DBRowSet extends D
* @param key the record key
* @return true if the constraints have been successfully set or false otherwise
*/
- protected boolean setKeyConstraints(DBCommand cmd, Object[] key)
+ protected void setKeyConstraints(DBCommand cmd, Object[] key)
{
// Check Primary key
if (primaryKey == null )
- return error(DBErrors.NoPrimaryKey, getName()); // Invalid Argument
+ throw new NoPrimaryKeyException(this); // Invalid Argument
// Check Columns
DBColumn[] keyColumns = primaryKey.getColumns();
if (key == null || key.length != keyColumns.length)
- return error(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));
}
- return true;
+ }
+
+ /**
+ * Reads a single record from the database using the given command object.<BR>
+ * If a record is found the DBRecord object will hold all record data.
+ * <P>
+ * @param rec the DBRecord object which holds the record data
+ * @param cmd the SQL-Command used to query the record
+ * @param conn a valid JDBC connection.
+ * @return true if successful
+ */
+ protected void readRecord(DBRecord rec, DBCommand cmd, Connection conn)
+ {
+ DBReader reader = null;
+ try
+ { // read record using a DBReader
+ reader = new DBReader();
+ reader.getRecordData(cmd, conn);
+ initRecord(rec, reader);
+
+ } finally {
+ reader.close();
+ }
}
/**
* 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
* @param conn a valid JDBC connection.
* @return true if successful
*/
- public boolean readRecord(DBRecord rec, Object[] key, Connection conn)
+ public void readRecord(DBRecord rec, Object[] key, Connection conn)
{
// Check Arguments
if (conn == null || rec == null)
- return error(Errors.InvalidArg, null, "conn|rec");
+ throw new InvalidArgumentException("conn|rec", null);
// Select
DBCommand cmd = db.createCommand();
cmd.select(columns);
// Set key constraints
- if (!setKeyConstraints(cmd, key))
- return false;
- // Read Record
- if (!readRecord(rec, cmd, conn))
- { // Record not found
- if (getErrorType()==DBErrors.QueryNoResult)
- return error(DBErrors.RecordNotFound, key);
- // Return given error
- return false;
+ setKeyConstraints(cmd, key);
+ try {
+ // Read Record
+ readRecord(rec, cmd, conn);
+ } catch (QueryNoResultException e) {
+ // Translate exception
+ throw new RecordNotFoundException(this, key);
}
- // Done
- return success();
}
/**
@@ -562,13 +551,12 @@ public abstract class DBRowSet extends D
{
// Check Arguments
if (conn == null)
- return error(Errors.InvalidArg, conn, "conn");
+ throw new InvalidArgumentException("conn", conn);
// Select
DBCommand cmd = db.createCommand();
cmd.select(count());
// Set key constraints
- if (!setKeyConstraints(cmd, key))
- return false;
+ setKeyConstraints(cmd, key);
// check exits
return (db.querySingleInt(cmd.getSelect(), conn)==1);
}
@@ -597,13 +585,13 @@ public abstract class DBRowSet extends D
* <P>
* @param rec the DBRecord object. contains all fields and the field properties
* @param conn a valid JDBC connection.
- * @return true if the update was sucessful or false otherwise
+ * @return true if the update was successful or false otherwise
*/
- public boolean updateRecord(DBRecord rec, Connection conn)
+ public void updateRecord(DBRecord rec, Connection conn)
{
// Check Arguments
if (conn == null)
- return error(Errors.InvalidArg, conn, "conn");
+ throw new InvalidArgumentException("conn", conn);
// Get the new Timestamp
String name = getName();
Timestamp timestamp = (timestampColumn!=null) ? db.getUpdateTimestamp(conn) : null;
@@ -620,7 +608,7 @@ public abstract class DBRowSet extends D
if (primaryKey == null)
{ // Requires a primary key
log.error("updateRecord: " + name + " no primary key defined!");
- return error(DBErrors.NoPrimaryKey, name);
+ throw new NoPrimaryKeyException(this);
}
for (int i = 0; i < columns.size(); i++)
{ // search for the column
@@ -657,8 +645,7 @@ public abstract class DBRowSet extends D
if (col.isReadOnly())
log.warn("updateRecord: Read-only column '" + col.getName() + " has been modified!");
// Check the value
- if (!col.checkValue(value))
- return error(col);
+ col.checkValue(value);
// Set the column
cmd.set(col.to(value));
setCount++;
@@ -694,19 +681,19 @@ public abstract class DBRowSet extends D
// Add the value to the command
if (empty==false)
{ // Check the value
- if (!col.isAutoGenerated() && !col.checkValue(value))
- return error(col);
+ if (col.isAutoGenerated()==false)
+ col.checkValue(value);
// Insert a field
cmd.set(col.to(value));
setCount++;
}
else if (primaryKey!=null && primaryKey.contains(col))
{ // All primary key fields must be supplied
- return error(DBErrors.FieldNotNull, col.getName());
+ throw new FieldNotNullException(col);
}
else if (col.isRequired())
{ // Error Column is required!
- return error(DBErrors.FieldNotNull, col.getName());
+ throw new FieldNotNullException(col);
}
}
sql = cmd.getInsert();
@@ -714,26 +701,26 @@ public abstract class DBRowSet extends D
default:
log.warn("updateRecord: " + name + " record has not been modified! ");
- return success();
+ return;
}
if (setCount == 0)
- { // Cannot update or insert fields
+ { // Nothing to update
log.info("updateRecord: " + name + " nothing to update or insert!");
- return success();
+ return;
}
// Perform action
int affected = db.executeSQL(sql, cmd.getParamValues(), conn, setGenKey);
if (affected < 0)
- { // Update Failed
- return error(db);
+ { // Update Failed
+ throw new UnexpectedReturnValueException(affected, "db.executeSQL()");
}
else if (affected == 0)
{ // Record not found
- return error(DBErrors.RecordUpdateFailed, name);
+ throw new RecordUpdateFailedException(this, getRecordKey(rec));
}
else if (affected > 1)
{ // Multiple Records affected
- return error(DBErrors.RecordUpdateInvalid, name);
+ throw new RecordUpdateInvalidException(this, getRecordKey(rec));
}
// Correct Timestamp
if (timestampColumn != null)
@@ -744,7 +731,6 @@ public abstract class DBRowSet extends D
}
// Change State
rec.changeState(DBRecord.REC_VALID, null);
- return success();
}
/**
@@ -754,9 +740,9 @@ public abstract class DBRowSet extends D
* @param conn a valid JDBC connection
* @return true if the record has been successfully deleted or false otherwise
*/
- public final boolean deleteRecord(Object id, Connection conn)
+ public final void deleteRecord(Object id, Connection conn)
{
- return deleteRecord(new Object[] { id }, conn);
+ deleteRecord(new Object[] { id }, conn);
}
/**
@@ -766,13 +752,13 @@ public abstract class DBRowSet extends D
* @param conn a valid connection
* @return true if all reference records could be deleted
*/
- protected final boolean deleteAllReferences(Object[] key, Connection conn)
+ protected final void deleteAllReferences(Object[] key, Connection conn)
{
// Merge Sub-Records
List<DBRelation> relations = db.getRelations();
DBColumn[] keyColumns = getKeyColumns();
if (keyColumns==null)
- return success(); // No primary key - no references!
+ return; // No primary key - no references!
// Find all relations
for (DBRelation rel : relations)
{ // References
@@ -782,28 +768,25 @@ public abstract class DBRowSet extends D
if (refs[i].getTargetColumn().equals(keyColumns[0]))
{ // Found a reference on RowSet
DBRowSet rs = refs[0].getSourceColumn().getRowSet();
- if (rs.deleteReferenceRecords(refs, key, conn)==false)
- return false;
+ rs.deleteReferenceRecords(refs, key, conn);
}
}
}
- // No delete this record
- return success();
}
/**
* Deletes all records which are referenced by a particular relation.
* <P>
- * @param refs the reference columns belonging to the releation
+ * @param refs the reference columns belonging to the relation
* @param parentKey the key of the parent element
* @param conn a valid connection
* @return true if all records could be deleted or false otherwise
*/
- protected boolean deleteReferenceRecords(DBReference[] refs, Object[] parentKey, Connection conn)
+ protected void deleteReferenceRecords(DBReference[] refs, Object[] parentKey, Connection conn)
{
// Key length and reference length must match
if (refs.length!=parentKey.length)
- return error(DBErrors.RecordInvalidKey);
+ throw new InvalidArgumentException("refs", refs);
// Rowset
DBColumn[] keyColumns = getKeyColumns();
if (keyColumns==null || keyColumns.length==0)
@@ -812,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)
- return error(db);
+ throw new UnexpectedReturnValueException(-1, "db.executeSQL()");
}
else
{ // Query all keys
@@ -828,12 +811,10 @@ public abstract class DBRowSet extends D
for (Object[] recKey : recKeys)
{
log.info("Deleting Record " + StringUtils.valueOf(recKey) + " from table " + getName());
- if (deleteRecord(recKey, conn)==false)
- return false;
+ deleteRecord(recKey, conn);
}
}
// Done
- return success();
}
}
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java Tue Aug 16 15:56:41 2011
@@ -23,7 +23,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
-import org.apache.empire.commons.ErrorObject;
+import org.apache.empire.db.exceptions.InternalSQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
* The class is used for obtaining and executing DDL commands supplied
* by the database driver (@see {@link DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)})
*/
-public class DBSQLScript extends ErrorObject implements Iterable<String>
+public class DBSQLScript implements Iterable<String>
{
// Logger
private static final Logger log = LoggerFactory.getLogger(DBSQLScript.class);
@@ -49,10 +49,9 @@ public class DBSQLScript extends ErrorOb
* @param sql the statement
* @return true if successful
*/
- public boolean addStmt(String sql)
+ public void addStmt(String sql)
{
sqlCmdList.add(sql);
- return success();
}
/**
@@ -61,17 +60,15 @@ public class DBSQLScript extends ErrorOb
* @param sql the statement
* @return true if successful
*/
- public final boolean addStmt(StringBuilder sql)
+ public final void addStmt(StringBuilder sql)
{
- if (!addStmt(sql.toString()))
- return false;
+ addStmt(sql.toString());
// Clear Builder
sql.setLength(0);
- return true;
}
/**
- * Returns the number of statemetns in this script
+ * Returns the number of statements in this script
* @return number of statements in this script
*/
public int getCount()
@@ -90,7 +87,7 @@ public class DBSQLScript extends ErrorOb
}
/**
- * Clears the script and delets all statements
+ * Clears the script by removing all statements
*/
public void clear()
{
@@ -102,9 +99,8 @@ public class DBSQLScript extends ErrorOb
* @param driver the driver used for statement execution
* @param conn the connection
* @param ignoreErrors true if errors should be ignored
- * @return true if the script has been run successful or false otherwise
*/
- public boolean run(DBDatabaseDriver driver, Connection conn, boolean ignoreErrors)
+ public void run(DBDatabaseDriver driver, Connection conn, boolean ignoreErrors)
{
log.debug("Running script containing " + String.valueOf(getCount()) + " statements.");
for(String stmt : sqlCmdList)
@@ -117,13 +113,24 @@ public class DBSQLScript extends ErrorOb
// SQLException
log.error(e.toString(), e);
if (ignoreErrors==false)
- return error(DBErrors.SQLException, e);
+ { // forward exception
+ throw new InternalSQLException(driver, e);
+ }
// continue
log.debug("Ignoring error. Continuing with script...");
}
}
log.debug("Script completed.");
- return success();
+ }
+
+ /**
+ * Runs all SQL Statements using the supplied driver and connection.
+ * @param driver the driver used for statement execution
+ * @param conn the connection
+ */
+ public void run(DBDatabaseDriver driver, Connection conn)
+ {
+ run(driver, conn, false);
}
/**
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java Tue Aug 16 15:56:41 2011
@@ -19,16 +19,21 @@
package org.apache.empire.db;
// java
-import org.apache.empire.commons.Errors;
-import org.apache.empire.data.DataMode;
-import org.apache.empire.data.DataType;
-
import java.lang.reflect.Field;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.empire.data.DataMode;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.exceptions.NoPrimaryKeyException;
+import org.apache.empire.db.exceptions.RecordDeleteFailedException;
+import org.apache.empire.db.exceptions.RecordUpdateInvalidException;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemExistsException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
+
/**
* This class represent one table of the database.
@@ -167,15 +172,14 @@ public class DBTable extends DBRowSet im
*
* @param column a column object
*/
- protected boolean addColumn(DBTableColumn column)
+ protected void addColumn(DBTableColumn column)
{ // find column by name
if (column==null || column.getRowSet()!=this)
- return error(Errors.InvalidArg, column, "column");
+ throw new InvalidArgumentException("column", column);
if (columns.contains(column) == true)
- return error(Errors.ItemExists, column.getName());
+ throw new ItemExistsException(column.getName());
// add now
columns.add(column);
- return true;
}
/**
@@ -267,17 +271,16 @@ public class DBTable extends DBRowSet im
*
* @return true on success
*/
- public boolean setPrimaryKey(DBColumn[] columns)
+ public void setPrimaryKey(DBColumn[] columns)
{
if (columns==null || columns.length==0)
- return error(Errors.InvalidArg, columns, "columns");
+ throw new InvalidArgumentException("columns", columns);
// All columns must belong to this table
for (int i=0; i<columns.length; i++)
if (columns[i].getRowSet()!=this)
- return error(Errors.InvalidArg, columns[i].getFullName(), "columns");
+ throw new InvalidArgumentException("columns["+String.valueOf(i)+"]", columns[i].getFullName());
// Set primary Key now
primaryKey = new DBIndex(name + "_PK", DBIndex.PRIMARYKEY, columns);
- return true;
}
/**
@@ -316,19 +319,18 @@ public class DBTable extends DBRowSet im
/**
* Adds an index.
*
- * @param indexName the index name
+ * @param name the index name
* @param unique is this a unique index
- * @param indexColumns the columns indexed by this index
+ * @param columns the columns indexed by this index
*
* @return true on success
*/
- public boolean addIndex(String indexName, boolean unique, DBColumn[] indexColumns)
+ public void addIndex(String name, boolean unique, DBColumn[] columns)
{
- if (indexName==null || indexColumns==null || indexColumns.length==0)
- return error(Errors.InvalidArg, null, "name|columns");
+ if (name==null || columns==null || columns.length==0)
+ throw new InvalidArgumentException("name|columns", null);
// add Index now
- indexes.add(new DBIndex(indexName, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, indexColumns));
- return true;
+ indexes.add(new DBIndex(name, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, columns));
}
/**
@@ -381,11 +383,10 @@ public class DBTable extends DBRowSet im
* @return true if successful
*/
@Override
- public boolean createRecord(DBRecord rec, Connection conn)
+ public void createRecord(DBRecord rec, Connection conn)
{
- // Inititialisierung
- if (!prepareInitRecord(rec, DBRecord.REC_NEW, null))
- return false;
+ // Prepare
+ prepareInitRecord(rec, DBRecord.REC_NEW, null);
// Set Defaults
int count = columns.size();
for (int i = 0; i < count; i++)
@@ -396,7 +397,7 @@ public class DBTable extends DBRowSet im
rec.modifyValue(i, value);
}
// Init
- return completeInitRecord(rec);
+ completeInitRecord(rec);
}
/**
@@ -429,44 +430,40 @@ public class DBTable extends DBRowSet im
* @return true if successful
*/
@Override
- public boolean deleteRecord(Object[] key, Connection conn)
+ public void deleteRecord(Object[] key, Connection conn)
{
// Check Primary key
if (primaryKey == null )
- return error(DBErrors.NoPrimaryKey, getName());
+ throw new NoPrimaryKeyException(this);
// Check Columns
DBColumn[] keyColumns = primaryKey.getColumns();
if (key == null || key.length != keyColumns.length)
- return error(Errors.InvalidArg, key); // Invalid Argument
+ throw new InvalidArgumentException("key", key);
// Delete References
- if (isCascadeDelete() && deleteAllReferences(key, conn)==false)
- return false; // Error deleting referenced records
+ if (isCascadeDelete())
+ deleteAllReferences(key, conn);
// Build SQL-Statement
DBCommand cmd = db.createCommand();
// Set key constraints
- if (!setKeyConstraints(cmd, key))
- return false;
-
+ setKeyConstraints(cmd, key);
// Perform delete
String sqlCmd = cmd.getDelete(this);
int affected = db.executeSQL(sqlCmd, cmd.getParamValues(), conn);
if (affected < 0)
{ // Delete Failed
- return error(db);
+ throw new UnexpectedReturnValueException(affected, "db.executeSQL()");
}
else if (affected == 0)
{ // Record not found
- return error(DBErrors.RecordDeleteFailed, name);
+ throw new RecordDeleteFailedException(this, key);
}
else if (affected > 1)
{ // Multiple Records affected
- return error(DBErrors.RecordUpdateInvalid, name);
+ throw new RecordUpdateInvalidException(this, key);
}
- // success
- return success();
}
}
\ No newline at end of file
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Tue Aug 16 15:56:41 2011
@@ -24,9 +24,12 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.empire.commons.Attributes;
-import org.apache.empire.commons.Errors;
import org.apache.empire.data.DataMode;
import org.apache.empire.data.DataType;
+import org.apache.empire.db.exceptions.FieldIllegalValueException;
+import org.apache.empire.db.exceptions.FieldNotNullException;
+import org.apache.empire.db.exceptions.FieldValueTooLongException;
+import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.apache.empire.xml.XMLUtil;
import org.w3c.dom.Element;
@@ -208,13 +211,11 @@ public class DBTableColumn extends DBCol
public void setRequired(boolean required)
{
if (isAutoGenerated())
- {
- // cannot change auto-generated columns
- error(Errors.NoAccess);
+ { // cannot change auto-generated columns
+ throw new PropertyReadOnlyException("required");
}
else
- {
- // Set DataMode
+ { // Set DataMode
dataMode=(required ? DataMode.NotNull : DataMode.Nullable);
}
}
@@ -261,11 +262,11 @@ public class DBTableColumn extends DBCol
* @return true if the value is valid or false otherwise.
*/
@Override
- public boolean checkValue(Object value)
+ public void checkValue(Object value)
{
// Check for NULL
if (isRequired() && (value == null || value.toString().length() < 1))
- return error(DBErrors.FieldNotNull, getName());
+ throw new FieldNotNullException(this);
// Is value valid
switch (type)
{
@@ -281,8 +282,8 @@ public class DBTableColumn extends DBCol
// OK
} catch (ParseException e)
{ // Error
- log.error("checkValue exception: " + e.toString() + " column=" + getName() + " value=" + value);
- return error(DBErrors.FieldInvalidDateFormat, getName());
+ log.error("checkValue failed: " + e.toString() + " column=" + getName() + " value=" + value);
+ throw new FieldIllegalValueException(this, String.valueOf(value), e);
}
}
break;
@@ -296,10 +297,10 @@ public class DBTableColumn extends DBCol
if (val.length() > 0)
Double.parseDouble(val);
// thows NumberFormatException if not a number!
- } catch (NumberFormatException nfe)
+ } catch (NumberFormatException e)
{
- log.error("checkValue exception: " + nfe.toString() + " column=" + getName() + " value=" + value);
- return error(DBErrors.FieldNotNumeric, getName());
+ log.error("checkValue exception: " + e.toString() + " column=" + getName() + " value=" + value);
+ throw new FieldIllegalValueException(this, String.valueOf(value), e);
}
}
break;
@@ -312,10 +313,10 @@ public class DBTableColumn extends DBCol
if (val.length() > 0)
Long.parseLong(val);
// throws NumberFormatException if not an integer!
- } catch (NumberFormatException nfe)
+ } catch (NumberFormatException e)
{
- log.error("checkValue exception: " + nfe.toString() + " column=" + getName() + " value=" + String.valueOf(value));
- return error(DBErrors.FieldNotNumeric, getName());
+ log.error("checkValue exception: " + e.toString() + " column=" + getName() + " value=" + String.valueOf(value));
+ throw new FieldIllegalValueException(this, String.valueOf(value), e);
}
}
break;
@@ -323,7 +324,7 @@ public class DBTableColumn extends DBCol
case TEXT:
case CHAR:
if (value!=null && value.toString().length() > size)
- return error(DBErrors.FieldValueTooLong, getName(), (int)size);
+ throw new FieldValueTooLongException(this);
break;
default:
@@ -332,7 +333,6 @@ public class DBTableColumn extends DBCol
break;
}
- return success();
}
/**
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBView.java Tue Aug 16 15:56:41 2011
@@ -21,10 +21,12 @@ package org.apache.empire.db;
import java.sql.Connection;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.empire.commons.Errors;
import org.apache.empire.commons.Options;
import org.apache.empire.data.DataType;
import org.apache.empire.db.expr.column.DBValueExpr;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemExistsException;
+import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.xml.XMLUtil;
import org.w3c.dom.Element;
@@ -117,11 +119,11 @@ public abstract class DBView extends DBR
}
@Override
- public boolean checkValue(Object value)
+ public void checkValue(Object value)
{
if (updateColumn==null)
- return true;
- return updateColumn.checkValue(value);
+ return;
+ updateColumn.checkValue(value);
}
@Override
@@ -283,15 +285,14 @@ public abstract class DBView extends DBR
* @param col a view column object
* @return true if the column was successfully added or false otherwise
*/
- protected boolean addColumn(DBViewColumn col)
+ protected void addColumn(DBViewColumn col)
{ // find column by name
if (col == null || col.getRowSet() != this)
- return error(Errors.InvalidArg, col, "col");
+ throw new InvalidArgumentException("col", col);
if (columns.contains(col) == true)
- return error(Errors.ItemExists, col.getName());
+ throw new ItemExistsException(col.getName());
// add now
columns.add(col);
- return true;
}
/**
@@ -304,7 +305,8 @@ public abstract class DBView extends DBR
protected final DBViewColumn addColumn(String columnName, DataType dataType)
{ // find column by name
DBViewColumn vc = new DBViewColumn(this, columnName, new DBValueExpr(db, null, dataType));
- return (addColumn(vc) ? vc : null);
+ addColumn(vc);
+ return vc;
}
/**
@@ -317,7 +319,8 @@ public abstract class DBView extends DBR
protected final DBViewColumn addColumn(String columnName, DBColumnExpr columnExpr)
{ // find column by name
DBViewColumn vc = new DBViewColumn(this, columnName, columnExpr);
- return (addColumn(vc) ? vc : null);
+ addColumn(vc);
+ return vc;
}
/**
@@ -329,14 +332,15 @@ public abstract class DBView extends DBR
protected final DBViewColumn addColumn(DBTableColumn sourceColumn)
{ // find column by name
DBViewColumn vc = new DBViewColumn(this, sourceColumn.getName(), sourceColumn);
- return (addColumn(vc) ? vc : null);
+ addColumn(vc);
+ return vc;
}
/**
* This function searchs for equal columns given by the specified DBColumnExpr object.
*
* @param expr the DBColumnExpr object
- * @return the located column (only DBViewColumn onjects)
+ * @return the located column (only DBViewColumn objects)
*/
public DBViewColumn findViewColumn(DBColumnExpr expr)
{
@@ -377,12 +381,12 @@ public abstract class DBView extends DBR
}
@Override
- public boolean updateRecord(DBRecord rec, Connection conn)
+ public void updateRecord(DBRecord rec, Connection conn)
{
if (updateable==false)
- return error(Errors.NotSupported, "updateRecord");
+ throw new NotSupportedException(this, "updateRecord");
// Update the record
- return super.updateRecord(rec, conn);
+ super.updateRecord(rec, conn);
}
/*
@@ -391,9 +395,9 @@ public abstract class DBView extends DBR
* @see org.apache.empire.db.DBRowSet#addRecord(org.apache.empire.db.DBRecord, java.sql.Connection)
*/
@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");
}
/*
@@ -402,8 +406,8 @@ public abstract class DBView extends DBR
* @see org.apache.empire.db.DBRowSet#deleteRecord(java.lang.Object[], java.sql.Connection, boolean)
*/
@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");
}
}
\ No newline at end of file
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/derby/DBDatabaseDriverDerby.java Tue Aug 16 15:56:41 2011
@@ -22,7 +22,6 @@ import java.sql.Connection;
import java.util.GregorianCalendar;
import java.util.Iterator;
-import org.apache.empire.commons.Errors;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.DataType;
import org.apache.empire.db.DBCmdType;
@@ -40,6 +39,9 @@ import org.apache.empire.db.DBSQLScript;
import org.apache.empire.db.DBTable;
import org.apache.empire.db.DBTableColumn;
import org.apache.empire.db.DBView;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
/**
@@ -283,22 +285,24 @@ public class DBDatabaseDriverDerby exten
/** {@inheritDoc} */
@Override
- public boolean getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
+ public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
{
// The Object's database must be attached to this driver
if (dbo == null || dbo.getDatabase().getDriver() != this)
- return error(Errors.InvalidArg, dbo, "dbo");
+ throw new InvalidArgumentException("dbo", String.valueOf(dbo));
// Check Type of object
if (dbo instanceof DBDatabase)
{ // Database
switch (type)
{
case CREATE:
- return createDatabase((DBDatabase) dbo, script, true);
+ createDatabase((DBDatabase) dbo, script, true);
+ return;
case DROP:
- return dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTable)
@@ -306,11 +310,13 @@ public class DBDatabaseDriverDerby exten
switch (type)
{
case CREATE:
- return createTable((DBTable) dbo, script);
+ createTable((DBTable) dbo, script);
+ return;
case DROP:
- return dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBView)
@@ -318,11 +324,13 @@ public class DBDatabaseDriverDerby exten
switch (type)
{
case CREATE:
- return createView((DBView) dbo, script);
+ createView((DBView) dbo, script);
+ return;
case DROP:
- return dropObject(((DBView) dbo).getName(), "VIEW", script);
+ dropObject(((DBView) dbo).getName(), "VIEW", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBRelation)
@@ -330,20 +338,23 @@ public class DBDatabaseDriverDerby exten
switch (type)
{
case CREATE:
- return createRelation((DBRelation) dbo, script);
+ createRelation((DBRelation) dbo, script);
+ return;
case DROP:
- return dropObject(((DBRelation) dbo).getName(), "CONSTRAINT", script);
+ dropObject(((DBRelation) dbo).getName(), "CONSTRAINT", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTableColumn)
{ // Table Column
- return alterTable((DBTableColumn) dbo, type, script);
+ alterTable((DBTableColumn) dbo, type, script);
+ return;
}
else
- { // an invalid argument has been supplied
- return error(Errors.InvalidArg, dbo, "dbo");
+ { // dll generation not supported for this type
+ throw new NotSupportedException(this, "getDDLScript() for "+dbo.getClass().getName());
}
}
@@ -363,7 +374,7 @@ public class DBDatabaseDriverDerby exten
/*
* return the sql for creating a Database
*/
- protected boolean createDatabase(DBDatabase db, DBSQLScript script, boolean createSchema)
+ protected void createDatabase(DBDatabase db, DBSQLScript script, boolean createSchema)
{
// // User Master to create Database
// if (createSchema)
@@ -382,25 +393,20 @@ public class DBDatabaseDriverDerby exten
Iterator<DBTable> tables = db.getTables().iterator();
while (tables.hasNext())
{
- if (!createTable(tables.next(), script))
- return false;
+ createTable(tables.next(), script);
}
// Create Relations
Iterator<DBRelation> relations = db.getRelations().iterator();
while (relations.hasNext())
{
- if (!createRelation(relations.next(), script))
- return false;
+ createRelation(relations.next(), script);
}
// Create Views
Iterator<DBView> views = db.getViews().iterator();
while (views.hasNext())
{
- if (!createView(views.next(), script))
- return false;
+ createView(views.next(), script);
}
- // Done
- return true;
}
/**
@@ -408,7 +414,7 @@ public class DBDatabaseDriverDerby exten
*
* @return true if the table has been created successfully
*/
- protected boolean createTable(DBTable t, DBSQLScript script)
+ protected void createTable(DBTable t, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("-- creating table ");
@@ -453,8 +459,7 @@ public class DBDatabaseDriverDerby exten
sql.append("'");
}
// Create the table
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
// Create other Indexes (except primary key)
Iterator<DBIndex> indexes = t.getIndexes().iterator();
while (indexes.hasNext())
@@ -482,11 +487,8 @@ public class DBDatabaseDriverDerby exten
}
sql.append(")");
// Create Index
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
}
- // done
- return success();
}
/**
@@ -614,7 +616,7 @@ public class DBDatabaseDriverDerby exten
*
* @return true if the relation has been created successfully
*/
- protected boolean createRelation(DBRelation r, DBSQLScript script)
+ protected void createRelation(DBRelation r, DBSQLScript script)
{
DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();
@@ -651,20 +653,17 @@ public class DBDatabaseDriverDerby exten
}
// done
sql.append(")");
- if (script.addStmt(sql) == false)
- return false;
- // done
- return success();
+ script.addStmt(sql);
}
/**
- * Creates an alter table dll statement for adding, modifiying or droping a column.
+ * Creates an alter table dll statement for adding, modifying or dropping a column.
* @param col the column which to add, modify or drop
* @param type the type of operation to perform
* @param script to which to append the sql statement to
* @return true if the statement was successfully appended to the buffer
*/
- protected boolean alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
+ protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("ALTER TABLE ");
@@ -685,7 +684,7 @@ public class DBDatabaseDriverDerby exten
break;
}
// done
- return script.addStmt(sql);
+ script.addStmt(sql);
}
/**
@@ -693,17 +692,15 @@ public class DBDatabaseDriverDerby exten
*
* @return true if the view has been created successfully
*/
- protected boolean createView(DBView v, DBSQLScript script)
+ protected void createView(DBView v, DBSQLScript script)
{
// Create the Command
DBCommandExpr cmd = v.createCommand();
if (cmd==null)
{ // Check whether Error information is available
log.error("No command has been supplied for view " + v.getName());
- if (v.hasError())
- return error(v);
// No error information available: Use Errors.NotImplemented
- return error(Errors.NotImplemented, v.getName() + ".createCommand");
+ throw new NotImplementedException(this, v.getName() + ".createCommand");
}
// Make sure there is no OrderBy
cmd.clearOrderBy();
@@ -726,7 +723,7 @@ public class DBDatabaseDriverDerby exten
sql.append(")\r\nAS\r\n");
cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -734,17 +731,17 @@ public class DBDatabaseDriverDerby exten
*
* @return true if the object has been dropped successfully
*/
- protected boolean dropObject(String name, String objType, DBSQLScript script)
+ protected void dropObject(String name, String objType, DBSQLScript script)
{
if (name == null || name.length() == 0)
- return error(Errors.InvalidArg, name, "name");
+ throw new InvalidArgumentException("name", name);
// Create Drop Statement
StringBuilder sql = new StringBuilder();
sql.append("DROP ");
sql.append(objType);
sql.append(" ");
appendElementName(sql, name);
- return script.addStmt(sql);
+ script.addStmt(sql);
}
}
Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/exceptions/
------------------------------------------------------------------------------
eol-style = native
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java Tue Aug 16 15:56:41 2011
@@ -22,7 +22,6 @@ import java.sql.Connection;
import java.util.GregorianCalendar;
import java.util.Iterator;
-import org.apache.empire.commons.Errors;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.DataType;
import org.apache.empire.db.DBCmdType;
@@ -40,6 +39,9 @@ import org.apache.empire.db.DBSQLScript;
import org.apache.empire.db.DBTable;
import org.apache.empire.db.DBTableColumn;
import org.apache.empire.db.DBView;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
/**
@@ -288,22 +290,24 @@ public class DBDatabaseDriverH2 extends
* @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)
*/
@Override
- public boolean getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
+ public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
{
// The Object's database must be attached to this driver
if (dbo==null || dbo.getDatabase().getDriver()!=this)
- return error(Errors.InvalidArg, dbo, "dbo");
+ throw new InvalidArgumentException("dbo", dbo);
// Check Type of object
if (dbo instanceof DBDatabase)
{ // Database
switch (type)
{
case CREATE:
- return createDatabase((DBDatabase) dbo, script, true);
+ createDatabase((DBDatabase) dbo, script, true);
+ return;
case DROP:
- return dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTable)
@@ -311,11 +315,13 @@ public class DBDatabaseDriverH2 extends
switch (type)
{
case CREATE:
- return createTable((DBTable) dbo, script);
+ createTable((DBTable) dbo, script);
+ return;
case DROP:
- return dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBView)
@@ -323,11 +329,13 @@ public class DBDatabaseDriverH2 extends
switch (type)
{
case CREATE:
- return createView((DBView) dbo, script);
+ createView((DBView) dbo, script);
+ return;
case DROP:
- return dropObject(((DBView) dbo).getName(), "VIEW", script);
+ dropObject(((DBView) dbo).getName(), "VIEW", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBRelation)
@@ -335,20 +343,23 @@ public class DBDatabaseDriverH2 extends
switch (type)
{
case CREATE:
- return createRelation((DBRelation) dbo, script);
+ createRelation((DBRelation) dbo, script);
+ return;
case DROP:
- return dropObject(((DBRelation) dbo).getName(), "CONSTRAINT", script);
+ dropObject(((DBRelation) dbo).getName(), "CONSTRAINT", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTableColumn)
{ // Table Column
- return alterTable((DBTableColumn) dbo, type, script);
+ alterTable((DBTableColumn) dbo, type, script);
+ return;
}
else
- { // an invalid argument has been supplied
- return error(Errors.InvalidArg, dbo, "dbo");
+ { // dll generation not supported for this type
+ throw new NotSupportedException(this, "getDDLScript() for "+dbo.getClass().getName());
}
}
@@ -387,22 +398,19 @@ public class DBDatabaseDriverH2 extends
Iterator<DBTable> tables = db.getTables().iterator();
while (tables.hasNext())
{
- if (!createTable(tables.next(), script))
- return false;
+ createTable(tables.next(), script);
}
// Create Relations
Iterator<DBRelation> relations = db.getRelations().iterator();
while (relations.hasNext())
{
- if (!createRelation(relations.next(), script))
- return false;
+ createRelation(relations.next(), script);
}
// Create Views
Iterator<DBView> views = db.getViews().iterator();
while (views.hasNext())
{
- if (!createView(views.next(), script))
- return false;
+ createView(views.next(), script);
}
// Done
return true;
@@ -413,7 +421,7 @@ public class DBDatabaseDriverH2 extends
*
* @return true if the table has been created successfully
*/
- protected boolean createTable(DBTable t, DBSQLScript script)
+ protected void createTable(DBTable t, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("-- creating table ");
@@ -458,8 +466,7 @@ public class DBDatabaseDriverH2 extends
sql.append("'");
}
// Create the table
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
// Create other Indexes (except primary key)
Iterator<DBIndex> indexes = t.getIndexes().iterator();
while (indexes.hasNext())
@@ -487,11 +494,8 @@ public class DBDatabaseDriverH2 extends
}
sql.append(")");
// Create Index
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
}
- // done
- return success();
}
/**
@@ -581,8 +585,8 @@ public class DBDatabaseDriverH2 extends
sql.append("CHAR(36)");
break;
case UNKNOWN:
- log.error("Cannot append column of Data-Type 'UNKNOWN'");
- return false;
+ log.warn("Cannot append column of Data-Type 'UNKNOWN'");
+ return false;
}
// Default Value
if (isDDLColumnDefaults() && !c.isAutoGenerated() && c.getDefaultValue()!=null)
@@ -601,7 +605,7 @@ public class DBDatabaseDriverH2 extends
*
* @return true if the relation has been created successfully
*/
- protected boolean createRelation(DBRelation r, DBSQLScript script)
+ protected void createRelation(DBRelation r, DBSQLScript script)
{
DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();
@@ -638,20 +642,17 @@ public class DBDatabaseDriverH2 extends
}
// done
sql.append(")");
- if (script.addStmt(sql) == false)
- return false;
- // done
- return success();
+ script.addStmt(sql);
}
/**
- * Creates an alter table dll statement for adding, modifiying or droping a column.
+ * Creates an alter table dll statement for adding, modifying or dropping a column.
* @param col the column which to add, modify or drop
* @param type the type of operation to perform
* @param script to which to append the sql statement to
* @return true if the statement was successfully appended to the buffer
*/
- protected boolean alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
+ protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("ALTER TABLE ");
@@ -672,7 +673,7 @@ public class DBDatabaseDriverH2 extends
break;
}
// done
- return script.addStmt(sql);
+ script.addStmt(sql);
}
/**
@@ -680,17 +681,14 @@ public class DBDatabaseDriverH2 extends
*
* @return true if the view has been created successfully
*/
- protected boolean createView(DBView v, DBSQLScript script)
+ protected void createView(DBView v, DBSQLScript script)
{
// Create the Command
DBCommandExpr cmd = v.createCommand();
if (cmd==null)
{ // Check whether Error information is available
log.error("No command has been supplied for view " + v.getName());
- if (v.hasError())
- return error(v);
- // No error information available: Use Errors.NotImplemented
- return error(Errors.NotImplemented, v.getName() + ".createCommand");
+ throw new NotImplementedException(this, v.getName() + ".createCommand");
}
// Make sure there is no OrderBy
cmd.clearOrderBy();
@@ -713,7 +711,7 @@ public class DBDatabaseDriverH2 extends
sql.append(")\r\nAS\r\n");
cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -721,17 +719,17 @@ public class DBDatabaseDriverH2 extends
*
* @return true if the object has been dropped successfully
*/
- protected boolean dropObject(String name, String objType, DBSQLScript script)
+ protected void dropObject(String name, String objType, DBSQLScript script)
{
if (name == null || name.length() == 0)
- return error(Errors.InvalidArg, name, "name");
+ throw new InvalidArgumentException("name", name);
// Create Drop Statement
StringBuilder sql = new StringBuilder();
sql.append("DROP ");
sql.append(objType);
sql.append(" ");
appendElementName(sql, name);
- return script.addStmt(sql);
+ script.addStmt(sql);
}
}
Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=1158339&r1=1158338&r2=1158339&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java Tue Aug 16 15:56:41 2011
@@ -22,7 +22,6 @@ import java.sql.Connection;
import java.util.GregorianCalendar;
import java.util.Iterator;
-import org.apache.empire.commons.Errors;
import org.apache.empire.data.DataType;
import org.apache.empire.db.DBCmdType;
import org.apache.empire.db.DBColumn;
@@ -39,6 +38,9 @@ import org.apache.empire.db.DBSQLScript;
import org.apache.empire.db.DBTable;
import org.apache.empire.db.DBTableColumn;
import org.apache.empire.db.DBView;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotImplementedException;
+import org.apache.empire.exceptions.NotSupportedException;
/**
@@ -253,22 +255,24 @@ public class DBDatabaseDriverHSql extend
* @see DBDatabaseDriver#getDDLScript(DBCmdType, DBObject, DBSQLScript)
*/
@Override
- public boolean getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
+ public void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
{
// The Object's database must be attached to this driver
if (dbo==null || dbo.getDatabase().getDriver()!=this)
- return error(Errors.InvalidArg, dbo, "dbo");
+ throw new InvalidArgumentException("dbo", dbo);
// Check Type of object
if (dbo instanceof DBDatabase)
{ // Database
switch (type)
{
case CREATE:
- return createDatabase((DBDatabase) dbo, script);
+ createDatabase((DBDatabase) dbo, script);
+ return;
case DROP:
- return dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ dropObject(((DBDatabase) dbo).getSchema(), "DATABASE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTable)
@@ -276,11 +280,13 @@ public class DBDatabaseDriverHSql extend
switch (type)
{
case CREATE:
- return createTable((DBTable) dbo, script);
+ createTable((DBTable) dbo, script);
+ return;
case DROP:
- return dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ dropObject(((DBTable) dbo).getName(), "TABLE", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBView)
@@ -288,11 +294,13 @@ public class DBDatabaseDriverHSql extend
switch (type)
{
case CREATE:
- return createView((DBView) dbo, script);
+ createView((DBView) dbo, script);
+ return;
case DROP:
- return dropObject(((DBView) dbo).getName(), "VIEW", script);
+ dropObject(((DBView) dbo).getName(), "VIEW", script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBRelation)
@@ -300,20 +308,23 @@ public class DBDatabaseDriverHSql extend
switch (type)
{
case CREATE:
- return alterRelation((DBRelation) dbo, type, script);
+ alterRelation((DBRelation) dbo, type, script);
+ return;
case DROP:
- return alterRelation((DBRelation) dbo, type, script);
+ alterRelation((DBRelation) dbo, type, script);
+ return;
default:
- return error(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
+ throw new NotImplementedException(this, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTableColumn)
{ // Table Column
- return alterTable((DBTableColumn) dbo, type, script);
+ alterTable((DBTableColumn) dbo, type, script);
+ return;
}
else
- { // an invalid argument has been supplied
- return error(Errors.InvalidArg, dbo, "dbo");
+ { // dll generation not supported for this type
+ throw new NotSupportedException(this, "getDDLScript() for "+dbo.getClass().getName());
}
}
@@ -333,7 +344,7 @@ public class DBDatabaseDriverHSql extend
/*
* return the sql for creating a Database
*/
- protected boolean createDatabase(DBDatabase db, DBSQLScript script)
+ protected void createDatabase(DBDatabase db, DBSQLScript script)
{
// Create all Sequences
Iterator<DBTable> seqtabs = db.getTables().iterator();
@@ -354,25 +365,20 @@ public class DBDatabaseDriverHSql extend
Iterator<DBTable> tables = db.getTables().iterator();
while (tables.hasNext())
{
- if (!createTable(tables.next(), script))
- return false;
+ createTable(tables.next(), script);
}
// Create Relations
Iterator<DBRelation> relations = db.getRelations().iterator();
while (relations.hasNext())
{
- if (!alterRelation(relations.next(), DBCmdType.CREATE, script))
- return false;
+ alterRelation(relations.next(), DBCmdType.CREATE, script);
}
// Create Views
Iterator<DBView> views = db.getViews().iterator();
while (views.hasNext())
{
- if (!createView(views.next(), script))
- return false;
+ createView(views.next(), script);
}
- // Done
- return true;
}
/**
@@ -380,7 +386,7 @@ public class DBDatabaseDriverHSql extend
*
* @return true if the sequence has been created successfully
*/
- protected boolean createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
+ protected void createSequence(DBDatabase db, DBTableColumn c, DBSQLScript script)
{
Object defValue = c.getDefaultValue();
String seqName = (defValue != null) ? defValue.toString() : c.toString();
@@ -393,7 +399,7 @@ public class DBDatabaseDriverHSql extend
db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
sql.append(" START WITH 1");
// executeDLL
- return script.addStmt(sql);
+ script.addStmt(sql);
}
/**
@@ -401,7 +407,7 @@ public class DBDatabaseDriverHSql extend
*
* @return true if the table has been created successfully
*/
- protected boolean createTable(DBTable t, DBSQLScript script)
+ protected void createTable(DBTable t, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("-- creating table ");
@@ -440,8 +446,7 @@ public class DBDatabaseDriverHSql extend
}
sql.append(")");
// Create the table
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
// Create other Indexes (except primary key)
Iterator<DBIndex> indexes = t.getIndexes().iterator();
while (indexes.hasNext())
@@ -469,11 +474,8 @@ public class DBDatabaseDriverHSql extend
}
sql.append(")");
// Create Index
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
}
- // done
- return success();
}
/**
@@ -552,8 +554,8 @@ public class DBDatabaseDriverHSql extend
sql.append("CHAR(36)");
break;
case UNKNOWN:
- log.error("Cannot append column of Data-Type 'UNKNOWN'");
- return false;
+ log.warn("Cannot append column of Data-Type 'UNKNOWN'");
+ return false;
}
// Default Value
if (isDDLColumnDefaults() && !c.isAutoGenerated() && c.getDefaultValue()!=null)
@@ -572,7 +574,7 @@ public class DBDatabaseDriverHSql extend
*
* @return true if the relation has been altered successfully
*/
- protected boolean alterRelation(DBRelation r, DBCmdType type, DBSQLScript script)
+ protected void alterRelation(DBRelation r, DBCmdType type, DBSQLScript script)
{
switch(type)
{
@@ -613,11 +615,8 @@ public class DBDatabaseDriverHSql extend
}
// done
sql.append(")");
- if (script.addStmt(sql.toString()) == false)
- return false;
- // done
- return success();
-
+ script.addStmt(sql.toString());
+ break;
}
case DROP:
{
@@ -631,22 +630,23 @@ public class DBDatabaseDriverHSql extend
sql.append(" DROP CONSTRAINT ");
appendElementName(sql, r.getName());
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
+ break;
}
default:
- return error(Errors.NotImplemented, "Type not supported (" + type + ")");
+ throw new NotImplementedException(this, "Type not supported (" + type + ")");
}
}
/**
- * Creates an alter table dll statement for adding, modifiying or droping a column.
+ * Creates an alter table dll statement for adding, modifying or dropping a column.
* @param col the column which to add, modify or drop
* @param type the type of operation to perform
* @param script to which to append the sql statement to
* @return true if the statement was successfully appended to the buffer
*/
- protected boolean alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
+ protected void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
{
StringBuilder sql = new StringBuilder();
sql.append("ALTER TABLE ");
@@ -667,7 +667,7 @@ public class DBDatabaseDriverHSql extend
break;
}
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -675,17 +675,14 @@ public class DBDatabaseDriverHSql extend
*
* @return true if the view has been created successfully
*/
- protected boolean createView(DBView v, DBSQLScript script)
+ protected void createView(DBView v, DBSQLScript script)
{
// Create the Command
DBCommandExpr cmd = v.createCommand();
if (cmd==null)
{ // Check whether Error information is available
log.error("No command has been supplied for view " + v.getName());
- if (v.hasError())
- return error(v);
- // No error information available: Use Errors.NotImplemented
- return error(Errors.NotImplemented, v.getName() + ".createCommand");
+ throw new NotImplementedException(this, v.getName() + ".createCommand");
}
// Make sure there is no OrderBy
cmd.clearOrderBy();
@@ -708,7 +705,7 @@ public class DBDatabaseDriverHSql extend
sql.append(")\r\nAS\r\n");
cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -716,10 +713,10 @@ public class DBDatabaseDriverHSql extend
*
* @return true if the object has been dropped successfully
*/
- protected boolean dropObject(String name, String objType, DBSQLScript script)
+ protected void dropObject(String name, String objType, DBSQLScript script)
{
if (name == null || name.length() == 0)
- return error(Errors.InvalidArg, name, "name");
+ throw new InvalidArgumentException("name", name);
// Create Drop Statement
StringBuilder sql = new StringBuilder();
sql.append("DROP ");
@@ -727,7 +724,7 @@ public class DBDatabaseDriverHSql extend
sql.append(" ");
appendElementName(sql, name);
// Done
- return script.addStmt(sql);
+ script.addStmt(sql);
}
}