Methods Summary |
---|
private javax.persistence.EntityManager | _getDelegate()
// Populate any transient objects the first time
// this method is called.
if( entityManagerFactory == null ) {
init();
}
EntityManager delegate = null;
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if( contextType == PersistenceContextType.TRANSACTION ) {
J2EETransaction tx = null;
try {
tx = (J2EETransaction) txManager.getTransaction();
} catch(Exception e) {
throw new IllegalStateException("exception retrieving tx", e);
}
if( tx != null ) {
// If there is an active extended persistence context
// for the same entity manager factory and the same tx,
// it takes precendence.
delegate = tx.getExtendedEntityManager(entityManagerFactory);
if( delegate == null ) {
delegate = tx.getTxEntityManager(entityManagerFactory);
if( delegate == null ) {
// If there is a transaction and this is the first
// access of the wrapped entity manager, create an
// actual entity manager and associate it with the
// entity manager factory.
delegate = entityManagerFactory.
createEntityManager(emProperties);
tx.addTxEntityManagerMapping(entityManagerFactory,
delegate);
}
}
} else {
nonTxEntityManager = entityManagerFactory.createEntityManager
(emProperties);
// Return a new non-transactional entity manager.
delegate = nonTxEntityManager;
}
} else {
// EXTENDED Persitence Context
if( extendedEntityManager == null ) {
extendedEntityManager = containerFactory.
lookupExtendedEntityManager(entityManagerFactory);
}
delegate = extendedEntityManager;
}
if( _logger.isLoggable(Level.FINE) ) {
_logger.fine("In EntityManagerWrapper::_getDelegate(). " +
"Logical entity manager = " + this);
_logger.fine("Physical entity manager = " + delegate);
}
return delegate;
|
private void | cleanupNonTxEntityManager()
if( nonTxEntityManager != null ) {
nonTxEntityManager.close();
nonTxEntityManager = null;
}
|
public void | clear()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CLEAR);
}
_getDelegate().clear();
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
public void | close()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CLOSE);
callFlowAgent.entityManagerMethodEnd();
}
// close() not allowed on container-managed EMs.
throw new IllegalStateException();
|
public boolean | contains(java.lang.Object entity)
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CONTAINS);
}
EntityManager delegate = _getDelegate();
return delegate.contains(entity);
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
public javax.persistence.Query | createNamedQuery(java.lang.String name)
Query returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CREATE_NAMED_QUERY);
}
EntityManager delegate = _getDelegate();
returnValue = delegate.createNamedQuery(name);
if( nonTxEntityManager != null ) {
Query queryDelegate = returnValue;
returnValue = QueryWrapper.createNamedQueryWrapper
(entityManagerFactory, emProperties, delegate,
queryDelegate, name);
// It's now the responsibility of the QueryWrapper to
// close the non-tx EM delegate
nonTxEntityManager = null;
}
} catch(RuntimeException re) {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
throw re;
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public javax.persistence.Query | createNativeQuery(java.lang.String sqlString)
Query returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CREATE_NATIVE_QUERY_STRING);
}
EntityManager delegate = _getDelegate();
returnValue = delegate.createNativeQuery(sqlString);
if( nonTxEntityManager != null ) {
Query queryDelegate = returnValue;
returnValue = QueryWrapper.createNativeQueryWrapper
(entityManagerFactory, emProperties, delegate,
queryDelegate, sqlString);
// It's now the responsibility of the QueryWrapper to
// close the non-tx EM delegate
nonTxEntityManager = null;
}
} catch(RuntimeException re) {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
throw re;
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public javax.persistence.Query | createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
Query returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CREATE_NATIVE_QUERY_STRING_CLASS);
}
EntityManager delegate = _getDelegate();
returnValue = delegate.createNativeQuery(sqlString, resultClass);
if( nonTxEntityManager != null ) {
Query queryDelegate = returnValue;
returnValue = QueryWrapper.createNativeQueryWrapper
(entityManagerFactory, emProperties, delegate,
queryDelegate, sqlString, resultClass);
// It's now the responsibility of the QueryWrapper to
// close the non-tx EM delegate
nonTxEntityManager = null;
}
} catch(RuntimeException re) {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
throw re;
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public javax.persistence.Query | createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
Query returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CREATE_NATIVE_QUERY_STRING_STRING);
}
EntityManager delegate = _getDelegate();
returnValue = delegate.createNativeQuery
(sqlString, resultSetMapping);
if( nonTxEntityManager != null ) {
Query queryDelegate = returnValue;
returnValue = QueryWrapper.createNativeQueryWrapper
(entityManagerFactory, emProperties, delegate,
queryDelegate, sqlString, resultSetMapping);
// It's now the responsibility of the QueryWrapper to
// close the non-tx EM delegate
nonTxEntityManager = null;
}
} catch(RuntimeException re) {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
throw re;
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public javax.persistence.Query | createQuery(java.lang.String ejbqlString)
Query returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.CREATE_QUERY);
}
EntityManager delegate = _getDelegate();
returnValue = delegate.createQuery(ejbqlString);
if( nonTxEntityManager != null ) {
Query queryDelegate = returnValue;
returnValue = QueryWrapper.createQueryWrapper
(entityManagerFactory, emProperties, delegate,
queryDelegate, ejbqlString);
// It's now the responsibility of the QueryWrapper to
// close the non-tx EM delegate
nonTxEntityManager = null;
}
} catch(RuntimeException re) {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
throw re;
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
private void | doTransactionScopedTxCheck()
if( contextType != PersistenceContextType.TRANSACTION) {
return;
}
doTxRequiredCheck();
|
private void | doTxRequiredCheck()
if( entityManagerFactory == null ) {
init();
}
J2EETransaction tx = null;
try {
tx = (J2EETransaction) txManager.getTransaction();
} catch(Exception e) {
throw new IllegalStateException("exception retrieving tx", e);
}
if( tx == null ) {
throw new TransactionRequiredException();
}
|
public T | find(java.lang.Class entityClass, java.lang.Object primaryKey)
T returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.FIND);
}
returnValue = _getDelegate().find(entityClass, primaryKey);
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public void | flush()
// tx is ALWAYS required, regardless of persistence context type.
doTxRequiredCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.FLUSH);
}
_getDelegate().flush();
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
// tx is required so there's no need to do any non-tx cleanup
|
public java.lang.Object | getDelegate()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.GET_DELEGATE);
}
return _getDelegate();
} finally {
if( nonTxEntityManager != null ) {
// In this case we can't close the physical EntityManager
// before returning it to the application, so we just clear
// the EM wrapper's reference to it.
nonTxEntityManager = null;
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
public javax.persistence.FlushModeType | getFlushMode()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.GET_FLUSH_MODE);
}
return _getDelegate().getFlushMode();
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
public T | getReference(java.lang.Class entityClass, java.lang.Object primaryKey)
T returnValue = null;
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.GET_REFERENCE);
}
returnValue = _getDelegate().getReference(entityClass, primaryKey);
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
return returnValue;
|
public javax.persistence.EntityTransaction | getTransaction()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.GET_TRANSACTION);
}
return _getDelegate().getTransaction();
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
private void | init()
entityManagerFactory = EntityManagerFactoryWrapper.
lookupEntityManagerFactory(unitName);
if( entityManagerFactory == null ) {
throw new IllegalStateException
("Unable to retrieve EntityManagerFactory for unitName "
+ unitName);
}
txManager = Switch.getSwitch().getTransactionManager();
containerFactory = Switch.getSwitch().getContainerFactory();
|
public boolean | isOpen()
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.IS_OPEN);
callFlowAgent.entityManagerMethodEnd();
}
// Not relevant for container-managed EMs. Just return true.
return true;
|
public void | joinTransaction()
// Doesn't apply to the container-managed case, but all the
// spec says is that an exception should be thrown if called
// without a tx.
doTxRequiredCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.JOIN_TRANSACTION);
callFlowAgent.entityManagerMethodEnd();
}
// There's no point in calling anything on the physical
// entity manager since in all tx cases it will be
// correctly associated with a tx already.
|
public void | lock(java.lang.Object entity, javax.persistence.LockModeType lockMode)
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.LOCK);
}
_getDelegate().lock(entity, lockMode);
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|
public T | merge(T entity)
doTransactionScopedTxCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.MERGE);
}
return _getDelegate().merge(entity);
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
// tx is required so there's no need to do any non-tx cleanup
|
public void | persist(java.lang.Object entity)
doTransactionScopedTxCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.PERSIST);
}
_getDelegate().persist(entity);
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
// tx is required so there's no need to do any non-tx cleanup
|
public void | refresh(java.lang.Object entity)
doTransactionScopedTxCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.REFRESH);
}
_getDelegate().refresh(entity);
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
// tx is required so there's no need to do any non-tx cleanup
|
public void | remove(java.lang.Object entity)
doTransactionScopedTxCheck();
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.REMOVE);
}
_getDelegate().remove(entity);
} finally {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
// tx is required so there's no need to do any non-tx cleanup
|
public void | setFlushMode(javax.persistence.FlushModeType flushMode)
Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
try {
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodStart(EntityManagerMethod.SET_FLUSH_MODE);
}
_getDelegate().setFlushMode(flushMode);
} finally {
if( nonTxEntityManager != null ) {
cleanupNonTxEntityManager();
}
if(callFlowAgent.isEnabled()) {
callFlowAgent.entityManagerMethodEnd();
}
}
|