Expresso 5-5-0

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
Version:
$Revision: 1.48 $ on $Date: 2004/02/18 05:41:03 $
Author:
Michael Rimov

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
protected  String buildPreparedAddSQL(DataObject oneObjectType)
          Helper Function to build a prepared statement's SQL for an ADD statement.
protected  String buildPreparedUpdateSQL(DataObject oneObjectType)
          Helper function to build a prepared update statement for batch updates.
 void delete(DataObject valueObject)
          Takes a DataObject and deletes it from the underlying data source.
protected  String prepareForStorage(DataFieldMetaData oneField, DBObject theObj)
          Format the field for storage into a prepared statement.
 boolean retrieve(DataObject valueObject)
          Retrieves 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 updateBatch(List valueObjectList)
          Updates an entire batch of DataObjects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

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

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

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)
                                 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.
Returns:
A FastStringBuffer containing the proper SQL to create a preparedStatement
Throws:
DBException - upon error

buildPreparedAddSQL

protected String buildPreparedAddSQL(DataObject oneObjectType)
                              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.
Returns:
a FastStringBuffer containing the build sql statement
Throws:
DBException - upon error

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

Expresso 5-5-0

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