FileDocCategorySizeDatePackage
EntityManagerImpl.javaAPI DocGlassfish v2 API13343Tue May 22 16:54:24 BST 2007oracle.toplink.essentials.internal.ejb.cmp3

EntityManagerImpl

public class EntityManagerImpl extends EntityManagerImpl implements EntityManager

Purpose: Contains the implementation of the EntityManager.

Description: This class provides the implementation for the combined TopLink and EJB3.0 EntityManager class.

Responsibilities:It is responcible for tracking transaction state and the objects within that transaction.

see
javax.persistence.EntityManager
see
oracle.toplink.essentials.ejb.cmp3.EntityManager

Fields Summary
private FlushModeType
flushMode
Constructors Summary
public EntityManagerImpl(String sessionName, boolean propagatePersistenceContext, boolean extended)
Constructor returns an EntityManager assigned to the a particular ServerSession.

param
sessionName the ServerSession name that should be used. This constructor can potentially throw TopLink exceptions regarding the existence, or errors with the specified session.

        super(sessionName, propagatePersistenceContext, extended);
        flushMode = FlushModeType.AUTO;
    
public EntityManagerImpl(ServerSession serverSession, boolean propagatePersistenceContext, boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager

param
serverSession the serverSession assigned to this deployment.

        this(serverSession, null, propagatePersistenceContext, extended);
    
public EntityManagerImpl(ServerSession serverSession, Map properties, boolean propagePersistenceContext, boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager

param
serverSession the serverSession assigned to this deployment. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented

        super(serverSession, properties, propagePersistenceContext, extended);
        flushMode = FlushModeType.AUTO;
    
public EntityManagerImpl(EntityManagerFactoryImpl factory, Map properties, boolean propagePersistenceContext, boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager

param
factory the EntityMangerFactoryImpl that created this entity manager. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented

        super(factory, properties, propagePersistenceContext, extended);
        flushMode = FlushModeType.AUTO;
    
Methods Summary
public javax.persistence.QuerycreateNamedQuery(java.lang.String name)
Create an instance of Query for executing a named query (in EJBQL or native SQL).

param
name the name of a query defined in metadata
return
the new query instance

        try {
            verifyOpen();
            return new EJBQueryImpl(name, this, true);
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
	
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString)
Create an instance of Query for executing a native SQL query.

param
sqlString a native SQL query string
return
the new query instance

        try {
            verifyOpen();
            return new EJBQueryImpl( EJBQueryImpl.buildSQLDatabaseQuery( sqlString, false), this );
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
	
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString, java.lang.Class resultType)
This method is used to create a query using SQL. The class, must be the expected return type.

        try {
            verifyOpen();
            DatabaseQuery query = createNativeQueryInternal(sqlString, resultType);
            return new EJBQueryImpl(query, this);
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
Create an instance of Query for executing a native SQL query.

param
sqlString a native SQL query string
param
resultSetMapping the name of the result set mapping
return
the new query instance
throws
IllegalArgumentException if query string is not valid

        try {
            verifyOpen();
            ResultSetMappingQuery query = new ResultSetMappingQuery();
            query.setSQLResultSetMappingName(resultSetMapping);
            query.setSQLString(sqlString);
            query.setIsUserDefined(true);
            return new EJBQueryImpl(query, this);
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public javax.persistence.QuerycreateQuery(oracle.toplink.essentials.expressions.Expression expression, java.lang.Class resultType)
This method is used to create a query using a Toplink Expression and the return type.

        try {
            verifyOpen();
            DatabaseQuery query = createQueryInternal(expression, resultType);
            return new EJBQueryImpl(query, this);
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public javax.persistence.QuerycreateQuery(java.lang.String ejbqlString)
Create an instance of Query for executing an EJBQL query.

param
ejbqlString an EJBQL query string
return
the new query instance

    
        try {
            verifyOpen();
            
            EJBQueryImpl ejbqImpl;
            
            try
            {
                ejbqImpl = new EJBQueryImpl(ejbqlString, this);    
            }
            
            catch(EJBQLException ex)
            {            
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("wrap_ejbql_exception"), ex);            
            }
            
            return ejbqImpl;
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
	
public Tfind(java.lang.Class entityClass, java.lang.Object primaryKey)
Find by primary key.

param
entityClass
param
primaryKey
return
the found entity instance or null if the entity does not exist
throws
IllegalArgumentException if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key

        try {
            verifyOpen();
            return (T) findInternal(entityClass, primaryKey);
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
	
public javax.persistence.FlushModeTypegetFlushMode()
Get the flush mode that applies to all objects contained in the persistence context.

return
flushMode

        try {
            verifyOpen();
            return flushMode;
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public TgetReference(java.lang.Class entityClass, java.lang.Object primaryKey)
Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The container is permitted to throw EntityNotFoundException when get 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.

param
entityClass
param
primaryKey
return
the found entity instance
throws
IllegalArgumentException if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key
throws
EntityNotFoundException if the entity state cannot be accessed

        try {
            verifyOpen();
            Object returnValue = findInternal(entityClass, primaryKey);
            if (returnValue ==null){
                Object[] o = {primaryKey};
                String message = ExceptionLocalization.buildMessage("no_entities_retrieved_for_get_reference", o);
                throw new javax.persistence.EntityNotFoundException(message);
            }
            return (T)returnValue;
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public javax.persistence.EntityTransactiongetTransaction()
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.

return
EntityTransaction instance
throws
IllegalStateException if invoked on a JTA EntityManager.

        try {
            return ((TransactionWrapper)transaction).getTransaction();
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
public booleanisFlushModeAUTO()
Internal method. Indicates whether flushMode is AUTO.

return
boolean

        return flushMode == FlushModeType.AUTO;    
    
public Tmerge(T entity)
Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.

param
entity
return
the instance that the state was merged to

        try{
            verifyOpen();
            return (T) mergeInternal(entity);
        }catch (RuntimeException e){
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
	
protected voidsetEntityTransactionWrapper()

   
        transaction = new EntityTransactionWrapper(this);
    
public voidsetFlushMode(javax.persistence.FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context.

param
flushMode

        try {
            verifyOpen();
            this.flushMode = flushMode;
        } catch (RuntimeException e) {
            this.transaction.setRollbackOnlyInternal();
            throw e;
        }
    
protected voidsetJTATransactionWrapper()

        transaction = new JTATransactionWrapper(this);