java.lang.Object |
↳ |
vars.jpa.DAO |
Known Direct Subclasses
ArtifactDAOImpl,
AssociationDAOImpl,
CameraDataDAOImpl,
CameraDeploymentDAOImpl,
ConceptDAOImpl,
ConceptMetadataDAOImpl,
ConceptNameDAOImpl,
HistoryDAOImpl,
LinkRealizationDAOImpl,
LinkTemplateDAOImpl,
MediaDAOImpl,
ObservationDAOImpl,
PhysicalDataDAOImpl,
UsageDAOImpl,
UserAccountDAOImpl,
VideoArchiveDAOImpl,
VideoArchiveSetDAOImpl,
VideoFrameDAOImpl
|
Class Overview
Persistence service implementation for use in Java SE environments. Basically,
it's a decorator for EntityManager
Use as:
DAO dao = new DAO(entityManager);
dao.startTransaction();
// Call whatever dao methods you need
dao.endTransaction();
Summary
Nested Classes |
enum |
DAO.TransactionType |
|
Fields |
protected
final
Logger |
log |
|
Public Constructors |
|
DAO(EntityManager entityManager)
Constructs ...
|
Public Methods |
void
|
close()
Closes the associated entityManger if it's open.
|
void
|
commit()
|
void
|
endTransaction()
Close any open transaction used on the current thread.
|
boolean
|
equalInDatastore(Object thisObj, Object thatObj)
True if the to objects represent the same object in the datastore.
|
<T>
T
|
find(T object)
Retrieves the object from the datastore.
|
List
|
findByNamedQuery(String name)
Executes a named query that does not take any parameters
|
List
|
findByNamedQuery(String name, Map<String, Object> namedParameters)
Executes a named query using a map of named parameters
|
<T>
T
|
findByPrimaryKey(Class<T> clazz, Object primaryKey)
|
EntityManager
|
getEntityManager()
|
boolean
|
isPersistent(Object entity)
Checks to see if the given object is persisted in the database
|
void
|
loadLazyRelations(Object entity)
Many one-to-many relations are lazy loaded in JPA.
|
<T>
T
|
merge(T entity)
Update an object in the database and bring it into the current transaction
|
void
|
persist(Object entity)
Insert an object into the database
|
void
|
remove(Object entity)
|
void
|
startTransaction()
Start a database transaction.
|
static
Map<String, Object>
|
toParameterMap(Object... args)
The findByNamedQuery method needs a Map of parameters.
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0)
|
final
void
|
wait(long arg0, int arg1)
|
|
From interface
vars.DAO
abstract
void
|
close()
|
abstract
void
|
commit()
|
abstract
void
|
endTransaction()
|
abstract
boolean
|
equalInDatastore(Object thisObj, Object thatObj)
True if the to objects represent the same object in the datastore.
|
abstract
<T>
T
|
find(T object)
Retrieves the object from the datastore.
|
abstract
List
|
findByNamedQuery(String name)
Executes a named query that does not take any parameters
|
abstract
List
|
findByNamedQuery(String name, Map<String, Object> namedParameters)
Executes a named query using a map of named parameters
|
abstract
<T>
T
|
findByPrimaryKey(Class<T> clazz, Object primaryKey)
|
abstract
EntityManager
|
getEntityManager()
|
abstract
boolean
|
isPersistent(Object entity)
Checks to see if the given object is persisted in the databas
|
abstract
void
|
loadLazyRelations(Object entity)
Many one-to-many relations are lazy loaded in JPA.
|
abstract
<T>
T
|
merge(T object)
|
abstract
void
|
persist(Object object)
|
abstract
void
|
remove(Object object)
|
abstract
void
|
startTransaction()
|
|
From interface
vars.jpa.EntityManagerAspect
|
Fields
protected
final
Logger
log
Public Constructors
public
DAO
(EntityManager entityManager)
Public Methods
public
void
close
()
Closes the associated entityManger if it's open.
public
void
endTransaction
()
Close any open transaction used on the current thread.
public
boolean
equalInDatastore
(Object thisObj, Object thatObj)
True if the to objects represent the same object in the datastore. (e.g.
It basically compares the primary key)
public
T
find
(T object)
Retrieves the object from the datastore. This ignores all state changes
in the provided object and returns the copy as found in the data store.
public
List
findByNamedQuery
(String name)
Executes a named query that does not take any parameters
Parameters
name
| The name of the JPL query |
Returns
- A list of objects returned by the query
public
List
findByNamedQuery
(String name, Map<String, Object> namedParameters)
Executes a named query using a map of named parameters
Parameters
name
| The name of the query to execute |
namedParameters
| A Map of the 'named' parameters to assign in
the query |
Returns
- A list of objects returned by the query.
public
T
findByPrimaryKey
(Class<T> clazz, Object primaryKey)
public
EntityManager
getEntityManager
()
public
boolean
isPersistent
(Object entity)
Checks to see if the given object is persisted in the database
Parameters
entity
| The object of interest |
Returns
- true if it's in the database. False if it is not
public
void
loadLazyRelations
(Object entity)
Many one-to-many relations are lazy loaded in JPA. For convience, this
method will load all lazy relations of an IEntity object. This method has
no effect on objects that are not persistant
Parameters
entity
| The persistent object whos children will be loaded from the
database.
|
public
T
merge
(T entity)
Update an object in the database and bring it into the current transaction
Parameters
entity
| The entity object whos fields are being updated in the
database. |
public
void
persist
(Object entity)
Insert an object into the database
Parameters
entity
| The entity object to persist in the database
|
public
void
remove
(Object entity)
public
void
startTransaction
()
Start a database transaction. Also initializes the EntityManager and
returns an instance of it.
public
static
Map<String, Object>
toParameterMap
(Object... args)
The findByNamedQuery method needs a Map of parameters. This method
generates the map for you. For example, instead of using:
Map<String, Object> map = new HashMap<String, Object>();
map.put("groupId", "vaap.annotation");
map.put("artifactId", "VARS-Histogram");
You could use
Map<String, Object> map = toParameterMap("groupId", "vaap-annotation", "artifactId", "VARS-Histogram")
Parameters
args
| An even numbered set of args. The first value in each pair is the parameter name
as a string, the 2nd value is the parameter value |
Returns
- A Map containing the key-value pairs