Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jcorporate.expresso.core.dataobjects.jdbc
Class JDBCDataObject  view JDBCDataObject download JDBCDataObject.java

java.lang.Object
  extended bycom.jcorporate.expresso.core.dataobjects.BaseDataObject
      extended bycom.jcorporate.expresso.core.dataobjects.jdbc.JDBCDataObject
All Implemented Interfaces:
com.jcorporate.expresso.core.cache.Cacheable, com.jcorporate.expresso.core.dataobjects.ContextNested, com.jcorporate.expresso.core.dataobjects.DataObject, java.io.Serializable

public abstract class JDBCDataObject
extends com.jcorporate.expresso.core.dataobjects.BaseDataObject

Base class for JDBC-based data objects.

Since:
Expresso 5.1

Modify by Yves Henri AMAIZO


Field Summary
 boolean anyFieldsDistinct
          If setFieldDistinct has been used to specify distinct/unique fields for the next query.
protected  boolean anyFieldsToRetrieve
          If setFieldsToRetrieve has been used to specify fields which will be retrieve by the next query.
protected  boolean appendCustomWhere
          Flag to indicate whether we append any custom WHERE clause to the one generated, or just use the supplied custom WHERE clause
protected  boolean caseSensitiveQuery
          This flag tells the buildWhereClause method(s) to either be case sensitive (normal queries) or to be case insensitive.
protected  java.lang.String customWhereClause
          If we are using a custom where clause for this query, it's stored here.
protected  java.lang.String dbKey
          dbKey is used to indicate that this object is actually stored in other than the default database.
protected  java.util.HashMap distinctFields
          Map of any distinct fields for retrieval.
protected  com.jcorporate.expresso.core.db.DBConnection localConnection
          Local connection that we use if it's initialized, but if it's null we generate our own connection
private static org.apache.log4j.Logger log
           
static int LONGBINARY_READ_DEFAULT_SIZE
           
private  java.lang.String mappedDataContext
          Normally originalDBKey is the same as DB key, except where the DB object is mapped to another database specifically, in which case originalDBKey can be used to determine the database to be used to find Expresso's own tables
protected  int maxRecords
           
protected  java.lang.String myClassName
          We use getClass().getName() a lot in this class, however, it takes actually significant time to use this over the time it takes to do, say, a concurrentReaderHashMap lookup.
private  com.jcorporate.expresso.core.db.DBConnectionPool myPool
          a local connection pool.
protected  java.util.ArrayList myUpdates
          Holds the FieldUpdate objects representing any changes made to this object since it was retrieved
protected  int offsetRecord
          The number of records we must skip over before we start reading the ResultSet proper in a searchAndRetrieve.
protected  java.util.ArrayList recordSet
          The ArrayList of DB objects retrieved by the last searchAndRetrieve method
 java.util.HashMap retrieveFields
          The actual fields retrieved
private static com.jcorporate.expresso.core.dataobjects.DataExecutorInterface sDataExecutor
          Helper component that provides the specific interactions between the DBObject and the underlying datasource, JDBC or later on, otherwise
private static com.jcorporate.expresso.core.dataobjects.DataQueryInterface sDataQueryObject
          Helper component that provides the specific querying capabilities against any particular datasrouce, JDBC, or later on, others.
private static JDBCUtil sJdbcUtil
          Utility class that currently provides help for getFieldDate() function.
protected static ConcurrentReaderHashMap sMetadataMap
          DBObjects themselves do not contain the "meta data" or the definition of what fields they contain and other information.
protected  java.util.ArrayList sortKeys
          The list of fields by which this object should be sorted when records are retrieved
 
Fields inherited from class com.jcorporate.expresso.core.dataobjects.BaseDataObject
currentStatus, globalMask
 
Fields inherited from interface com.jcorporate.expresso.core.dataobjects.DataObject
STATUS_CURRENT, STATUS_DELETED, STATUS_NEW, STATUS_UPDATED
 
Constructor Summary
JDBCDataObject()
          Default constructor
 
Method Summary
protected  void addInParam(java.lang.String inFieldName)
          Add a new field to the list of fields that are part of this object's list of input parameters.
protected  void addOutParam(java.lang.String outFieldName)
          Add a new field to the list of fields that are part of this object's list of output parameter.
 java.lang.String buildWhereClause(boolean useAllFields)
          Build and return a string consisting of an SQL 'where' clause using the current field values as criteria for the search.
protected  com.jcorporate.expresso.kernel.util.FastStringBuffer buildWhereClauseBuffer(boolean useAllFields, com.jcorporate.expresso.kernel.util.FastStringBuffer allocatedBuffer)
          Build and return a FastStringBuffer ring consisting of an SQL 'where' clause using the current field values as criteria for the search.
 boolean checkZeroUpdate()
          Returns the checkzero update as defined by the object's metadata.
protected  com.jcorporate.expresso.core.dbobj.DBObjectDef constructNewMetaData()
          Construction method to allow for specialized metadata with specialized fields other than DBObjectDef.
 com.jcorporate.expresso.core.db.DBConnection createAndExecuteSearch(java.util.ArrayList retrievedFieldList)
          Refactoring to split the execution of a query statement into the query part and the load part.
 com.jcorporate.expresso.core.db.DBConnection createAndRunStoreProcedure(java.util.ArrayList retrievedFieldList)
          Refactoring to split the execution of a query statement into the query part and the load part.
 com.jcorporate.expresso.core.db.DBConnectionPool getConnectionPool()
          Retrieve the connection pool associated with this DBObject.
 java.lang.String getCustomStringFieldValue(com.jcorporate.expresso.core.db.DBConnection connection, java.lang.String oneFieldName)
          This convenience method retrieve through the resultSet.MetaData the date value of field define as date or time DBObject
protected  com.jcorporate.expresso.core.dbobj.DBObjectDef getDef()
          Return the DBObjectRef object that contains the definition of the current DBObject.
 java.util.ArrayList getDistinctFieldArrayList()
          Get a special ArrayList object list of all of the fields in this object that are set to distinct
 com.jcorporate.expresso.core.dataobjects.DataExecutorInterface getExecutor()
          Use this function to acquire the Executor interface that is associated with this data object
 java.util.Iterator getFieldsToRetrieveIterator()
          Get a special Iterator object list of all of the fields in this object that are set to retrieve
 JDBCObjectMetaData getJDBCMetaData()
          Retrieve the JDBCObjectMetaData
protected  JDBCUtil getJDBCUtil()
          Get the JDBC Util functions
 com.jcorporate.expresso.core.db.DBConnection getLocalConnection()
          Return local DBConnection value

author Yves Henri AMAIZO <amy_amaizo@compuserve.com>

 java.lang.String getMappedDataContext()
          Returns the name of the physical database that we're talking with.
 com.jcorporate.expresso.core.dataobjects.DataObjectMetaData getMetaData()
          Retrieve the database object's metadata
 com.jcorporate.expresso.core.dataobjects.DataQueryInterface getQueryInterface()
          Use this function to acquire the DataQueryInterface that is associated with this data object
 java.lang.String getSerialForm(com.jcorporate.expresso.core.dataobjects.DataFieldMetaData theField)
          This function is called whenever the DBField is about to be written to the database.
 void loadFromConnection(JDBCDataObject myObj, com.jcorporate.expresso.core.db.DBConnection myConnection, java.util.ArrayList retrievedFieldList)
          Fills the given constructed data object with data from the connection given the field order specified in retrievedFieldList.
protected  java.lang.String makeLimitationStub(com.jcorporate.expresso.core.db.DBConnection theConnection)
          Creates the limitation syntax optimisation stub to embed inside the SQL command that performs search and retrieve.
 java.lang.String quoteIfNeeded(java.lang.String fieldName, java.lang.String rangeString)
          Return the value of this field, placing double quotes around it if the field's datatype requires it.
 void runStoredProcedure()
          Run a particular store procedure in the database into this object's fields
protected  java.util.ArrayList runStoredProcedureAndRetrieveList()
          Run a particular store procedure in the database into this object's fields
 java.lang.String selectFieldString(java.lang.String fieldName)
          Build an appropriate String for use in the select part of an SQL statement by doing the
 void setCaseSensitiveQuery(boolean caseSensitiveQuery)
          This tells the buildWhereClause to either respect case (true) or ignore case (false).
 void setConnection(com.jcorporate.expresso.core.db.DBConnection newConnection)
          Set a specific DB connection for use with this db object.
 void setConnection(com.jcorporate.expresso.core.db.DBConnection newConnection, java.lang.String setupTablesContext)
          

Set a specific DB connection for use with this db object.

protected  void setDBConnectionPool(com.jcorporate.expresso.core.db.DBConnectionPool newPool)
          Sets the connection pool associated with this dbobject.
 void setDBName(java.lang.String newOther)
          Set the database name/context for this db object.
protected  void setMappedDataContext(java.lang.String newMappedName)
           
protected  void setOriginalDBName(java.lang.String newOriginalName)
          Set the name of the db context that was the "original" context for this object - e.g.
 void setTargetStoreProcedure(java.lang.String theStoreProcedure)
          Set the target store procedure for this DBObject.
 
Methods inherited from class com.jcorporate.expresso.core.dataobjects.BaseDataObject
getGlobalMask, getStatus, isGlobalMasked, setFieldsWithDefaults, setGlobalMask, setStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jcorporate.expresso.core.dataobjects.DataObject
add, checkField, clear, count, delete, equals, find, get, getAllAttributes, getAttribute, getDataField, getField, getFieldMetaData, getLocale, getMaxRecords, getOffsetRecord, getValidValuesList, searchAndRetrieveList, searchAndRetrieveList, set, setAttribute, setLocale, setMaxRecords, setOffsetRecord, update
 
Methods inherited from interface com.jcorporate.expresso.core.cache.Cacheable
getKey
 
Methods inherited from interface com.jcorporate.expresso.core.dataobjects.ContextNested
getDataContext, setDataContext
 

Field Detail

log

private static final transient org.apache.log4j.Logger log

LONGBINARY_READ_DEFAULT_SIZE

public static int LONGBINARY_READ_DEFAULT_SIZE

myPool

private transient com.jcorporate.expresso.core.db.DBConnectionPool myPool
a local connection pool. Often used to save on going back and forth to the connection pool, or if you want JDBC transactions.


mappedDataContext

private java.lang.String mappedDataContext
Normally originalDBKey is the same as DB key, except where the DB object is mapped to another database specifically, in which case originalDBKey can be used to determine the database to be used to find Expresso's own tables


customWhereClause

protected java.lang.String customWhereClause
If we are using a custom where clause for this query, it's stored here. If null, then build the where clause


appendCustomWhere

protected boolean appendCustomWhere
Flag to indicate whether we append any custom WHERE clause to the one generated, or just use the supplied custom WHERE clause


dbKey

protected java.lang.String dbKey
dbKey is used to indicate that this object is actually stored in other than the default database. Null indicates it's in the default database


recordSet

protected java.util.ArrayList recordSet
The ArrayList of DB objects retrieved by the last searchAndRetrieve method


myClassName

protected transient java.lang.String myClassName
We use getClass().getName() a lot in this class, however, it takes actually significant time to use this over the time it takes to do, say, a concurrentReaderHashMap lookup. So we precalculate this value at instantiation and go from there.


distinctFields

protected java.util.HashMap distinctFields
Map of any distinct fields for retrieval.


retrieveFields

public java.util.HashMap retrieveFields
The actual fields retrieved


sMetadataMap

protected static transient volatile ConcurrentReaderHashMap sMetadataMap
DBObjects themselves do not contain the "meta data" or the definition of what fields they contain and other information. Instead, a DBObjectRef object (one per TYPE of DBObject) contains this info and is looked up as needed. This HashMap contains the DBObjectRef objects for all initialized DBObjects


anyFieldsToRetrieve

protected boolean anyFieldsToRetrieve
If setFieldsToRetrieve has been used to specify fields which will be retrieve by the next query.


localConnection

protected transient com.jcorporate.expresso.core.db.DBConnection localConnection
Local connection that we use if it's initialized, but if it's null we generate our own connection


offsetRecord

protected transient int offsetRecord
The number of records we must skip over before we start reading the ResultSet proper in a searchAndRetrieve. 0 means no limit author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001


maxRecords

protected transient int maxRecords

sortKeys

protected transient java.util.ArrayList sortKeys
The list of fields by which this object should be sorted when records are retrieved


myUpdates

protected transient java.util.ArrayList myUpdates
Holds the FieldUpdate objects representing any changes made to this object since it was retrieved


anyFieldsDistinct

public boolean anyFieldsDistinct
If setFieldDistinct has been used to specify distinct/unique fields for the next query.


caseSensitiveQuery

protected boolean caseSensitiveQuery
This flag tells the buildWhereClause method(s) to either be case sensitive (normal queries) or to be case insensitive. The case insensitive query is useful when you want to do a search and retreive and want case insensitive matching.


sJdbcUtil

private static transient JDBCUtil sJdbcUtil
Utility class that currently provides help for getFieldDate() function.


sDataExecutor

private static transient com.jcorporate.expresso.core.dataobjects.DataExecutorInterface sDataExecutor
Helper component that provides the specific interactions between the DBObject and the underlying datasource, JDBC or later on, otherwise

Since:
Expresso 5.0

sDataQueryObject

private static transient com.jcorporate.expresso.core.dataobjects.DataQueryInterface sDataQueryObject
Helper component that provides the specific querying capabilities against any particular datasrouce, JDBC, or later on, others.

Since:
Expresso 5.0
Constructor Detail

JDBCDataObject

public JDBCDataObject()
Default constructor

Method Detail

getMappedDataContext

public java.lang.String getMappedDataContext()
Returns the name of the physical database that we're talking with. This is opposed to getDataContext() which returns the security context as well. getMappedDataContext() is strictly used to get at the low level database connection.


getConnectionPool

public com.jcorporate.expresso.core.db.DBConnectionPool getConnectionPool()
                                                                   throws com.jcorporate.expresso.core.dataobjects.DataException
Retrieve the connection pool associated with this DBObject.


setDBConnectionPool

protected void setDBConnectionPool(com.jcorporate.expresso.core.db.DBConnectionPool newPool)
Sets the connection pool associated with this dbobject. Is only settable from derived classes as we normally create our own as needed.


getSerialForm

public java.lang.String getSerialForm(com.jcorporate.expresso.core.dataobjects.DataFieldMetaData theField)
                               throws com.jcorporate.expresso.core.dataobjects.DataException
This function is called whenever the DBField is about to be written to the database. It may do additional processing such as encryption depending on the field attributes.


setDBName

public void setDBName(java.lang.String newOther)
               throws com.jcorporate.expresso.core.db.DBException
Set the database name/context for this db object. If setDBName is not called, the "default" db name and context is used. See com.jcorporate.expresso.core.misc.ConfigManager for information about multiple contexts. Note that setting a db/context name only affects the object when it allocates it's own db connections - if a specific connection is used (via the setConnection(DBConnection) method) then that connection must be already associated with the correct db/context. If there is an entry in the DBOtherMap table for this object, it is forced to that database, and a warning is logged if any other database is specified.


getMetaData

public final com.jcorporate.expresso.core.dataobjects.DataObjectMetaData getMetaData()
Retrieve the database object's metadata


getJDBCMetaData

public final JDBCObjectMetaData getJDBCMetaData()
Retrieve the JDBCObjectMetaData


getDef

protected final com.jcorporate.expresso.core.dbobj.DBObjectDef getDef()
Return the DBObjectRef object that contains the definition of the current DBObject. If there isn't one in the dbobjMetadata hashmap, initialize a new one as required


constructNewMetaData

protected com.jcorporate.expresso.core.dbobj.DBObjectDef constructNewMetaData()
                                                                       throws com.jcorporate.expresso.core.db.DBException
Construction method to allow for specialized metadata with specialized fields other than DBObjectDef. Override in classes that need custom derived from DBObjectDef classes.


checkZeroUpdate

public boolean checkZeroUpdate()
Returns the checkzero update as defined by the object's metadata.


setOriginalDBName

protected void setOriginalDBName(java.lang.String newOriginalName)
Set the name of the db context that was the "original" context for this object - e.g. before any database mapping took place.


setMappedDataContext

protected void setMappedDataContext(java.lang.String newMappedName)

setCaseSensitiveQuery

public void setCaseSensitiveQuery(boolean caseSensitiveQuery)
This tells the buildWhereClause to either respect case (true) or ignore case (false). You can call this method before doing a search and retrieve if you want to match without worrying about case. For example if you were to call this method with isCaseSensitiveQuery = FALSE then this comparison would match in the search:

vendor_name actual value = "My Name"

query value = "my name"

This would match in a search and retrieve.

author Adam Rossi, PlatinumSolutions


selectFieldString

public java.lang.String selectFieldString(java.lang.String fieldName)
                                   throws com.jcorporate.expresso.core.db.DBException
Build an appropriate String for use in the select part of an SQL statement by doing the


quoteIfNeeded

public java.lang.String quoteIfNeeded(java.lang.String fieldName,
                                      java.lang.String rangeString)
                               throws com.jcorporate.expresso.core.db.DBException
Return the value of this field, placing double quotes around it if the field's datatype requires it.


setConnection

public void setConnection(com.jcorporate.expresso.core.db.DBConnection newConnection)
                   throws com.jcorporate.expresso.core.db.DBException
Set a specific DB connection for use with this db object. If you do not set a connection, the db object will request it's own connection from the appropriate connection pool & release it again after every operation (e.g. add, update, etc). It is important to use your own explicit connection when dealing with a database transactional environment (e.g. commit(), rollback()).


setConnection

public void setConnection(com.jcorporate.expresso.core.db.DBConnection newConnection,
                          java.lang.String setupTablesContext)
                   throws com.jcorporate.expresso.core.db.DBException

Set a specific DB connection for use with this db object. If you do not set a connection, the db object will request it's own connection from the appropriate connection pool & release it again after every operation (e.g. add, update, etc). It is important to use your own explicit connection when dealing with a database transactional environment (e.g. commit(), rollback()).

The difference between this and setConnection(DBConnection) is that this is used for using otherDB capabilities within a transaction. So you use a dbconnection from your other pool, but the setup tables are in a different context


createAndExecuteSearch

public com.jcorporate.expresso.core.db.DBConnection createAndExecuteSearch(java.util.ArrayList retrievedFieldList)
                                                                    throws com.jcorporate.expresso.core.db.DBException
Refactoring to split the execution of a query statement into the query part and the load part. The DBConnection returned will have the query already executed.

SIDE-EFFECT: custom 'where' clause is set to null.

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

loadFromConnection

public void loadFromConnection(JDBCDataObject myObj,
                               com.jcorporate.expresso.core.db.DBConnection myConnection,
                               java.util.ArrayList retrievedFieldList)
                        throws com.jcorporate.expresso.core.db.DBException
Fills the given constructed data object with data from the connection given the field order specified in retrievedFieldList. Similar to loadFromConnection but much faster because the connection fields are retrieved via number instead of name.


makeLimitationStub

protected java.lang.String makeLimitationStub(com.jcorporate.expresso.core.db.DBConnection theConnection)
Creates the limitation syntax optimisation stub to embed inside the SQL command that performs search and retrieve.

This method takes the limitation syntax string and performs a string replacement on the following tokens

  • %offset%

  • the number of rows in the ResultSet to skip before reading the data.

  • %maxrecord%

  • the maximum number of rows to read from the ResultSet. Also known as the rowlength.

  • %endrecord%

  • the last record of in the ResultSet that the search and retrieved should retrieve. The end record number is equal to ( %offset% + %maxrecord% - 1 )

author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001


getDistinctFieldArrayList

public java.util.ArrayList getDistinctFieldArrayList()
                                              throws com.jcorporate.expresso.core.db.DBException
Get a special ArrayList object list of all of the fields in this object that are set to distinct


getFieldsToRetrieveIterator

public java.util.Iterator getFieldsToRetrieveIterator()
                                               throws com.jcorporate.expresso.core.db.DBException
Get a special Iterator object list of all of the fields in this object that are set to retrieve

Author Yves henri Amaizo


buildWhereClause

public java.lang.String buildWhereClause(boolean useAllFields)
                                  throws com.jcorporate.expresso.core.db.DBException
Build and return a string 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.


buildWhereClauseBuffer

protected com.jcorporate.expresso.kernel.util.FastStringBuffer buildWhereClauseBuffer(boolean useAllFields,
                                                                                      com.jcorporate.expresso.kernel.util.FastStringBuffer allocatedBuffer)
                                                                               throws com.jcorporate.expresso.core.db.DBException
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.


getJDBCUtil

protected JDBCUtil getJDBCUtil()
Get the JDBC Util functions


getExecutor

public com.jcorporate.expresso.core.dataobjects.DataExecutorInterface getExecutor()
Use this function to acquire the Executor interface that is associated with this data object


getQueryInterface

public com.jcorporate.expresso.core.dataobjects.DataQueryInterface getQueryInterface()
Use this function to acquire the DataQueryInterface that is associated with this data object


getCustomStringFieldValue

public java.lang.String getCustomStringFieldValue(com.jcorporate.expresso.core.db.DBConnection connection,
                                                  java.lang.String oneFieldName)
                                           throws com.jcorporate.expresso.core.db.DBException

This convenience method retrieve through the resultSet.MetaData the date value of field define as date or time DBObject


getLocalConnection

public com.jcorporate.expresso.core.db.DBConnection getLocalConnection()

Return local DBConnection value

author Yves Henri AMAIZO <amy_amaizo@compuserve.com>


createAndRunStoreProcedure

public com.jcorporate.expresso.core.db.DBConnection createAndRunStoreProcedure(java.util.ArrayList retrievedFieldList)
                                                                        throws com.jcorporate.expresso.core.db.DBException
Refactoring to split the execution of a query statement into the query part and the load part. The DBConnection returned will have the query already executed, it is ready to


addInParam

protected void addInParam(java.lang.String inFieldName)
                   throws com.jcorporate.expresso.core.db.DBException
Add a new field to the list of fields that are part of this object's list of input parameters. Called after all of the "addField" calls in the setupFields() method to specify which fields make up the primary key of this object.


addOutParam

protected void addOutParam(java.lang.String outFieldName)
                    throws com.jcorporate.expresso.core.db.DBException
Add a new field to the list of fields that are part of this object's list of output parameter. Called after all of the "addField" calls in the setupFields() method to specify which fields make up the primary key of this object.


setTargetStoreProcedure

public void setTargetStoreProcedure(java.lang.String theStoreProcedure)
                             throws com.jcorporate.expresso.core.db.DBException
Set the target store procedure for this DBObject.


runStoredProcedure

public void runStoredProcedure()
                        throws com.jcorporate.expresso.core.db.DBException
Run a particular store procedure in the database into this object's fields


runStoredProcedureAndRetrieveList

protected java.util.ArrayList runStoredProcedureAndRetrieveList()
                                                         throws com.jcorporate.expresso.core.db.DBException
Run a particular store procedure in the database into this object's fields