Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Development/JPA 2.0/entitymanager updates"
m |
|||
Line 5: | Line 5: | ||
In JPA 2.0 the specification extends EntityManager and Query APIs. New APIs have been added for getting supported properties and getting the owning Entity Manager Factory. | In JPA 2.0 the specification extends EntityManager and Query APIs. New APIs have been added for getting supported properties and getting the owning Entity Manager Factory. | ||
− | A new operation ' | + | A new operation 'detach' was also added including a new Cascade Type. Calling detach on an Entity allows the user to remove an Entity and cascaded related entities from the persistence context. Effectively an unregister call. |
See JPA 2.0 ED section 3.1.1 and 3.2.6 for details. | See JPA 2.0 ED section 3.1.1 and 3.2.6 for details. | ||
− | New methods are added to EM API in the latest spec. Here are the new methods that | + | New methods are added to EM API in the latest spec. Here are the new methods that are added to the latest specification: |
find(Class <T> entityClass, Object primaryKey, Map<String,Object> properties) | find(Class <T> entityClass, Object primaryKey, Map<String,Object> properties) | ||
Line 36: | Line 36: | ||
# public Map<String,Object> getProperties(); | # public Map<String,Object> getProperties(); | ||
# public Set<String> getSupportedProperties(); | # public Set<String> getSupportedProperties(); | ||
− | # public void | + | # public void detach(Object entity); |
# public <T> T unwrap(Class<T> cls); | # public <T> T unwrap(Class<T> cls); | ||
# public EntityManagerFactory getEntityManagerFactory(); | # public EntityManagerFactory getEntityManagerFactory(); | ||
# public LockModeType getLockMode(Object entity); | # public LockModeType getLockMode(Object entity); | ||
− | + | #find(Class <T> entityClass, Object primaryKey, Map<String,Object> properties) | |
+ | #refresh(Object entity, Map<String,Object> properties) | ||
+ | |||
+ | ==Implementation Details== | ||
Here are the implementation details described briefly of the 'getLockMode(Object entity)' method -- | Here are the implementation details described briefly of the 'getLockMode(Object entity)' method -- | ||
Line 48: | Line 51: | ||
following has to be checked to determine the lockmodetype- | following has to be checked to determine the lockmodetype- | ||
# OPTIMISTIC --- getOptimisticReadLockObjects() should contain the entity with boolean value 'false' | # OPTIMISTIC --- getOptimisticReadLockObjects() should contain the entity with boolean value 'false' | ||
− | # | + | # PESSIMISTIC_READ ---getPessimisticReadLockObjects() should contain the entity |
# OPTIMISTIC_FORCE_INCREMENT ---- getOptimisticReadLockObjects() should contain the entity with boolean value 'true' | # OPTIMISTIC_FORCE_INCREMENT ---- getOptimisticReadLockObjects() should contain the entity with boolean value 'true' | ||
#: and 'getPessimisticReadLockObjects()' should NOT contain the entity | #: and 'getPessimisticReadLockObjects()' should NOT contain the entity | ||
# PESSIMISTIC_FORCE_INCREMENT---getOptimisticReadLockObjects() should the entity with boolean value 'true' | # PESSIMISTIC_FORCE_INCREMENT---getOptimisticReadLockObjects() should the entity with boolean value 'true' | ||
#: and 'getPessimisticReadLockObjects()' should contain the entity. | #: and 'getPessimisticReadLockObjects()' should contain the entity. | ||
− | # NONE --- | + | # NONE |
+ | #READ --- It is same as OPTIMISTIC | ||
+ | #WRITE --- It is same as OPTIMISTIC_FORCE_INCREMENT | ||
+ | |||
As discussed , when getLockMode(entity) is called on an entity that is removed, it throws 'IllegalArgumentException.' This has been | As discussed , when getLockMode(entity) is called on an entity that is removed, it throws 'IllegalArgumentException.' This has been | ||
+ | |||
taken care by checking whether the entity is contained in the active unit of work or not. | taken care by checking whether the entity is contained in the active unit of work or not. | ||
+ | |||
+ | The new lockmode 'PESSIMISTIC_WRITE' is yet to be implemented. | ||
+ | |||
+ | 'getProperties()' method returns a unmodifiable Map of properties that the entity manager possess. | ||
+ | |||
+ | 'getSupportedProperties()' method returns all the properties that the entity manager can support irrespective of whether it is set or not. | ||
+ | |||
+ | Here are the list of supported properties in Entity Manager API: | ||
+ | |||
+ | #JOIN_EXISTING_TRANSACTION | ||
+ | #PERSISTENCE_CONTEXT_REFERENCE_MODE | ||
+ | #PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT | ||
+ | #PERSISTENCE_CONTEXT_PERSIST_ON_COMMIT | ||
+ | #PERSISTENCE_CONTEXT_FLUSH_MODE | ||
+ | #ORACLE_PROXY_TYPE | ||
+ | #EXCLUSIVE_CONNECTION_MODE | ||
+ | #EXCLUSIVE_CONNECTION_IS_LAZY | ||
+ | #JTA_DATASOURCE | ||
+ | #NON_JTA_DATASOURCE | ||
+ | #JDBC_DRIVER | ||
+ | #JDBC_URL | ||
+ | #JDBC_USER | ||
+ | #JDBC_PASSWORD | ||
+ | #CONNECTION_POLICY | ||
+ | #VALIDATE_EXISTENCE | ||
+ | #FLUSH_CLEAR_CACHE | ||
+ | |||
+ | 'unwrap(Class<T> cls)' unwraps the following classes : | ||
+ | #unwrapping UnitOfWork.class --- returns UnitOfWork | ||
+ | #unwrapping JpaEntityManager.class --- returns EntityManagerImpl | ||
+ | #unwrapping Session.class --- returns ServerSession | ||
+ | #unwrapping Connection.class --- returns Connection | ||
+ | |||
+ | unwrapping classes other than the above throws an persistence exception. | ||
+ | |||
+ | 'detach(Object entity)' throws an 'IllegalArgumentException' if null or a non-entity is passed as argument. 'detach(entity)' basically unregisters | ||
+ | |||
+ | the object from the unitofwork. It basically removes it from IdentityMapAccessor and also from the clone mapping. | ||
+ | |||
+ | Rest of the method implementations are quite straight-forward. |
Revision as of 14:35, 17 March 2009
Contents
Updated EntityManager / Query APIs
JPA 2.0 Root | Enhancement Request
Issue Summary
In JPA 2.0 the specification extends EntityManager and Query APIs. New APIs have been added for getting supported properties and getting the owning Entity Manager Factory.
A new operation 'detach' was also added including a new Cascade Type. Calling detach on an Entity allows the user to remove an Entity and cascaded related entities from the persistence context. Effectively an unregister call.
See JPA 2.0 ED section 3.1.1 and 3.2.6 for details.
New methods are added to EM API in the latest spec. Here are the new methods that are added to the latest specification:
find(Class <T> entityClass, Object primaryKey, Map<String,Object> properties)
refresh(Object entity, Map<String,Object> properties)
detach(Object entity)
setProperty(String propertyName,Object value)
General Solution
The implementation of this functionality should be straight forward.
Work Required
- Develop test for testing new non-pessimistic locking APIs
- approx 2 days
- Update Processing to
- approx 3 days - clear(Object entity)
- approx 2 days - remaining APIs
- approx 2 days - Query Hints
Work Completed
Implementation of the following functions have been completed so far in EM API Update
- public Map<String,Object> getProperties();
- public Set<String> getSupportedProperties();
- public void detach(Object entity);
- public <T> T unwrap(Class<T> cls);
- public EntityManagerFactory getEntityManagerFactory();
- public LockModeType getLockMode(Object entity);
- find(Class <T> entityClass, Object primaryKey, Map<String,Object> properties)
- refresh(Object entity, Map<String,Object> properties)
Implementation Details
Here are the implementation details described briefly of the 'getLockMode(Object entity)' method -- In EclipseLink, optimistically and pessimistically locked objects are tracked in 'getOptimisticReadLockObjects()' and 'getPessimisticReadLockObjects()' . The 'getOptimisticReadLockObjects()' returns a map that contains boolean as value . The 'getPessimisticReadLockObjects()' returns a map that contains an object as value. When an object is locked , the following has to be checked to determine the lockmodetype-
- OPTIMISTIC --- getOptimisticReadLockObjects() should contain the entity with boolean value 'false'
- PESSIMISTIC_READ ---getPessimisticReadLockObjects() should contain the entity
- OPTIMISTIC_FORCE_INCREMENT ---- getOptimisticReadLockObjects() should contain the entity with boolean value 'true'
- and 'getPessimisticReadLockObjects()' should NOT contain the entity
- PESSIMISTIC_FORCE_INCREMENT---getOptimisticReadLockObjects() should the entity with boolean value 'true'
- and 'getPessimisticReadLockObjects()' should contain the entity.
- NONE
- READ --- It is same as OPTIMISTIC
- WRITE --- It is same as OPTIMISTIC_FORCE_INCREMENT
As discussed , when getLockMode(entity) is called on an entity that is removed, it throws 'IllegalArgumentException.' This has been
taken care by checking whether the entity is contained in the active unit of work or not.
The new lockmode 'PESSIMISTIC_WRITE' is yet to be implemented.
'getProperties()' method returns a unmodifiable Map of properties that the entity manager possess.
'getSupportedProperties()' method returns all the properties that the entity manager can support irrespective of whether it is set or not.
Here are the list of supported properties in Entity Manager API:
- JOIN_EXISTING_TRANSACTION
- PERSISTENCE_CONTEXT_REFERENCE_MODE
- PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT
- PERSISTENCE_CONTEXT_PERSIST_ON_COMMIT
- PERSISTENCE_CONTEXT_FLUSH_MODE
- ORACLE_PROXY_TYPE
- EXCLUSIVE_CONNECTION_MODE
- EXCLUSIVE_CONNECTION_IS_LAZY
- JTA_DATASOURCE
- NON_JTA_DATASOURCE
- JDBC_DRIVER
- JDBC_URL
- JDBC_USER
- JDBC_PASSWORD
- CONNECTION_POLICY
- VALIDATE_EXISTENCE
- FLUSH_CLEAR_CACHE
'unwrap(Class<T> cls)' unwraps the following classes :
- unwrapping UnitOfWork.class --- returns UnitOfWork
- unwrapping JpaEntityManager.class --- returns EntityManagerImpl
- unwrapping Session.class --- returns ServerSession
- unwrapping Connection.class --- returns Connection
unwrapping classes other than the above throws an persistence exception.
'detach(Object entity)' throws an 'IllegalArgumentException' if null or a non-entity is passed as argument. 'detach(entity)' basically unregisters
the object from the unitofwork. It basically removes it from IdentityMapAccessor and also from the clone mapping.
Rest of the method implementations are quite straight-forward.