|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.extras.cayenne.CayenneTemplate
Provides base Cayenne data access object or service class to extend, following the Spring DAO template pattern. This class uses thread bound DataContext for all data access operations.
This class is designed to be extended by custom DAO or Service subclasses which provide their own public interface. All methods on CayenneTemplate have protected visibility so they are not publicly visible on the custom subclasses. CayenneTemplate provides many convience DataContext methods using the DataContext object bound to the current thread.
Constructor Summary | |
CayenneTemplate()
|
Method Summary | |
protected void |
commitChanges()
Commit any changes in the thread local DataContext. |
protected org.apache.cayenne.DataObject |
createAndRegisterNewObject(Class dataObjectClass)
Instantiates new object and registers it with itself. |
protected void |
deleteObject(org.apache.cayenne.DataObject dataObject)
Schedules an object for deletion on the next commit of this DataContext. |
protected org.apache.cayenne.DataObject |
findObject(Class dataObjectClass,
String property,
Object value)
Find the data object for the specified class, property name and property value, or null if no data object was found. |
protected org.apache.cayenne.access.DataContext |
getDataContext()
Return the thread local DataContext. |
protected org.apache.cayenne.DataObject |
getObjectForPK(Class doClass,
Object id)
Perform a database query returning the data object specified by the class and the primary key. |
protected org.apache.cayenne.DataObject |
getObjectForPK(Class dataObjectClass,
Object id,
boolean refresh)
Perform a query returning the data object specified by the class and the primary key value. |
protected String |
getPkName(Class dataObjectClass)
Return the database primary key column name for the given data object. |
protected int[] |
performNonSelectingQuery(org.apache.cayenne.query.Query query)
Performs a single database query that does not select rows. |
protected int[] |
performNonSelectingQuery(String queryName)
Performs a named mapped query that does not select rows. |
protected int[] |
performNonSelectingQuery(String queryName,
Map parameters)
Performs a named mapped non-selecting query using a map of parameters. |
protected List |
performQuery(Class dataObjectClass,
String property,
Object value)
Return a list of data object of the specified class for the given property and value. |
protected List |
performQuery(org.apache.cayenne.query.Query query)
Performs a single selecting query. |
protected List |
performQuery(String queryName,
boolean refresh)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
protected List |
performQuery(String queryName,
Map parameters,
boolean refresh)
Returns a list of objects or DataRows for a named query stored in one of the DataMaps. |
protected void |
registerNewObject(org.apache.cayenne.DataObject dataObject)
Registers a transient object with the context, recursively registering all transient DataObjects attached to this object via relationships. |
protected void |
rollbackChanges()
Reverts any changes that have occurred to objects registered in the thread local DataContext. |
protected Map |
toMap(String key,
Object value)
Return a Map containing the given key name and value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CayenneTemplate()
Method Detail |
protected org.apache.cayenne.DataObject createAndRegisterNewObject(Class dataObjectClass)
dataObjectClass
- the data object class to create and register
protected void commitChanges()
protected void deleteObject(org.apache.cayenne.DataObject dataObject) throws org.apache.cayenne.DeleteDenyException
dataObject
- a persistent data object that we want to delete
org.apache.cayenne.DeleteDenyException
- if a DENY delete rule
is applicable for object deletionprotected org.apache.cayenne.DataObject findObject(Class dataObjectClass, String property, Object value)
dataObjectClass
- the data object class to findproperty
- the name of the propertyvalue
- the value of the property
RuntimeException
- if more than one data object was identified for the
given property name and valueprotected org.apache.cayenne.access.DataContext getDataContext()
IllegalStateException
- if there is no DataContext bound to the current threadprotected org.apache.cayenne.DataObject getObjectForPK(Class doClass, Object id)
doClass
- the data object class to retrieveid
- the data object primary key
protected org.apache.cayenne.DataObject getObjectForPK(Class dataObjectClass, Object id, boolean refresh)
dataObjectClass
- the data object class to retrieveid
- the data object primary keyrefresh
- the refresh the object cache mode
protected String getPkName(Class dataObjectClass)
dataObjectClass
- the class of the data object
protected List performQuery(org.apache.cayenne.query.Query query)
query
- the query to perform
protected List performQuery(String queryName, boolean refresh)
queryName
- a name of a GenericSelectQuery defined in one of the DataMaps. If
no such query is defined, this method will throw a CayenneRuntimeExceptionrefresh
- A flag that determines whether refresh of cached lists
is required in case a query uses caching.
protected List performQuery(String queryName, Map parameters, boolean refresh)
queryName
- a name of a GenericSelectQuery defined in one of the DataMaps. If
no such query is defined, this method will throw a CayenneRuntimeExceptionparameters
- A map of parameters to use with stored queryrefresh
- A flag that determines whether refresh of cached lists
is required in case a query uses caching.
protected List performQuery(Class dataObjectClass, String property, Object value)
dataObjectClass
- the data object class to returnproperty
- the name of the property to selectvalue
- the property value to select
protected int[] performNonSelectingQuery(org.apache.cayenne.query.Query query)
query
- the query to perform
protected int[] performNonSelectingQuery(String queryName)
queryName
- the name of the query to perform
protected int[] performNonSelectingQuery(String queryName, Map parameters)
queryName
- the name of the query to performparameters
- the Map of query paramater names and values
protected void registerNewObject(org.apache.cayenne.DataObject dataObject)
dataObject
- new object that needs to be made persistentprotected void rollbackChanges()
protected Map toMap(String key, Object value)
key
- the map key namevalue
- the map key value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |