public class FullTextEntityManagerImpl extends Object implements FullTextEntityManager, Serializable
Constructor and Description |
---|
FullTextEntityManagerImpl(EntityManager em) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the persistence context, causing all managed
entities to become detached.
|
void |
close()
Close an application-managed entity manager.
|
boolean |
contains(Object entity)
Check if the instance is a managed entity instance belonging
to the current persistence context.
|
FullTextQuery |
createFullTextQuery(org.apache.lucene.search.Query luceneQuery,
Class<?>... entities)
Create a fulltext query on top of a native Lucene query returning the matching objects
of type
entities and their respective subclasses. |
MassIndexer |
createIndexer(Class<?>... types)
Creates a MassIndexer to rebuild the indexes of some
or all indexed entity types.
|
Query |
createNamedQuery(String name)
Create an instance of
Query for executing a named query
(in the Java Persistence query language or in native SQL). |
<T> TypedQuery<T> |
createNamedQuery(String name,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language named query. |
Query |
createNativeQuery(String sqlString)
Create an instance of
Query for executing
a native SQL statement, e.g., for update or delete. |
Query |
createNativeQuery(String sqlString,
Class resultClass)
Create an instance of
Query for executing
a native SQL query. |
Query |
createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of
Query for executing
a native SQL query. |
<T> TypedQuery<T> |
createQuery(CriteriaQuery<T> criteriaQuery)
Create an instance of
TypedQuery for executing a
criteria query. |
Query |
createQuery(String ejbqlString)
Create an instance of
Query for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(String qlString,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language statement. |
void |
detach(Object entity)
Remove the given entity from the persistence context, causing
a managed entity to become detached.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey)
Find by primary key.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockModeType)
Find by primary key and lock.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockModeType,
Map<String,Object> hints)
Find by primary key and lock, using the specified properties.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
Map<String,Object> hints)
Find by primary key, using the specified properties.
|
void |
flush()
Synchronize the persistence context to the
underlying database.
|
void |
flushToIndexes()
Flush all index changes forcing Hibernate Search to apply all changes to the index not waiting for the batch limit.
|
CriteriaBuilder |
getCriteriaBuilder()
Return an instance of
CriteriaBuilder for the creation of
CriteriaQuery objects. |
Object |
getDelegate()
Return the underlying provider object for the
EntityManager ,
if available. |
EntityManagerFactory |
getEntityManagerFactory()
Return the entity manager factory for the entity manager.
|
FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained
in the persistence context.
|
LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance.
|
Metamodel |
getMetamodel()
Return an instance of
Metamodel interface for access to the
metamodel of the persistence unit. |
Map<String,Object> |
getProperties()
Get the properties and hints and associated values that are in effect
for the entity manager.
|
<T> T |
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
org.hibernate.search.SearchFactory |
getSearchFactory() |
EntityTransaction |
getTransaction()
Return the resource-level
EntityTransaction object. |
<T> void |
index(T entity)
Force the (re)indexing of a given managed object.
|
boolean |
isOpen()
Determine whether the entity manager is open.
|
void |
joinTransaction()
Indicate to the entity manager that a JTA transaction is
active.
|
void |
lock(Object entity,
LockModeType lockMode)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type.
|
void |
lock(Object entity,
LockModeType lockModeType,
Map<String,Object> hints)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type and with specified
properties.
|
<T> T |
merge(T entity)
Merge the state of the given entity into the
current persistence context.
|
void |
persist(Object entity)
Make an instance managed and persistent.
|
<T> void |
purge(Class<T> entityType,
Serializable id)
Remove the entity with the type
entityType and the identifier id from the index. |
<T> void |
purgeAll(Class<T> entityType)
Remove all entities from of particular class and all its subclasses from the index.
|
void |
refresh(Object entity)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any.
|
void |
refresh(Object entity,
LockModeType lockModeType)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any, and
lock it with respect to given lock mode type.
|
void |
refresh(Object entity,
LockModeType lockModeType,
Map<String,Object> hints)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any, and
lock it with respect to given lock mode type and with
specified properties.
|
void |
refresh(Object entity,
Map<String,Object> hints)
Refresh the state of the instance from the database, using
the specified properties, and overwriting changes made to
the entity, if any.
|
void |
remove(Object entity)
Remove the entity instance.
|
void |
setFlushMode(FlushModeType flushMode)
Set the flush mode that applies to all objects contained
in the persistence context.
|
void |
setProperty(String key,
Object value)
Set an entity manager property or hint.
|
<T> T |
unwrap(Class<T> type)
Return an object of the specified type to allow access to the
provider-specific API.
|
public FullTextEntityManagerImpl(EntityManager em)
public FullTextQuery createFullTextQuery(org.apache.lucene.search.Query luceneQuery, Class<?>... entities)
FullTextEntityManager
entities
and their respective subclasses.createFullTextQuery
in interface FullTextEntityManager
luceneQuery
- The native Lucene query to be rn against the Lucene index.entities
- List of classes for type filtering. The query result will only return entities of
the specified types and their respective subtype. If no class is specified no type filtering will take place.FullTextQuery
wrapping around the native Lucene wuery.public <T> void index(T entity)
FullTextEntityManager
index
in interface FullTextEntityManager
entity
- The entity to index - must not be null
.public org.hibernate.search.SearchFactory getSearchFactory()
getSearchFactory
in interface FullTextEntityManager
SearchFactory
instance.public <T> void purge(Class<T> entityType, Serializable id)
FullTextEntityManager
entityType
and the identifier id
from the index.
If id == null
all indexed entities of this type and its indexed subclasses are deleted. In this
case this method behaves like FullTextEntityManager.purgeAll(Class)
.purge
in interface FullTextEntityManager
entityType
- The type of the entity to delete.id
- The id of the entity to delete.public <T> void purgeAll(Class<T> entityType)
FullTextEntityManager
purgeAll
in interface FullTextEntityManager
entityType
- The class of the entities to remove.public void flushToIndexes()
FullTextEntityManager
flushToIndexes
in interface FullTextEntityManager
public void persist(Object entity)
EntityManager
persist
in interface EntityManager
entity
- entity instancepublic <T> T merge(T entity)
EntityManager
merge
in interface EntityManager
entity
- entity instancepublic void remove(Object entity)
EntityManager
remove
in interface EntityManager
entity
- entity instancepublic <T> T find(Class<T> entityClass, Object primaryKey)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keypublic <T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> hints)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keyhints
- standard and vendor-specific properties
and hintspublic <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType)
EntityManager
If the entity is found within the persistence context and the
lock mode type is pessimistic and the entity has a version
attribute, the persistence provider must perform optimistic
version checks when obtaining the database lock. If these
checks fail, the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keylockModeType
- lock modepublic <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String,Object> hints)
EntityManager
If the entity is found
within the persistence context and the lock mode type
is pessimistic and the entity has a version attribute, the
persistence provider must perform optimistic version checks
when obtaining the database lock. If these checks fail,
the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keylockModeType
- lock modehints
- standard and vendor-specific properties
and hintspublic <T> T getReference(Class<T> entityClass, Object primaryKey)
EntityManager
EntityNotFoundException
is thrown when the instance
state is first accessed. (The persistence provider runtime is
permitted to throw the EntityNotFoundException
when
getReference
is called.)
The application should not expect that the instance state will
be available upon detachment, unless it was accessed by the
application while the entity manager was open.getReference
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keypublic void flush()
EntityManager
flush
in interface EntityManager
public void setFlushMode(FlushModeType flushMode)
EntityManager
setFlushMode
in interface EntityManager
flushMode
- flush modepublic FlushModeType getFlushMode()
EntityManager
getFlushMode
in interface EntityManager
public void lock(Object entity, LockModeType lockMode)
EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
lock
in interface EntityManager
entity
- entity instancelockMode
- lock modepublic void lock(Object entity, LockModeType lockModeType, Map<String,Object> hints)
EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
lock
in interface EntityManager
entity
- entity instancelockModeType
- lock modehints
- standard and vendor-specific properties
and hintspublic void refresh(Object entity)
EntityManager
refresh
in interface EntityManager
entity
- entity instancepublic void refresh(Object entity, Map<String,Object> hints)
EntityManager
If a vendor-specific property or hint is not recognized, it is silently ignored.
refresh
in interface EntityManager
entity
- entity instancehints
- standard and vendor-specific properties
and hintspublic void refresh(Object entity, LockModeType lockModeType)
EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the
database locking failure causes only statement-level
rollback.
refresh
in interface EntityManager
entity
- entity instancelockModeType
- lock modepublic void refresh(Object entity, LockModeType lockModeType, Map<String,Object> hints)
EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
refresh
in interface EntityManager
entity
- entity instancelockModeType
- lock modehints
- standard and vendor-specific properties
and hintspublic void clear()
EntityManager
clear
in interface EntityManager
public void detach(Object entity)
EntityManager
detach
in interface EntityManager
entity
- entity instancepublic boolean contains(Object entity)
EntityManager
contains
in interface EntityManager
entity
- entity instancepublic LockModeType getLockMode(Object entity)
EntityManager
getLockMode
in interface EntityManager
entity
- entity instancepublic void setProperty(String key, Object value)
EntityManager
setProperty
in interface EntityManager
key
- name of property or hintvalue
- value for property or hintpublic Map<String,Object> getProperties()
EntityManager
getProperties
in interface EntityManager
public Query createQuery(String ejbqlString)
EntityManager
Query
for executing a
Java Persistence query language statement.createQuery
in interface EntityManager
ejbqlString
- a Java Persistence query stringpublic <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
EntityManager
TypedQuery
for executing a
criteria query.createQuery
in interface EntityManager
criteriaQuery
- a criteria query objectpublic <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
EntityManager
TypedQuery
for executing a
Java Persistence query language statement.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.createQuery
in interface EntityManager
qlString
- a Java Persistence query stringresultClass
- the type of the query resultpublic Query createNamedQuery(String name)
EntityManager
Query
for executing a named query
(in the Java Persistence query language or in native SQL).createNamedQuery
in interface EntityManager
name
- the name of a query defined in metadatapublic <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
EntityManager
TypedQuery
for executing a
Java Persistence query language named query.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.createNamedQuery
in interface EntityManager
name
- the name of a query defined in metadataresultClass
- the type of the query resultpublic Query createNativeQuery(String sqlString)
EntityManager
Query
for executing
a native SQL statement, e.g., for update or delete.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringpublic Query createNativeQuery(String sqlString, Class resultClass)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)public Query createNativeQuery(String sqlString, String resultSetMapping)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mappingpublic void joinTransaction()
EntityManager
joinTransaction
in interface EntityManager
public <T> T unwrap(Class<T> type)
EntityManager
EntityManager
implementation does not support the specified class, the
PersistenceException
is thrown.unwrap
in interface EntityManager
type
- the class of the object to be returned. This is
normally either the underlying EntityManager
implementation
class or an interface that it implements.public Object getDelegate()
EntityManager
EntityManager
,
if available. The result of this method is implementation
specific. The unwrap
method is to be preferred for new
applications.getDelegate
in interface EntityManager
public void close()
EntityManager
EntityManager
instance and any
Query
and TypedQuery
objects obtained from it will throw the IllegalStateException
except for getProperties
,
getTransaction
, and isOpen
(which will return false).
If this method is called when the entity manager is
associated with an active transaction, the persistence
context remains managed until the transaction completes.close
in interface EntityManager
public boolean isOpen()
EntityManager
isOpen
in interface EntityManager
public EntityTransaction getTransaction()
EntityManager
EntityTransaction
object.
The EntityTransaction
instance may be used serially to
begin and commit multiple transactions.getTransaction
in interface EntityManager
public EntityManagerFactory getEntityManagerFactory()
EntityManager
getEntityManagerFactory
in interface EntityManager
public CriteriaBuilder getCriteriaBuilder()
EntityManager
CriteriaBuilder
for the creation of
CriteriaQuery
objects.getCriteriaBuilder
in interface EntityManager
public Metamodel getMetamodel()
EntityManager
Metamodel
interface for access to the
metamodel of the persistence unit.getMetamodel
in interface EntityManager
public MassIndexer createIndexer(Class<?>... types)
FullTextEntityManager
createIndexer
in interface FullTextEntityManager
types
- optionally restrict the operation to selected typesCopyright © 2018 JBoss by Red Hat. All rights reserved.