Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.jpa
Class ResourceLocalEntityManager

    java.lang.Object
      org.apache.cayenne.jpa.ResourceLocalEntityManager

All Implemented Interfaces:
  javax.persistence.EntityManager, CayenneEntityManager

Direct Known Subclasses:
  JtaEntityManager

    public class ResourceLocalEntityManager

extends Object
implements javax.persistence.EntityManager, CayenneEntityManager

Field Summary
`protected ObjectContext` | `context`
`protected ResourceLocalEntityManagerFactory` | `factory`
`protected javax.persistence.FlushModeType` | `flushMode`
`protected boolean` | `open`
`protected javax.persistence.EntityTransaction` | `transaction`

Constructor Summary
`ResourceLocalEntityManager(ObjectContext context, ResourceLocalEntityManagerFactory factory)`

Method Summary
`protected void` | `checkAttached(Object entity)` Checks if an entity is attached to the current EntityManager, throwing IllegalArgumentException if not.
`protected void` | `checkClosed()` Throws an exception if called on closed factory.
`protected void` | `checkNotRemoved(Object entity)` Checks if an entity is not removed in the current EntityManager, throwing IllegalArgumentException if it is.
`void` | `clear()` Clear the persistence context, causing all managed entities to become detached.
`void` | `close()` Close an application-managed EntityManager.
`boolean` | `contains(Object entity)` Check if the instance belongs to the current persistence context.
`javax.persistence.Query` | `createNamedQuery(String name)` Create an instance of Query for executing a named query (in EJB QL or native SQL).
`javax.persistence.Query` | `createNativeQuery(String sqlString)` Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
`javax.persistence.Query` | `createNativeQuery(String sqlString, Class resultClass)`
`javax.persistence.Query` | `createNativeQuery(String sqlString, String resultSetMapping)` Create an instance of Query for executing a native SQL query.
`javax.persistence.Query` | `createQuery(String ejbqlString)` Create an instance of Query for executing an EJB QL statement.
`
`<T> T`
` | `find(Class<T> entityClass, Object primaryKey)` Find by primary key.
`void` | `flush()` Synchronize the persistence context to the underlying database.
`DataChannel` | `getChannel()` Returns a DataChannel of the peer ObjectContext.
`Object` | `getDelegate()`
`protected ResourceLocalEntityManagerFactory` | `getFactory()` Returns parent EntityManagerFactory.
`javax.persistence.FlushModeType` | `getFlushMode()` Get the flush mode that applies to all objects contained in the persistence context.
`
`<T> T`
` | `getReference(Class<T> entityClass, Object primaryKey)` Get an instance, whose state may be lazily fetched.
`javax.persistence.EntityTransaction` | `getTransaction()` Return the resource-level transaction object.
`boolean` | `isOpen()`
`void` | `joinTransaction()` Indicates to the EntityManager that a JTA transaction is active.
`void` | `lock(Object entity, javax.persistence.LockModeType lockMode)`
`
`<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.
`void` | `refresh(Object entity)` Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
`void` | `remove(Object entity)` Remove the entity instance.
`void` | `setFlushMode(javax.persistence.FlushModeType flushMode)` Set the flush mode that applies to all objects contained in the persistence context.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### transaction

    protected javax.persistence.EntityTransaction transaction

### factory

    protected ResourceLocalEntityManagerFactory factory

### flushMode

    protected javax.persistence.FlushModeType flushMode

### open

    protected boolean open

### context

    protected ObjectContext context

Constructor Detail

### ResourceLocalEntityManager

    public ResourceLocalEntityManager(ObjectContext context,
                                      ResourceLocalEntityManagerFactory factory)

Method Detail

### getChannel

    public DataChannel getChannel()

  Returns a DataChannel of the peer ObjectContext.

  Specified by:
    `getChannel` in interface `CayenneEntityManager`

### getFactory

    protected ResourceLocalEntityManagerFactory getFactory()

  Returns parent EntityManagerFactory.

### close

    public void close()

  Close an application-managed EntityManager. After an EntityManager has been closed, all methods on the EntityManager instance will throw the IllegalStateException except for isOpen, which will return false. This method can only be called when the EntityManager is not associated with an active transaction.

  Specified by:
    `close` in interface `javax.persistence.EntityManager`
  Throws:
    `IllegalStateException` - if the EntityManager is associated with an active transaction or if the EntityManager is container-managed.

### isOpen

    public boolean isOpen()

  Specified by:
    `isOpen` in interface `javax.persistence.EntityManager`

### getDelegate

    public Object getDelegate()

  Specified by:
    `getDelegate` in interface `javax.persistence.EntityManager`

### persist

    public void persist(Object entity)

  Make an instance managed and persistent.

  Specified by:
    `persist` in interface `javax.persistence.EntityManager`
  Parameters:
    `entity` - an object to be made persistent
  Throws:
    `IllegalArgumentException` - if not an entity.

### merge

    public <T> T merge(T entity)

  Merge the state of the given entity into the current persistence context. Cayenne: Is this like localObject(s)?

  Specified by:
    `merge` in interface `javax.persistence.EntityManager`
  Parameters:
    `entity` -
  Returns:
    the instance that the state was merged to
  Throws:
    `IllegalArgumentException` - if instance is not an entity or is a removed entity

### remove

    public void remove(Object entity)

  Remove the entity instance.

  Specified by:
    `remove` in interface `javax.persistence.EntityManager`
  Parameters:
    `entity` -
  Throws:
    `IllegalArgumentException` - if not an entity or if a detached entity.

### find

    public <T> T find(Class<T> entityClass,
                      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:
    `IllegalArgumentException` - if the first argument does not denote an entity type or the second argument is not a valid type for that

### getReference

    public <T> T getReference(Class<T> entityClass,
                              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 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.

  Specified by:
    `getReference` in interface `javax.persistence.EntityManager`
  Parameters:
    `entityClass` -
    `primaryKey` -
  Returns:
    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
    `javax.persistence.EntityNotFoundException` - if the entity state cannot be accessed

### flush

    public void flush()

  Synchronize the persistence context to the underlying database.

  Specified by:
    `flush` in interface `javax.persistence.EntityManager`
  Throws:
    `javax.persistence.PersistenceException` - if the flush fails

### setFlushMode

    public void setFlushMode(javax.persistence.FlushModeType flushMode)

  Set the flush mode that applies to all objects contained in the persistence context.

  Specified by:
    `setFlushMode` in interface `javax.persistence.EntityManager`
  Parameters:
    `flushMode` -

### getFlushMode

    public javax.persistence.FlushModeType getFlushMode()

  Get the flush mode that applies to all objects contained in the persistence context.

  Specified by:
    `getFlushMode` in interface `javax.persistence.EntityManager`
  Returns:
    flushMode

### refresh

    public void refresh(Object entity)

  Refresh the state of the instance from the database, overwriting changes made to the entity, if any.

  Specified by:
    `refresh` in interface `javax.persistence.EntityManager`
  Parameters:
    `entity` -
  Throws:
    `IllegalArgumentException` - if not an entity or entity is not managed
    `javax.persistence.EntityNotFoundException` - if the entity no longer exists in the database

### clear

    public void clear()

  Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.

  Specified by:
    `clear` in interface `javax.persistence.EntityManager`

### contains

    public boolean contains(Object entity)

  Check if the instance belongs to the current persistence context.

  Specified by:
    `contains` in interface `javax.persistence.EntityManager`
  Throws:
    `IllegalArgumentException` - if not an entity

### createQuery

    public javax.persistence.Query createQuery(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:
    `IllegalArgumentException` - if query string is not valid

### createNamedQuery

    public javax.persistence.Query createNamedQuery(String name)

  Create an instance of Query for executing a named query (in 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:
    `IllegalArgumentException` - if a query has not been defined with the given name

### createNativeQuery

    public javax.persistence.Query createNativeQuery(String sqlString,
                                                     Class resultClass)

  Specified by:
    `createNativeQuery` in interface `javax.persistence.EntityManager`

### createNativeQuery

    public javax.persistence.Query createNativeQuery(String sqlString)

  Create an instance of Query for executing a native SQL statement, e.g., for update or delete.

  Specified by:
    `createNativeQuery` in interface `javax.persistence.EntityManager`
  Parameters:
    `sqlString` - a native SQL query string
  Returns:
    the new query instance

### createNativeQuery

    public javax.persistence.Query createNativeQuery(String sqlString,
                                                     String resultSetMapping)

  Create an instance of Query for executing a native SQL query.

  Specified by:
    `createNativeQuery` in interface `javax.persistence.EntityManager`
  Parameters:
    `sqlString` - a native SQL query string
    `resultSetMapping` - the name of the result set mapping
  Returns:
    the new query instance

### joinTransaction

    public void joinTransaction()

  Indicates to the EntityManager that a JTA transaction is active. This method should be called on a JTA application managed EntityManager that was created outside the scope of the active transaction to associate it with the current JTA transaction.

  This implementation throws a JpaProviderException, as it only supports resource-local operation.

  Specified by:
    `joinTransaction` in interface `javax.persistence.EntityManager`
  Throws:
    `JpaProviderException` - as this impementation only supports resource-local operation.

### lock

    public void lock(Object entity,
                     javax.persistence.LockModeType lockMode)

  Specified by:
    `lock` in interface `javax.persistence.EntityManager`

### getTransaction

    public javax.persistence.EntityTransaction getTransaction()

  Return the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.

  Specified by:
    `getTransaction` in interface `javax.persistence.EntityManager`
  Returns:
    EntityTransaction instance

### checkAttached

    protected void checkAttached(Object entity)
                          throws IllegalArgumentException

  Checks if an entity is attached to the current EntityManager, throwing IllegalArgumentException if not.

  Throws:
    `IllegalArgumentException`

### checkNotRemoved

    protected void checkNotRemoved(Object entity)
                            throws IllegalArgumentException

  Checks if an entity is not removed in the current EntityManager, throwing IllegalArgumentException if it is.

  Throws:
    `IllegalArgumentException`

### checkClosed

    protected void checkClosed()
                        throws IllegalStateException

  Throws an exception if called on closed factory.

  Throws:
    `IllegalStateException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2008 Apache Cayenne. All Rights Reserved.