| java.lang.Object org.jpublish.module.cayenne.CayenneTemplate
All known Subclasses: org.jpublish.module.cayenne.JPCayenneService,
CayenneTemplate | public class CayenneTemplate (Code) | | 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.
author: Malcolm Edgar author: Andrei Adamchik author: Florin T.PATRASCU since: $Revision$ (created: Sep 22, 2007 11:45:03 PM) |
Method Summary | |
protected void | commitChanges() Commit any changes in the thread local DataContext. | protected Persistent | createAndRegisterNewObject(Class dataObjectClass) Instantiates new object and registers it with itself. | protected void | deleteObject(DataObject dataObject) Schedules an object for deletion on the next commit of this DataContext. | protected 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 DataContext | getDataContext() Return the thread local DataContext. | protected DataObject | getObjectForPK(Class doClass, Object id) Perform a database query returning the data object specified by the
class and the primary key. | protected 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(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(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 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 void | registerNewObject(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. |
commitChanges | protected void commitChanges()(Code) | | Commit any changes in the thread local DataContext.
|
createAndRegisterNewObject | protected Persistent createAndRegisterNewObject(Class dataObjectClass)(Code) | | Instantiates new object and registers it with itself. Object class must
have a default constructor.
Parameters: dataObjectClass - the data object class to create and register the new registered data object |
deleteObject | protected void deleteObject(DataObject dataObject) throws DeleteDenyException(Code) | | Schedules an object for deletion on the next commit of this DataContext. Object's
persistence state is changed to PersistenceState.DELETED; objects related to this
object are processed according to delete rules, i.e. relationships can be unset
("nullify" rule), deletion operation is cascaded (cascade rule).
Parameters: dataObject - a persistent data object that we want to delete throws: org.apache.cayenne.DeleteDenyException - if a DENY delete ruleis applicable for object deletion |
findObject | protected DataObject findObject(Class dataObjectClass, String property, Object value)(Code) | | Find the data object for the specified class, property name and property
value, or null if no data object was found.
Parameters: dataObjectClass - the data object class to find Parameters: property - the name of the property Parameters: value - the value of the property the data object for the specified class, property name and property value throws: RuntimeException - if more than one data object was identified for thegiven property name and value |
getDataContext | protected DataContext getDataContext()(Code) | | Return the thread local DataContext.
the thread local DataContext throws: IllegalStateException - if there is no DataContext bound to the current thread |
getObjectForPK | protected DataObject getObjectForPK(Class doClass, Object id)(Code) | | Perform a database query returning the data object specified by the
class and the primary key. This method will perform a database query
and refresh the object cache.
Parameters: doClass - the data object class to retrieve Parameters: id - the data object primary key the data object for the given class and id |
getObjectForPK | protected DataObject getObjectForPK(Class dataObjectClass, Object id, boolean refresh)(Code) | | Perform a query returning the data object specified by the
class and the primary key value. If the refresh parameter is true a
database query will be performed, otherwise the a query against the
object cache will be performed first.
Parameters: dataObjectClass - the data object class to retrieve Parameters: id - the data object primary key Parameters: refresh - the refresh the object cache mode the data object for the given class and id |
getPkName | protected String getPkName(Class dataObjectClass)(Code) | | Return the database primary key column name for the given data object.
Parameters: dataObjectClass - the class of the data object the primary key column name |
performNonSelectingQuery | protected int[] performNonSelectingQuery(Query query)(Code) | | Performs a single database query that does not select rows. Returns an
array of update counts.
Parameters: query - the query to perform the array of update counts |
performNonSelectingQuery | protected int[] performNonSelectingQuery(String queryName)(Code) | | Performs a named mapped query that does not select rows. Returns an array
of update counts.
Parameters: queryName - the name of the query to perform the array of update counts |
performNonSelectingQuery | protected int[] performNonSelectingQuery(String queryName, Map parameters)(Code) | | Performs a named mapped non-selecting query using a map of parameters.
Returns an array of update counts.
Parameters: queryName - the name of the query to perform Parameters: parameters - the Map of query paramater names and values the array of update counts |
performQuery | protected List performQuery(Query query)(Code) | | Performs a single selecting query. Various query setting control the behavior of
this method and the results returned:
- Query caching policy defines whether the results are retrieved from cache or
fetched from the database. Note that queries that use caching must have a name that
is used as a caching key.
- Query refreshing policy controls whether to refresh existing data objects and
ignore any cached values.
- Query data rows policy defines whether the result should be returned as
DataObjects or DataRows.
Parameters: query - the query to perform a list of DataObjects or a DataRows for the query |
performQuery | protected List performQuery(String queryName, boolean refresh)(Code) | | Returns a list of objects or DataRows for a named query stored in one of the
DataMaps. Internally Cayenne uses a caching policy defined in the named query. If
refresh flag is true, a refresh is forced no matter what the caching policy is.
Parameters: queryName - a name of a GenericSelectQuery defined in one of the DataMaps. Ifno such query is defined, this method will throw a CayenneRuntimeException Parameters: refresh - A flag that determines whether refresh of cached listsis required in case a query uses caching. the list of data object or DataRows for the named query |
performQuery | protected List performQuery(String queryName, Map parameters, boolean refresh)(Code) | | Returns a list of objects or DataRows for a named query stored in one of the
DataMaps. Internally Cayenne uses a caching policy defined in the named query. If
refresh flag is true, a refresh is forced no matter what the caching policy is.
Parameters: queryName - a name of a GenericSelectQuery defined in one of the DataMaps. Ifno such query is defined, this method will throw a CayenneRuntimeException Parameters: parameters - A map of parameters to use with stored query Parameters: refresh - A flag that determines whether refresh of cached listsis required in case a query uses caching. the list of data object or DataRows for the named query |
performQuery | protected List performQuery(Class dataObjectClass, String property, Object value)(Code) | | Return a list of data object of the specified class for the given property
and value.
Parameters: dataObjectClass - the data object class to return Parameters: property - the name of the property to select Parameters: value - the property value to select a list of data objects for the given class and property name and value |
registerNewObject | protected void registerNewObject(DataObject dataObject)(Code) | | Registers a transient object with the context, recursively registering all
transient DataObjects attached to this object via relationships.
Parameters: dataObject - new object that needs to be made persistent |
rollbackChanges | protected void rollbackChanges()(Code) | | Reverts any changes that have occurred to objects registered in the
thread local DataContext.
|
toMap | protected Map toMap(String key, Object value)(Code) | | Return a Map containing the given key name and value.
Parameters: key - the map key name Parameters: value - the map key value a Map containing the given key name and value |
|
|