|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.extras.cayenne.CayenneTemplate
public class 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 convenience 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
|
createAndRegisterNewObject(Class<T> persistentClass)
Deprecated. since 2.3.0, use newObject(java.lang.Class) instead. |
|
protected void |
deleteObject(org.apache.cayenne.DataObject dataObject)
Schedules an object for deletion on the next commit of this DataContext. |
|
protected
|
findObject(Class<T> persistentClass,
String property,
Object value)
Find the persistent object for the specified class, property name and property value, or null if no persistent object was found. |
|
protected Connection |
getConnection()
Return a pooled Cayenne connection for the shared configuration and the first configured DataNode. |
|
protected org.apache.cayenne.access.DataContext |
getDataContext()
Return the thread local DataContext. |
|
protected
|
getObjectForPK(Class<T> persistentClass,
Object id)
Perform a database query returning the data object specified by the class and the primary key. |
|
protected
|
getObjectForPK(Class<T> persistentClass,
Object id,
boolean refresh)
Perform a query returning the persistent object specified by the class and the primary key value. |
|
protected String |
getPkName(Class persistentClass)
Return the database primary key column name for the given data object. |
|
protected
|
newObject(Class<T> persistentClass)
Instantiate and register a new persistent 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<String,?> 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 <T> T newObject(Class<T> persistentClass)
persistentClass
- the persistent object class to create and register
protected <T> T createAndRegisterNewObject(Class<T> persistentClass)
newObject(java.lang.Class)
instead.
persistentClass
- the persistent 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 <T> T findObject(Class<T> persistentClass, String property, Object value)
persistentClass
- the persistent object class to findproperty
- the name of the propertyvalue
- the value of the property
RuntimeException
- if more than one persistent object was identified
for the given property name and valueprotected Connection getConnection() throws SQLException
SQLException
- if a database connection could not be obtainedprotected org.apache.cayenne.access.DataContext getDataContext()
protected <T> T getObjectForPK(Class<T> persistentClass, Object id)
persistentClass
- the persistent object class to retrieveid
- the data object primary key
protected <T> T getObjectForPK(Class<T> persistentClass, Object id, boolean refresh)
persistentClass
- the persistent object class to retrieveid
- the persistent object primary keyrefresh
- the refresh the object cache mode
protected String getPkName(Class persistentClass)
persistentClass
- the class of the persistent 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<String,?> parameters)
queryName
- the name of the query to performparameters
- the Map of query parameter 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 |