You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2011/07/19 18:53:41 UTC
svn commit: r1148444 [4/4] - in
/incubator/empire-db/branches/EMPIREDB-99/empire-db/src:
main/java/org/apache/empire/ main/java/org/apache/empire/commons/
main/java/org/apache/empire/data/ main/java/org/apache/empire/data/bean/
main/java/org/apache/emp...
Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java Tue Jul 19 16:53:34 2011
@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.GregorianCalendar;
import java.util.Iterator;
+import org.apache.empire.EmpireException;
import org.apache.empire.commons.Errors;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.DataType;
@@ -33,6 +34,7 @@ import org.apache.empire.db.DBCommandExp
import org.apache.empire.db.DBDatabase;
import org.apache.empire.db.DBDatabaseDriver;
import org.apache.empire.db.DBDriverFeature;
+import org.apache.empire.db.DBErrors;
import org.apache.empire.db.DBExpr;
import org.apache.empire.db.DBIndex;
import org.apache.empire.db.DBObject;
@@ -92,17 +94,15 @@ public class DBDatabaseDriverPostgreSQL
}
@Override
- public boolean limitRows(int numRows)
+ public void limitRows(int numRows)
{
limit = numRows;
- return success();
}
@Override
- public boolean skipRows(int numRows)
+ public void skipRows(int numRows)
{
skip = numRows;
- return success();
}
@Override
@@ -113,10 +113,9 @@ public class DBDatabaseDriverPostgreSQL
}
@Override
- public boolean getSelect(StringBuilder buf)
+ public void getSelect(StringBuilder buf)
{ // call base class
- if (super.getSelect(buf)==false)
- return false;
+ super.getSelect(buf);
// add limit and offset
if (limit>=0)
{ buf.append("\r\nLIMIT ");
@@ -127,11 +126,7 @@ public class DBDatabaseDriverPostgreSQL
buf.append(String.valueOf(skip));
}
}
- // done
- return success();
}
-
-
}
private String databaseName;
@@ -280,14 +275,15 @@ public class DBDatabaseDriverPostgreSQL
* @param conn a valid database connection
* @return true if the reverse function was created successfully or false otherwise
*/
- public boolean createReverseFunction(Connection conn)
+ public void createReverseFunction(Connection conn)
{
try {
log.info("Creating reverse function: " + CREATE_REVERSE_FUNCTION);
- return (executeSQL(CREATE_REVERSE_FUNCTION, null, conn, null)>=0);
+ executeSQL(CREATE_REVERSE_FUNCTION, null, conn, null);
} catch(SQLException e) {
log.error("Unable to create reverse function!", e);
- return error(e);
+ String msg = extractErrorMessage(e);
+ throw new EmpireException(DBErrors.SQLException, new Object[] { msg }, e);
}
}
@@ -307,7 +303,7 @@ public class DBDatabaseDriverPostgreSQL
/**
* Returns whether or not a particular feature is supported by this driver
- * @param type type of requrested feature. @see DBDriverFeature
+ * @param type type of requested feature. @see DBDriverFeature
* @return true if the features is supported or false otherwise
*/
@Override
@@ -444,22 +440,24 @@ public class DBDatabaseDriverPostgreSQL
* @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 EmpireException(Errors.InvalidArg, 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()+"."+String.valueOf(type));
+ throw new EmpireException(Errors.NotImplemented, "getDDLScript."+dbo.getClass().getName()+"."+String.valueOf(type));
}
}
else if (dbo instanceof DBTable)
@@ -467,11 +465,13 @@ public class DBDatabaseDriverPostgreSQL
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 EmpireException(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBView)
@@ -479,11 +479,13 @@ public class DBDatabaseDriverPostgreSQL
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 EmpireException(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBRelation)
@@ -491,20 +493,23 @@ public class DBDatabaseDriverPostgreSQL
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 EmpireException(Errors.NotImplemented, "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");
+ throw new EmpireException(Errors.InvalidArg, dbo, "dbo");
}
}
@@ -546,22 +551,19 @@ public class DBDatabaseDriverPostgreSQL
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;
@@ -577,7 +579,7 @@ public class DBDatabaseDriverPostgreSQL
*
* @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)
{
String seqName = createSequenceName(c);
// createSQL
@@ -594,7 +596,7 @@ public class DBDatabaseDriverPostgreSQL
sql.append(" INCREMENT BY 1 START WITH 1 MINVALUE 0");
// executeDLL
- return script.addStmt(sql);
+ script.addStmt(sql);
}
/**
@@ -602,7 +604,7 @@ public class DBDatabaseDriverPostgreSQL
*
* @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 ");
@@ -647,8 +649,7 @@ public class DBDatabaseDriverPostgreSQL
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())
@@ -676,11 +677,8 @@ public class DBDatabaseDriverPostgreSQL
}
sql.append(")");
// Create Index
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
}
- // done
- return success();
}
/**
@@ -790,8 +788,8 @@ public class DBDatabaseDriverPostgreSQL
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)
@@ -810,7 +808,7 @@ public class DBDatabaseDriverPostgreSQL
*
* @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();
@@ -847,10 +845,7 @@ public class DBDatabaseDriverPostgreSQL
}
// done
sql.append(")");
- if (script.addStmt(sql) == false)
- return false;
- // done
- return success();
+ script.addStmt(sql);
}
/**
@@ -860,7 +855,7 @@ public class DBDatabaseDriverPostgreSQL
* @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 ");
@@ -881,7 +876,7 @@ public class DBDatabaseDriverPostgreSQL
break;
}
// done
- return script.addStmt(sql);
+ script.addStmt(sql);
}
@@ -891,17 +886,14 @@ public class DBDatabaseDriverPostgreSQL
*
* @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 EmpireException(Errors.NotImplemented, v.getName() + ".createCommand");
}
// Make sure there is no OrderBy
cmd.clearOrderBy();
@@ -924,7 +916,7 @@ public class DBDatabaseDriverPostgreSQL
sql.append(")\r\nAS\r\n");
cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -932,17 +924,17 @@ public class DBDatabaseDriverPostgreSQL
*
* @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 EmpireException(Errors.InvalidArg, 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/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java Tue Jul 19 16:53:34 2011
@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.GregorianCalendar;
import java.util.Iterator;
+import org.apache.empire.EmpireException;
import org.apache.empire.commons.Errors;
import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
@@ -34,6 +35,7 @@ import org.apache.empire.db.DBCommandExp
import org.apache.empire.db.DBDatabase;
import org.apache.empire.db.DBDatabaseDriver;
import org.apache.empire.db.DBDriverFeature;
+import org.apache.empire.db.DBErrors;
import org.apache.empire.db.DBExpr;
import org.apache.empire.db.DBIndex;
import org.apache.empire.db.DBObject;
@@ -68,10 +70,9 @@ public class DBDatabaseDriverMSSQL exten
}
@Override
- public boolean limitRows(int numRows)
+ public void limitRows(int numRows)
{
limit = numRows;
- return success();
}
@Override
@@ -104,7 +105,7 @@ public class DBDatabaseDriverMSSQL exten
private String objectOwner = "dbo";
private String sequenceTableName = "Sequences";
// Sequence treatment
- // When set to 'false' (default) MySQL's autoincrement feature is used.
+ // When set to 'false' (default) MySQL's auto-increment feature is used.
private boolean useSequenceTable = false;
/**
@@ -175,7 +176,7 @@ public class DBDatabaseDriverMSSQL exten
/** {@inheritDoc} */
@Override
- public boolean attachDatabase(DBDatabase db, Connection conn)
+ public void attachDatabase(DBDatabase db, Connection conn)
{
// Prepare
try
@@ -194,11 +195,12 @@ public class DBDatabaseDriverMSSQL exten
db.setSchema(schema + "." + objectOwner);
}
// call Base implementation
- return super.attachDatabase(db, conn);
+ super.attachDatabase(db, conn);
- } catch (SQLException e)
- {
- return error(e);
+ } catch (SQLException e) {
+ // throw exception
+ String msg = extractErrorMessage(e);
+ throw new EmpireException(DBErrors.SQLException, new Object[] { msg }, e);
}
}
@@ -377,22 +379,24 @@ public class DBDatabaseDriverMSSQL exten
* @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 EmpireException(Errors.InvalidArg, 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 EmpireException(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBTable)
@@ -400,11 +404,13 @@ public class DBDatabaseDriverMSSQL 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 EmpireException(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBView)
@@ -412,11 +418,13 @@ public class DBDatabaseDriverMSSQL 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 EmpireException(Errors.NotImplemented, "getDDLScript." + dbo.getClass().getName() + "." + type);
}
}
else if (dbo instanceof DBRelation)
@@ -424,20 +432,23 @@ public class DBDatabaseDriverMSSQL 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 EmpireException(Errors.NotImplemented, "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");
+ throw new EmpireException(Errors.InvalidArg, dbo, "dbo");
}
}
@@ -463,7 +474,7 @@ public class DBDatabaseDriverMSSQL exten
if (createSchema)
{ // check database Name
if (StringUtils.isEmpty(databaseName))
- return error(Errors.InvalidProperty, "databaseName");
+ throw new EmpireException(Errors.InvalidProperty, "databaseName");
// Create Database
script.addStmt("USE master");
script.addStmt("IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '" + databaseName + "') CREATE DATABASE " + databaseName);
@@ -477,22 +488,19 @@ public class DBDatabaseDriverMSSQL 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;
@@ -503,7 +511,7 @@ public class DBDatabaseDriverMSSQL 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 ");
@@ -542,8 +550,7 @@ public class DBDatabaseDriverMSSQL 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())
@@ -572,11 +579,8 @@ public class DBDatabaseDriverMSSQL exten
}
sql.append(")");
// Create Index
- if (script.addStmt(sql) == false)
- return false;
+ script.addStmt(sql);
}
- // done
- return success();
}
/**
@@ -684,7 +688,7 @@ public class DBDatabaseDriverMSSQL 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();
@@ -721,10 +725,7 @@ public class DBDatabaseDriverMSSQL exten
}
// done
sql.append(")");
- if (script.addStmt(sql) == false)
- return false;
- // done
- return success();
+ script.addStmt(sql);
}
/**
@@ -734,7 +735,7 @@ public class DBDatabaseDriverMSSQL exten
* @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 ");
@@ -755,7 +756,7 @@ public class DBDatabaseDriverMSSQL exten
break;
}
// done
- return script.addStmt(sql);
+ script.addStmt(sql);
}
/**
@@ -763,17 +764,14 @@ public class DBDatabaseDriverMSSQL 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 EmpireException(Errors.NotImplemented, v.getName() + ".createCommand");
}
// Make sure there is no OrderBy
cmd.clearOrderBy();
@@ -796,7 +794,7 @@ public class DBDatabaseDriverMSSQL exten
sql.append(")\r\nAS\r\n");
cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
// done
- return script.addStmt(sql.toString());
+ script.addStmt(sql.toString());
}
/**
@@ -804,17 +802,17 @@ public class DBDatabaseDriverMSSQL 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 EmpireException(Errors.InvalidArg, 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/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java Tue Jul 19 16:53:34 2011
@@ -30,6 +30,7 @@ import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.EmpireException;
import org.apache.empire.commons.ErrorObject;
import org.apache.empire.commons.Errors;
import org.apache.empire.commons.ObjectUtils;
@@ -65,13 +66,10 @@ public class XMLConfiguration extends Er
*
* @return true on success
*/
- public boolean init(String filename, boolean fromResource)
+ public void init(String filename, boolean fromResource)
{
// Read the properties file
- if (readConfiguration(filename, fromResource) == false)
- return false;
- // Done
- return success();
+ readConfiguration(filename, fromResource);
}
/**
@@ -86,7 +84,7 @@ public class XMLConfiguration extends Er
/**
* Reads the configuration file and parses the XML Configuration.
*/
- protected boolean readConfiguration(String fileName, boolean fromResource)
+ protected void readConfiguration(String fileName, boolean fromResource)
{
FileReader reader = null;
InputStream inputStream = null;
@@ -110,23 +108,22 @@ public class XMLConfiguration extends Er
}
// Get Root Element
configRootNode = doc.getDocumentElement();
- return success();
} catch (FileNotFoundException e)
{
log.error("Configuration file {} not found!", fileName, e);
- return error(Errors.FileNotFound, fileName);
+ throw new EmpireException(Errors.FileNotFound, fileName);
} catch (IOException e)
{
log.error("Error reading configuration file {}", fileName, e);
- return error(Errors.FileReadError, fileName);
+ throw new EmpireException(Errors.FileReadError, fileName);
} catch (SAXException e)
{
log.error("Invalid XML in configuration file {}", fileName, e);
- return error(e);
+ throw new EmpireException(e);
} catch (ParserConfigurationException e)
{
log.error("ParserConfigurationException: {}", e.getMessage(), e);
- return error(e);
+ throw new EmpireException(e);
} finally
{
close(reader);
@@ -140,30 +137,30 @@ public class XMLConfiguration extends Er
* @param propertiesNodeName the name of the properties node below the root element
* @return true of successful or false otherwise
*/
- public boolean readProperties(Object bean, String... propertiesNodeNames)
+ public void readProperties(Object bean, String... propertiesNodeNames)
{
// Check state
if (configRootNode == null)
- return error(Errors.ObjectNotValid, getClass().getName());
+ throw new EmpireException(Errors.ObjectNotValid, getClass().getName());
// Check arguments
if (bean == null)
- return error(Errors.InvalidArg, null, "bean");
+ throw new EmpireException(Errors.InvalidArg, null, "bean");
Element propertiesNode = configRootNode;
for(String nodeName : propertiesNodeNames)
{
if (StringUtils.isEmpty(nodeName))
- return error(Errors.InvalidArg, null, "propertiesNodeNames");
+ throw new EmpireException(Errors.InvalidArg, null, "propertiesNodeNames");
// Get configuration node
propertiesNode = XMLUtil.findFirstChild(propertiesNode, nodeName);
if (propertiesNode == null)
{ // Configuration
log.error("Property-Node {} has not been found.", nodeName);
- return error(Errors.ItemNotFound, nodeName);
+ throw new EmpireException(Errors.ItemNotFound, nodeName);
}
}
// read the properties
- return readProperties(bean, propertiesNode);
+ readProperties(bean, propertiesNode);
}
/**
@@ -172,13 +169,13 @@ public class XMLConfiguration extends Er
* @param propertiesNode the properties node
* @return true of successful or false otherwise
*/
- public boolean readProperties(Object bean, Element propertiesNode)
+ public void readProperties(Object bean, Element propertiesNode)
{
// Check arguments
if (propertiesNode == null)
- return error(Errors.InvalidArg, null, "propertiesNode");
+ throw new EmpireException(Errors.InvalidArg, null, "propertiesNode");
if (bean == null)
- return error(Errors.InvalidArg, null, "bean");
+ throw new EmpireException(Errors.InvalidArg, null, "bean");
// apply configuration
log.info("reading bean properties from node: {}", propertiesNode.getNodeName());
NodeList nodeList = propertiesNode.getChildNodes();
@@ -190,8 +187,6 @@ public class XMLConfiguration extends Er
// Get the Text and set the Property
setPropertyValue(bean, item);
}
- // done
- return success();
}
protected void setPropertyValue(Object bean, Node item)
Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/DBCommandTest.java Tue Jul 19 16:53:34 2011
@@ -85,9 +85,9 @@ public class DBCommandTest
}
@Override
- public boolean checkValue(Object value)
+ public void checkValue(Object value)
{
- return false;
+ return;
}
@Override
Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/IntegerTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/IntegerTest.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/IntegerTest.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/IntegerTest.java Tue Jul 19 16:53:34 2011
@@ -26,7 +26,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.empire.commons.ErrorObject;
import org.apache.empire.data.DataMode;
import org.apache.empire.data.DataType;
import org.apache.empire.db.derby.DBDatabaseDriverDerby;
@@ -36,7 +35,6 @@ import org.apache.empire.db.mysql.DBData
import org.apache.empire.db.oracle.DBDatabaseDriverOracle;
import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL;
-import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
@@ -49,11 +47,6 @@ import org.slf4j.LoggerFactory;
public class IntegerTest {
private static final Logger LOGGER = LoggerFactory.getLogger(IntegerTest.class);
-
- @Before
- public void enableExceptions(){
- ErrorObject.setExceptionsEnabled(true);
- }
@Test
public void testHsqldb() {
Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/PreparedStatementTest.java Tue Jul 19 16:53:34 2011
@@ -26,7 +26,6 @@ import java.sql.Connection;
import org.apache.empire.DBResource;
import org.apache.empire.DBResource.DB;
-import org.apache.empire.commons.ErrorObject;
import org.apache.empire.db.DBCommand.DBCommandParam;
import org.junit.Rule;
import org.junit.Test;
@@ -40,8 +39,6 @@ public class PreparedStatementTest{
@Test
public void testPreparedStatement()
{
- ErrorObject.setExceptionsEnabled(true);
-
Connection conn = dbResource.getConnection();
DBDatabaseDriver driver = dbResource.newDriver();
Modified: incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java?rev=1148444&r1=1148443&r2=1148444&view=diff
==============================================================================
--- incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java (original)
+++ incubator/empire-db/branches/EMPIREDB-99/empire-db/src/test/java/org/apache/empire/db/hsql/DBDatabaseDriverHSqlTest.java Tue Jul 19 16:53:34 2011
@@ -27,7 +27,6 @@ import java.util.Date;
import org.apache.empire.DBResource;
import org.apache.empire.DBResource.DB;
-import org.apache.empire.commons.ErrorObject;
import org.apache.empire.db.CompanyDB;
import org.apache.empire.db.DBCmdType;
import org.apache.empire.db.DBDatabaseDriver;
@@ -45,8 +44,6 @@ public class DBDatabaseDriverHSqlTest{
@Test
public void test()
{
- ErrorObject.setExceptionsEnabled(true);
-
Connection conn = dbResource.getConnection();
DBDatabaseDriver driver = dbResource.newDriver();