org.objectweb.speedo.pm.ejb.lib
Class EJBPOManager

java.lang.Object
  extended by org.objectweb.speedo.pm.lib.AbstractPOManager
      extended by org.objectweb.speedo.pm.ejb.lib.EJBPOManager
All Implemented Interfaces:
javax.persistence.EntityManager, javax.transaction.Synchronization, POManagerItf, EJBPOManagerItf

public class EJBPOManager
extends AbstractPOManager
implements EJBPOManagerItf

TODO: runtimeException thrown by the methods will cause the current transaction to rollback

Author:
S.Chassande-Barrioz

Field Summary
 
Fields inherited from class org.objectweb.speedo.pm.lib.AbstractPOManager
COMPONENT_BINDING, connectionSpec, currentThread, fetchPlan, jf, JORM_FACTORY_BINDING, logger, loggerFactory, nbUse, pmf, PNAME_CODER_BINDING, pnc, PO_MANAGER_FACTORY_BINDING, prefetchOnExtent, prefetchOnQuery, QUERY_MANAGER_BINDING, queryManager, semaphore, thisPM, tpm, TRANSACTION_BINDING, TRANSACTIONAL_PERSISTENCE_MANAGER_BINDING, tx
 
Constructor Summary
EJBPOManager()
           
 
Method Summary
 void clear()
           
 void close()
          closes an application-managed EntityManager.
 boolean contains(java.lang.Object entity)
          Check if the instance belongs to the current persistence context
 javax.persistence.Query createNamedQuery(java.lang.String name)
          Create an instance of Query for executing a named query (EJB QL or native SQL).
 javax.persistence.Query createNativeQuery(java.lang.String sqlString)
          Create an instance of Query for executing a native SQL statement.
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
          Create an instance of Query for executing a native SQL statement.
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
          Create an instance of Query for executing a native SQL statement.
 javax.persistence.Query createQuery(java.lang.String ejbqlString)
          Create an instance of Query for executing an EJB QL statement
 java.lang.Object find(java.lang.Class entityClass, java.lang.Object primaryKey)
          Find by primary key
 void flush()
          Synchronize the persistence context to the underlying database.
 javax.persistence.FlushModeType getFlushMode()
           
 java.lang.Object getReference(java.lang.Class entityClass, java.lang.Object primaryKey)
          Get an instance, whoose state may be lazily fetched.
 javax.persistence.EntityTransaction getTransaction()
          Returns the resource-level transaction object.
 boolean isOpen()
          Indicates whether the EntityManager is open.
 void lock(java.lang.Object arg0, javax.persistence.LockModeType arg1)
           
 java.lang.Object merge(java.lang.Object entity)
          Merge the state of the given entry into the current persistence context
 void persist(java.lang.Object entity)
          Make an instance managed and persistent
 void refresh(java.lang.Object entity)
          Refresh the state of the instanc from the database overwriting chages mades to the entity, if any.
 void remove(java.lang.Object entity)
          Remove the instance
 void setFlushMode(javax.persistence.FlushModeType fmt)
           
 java.lang.Object speedoAttachCopy(java.lang.Object detached, java.util.Map map)
           
 void speedoDeletePersistent(java.lang.Object o)
          Delete persistent a PersistentObjectItf.
 void speedoDeletePersistent(java.lang.Object oid, java.lang.Class pc)
           
 java.lang.Object speedoDetachCopy(PersistentObjectItf sp, java.util.Map map, java.util.Collection fgHints)
           
 FetchPlanItf speedoGetFetchPlan()
           
 java.lang.Object speedoMakePersistent(PersistentObjectItf sp, java.util.Map map)
          Make persistent a PersistentObjectItf.
 void speedoRefresh(PersistentObjectItf sp, java.util.Map map, java.util.Collection fgHints)
           
 void speedoRetrieve(PersistentObjectItf sp, java.util.Map map, java.util.Collection fgHints)
           
 
Methods inherited from class org.objectweb.speedo.pm.lib.AbstractPOManager
addUse, afterCompletion, assertIsOpen, assertIsPO, assertPOManager, beforeCompletion, bindFc, bindPMThread, closePOManager, decodeIdentifier, getConnectionSpec, getEncodedPName, getPOManagerFactory, getSemaphore, getSpeedoTransaction, getTransactionalPersistenceManager, isPOMClosed, listFc, lookupFc, open, resetPMOnOpen, speedoDeletePersistentAll, speedoFlush, speedoGetObject, speedoGetObject, speedoPersist, unbindFc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.speedo.pm.api.POManagerItf
addUse, closePOManager, decodeIdentifier, getConnectionSpec, getEncodedPName, getPOManagerFactory, getSemaphore, getSpeedoTransaction, getTransactionalPersistenceManager, isPOMClosed, open, speedoDeletePersistentAll, speedoGetObject
 
Methods inherited from interface javax.transaction.Synchronization
afterCompletion, beforeCompletion
 

Constructor Detail

EJBPOManager

public EJBPOManager()
Method Detail

speedoGetFetchPlan

public FetchPlanItf speedoGetFetchPlan()
Specified by:
speedoGetFetchPlan in interface POManagerItf
Specified by:
speedoGetFetchPlan in class AbstractPOManager

persist

public void persist(java.lang.Object entity)
Make an instance managed and persistent

Specified by:
persist in interface javax.persistence.EntityManager
Parameters:
entity -
Throws:
java.lang.IllegalArgumentException - if not an entity or entity is detached
javax.persistence.TransactionRequiredException - if there is no transaction
See Also:
EntityManager.persist(java.lang.Object)

merge

public java.lang.Object merge(java.lang.Object entity)
Merge the state of the given entry into the current persistence context

Specified by:
merge in interface javax.persistence.EntityManager
Parameters:
entity -
Returns:
the instance that the state was merge to
Throws:
java.lang.IllegalArgumentException - if instance is not an entity or is a removed instance
javax.persistence.TransactionRequiredException - if there is no transaction
See Also:
EntityManager.merge(java.lang.Object)

remove

public void remove(java.lang.Object entity)
Remove the instance

Specified by:
remove in interface javax.persistence.EntityManager
Parameters:
entity -
Throws:
java.lang.IllegalArgumentException - if not an entity or if a detached entity
javax.persistence.TransactionRequiredException - if there is no transaction
See Also:
EntityManager.remove(java.lang.Object)

find

public java.lang.Object find(java.lang.Class entityClass,
                             java.lang.Object primaryKey)
Find by primary key

Specified by:
find in interface javax.persistence.EntityManager
Parameters:
entityClass -
primaryKey -
Returns:
the found entity instance or null if the entity does not exist throws
Throws:
java.lang.IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity'primary key
See Also:
EntityManager.find(java.lang.Class, java.lang.Object)

getReference

public java.lang.Object getReference(java.lang.Class entityClass,
                                     java.lang.Object primaryKey)
Get an instance, whoose state may be lazily fetched. If the requested instance does not exist in the database, throws javax.persistence.EntityNotFoundException when the instance state is first accessed. (The container is permitted to throw EntityNotFoundException when get is called.) The application shoud not expect that the instance state will be availlable upon detachment, unless it was accessed by the application while the entity manager was open.

Specified by:
getReference in interface javax.persistence.EntityManager
Parameters:
entityClass -
primaryKey -
Returns:
the found entity instance
Throws:
java.lang.IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity'primary key
javax.persistence.EntityNotFoundException - if the entity state cannot be accessed
See Also:
EntityManager.getReference(java.lang.Class, java.lang.Object)

flush

public void flush()
Synchronize the persistence context to the underlying database.

Specified by:
flush in interface javax.persistence.EntityManager
Throws:
javax.persistence.TransactionRequiredException - if there is no transaction
javax.persistence.PersistenceException - if there the flush fails
See Also:
EntityManager.flush()

refresh

public void refresh(java.lang.Object entity)
Refresh the state of the instanc from the database overwriting chages mades to the entity, if any.

Specified by:
refresh in interface javax.persistence.EntityManager
Parameters:
entity -
Throws:
java.lang.IllegalArgumentException - if not an entity or entity is not managed.
javax.persistence.TransactionRequiredException - if there is no transaction
javax.persistence.EntityNotFoundException - if there is no longer exists in the database
See Also:
EntityManager.refresh(java.lang.Object)

contains

public boolean contains(java.lang.Object entity)
Check if the instance belongs to the current persistence context

Specified by:
contains in interface javax.persistence.EntityManager
Parameters:
entity -
Throws:
java.lang.IllegalArgumentException - if not an entity
See Also:
EntityManager.contains(java.lang.Object)

close

public void close()
closes an application-managed EntityManager. This method can only be called when the EntityManaged is not associated with an active transaction. After an EntityManager has been closed, all methodes on the EntityManager instance will throw the IllegalStateException except for isOpen, which will return false;

Specified by:
close in interface javax.persistence.EntityManager
Throws:
java.lang.IllegalStateException - if the EntityManager is associated with an active transaction or if the EntityManager is container-managed.
See Also:
EntityManager.close()

isOpen

public boolean isOpen()
Indicates whether the EntityManager is open.

Specified by:
isOpen in interface javax.persistence.EntityManager
Returns:
true until the EntityManager has been closed.
See Also:
EntityManager.isOpen()

getTransaction

public javax.persistence.EntityTransaction getTransaction()
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to bein and commit multiple transactions.

Specified by:
getTransaction in interface javax.persistence.EntityManager
Returns:
EntityTransaction instance
Throws:
java.lang.IllegalStateException - if invoked on a JTA EntityManager or an EntityManager that has been closed.
See Also:
EntityManager.getTransaction()

setFlushMode

public void setFlushMode(javax.persistence.FlushModeType fmt)
Specified by:
setFlushMode in interface javax.persistence.EntityManager
See Also:
EntityManager.setFlushMode(javax.persistence.FlushModeType)

createQuery

public javax.persistence.Query createQuery(java.lang.String ejbqlString)
Create an instance of Query for executing an EJB QL statement

Specified by:
createQuery in interface javax.persistence.EntityManager
Parameters:
ejbqlString - an EJB QL query string
Returns:
the new query instance
Throws:
java.lang.IllegalArgumentException - if query string is not valid
See Also:
EntityManager.createQuery(java.lang.String)

createNamedQuery

public javax.persistence.Query createNamedQuery(java.lang.String name)
Create an instance of Query for executing a named query (EJB QL or native SQL).

Specified by:
createNamedQuery in interface javax.persistence.EntityManager
Parameters:
name - the name of a query defined in metadata
Returns:
the new query instance
Throws:
java.lang.IllegalArgumentException - if query string is not valid
See Also:
EntityManager.createNamedQuery(java.lang.String)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString)
Create an instance of Query for executing a native SQL statement.

Specified by:
createNativeQuery in interface javax.persistence.EntityManager
Parameters:
sqlString - an EJB QL query string
Returns:
the new query instance
Throws:
java.lang.IllegalArgumentException - if query string is not valid
See Also:
EntityManager.createNativeQuery(java.lang.String)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.Class resultClass)
Create an instance of Query for executing a native SQL statement.

Specified by:
createNativeQuery in interface javax.persistence.EntityManager
Parameters:
sqlString - an EJB QL query string
resultClass - the class of the resulting instances
Returns:
the new query instance
Throws:
java.lang.IllegalArgumentException - if query string is not valid
See Also:
EntityManager.createNativeQuery(java.lang.String, java.lang.Class)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.String resultSetMapping)
Create an instance of Query for executing a native SQL statement.

Specified by:
createNativeQuery in interface javax.persistence.EntityManager
Parameters:
sqlString - an EJB QL query string
resultSetMapping - the class of the resulting instances
Returns:
the new query instance
Throws:
java.lang.IllegalArgumentException - if query string is not valid
See Also:
EntityManager.createNativeQuery(java.lang.String, java.lang.String)

clear

public void clear()
Specified by:
clear in interface javax.persistence.EntityManager

getFlushMode

public javax.persistence.FlushModeType getFlushMode()
Specified by:
getFlushMode in interface javax.persistence.EntityManager

lock

public void lock(java.lang.Object arg0,
                 javax.persistence.LockModeType arg1)
Specified by:
lock in interface javax.persistence.EntityManager

speedoDeletePersistent

public void speedoDeletePersistent(java.lang.Object o)
Description copied from interface: POManagerItf
Delete persistent a PersistentObjectItf. This method does the same thing than the PersistenceManager.deletePersistent(Object) method except the call to the bind to the POManagerItf to the current thread.

Specified by:
speedoDeletePersistent in interface POManagerItf
Parameters:
o - is the instance to make persistent.

speedoDeletePersistent

public void speedoDeletePersistent(java.lang.Object oid,
                                   java.lang.Class pc)
Specified by:
speedoDeletePersistent in interface POManagerItf

speedoAttachCopy

public java.lang.Object speedoAttachCopy(java.lang.Object detached,
                                         java.util.Map map)
Specified by:
speedoAttachCopy in interface POManagerItf

speedoDetachCopy

public java.lang.Object speedoDetachCopy(PersistentObjectItf sp,
                                         java.util.Map map,
                                         java.util.Collection fgHints)
Specified by:
speedoDetachCopy in interface POManagerItf

speedoMakePersistent

public java.lang.Object speedoMakePersistent(PersistentObjectItf sp,
                                             java.util.Map map)
Description copied from interface: POManagerItf
Make persistent a PersistentObjectItf. This method does the same thing than the PersistenceManager.makePersistent(Object) method except the call to the bind to the POManagerItf to the current thread.

Specified by:
speedoMakePersistent in interface POManagerItf
Parameters:
sp - is the instance to make persistent.
map - is the context of the attachment process if any. If no attachment, it is null.
Returns:
TODO

speedoRefresh

public void speedoRefresh(PersistentObjectItf sp,
                          java.util.Map map,
                          java.util.Collection fgHints)
Specified by:
speedoRefresh in interface POManagerItf

speedoRetrieve

public void speedoRetrieve(PersistentObjectItf sp,
                           java.util.Map map,
                           java.util.Collection fgHints)
Specified by:
speedoRetrieve in interface POManagerItf