Expresso 5-6

com.jcorporate.expresso.core.dataobjects.jdbc
Class JDBCExecutor

java.lang.Object
  extended bycom.jcorporate.expresso.core.dataobjects.jdbc.JDBCExecutor
All Implemented Interfaces:
DataExecutorInterface

public class JDBCExecutor
extends Object
implements DataExecutorInterface

Initial separation of DBObjects from the underlying JDBC code that gets executed. This is part number 1 where we move a lot of the JDBC code over to this helper class. For round #1 iteration, we're assuming that the valueObject is actually a DBObject that implements the DataObject interface (which it does). This is because we're interested in getting something working and demonstratable, and then slowly flesh out the DataObject interface so that we can eventually completely prune this class completely away from the DBObject class and work strictly with the DataObject Interface.

Since:
Expresso 5.0
Author:
Michael Rimov, Yves Henri AMAIZO

Field Summary
static int LONGBINARY_READ_DEFAULT_SIZE
           
static String LONGVARBINARY_TYPE
           
static String LONGVARCHAR_TYPE
           
static String VARBINARY_TYPE
           
 
Constructor Summary
JDBCExecutor()
           
 
Method Summary
 void add(DataObject valueObject)
          Takes a DataObject and adds it to the underlying data source
 void addBatch(List valueObjectList)
          Adds an entire batch of DataObjects to the underlying JDBC data source
 void addBatch(List valueObjectList, boolean addChangedFieldsOnly)
          Adds an entire batch of DataObjects to the underlying JDBC data source
protected  String buildPreparedAddSQL(DataObject oneObjectType, boolean addChangedFieldsOnly)
          Helper Function to build a prepared statement's SQL for an ADD statement.
protected  String buildPreparedDeleteSQL(DataObject oneObjectType, boolean deleteWithSetFieldsOnly)
          Helper function to build a prepared delete statement for batch deletes.
protected  String buildPreparedStoreProcedureSQL(DataObject oneObjectType)
          Helper Function to build a prepared statement's SQL for running STore Procedure statement.
protected  String buildPreparedUpdateSQL(DataObject oneObjectType, boolean updateChangedFieldsOnly)
          Helper function to build a prepared update statement for batch updates.
protected  void buildStoreProcedureCallableStatement(DBObject criteria, CallableStatement myCallableStatement)
          Build and return a FastStringBuffer ring consisting of an SQL 'where' clause using the current field values as criteria for the search.
 void delete(DataObject valueObject)
          Takes a DataObject and deletes it from the underlying data source.
 void deleteAll(DataObject valueObject, boolean deleteChangedCache)
          Takes a DataObject and deletes it from the underlying data source.
 void deleteBatch(List valueObjectList)
          Deletes an entire batch of DataObjects
 void deleteBatch(List valueObjectList, boolean deleteWithSetFieldsOnly)
          Updates an entire batch of DataObjects
protected  String prepareForStorage(DataFieldMetaData oneField, DBObject theObj)
          Format the field for storage into a prepared statement.
protected  String prepareForStorage(DataFieldMetaData oneField, DBObject theObj, boolean dateFormatted)
          Format the field for storage into a prepared statement.
 boolean retrieve(DataObject valueObject)
          Retrieves the object with keys specified by the valueObject parameter.
 void runStoreProcedure(DataObject valueObject)
          Run a store procedure identify by the object with keys specified by the valueObject parameter.
 void update(DataObject valueObject, boolean updateChangedFieldsOnly)
          Takes a DataObject and updates it to the underlying data source
 void updateAll(DataObject valueObject, boolean updateChangedCache)
          Takes a DataObject and updates all to the underlying data source
 void updateBatch(List valueObjectList)
          Updates an entire batch of DataObjects
 void updateBatch(List valueObjectList, boolean updateChangedFieldsOnly)
          Updates an entire batch of DataObjects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LONGVARBINARY_TYPE

public static final transient String LONGVARBINARY_TYPE
See Also:
Constant Field Values

VARBINARY_TYPE

public static final transient String VARBINARY_TYPE
See Also:
Constant Field Values

LONGVARCHAR_TYPE

public static final transient String LONGVARCHAR_TYPE
See Also:
Constant Field Values

LONGBINARY_READ_DEFAULT_SIZE

public static int LONGBINARY_READ_DEFAULT_SIZE
Constructor Detail

JDBCExecutor

public JDBCExecutor()
Method Detail

add

public void add(DataObject valueObject)
         throws DataException,
                DuplicateKeyException
Takes a DataObject and adds it to the underlying data source

Specified by:
add in interface DataExecutorInterface
Parameters:
valueObject - the DataObject to add.
Throws:
DataException - upon error adding the object to the data source
DuplicateKeyException - if the object already existed in the data source.

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

delete

public void delete(DataObject valueObject)
            throws DataException
Takes a DataObject and deletes it from the underlying data source. Note: The current implementation only expects a DBObject and actually routes the call back to that object. Will be fixed in the future as the interface becomes more rich.

Specified by:
delete in interface DataExecutorInterface
Parameters:
valueObject - the DataObject to delete.
Throws:
DataException - upon error deleting the object to the data source

update

public void update(DataObject valueObject,
                   boolean updateChangedFieldsOnly)
            throws DataException
Takes a DataObject and updates it to the underlying data source

Specified by:
update in interface DataExecutorInterface
Parameters:
valueObject - the DataObject to update.
updateChangedFieldsOnly - if true only modified fields (isChanged = true) will be included in the update
Throws:
DataException - upon error updating the object to the data source

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

retrieve

public boolean retrieve(DataObject valueObject)
                 throws DataException
Retrieves the object with keys specified by the valueObject parameter. This has the same semantics as DBObject's retrieve method.

Specified by:
retrieve in interface DataExecutorInterface
Parameters:
valueObject - the DataObject who's keys are already set to retrieve
Returns:
true if the data object was successfully retrieved
Throws:
DataException - Modify by Yves Henri AMAIZO
Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

addBatch

public void addBatch(List valueObjectList)
              throws DataException,
                     DuplicateKeyException
Adds an entire batch of DataObjects to the underlying JDBC data source

Specified by:
addBatch in interface DataExecutorInterface
Parameters:
valueObjectList - A list of DataObjects to add to the underlying data source NOTE: you will get best performance if valueObjectList is all one dataobject underneath.

WARNING: I DON'T UNDERSTAND WHY LOOP VAR ISN'T USED BELOW, AND SUSPECT THIS METHOD ISN'T DOING ALL IT PURPORTS TO DO; SEE "todo" (Larry Hamel, 3/03)

Throws:
DataException - upon error communicating with the underlying data source
DuplicateKeyException - if one of the records was already in the data source

updateBatch

public void updateBatch(List valueObjectList)
                 throws DataException
Updates an entire batch of DataObjects

Specified by:
updateBatch in interface DataExecutorInterface
Parameters:
valueObjectList - A list of DataObjects to update to the underlying data source
Throws:
DataException - upon error updating the data source

buildPreparedUpdateSQL

protected String buildPreparedUpdateSQL(DataObject oneObjectType,
                                        boolean updateChangedFieldsOnly)
                                 throws DBException
Helper function to build a prepared update statement for batch updates.

Parameters:
oneObjectType - A single DataObject that is used to model the prepared statement. Only metadata about the DataObject is used.
updateChangedFieldsOnly - true if the changed fields should be the only ones sent through the SQL query.
Returns:
A FastStringBuffer containing the proper SQL to create a preparedStatement
Throws:
DBException - upon error

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

buildPreparedDeleteSQL

protected String buildPreparedDeleteSQL(DataObject oneObjectType,
                                        boolean deleteWithSetFieldsOnly)
                                 throws DBException
Helper function to build a prepared delete statement for batch deletes.

Parameters:
oneObjectType - A single DataObject that is used to model the prepared statement. Only metadata about the DataObject is used.
Returns:
A FastStringBuffer containing the proper SQL to create a preparedStatement
Throws:
DBException - upon error

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

buildPreparedAddSQL

protected String buildPreparedAddSQL(DataObject oneObjectType,
                                     boolean addChangedFieldsOnly)
                              throws DBException
Helper Function to build a prepared statement's SQL for an ADD statement.

Parameters:
oneObjectType - A single DataObject that is used to model the prepared statement. Only metadata about the DataObject is used.
addChangedFieldsOnly - flag to signify if only fields whose value has changed should be included in the add.
Returns:
a FastStringBuffer containing the build sql statement
Throws:
DBException - upon error

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

prepareForStorage

protected String prepareForStorage(DataFieldMetaData oneField,
                                   DBObject theObj)
                            throws DBException
Format the field for storage into a prepared statement. This is similar to the old DBObject.quoteIfNeeded() but it does not insert quotes around the values since the prepared statements will take care of special characters like that

Parameters:
oneField - The metadata of the field to retrieve
theObj - The DBObject that contains the data to store.
Returns:
java.lang.String for the appropriate data value.
Throws:
DBException

prepareForStorage

protected String prepareForStorage(DataFieldMetaData oneField,
                                   DBObject theObj,
                                   boolean dateFormatted)
                            throws DBException
Format the field for storage into a prepared statement. This is similar to the old DBObject.quoteIfNeeded() but it does not insert quotes around the values since the prepared statements will take care of special characters like that

Parameters:
oneField - The metadata of the field to retrieve
theObj - The DBObject that contains the data to store.
Returns:
java.lang.String for the appropriate data value.
Throws:
DBException

updateAll

public void updateAll(DataObject valueObject,
                      boolean updateChangedCache)
               throws DataException
Takes a DataObject and updates all to the underlying data source

Specified by:
updateAll in interface DataExecutorInterface
Parameters:
valueObject - the DataObject to update.
updateChangedCache - if true only modified fields (isChanged = true) will be included in the update
Throws:
DataException - upon error updating the object to the data source

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/18 02:03:27 $

deleteAll

public void deleteAll(DataObject valueObject,
                      boolean deleteChangedCache)
               throws DataException
Takes a DataObject and deletes it from the underlying data source. Note: The current implementation only expects a DBObject and actually routes the call back to that object. Will be fixed in the future as the interface becomes more rich.

Specified by:
deleteAll in interface DataExecutorInterface
Parameters:
valueObject - the DataObject to delete.
Throws:
DataException - upon error deleting the object to the data source

buildPreparedStoreProcedureSQL

protected String buildPreparedStoreProcedureSQL(DataObject oneObjectType)
                                         throws DBException
Helper Function to build a prepared statement's SQL for running STore Procedure statement.

Parameters:
oneObjectType - A single DataObject that is used to model the prepared statement. Only metadata about the DataObject is used.
Returns:
a FastStringBuffer containing the build sql statement
Throws:
DBException - upon error

buildStoreProcedureCallableStatement

protected void buildStoreProcedureCallableStatement(DBObject criteria,
                                                    CallableStatement myCallableStatement)
                                             throws DataException
Build and return a FastStringBuffer ring consisting of an SQL 'where' clause using the current field values as criteria for the search. See setCustomWhereClause for information on specifying a more complex where clause.

Parameters:
criteria - the JDBCDataObject to build from
myCallableStatement - the statement
Returns:
A FastStringBuffer containing the "where" clause for the SQL statement
Throws:
DataException - upon error

runStoreProcedure

public void runStoreProcedure(DataObject valueObject)
                       throws DataException
Run a store procedure identify by the object with keys specified by the valueObject parameter.

Specified by:
runStoreProcedure in interface DataExecutorInterface
Parameters:
valueObject - the DataObject who's keys are already set to retrieve
Returns:
true if the data object was successfully retrieved
Throws:
DataException - upon error retriving the object from the data source

addBatch

public void addBatch(List valueObjectList,
                     boolean addChangedFieldsOnly)
              throws DataException,
                     DuplicateKeyException
Adds an entire batch of DataObjects to the underlying JDBC data source

Parameters:
valueObjectList - A list of DataObjects to add to the underlying data source NOTE: you will get best performance if valueObjectList is all one dataobject underneath.
addChangedFieldsOnly - flag to signify if only fields whose value has changed should be included in the add.

WARNING: I DON'T UNDERSTAND WHY LOOP VAR ISN'T USED BELOW, AND SUSPECT THIS METHOD ISN'T DOING ALL IT PURPORTS TO DO; SEE "todo" (Larry Hamel, 3/03)

Throws:
DataException - upon error communicating with the underlying data source
DuplicateKeyException - if one of the records was already in the data source

updateBatch

public void updateBatch(List valueObjectList,
                        boolean updateChangedFieldsOnly)
                 throws DataException
Updates an entire batch of DataObjects

Specified by:
updateBatch in interface DataExecutorInterface
Parameters:
valueObjectList - A list of DataObjects to update to the underlying data source
updateChangedFieldsOnly - flag to signify if only fields whose value has changed should be included in the update.
Throws:
DataException - upon error updating the data source

deleteBatch

public void deleteBatch(List valueObjectList,
                        boolean deleteWithSetFieldsOnly)
                 throws DataException
Updates an entire batch of DataObjects

Specified by:
deleteBatch in interface DataExecutorInterface
Parameters:
valueObjectList - A list of DataObjects to update to the underlying data source
deleteWithSetFieldsOnly - Only include changed fields in the update
Throws:
DataException - upon error updating the data source

deleteBatch

public void deleteBatch(List valueObjectList)
                 throws DataException
Deletes an entire batch of DataObjects

Specified by:
deleteBatch in interface DataExecutorInterface
Parameters:
valueObjectList - A list of DataObjects to delete to the underlying data source
Throws:
DataException - upon error deleting the data source

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.