|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.persist.AbstractBroker | +--com.objectwave.persist.broker.RDBBroker
An implementation of the Broker interface. This implementation is very
specific to Relational Database Solutions. Any instances of this class
should be obtained from the static getDefaultBroker() method. Special system
properties:
ow.persistVerbose
ow.persistMetrics
ow.persistUser
ow.persistPassword
ow.persistDriver
ow.persistConnections
ow.connectUrl
ow.databaseImpl
ow.persistPrepared 'false'
ow.userConnectionPool 'true'
Could use connection per thread ow.exceptionSupportClass A fully qualified
class name of a implementation of SQLConvertExceptionIF. The default
primaryKeySupport assumes a table called SEQUENCE with a column called
nextVal. This approach is prone to race conditions and should be overriden
by specific broker instances. The following two SQL statements must be run
to generate primary keys.
CREATE TABLE sequence(nextval INTEGER PRIMARY KEY)
INSERT INTO sequence(nextval) VALUES (1000)
Broker
,
BrokerFactory
Nested Class Summary | |
static class |
RDBBroker.Test
|
Field Summary | |
protected static RDBBroker |
broker
|
protected BrokerPropertySource |
brokerPropertySource
|
protected boolean |
connectionPerThread
|
protected RDBConnectionPool |
connectionPool
|
protected ObjectPool |
pool
|
protected ProcessResultSet |
resultEngine
|
protected SaveObjectsStrategy |
saveObjectsStrategy
|
protected SqlModifierBuilder |
sqlModifyEngine
|
protected SqlQueryBuilder |
sqlQueryEngine
|
protected StatementFactory |
statementFactory
|
protected java.lang.ThreadLocal |
threadLocal
Used only for connection per thread support. |
Fields inherited from class com.objectwave.persist.AbstractBroker |
exceptionConverter, metrics, props, verbose |
Constructor Summary | |
RDBBroker()
|
Method Summary | |
void |
beginTransaction()
If the database supports transactions this method would begin the transaction. |
protected Persistence |
checkObjectPool(SQLQuery query)
Checks the object pool for a search done by primary key. |
protected void |
cleanupSelect(SQLSelect sqlObj,
GrinderResultSet resultSet)
Return the sqlObject to the statementFactory. |
void |
close()
A 'closed' RDBBroker will flush it's object pool cache and close all open connections. |
void |
commit()
Issues a database Commit. |
void |
constrainWhereClause(SQLSelect sqlObj,
Persistence subject,
Persistence p)
Limit the query to only those instances that exist as foreign keys in the parameter p. |
int |
count(SQLQuery obj)
This is the entry point for the find. |
SQLSelect |
createAttributeSelect(SQLQuery q,
java.lang.String[] atts,
SQLSelect tempSelect)
Create the SQLSelect statement for the findAttributes(SQLQuery,String[]) method. |
protected void |
customizeDetail(BrokerPropertySource propertySource,
boolean override)
Allows subclasses to setup any values they deem necessary prior to any values being fetched from the source. |
RDBBroker |
defaultBroker()
This method enables different default brokers. |
protected void |
defineSelectList(Persistence p,
java.lang.String[] paths,
SQLSelect sqlObj)
Modify the sqlObj parameter to contain only those columns specified by the 'paths' parameter. |
void |
delete(Persistence obj)
Remove the specified object from the database. |
void |
deleteAll(SQLQuery obj)
Delete all objects matching the passed search criteria. |
void |
deleteObjects(java.util.ArrayList objs)
Delete all of the objects in the objs collection. |
protected void |
deleteObjects(java.util.ArrayList objs,
int laterListSize)
We may have several objects to delete. |
protected void |
determinePrimaryKey(RDBPersistence pObj)
Sometimes we can not determine the primary key until after the insert has been completed ( MS-Access ). |
void |
dumpSQLException(java.sql.SQLException ex)
A SQLException was generated. |
java.lang.Object |
find(SQLQuery q)
Find all objects matching the passed search criteria. |
java.util.Vector |
findAttributes(SQLQuery q,
java.lang.String[] atts)
Used to optimize large queries. |
Pair[] |
findColumnSqlTypes(SQLQuery query)
Determine the sql types of each column that will be a part of the query. |
protected CollectionAdapter |
findResults(SQLQuery obj)
This is the entry point for the find. |
Persistence |
findUnique(SQLQuery q)
Find the one, and only one, object matching the search criteria. |
void |
finishBuildingQuery(SQLQuery query,
SQLSelect sqlObj)
|
protected void |
generateInsertValues(RDBPersistence pObj)
The default behavior is to generate insert values (the primary key ) prior to actually doing the insert. |
BrokerPropertySource |
getBrokerPropertySource()
Does not matter if not synchronized, the source object is stateless. |
RDBConnection |
getConnection()
Using this method could be VERY dangerous. |
static RDBBroker |
getDefaultBroker()
Most systems will have only one database broker. |
protected java.lang.String |
getDefaultDriverName()
For this broker, the ODBC driver is the default. |
protected PrimaryKeyStrategy |
getDefaultPrimaryKeyStrategy()
Default the primary key strategy to the SelectAndUpdate approach. |
ObjectPool |
getObjectPool()
Object pool are an in memory cache of database objects. |
RDBPersistence |
getRDBAdapter(Persistence object)
A utility method that simplifies code. |
void |
initConfiguration()
To determine the values of userName, password, and connectUrl the configuration will first use what the attribute values contain. |
void |
initialize()
Normally you would use the 'getDefaultBroker' method. |
protected void |
initializeConnections()
Look in the BrokerPropertyIF for a property indicating the number of connections to create. |
protected void |
initializeConnections(int connectionCount)
Create the RDBConnections to the database. |
protected void |
initializeObjectPooling(ObjectPool aPool)
We are turning on object pooling. |
void |
insert(RDBPersistence pObj,
Persistence obj)
Builds and executes an insert statement. |
static void |
main(java.lang.String[] args)
Test method. |
protected RDBConnection |
newRDBConnection(RDBConnectionPool connectionPool,
java.lang.String connectUrl,
java.lang.String userName,
java.lang.String userPassword)
Create an RDBConnection instance using the specified configuration. |
protected java.lang.Object |
nextPrimaryKey(RDBPersistence pObj)
Do a query to determine the next primary key. |
protected void |
removeObjectPooling()
Remove ObjectPoolBrokers from each connection and clear the result engine object pool instance. |
void |
rollback()
Issues a database rollback. |
void |
save(Persistence obj)
If the object is new we will insert it. |
void |
saveObjects(java.util.ArrayList objs)
Save all of the objects in the objs collection. |
void |
setBrokerPropertySource(BrokerPropertySource source)
Plug in your own broker property source. |
void |
setDriver(java.sql.Driver driver)
When creating a connection use the specified driver. |
void |
setObjectPool(ObjectPool val)
Provide the ObjectPool that is to be used for Object Pooling. |
void |
setUsingObjectPool(boolean value)
As currently implmented it will preserve the object pool. |
void |
update(RDBPersistence pObj,
Persistence obj)
Builds and executes an update statement. |
void |
update(SQLInsert sql,
RDBPersistence obj)
Allow database specific changes to a sqlInsert. |
Methods inherited from class com.objectwave.persist.AbstractBroker |
convertException, convertException, getExceptionConverter, println, setBrokerProperty, setExceptionConverter |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static RDBBroker broker
protected ProcessResultSet resultEngine
protected SqlQueryBuilder sqlQueryEngine
protected SqlModifierBuilder sqlModifyEngine
protected StatementFactory statementFactory
protected SaveObjectsStrategy saveObjectsStrategy
protected RDBConnectionPool connectionPool
protected ObjectPool pool
protected boolean connectionPerThread
protected java.lang.ThreadLocal threadLocal
protected BrokerPropertySource brokerPropertySource
Constructor Detail |
public RDBBroker()
Method Detail |
public static RDBBroker getDefaultBroker()
public static void main(java.lang.String[] args)
args
- java.lang.String[]public void setDriver(java.sql.Driver driver) throws java.sql.SQLException
driver
- The new Driver value
java.sql.SQLException
#connect
public void setObjectPool(ObjectPool val)
val
- The ObjectPool to use.setUsingObjectPool(boolean)
public void setUsingObjectPool(boolean value)
value
- true if this broker is to use an object pool.public void setBrokerPropertySource(BrokerPropertySource source)
source
- The new BrokerPropertySource valuepublic RDBConnection getConnection()
public ObjectPool getObjectPool()
setObjectPool(ObjectPool)
public final RDBPersistence getRDBAdapter(Persistence object)
object
-
public BrokerPropertySource getBrokerPropertySource()
protected java.lang.String getDefaultDriverName()
protected PrimaryKeyStrategy getDefaultPrimaryKeyStrategy()
protected void customizeDetail(BrokerPropertySource propertySource, boolean override)
propertySource
- The source that will be our 'source' of configuration informationoverride
- Change the values in the propertySource with information from the command linepublic void beginTransaction() throws QueryException
QueryException
public void commit() throws QueryException
QueryException
public int count(SQLQuery obj) throws QueryException
count
in interface Broker
count
in class AbstractBroker
obj
- The query object detailing the objects being counted and the
constraints of the query.
QueryException
public RDBBroker defaultBroker()
BrokerFactory
public void delete(Persistence obj) throws QueryException
obj
- The object to delete.
QueryException
public void deleteObjects(java.util.ArrayList objs) throws QueryException
deleteObjects
in interface Broker
deleteObjects
in class AbstractBroker
objs
- ArrayList of Persistence objects
QueryException
public void dumpSQLException(java.sql.SQLException ex)
ex
- The SQLException to displaypublic java.lang.Object find(SQLQuery q) throws QueryException
q
- The query object detailing the object that will be found and the
constraints of the query.
QueryException
public SQLSelect createAttributeSelect(SQLQuery q, java.lang.String[] atts, SQLSelect tempSelect) throws QueryException
q
- - the query objectatts
- Array of string denoting path to object attribute. Each entry
will correspond to a mapped instance variable. Compound objects can be
represeneted by periods in the path. "employee.company.firstName" or
"someValue";tempSelect
- - a temporary SQLSelect instance that can be provided to
this method to use in building the select statement. Used to minimize
object creation. Can be null.
QueryException
findAttributes(SQLQuery, String[])
,
com.objectwave.persist.constratins.ConstraintSubselect
public void finishBuildingQuery(SQLQuery query, SQLSelect sqlObj)
query
- sqlObj
- public java.util.Vector findAttributes(SQLQuery q, java.lang.String[] atts) throws QueryException
atts
- Array of string denoting path to object attribute. Each entry
will correspond to a mapped instance variable. Compound objects can be
represeneted by periods in the path. "employee.company.firstName" or
"someValue";q
- SQLQuery The details of the request.
QueryException
find(com.objectwave.persist.SQLQuery)
public Pair[] findColumnSqlTypes(SQLQuery query) throws QueryException
query
- The query object detailing the object of the search and the
constraints of the query.
QueryException
public void deleteAll(SQLQuery obj) throws QueryException
obj
- The query object that will make up the where clause of the
delete statement.
QueryException
public Persistence findUnique(SQLQuery q) throws QueryException
q
- The query object detailing the object that will be found and the
constraints of the query.
QueryException
public void initConfiguration()
public void initialize()
com.objectwave.persist.Broker#getDefaultBroker
public void insert(RDBPersistence pObj, Persistence obj) throws QueryException, java.sql.SQLException
obj
- is the object to insert.pObj
-
QueryException
java.sql.SQLException
public void rollback() throws QueryException
QueryException
public void save(Persistence obj) throws QueryException
obj
- The peristent object to save.
QueryException
public void saveObjects(java.util.ArrayList objs) throws QueryException
objs
- The peristent objects to save.
QueryException
public void update(RDBPersistence pObj, Persistence obj) throws QueryException, java.sql.SQLException
obj
- The object to update.pObj
-
QueryException
java.sql.SQLException
public void close()
close
in interface Broker
close
in class AbstractBroker
public void constrainWhereClause(SQLSelect sqlObj, Persistence subject, Persistence p)
p
- Assumes p has a foreignKey or InstanceLink w/columnName pointer to
parameter subject;subject
- The subject of a foreignKey or instanceLink in p;sqlObj
- public void update(SQLInsert sql, RDBPersistence obj)
sql
- com.objectwave.persist.SQLInsertobj
- com.objectwave.persist.RDBPersistenceprotected void initializeObjectPooling(ObjectPool aPool)
aPool
- protected void removeObjectPooling()
protected Persistence checkObjectPool(SQLQuery query)
query
- defined query
protected void defineSelectList(Persistence p, java.lang.String[] paths, SQLSelect sqlObj) throws QueryException
p
- The persistent objectpaths
- Paths in the object. These will be mapped to DB columns. Only
those persistent fields in this object will be found.sqlObj
- The current select object.
QueryException
findAttributes(com.objectwave.persist.SQLQuery, java.lang.String[])
protected void deleteObjects(java.util.ArrayList objs, int laterListSize) throws QueryException
objs
- A list of persistent objects.laterListSize
-
QueryException
save(com.objectwave.persist.Persistence)
protected void determinePrimaryKey(RDBPersistence pObj) throws java.sql.SQLException, QueryException
pObj
-
java.sql.SQLException
QueryException
generateInsertValues(com.objectwave.persist.RDBPersistence)
protected CollectionAdapter findResults(SQLQuery obj) throws QueryException
obj
- The query object detailing the object that will be found and the
constraints of the query.
QueryException
CollectionAdapter
protected void cleanupSelect(SQLSelect sqlObj, GrinderResultSet resultSet) throws QueryException
sqlObj
- resultSet
-
QueryException
protected void generateInsertValues(RDBPersistence pObj) throws java.sql.SQLException, QueryException
pObj
- The source of the data for the insert statement.
java.sql.SQLException
QueryException
nextPrimaryKey(com.objectwave.persist.RDBPersistence)
protected void initializeConnections()
AbstractBroker.setBrokerProperty(BrokerPropertyIF)
,
initializeConnections(int)
protected void initializeConnections(int connectionCount)
connectionCount
- The number of connections to the relational
database.protected RDBConnection newRDBConnection(RDBConnectionPool connectionPool, java.lang.String connectUrl, java.lang.String userName, java.lang.String userPassword)
connectionPool
- connectUrl
- userName
- userPassword
-
protected java.lang.Object nextPrimaryKey(RDBPersistence pObj) throws java.sql.SQLException, QueryException
pObj
-
java.sql.SQLException
QueryException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |