Package org.conical.common.bbl.jpa
Interface DataManager
- All Known Implementing Classes:
JpaDataManager
public interface DataManager
This interface, coupled with the JpaDataManager base class, allows for transaction-aware
database operations using JPA. See example in DbWorker for details.
- Author:
- rdoherty
-
Method Summary
Modifier and TypeMethodDescription<T extends Identifiable>
voiddeleteObject
(T obj) Deletes the record represented by the passed object.<T extends DataManager>
voidSets up classes needed to interface with the database, then begins a database transaction and calls doDbTasks() on the passed DbWorker.<T extends Identifiable>
TLooks up an instance of any class implementing Identifiable by its ID and returns it.<T extends Identifiable>
TsaveObject
(T obj) Saves a JPA entity that implements Identifiable to the database.
-
Method Details
-
doUpdates
Sets up classes needed to interface with the database, then begins a database transaction and calls doDbTasks() on the passed DbWorker. When that method returns, ends the transaction, either commiting when successful or rolling back if any exception was thrown from doDbTasks().- Type Parameters:
T
- implementation of DataManager- Parameters:
iface
- an instance of a DbWorker for that DataManager type- Throws:
Exception
- after rolling back the transaction, rethrows any exception that occurs in doDbTasks()
-
saveObject
Saves a JPA entity that implements Identifiable to the database. The argument will be merged if it represents an existing record (i.e. already has an ID), or persisted if it is a new record (no ID yet). There are a few requirements for this to work:- The object must be a JPA entity
- The object's class must be configured to generate its ID
- Type Parameters:
T
- class of the object- Parameters:
obj
- instance of that class- Returns:
- "attached" instance
-
deleteObject
Deletes the record represented by the passed object. If the object is detached, it will be looked up using its ID and removed.- Type Parameters:
T
- class of object to be removed- Parameters:
obj
- object to be removed- Throws:
IllegalArgumentException
- if object passed does not have an ID or does not exist
-
findById
Looks up an instance of any class implementing Identifiable by its ID and returns it.- Type Parameters:
T
- class of object to be retrieved- Parameters:
obj
- class of object to be retrievedid
- id of object to be retrieved- Returns:
- object retrieved
-