项目:spring4-understanding
文件:ApplicationManagedEntityManagerIntegrationTests.java
public void testCannotFlushWithoutGettingTransaction() {
EntityManager em = entityManagerFactory.createEntityManager();
try {
doInstantiateAndSave(em);
fail("Should have thrown TransactionrequiredException");
}
catch (TransactionrequiredException ex) {
// expected
}
// Todo following lines are a workaround for Hibernate bug
// If Hibernate throws an exception due to flush(),// it actually HAS flushed,meaning that the database
// was updated outside the transaction
deleteallPeopleUsingEntityManager(sharedEntityManager);
setComplete();
}
项目:cibet
文件:Controllable.java
/**
* releases an event on a JPA resource. If it is the second release of a 6-eyes process the controlled object entry
* is updated. If it is a 4-eyes process the real object is updated.
*
* @param entityManager
* EntityManager for performing the release. Could be null in case of a INVOKE event. If JDBC,use new
* JdbcBridgeEntityManager(connection)
* @param remark
* comment
* @throws ResourceApplyException
* if the release action fails.
*/
@CibetContext
public Object release(EntityManager entityManager,String remark) throws ResourceApplyException {
log.debug("start release");
if (entityManager != null) {
if ((entityManager instanceof CEntityManager && ((CEntityManager) entityManager).supportsTransactions()
|| !(entityManager instanceof CEntityManager)) && !entityManager.isJoinedToTransaction()) {
String err = "release method must be called within a transaction boundary";
log.error(err);
throw new TransactionrequiredException(err);
}
Context.internalRequestScope().setApplicationEntityManager(entityManager);
}
if (getExecutionStatus() != ExecutionStatus.SCHEDULED) {
Context.internalRequestScope().setScheduledDate(getScheduledDate());
}
DcActuator dc = (DcActuator) Configuration.instance().getActuator(getActuator());
Object obj = dc.release(this,remark);
return obj;
}
项目:cibet
文件:ActuatorIT.java
@Test
public void releasepersistNoTransaction() throws Exception {
log.info("start releasepersistNoTransaction()");
List<String> schemes = new ArrayList<String>();
schemes.add(FourEyesActuator.DEFAULTNAME);
registerSetpoint(TEntity.class.getName(),schemes,ControlEvent.INSERT,ControlEvent.RELEASE);
Context.requestScope().setRemark("created");
TEntity ent = createTEntity(12,"Hirsch");
persist(ent);
Assert.assertEquals(0,ent.getId());
List<Controllable> l = DcLoader.findUnreleased();
Assert.assertEquals(1,l.size());
Controllable co = l.get(0);
Assert.assertEquals("created",co.getCreateRemark());
Context.sessionScope().setUser("tester2");
try {
co.release(applEman,"blabla");
Assert.fail();
} catch (TransactionrequiredException e) {
}
}
项目:cibet
文件:DcManagerImplIntegrationTest.java
@Test
public void releasePersistNoTransaction() throws Exception {
log.info("start releasePersistNoTransaction()");
registerSetpoint(TEntity.class,FourEyesActuator.DEFAULTNAME,ControlEvent.RELEASE);
Context.requestScope().setRemark("created");
TEntity ent = persistTEntity();
Assert.assertEquals(0,co.getCreateRemark());
Context.sessionScope().setUser("test2");
applEman.getTransaction().commit();
try {
co.release(applEman,null);
Assert.fail();
} catch (TransactionrequiredException e) {
}
applEman.getTransaction().begin();
}
项目:class-guard
文件:ApplicationManagedEntityManagerIntegrationTests.java
public void testCannotFlushWithoutGettingTransaction() {
EntityManager em = entityManagerFactory.createEntityManager();
try {
doInstantiateAndSave(em);
fail("Should have thrown TransactionrequiredException");
}
catch (TransactionrequiredException ex) {
// expected
}
// Todo following lines are a workaround for Hibernate bug
// If Hibernate throws an exception due to flush(),meaning that the database
// was updated outside the transaction
deleteallPeopleUsingEntityManager(sharedEntityManager);
setComplete();
}
项目:tomee
文件:JtaEntityManagerRegistry.java
private void transactionStarted(final InstanceId instanceId) {
if (instanceId == null) {
throw new NullPointerException("instanceId is null");
}
if (!isTransactionActive()) {
throw new TransactionrequiredException();
}
final Map<EntityManagerFactory,EntityManagerTracker> entityManagers = entityManagersByDeploymentId.get(instanceId);
if (entityManagers == null) {
return;
}
for (final Map.Entry<EntityManagerFactory,EntityManagerTracker> entry : entityManagers.entrySet()) {
final EntityManagerFactory entityManagerFactory = entry.getKey();
final EntityManagerTracker value = entry.getValue();
final EntityManager entityManager = value.getEntityManager();
if (value.autoJoinTx) {
entityManager.joinTransaction();
}
final EntityManagerTxKey txKey = new EntityManagerTxKey(entityManagerFactory);
transactionRegistry.putResource(txKey,entityManager);
}
}
项目:lams
文件:ExtendedEntityManagerCreator.java
/**
* Join an existing transaction,if not already joined.
* @param enforce whether to enforce the transaction
* (i.e. whether failure to join is considered fatal)
*/
private void doJoinTransaction(boolean enforce) {
if (this.jta) {
// Let's try whether we're in a JTA transaction.
try {
this.target.joinTransaction();
logger.debug("Joined JTA transaction");
}
catch (TransactionrequiredException ex) {
if (!enforce) {
logger.debug("No JTA transaction to join: " + ex);
}
else {
throw ex;
}
}
}
else {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
if (!TransactionSynchronizationManager.hasResource(this.target) &&
!this.target.getTransaction().isActive()) {
enlistInCurrentTransaction();
}
logger.debug("Joined local transaction");
}
else {
if (!enforce) {
logger.debug("No local transaction to join");
}
else {
throw new TransactionrequiredException("No local transaction to join");
}
}
}
}
项目:spring4-understanding
文件:ExtendedEntityManagerCreator.java
/**
* Join an existing transaction,if not already joined.
* @param enforce whether to enforce the transaction
* (i.e. whether failure to join is considered fatal)
*/
private void doJoinTransaction(boolean enforce) {
if (this.jta) {
// Let's try whether we're in a JTA transaction.
try {
this.target.joinTransaction();
logger.debug("Joined JTA transaction");
}
catch (TransactionrequiredException ex) {
if (!enforce) {
logger.debug("No JTA transaction to join: " + ex);
}
else {
throw ex;
}
}
}
else {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
if (!TransactionSynchronizationManager.hasResource(this.target) &&
!this.target.getTransaction().isActive()) {
enlistInCurrentTransaction();
}
logger.debug("Joined local transaction");
}
else {
if (!enforce) {
logger.debug("No local transaction to join");
}
else {
throw new TransactionrequiredException("No local transaction to join");
}
}
}
}
项目:spring4-understanding
文件:EntityManagerFactoryUtilsTests.java
@Test
@SuppressWarnings("serial")
public void testConvertJpaPersistenceException() {
EntityNotFoundException entityNotFound = new EntityNotFoundException();
assertSame(JpaObjectRetrievalFailureException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityNotFound).getClass());
noresultException noresult = new noresultException();
assertSame(EmptyResultDataAccessException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(noresult).getClass());
NonUniqueResultException nonUniqueResult = new NonUniqueResultException();
assertSame(IncorrectResultSizeDataAccessException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass());
OptimisticLockException optimisticLock = new OptimisticLockException();
assertSame(JpaOptimisticLockingFailureException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass());
EntityExistsException entityExists = new EntityExistsException("foo");
assertSame(DataIntegrityViolationException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityExists).getClass());
TransactionrequiredException transactionrequired = new TransactionrequiredException("foo");
assertSame(InvalidDataAccessApiUsageException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(transactionrequired).getClass());
PersistenceException unkNown = new PersistenceException() {
};
assertSame(JpaSystemException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unkNown).getClass());
}
项目:spring4-understanding
文件:ContainerManagedEntityManagerIntegrationTests.java
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
try {
createContainerManagedEntityManager().joinTransaction();
fail("Should have thrown a TransactionrequiredException");
}
catch (TransactionrequiredException e) {
/* expected */
}
}
/**
* Return the EntityManager instance for persistence of the Cibet entities.
*
* @return
* @throws CibetException
* if no EntityManager set in CibetContext
*/
@Override
public EntityManager getorCreateEntityManager(boolean transacted) {
EntityManager manager = (EntityManager) getProperty(CIBET_ENTITYMANAGER);
if (manager == null) {
manager = Context.getorCreateEntityManagers();
if (manager == null) {
throw new CibetException("No Cibet EntityManager set in CibetContext");
}
}
if (log.isDebugEnabled()) {
log.debug("get Cibet EntityManager from CibetContext: " + manager);
}
EntityManagerType emType = (EntityManagerType) getProperty(ENTITYMANAGER_TYPE);
if (EntityManagerType.JTA == emType) {
try {
manager.joinTransaction();
log.debug("... and join JTA transaction");
} catch (TransactionrequiredException e) {
log.info("... but cannot join transaction: " + e.getMessage());
}
}
if (transacted && manager instanceof CEntityManager && ((CEntityManager) manager).supportsTransactions()
&& !manager.isJoinedToTransaction()) {
throw new TransactionrequiredException();
}
return manager;
}
项目:flowable-engine
文件:EntityManagerSessionImpl.java
@Override
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive())) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new FlowableException("Error while flushing EntityManager,illegal state",ise);
} catch (TransactionrequiredException tre) {
throw new FlowableException("Cannot flush EntityManager,an active transaction is required",tre);
} catch (PersistenceException pe) {
throw new FlowableException("Error while flushing EntityManager: " + pe.getMessage(),pe);
}
}
}
项目:flowable-engine
文件:EntityManagerSessionImpl.java
@Override
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive())) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while flushing EntityManager,ise);
} catch (TransactionrequiredException tre) {
throw new ActivitiException("Cannot flush EntityManager,tre);
} catch (PersistenceException pe) {
throw new ActivitiException("Error while flushing EntityManager: " + pe.getMessage(),pe);
}
}
}
项目:hopsworks
文件:UsersController.java
public void updateStatus(Users id,PeopleAccountStatus stat) throws ApplicationException {
id.setStatus(stat);
try {
userFacade.update(id);
} catch (TransactionrequiredException ex) {
throw new ApplicationException("Need a transaction to update the user status");
}
}
项目:SecureBPMN
文件:EntityManagerSessionImpl.java
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive()) ) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while flushing EntityManager,ise);
} catch (TransactionrequiredException tre) {
throw new ActivitiException("Cannot flush EntityManager,tre);
} catch (PersistenceException pe) {
throw new ActivitiException("Error while flushing EntityManager: " + pe.getMessage(),pe);
}
}
}
/**
* Register an entity manager with a transaction manager.
*
* @param manager The entity manager to register,which is a non-proxy one
* @param local The thread local that maintains the entity managers for the varIoUs threads
* @param transactionManager The transaction manager to register with
*/
private static void registerEntityManagerUnkNown(EntityManager manager,final ThreadLocal<EntityManager> local,final TransactionManager transactionManager) throws Exception {
try {
manager.joinTransaction();
Synchronization sync = new JTASynchronization(manager,local);
transactionManager.getTransaction().registerSynchronization(sync);
} catch (TransactionrequiredException exc) {
registerEntityManagerResourceLocal(manager,local,transactionManager);
}
}
项目:class-guard
文件:ExtendedEntityManagerCreator.java
/**
* Join an existing transaction,if not already joined.
* @param enforce whether to enforce the transaction
* (i.e. whether failure to join is considered fatal)
*/
private void doJoinTransaction(boolean enforce) {
if (this.jta) {
// Let's try whether we're in a JTA transaction.
try {
this.target.joinTransaction();
logger.debug("Joined JTA transaction");
}
catch (TransactionrequiredException ex) {
if (!enforce) {
logger.debug("No JTA transaction to join: " + ex);
}
else {
throw ex;
}
}
}
else {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
if (!TransactionSynchronizationManager.hasResource(this.target) &&
!this.target.getTransaction().isActive()) {
enlistInCurrentTransaction();
}
logger.debug("Joined local transaction");
}
else {
if (!enforce) {
logger.debug("No local transaction to join");
}
else {
throw new TransactionrequiredException("No local transaction to join");
}
}
}
}
项目:class-guard
文件:EntityManagerFactoryUtilsTests.java
@Test
@SuppressWarnings("serial")
public void testConvertJpaPersistenceException() {
EntityNotFoundException entityNotFound = new EntityNotFoundException();
assertSame(JpaObjectRetrievalFailureException.class,EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unkNown).getClass());
}
项目:FiWare-Template-Handler
文件:EntityManagerSessionImpl.java
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive()) ) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while flushing EntityManager,pe);
}
}
}
项目:exportlibrary
文件:TrackerSerializer.java
public Long serializeProcedureSubmissionSet(long trackerID,Calendar submissionDate,String submissionFilename) throws JAXBException,FileNotFoundException,IllegalStateException,EntityExistsException,IllegalArgumentException,TransactionrequiredException,XMLloadingException,IOException {
this.submissionset = new SubmissionSet();
this.submission = new Submission();
this.submissionset.getSubmission().add(this.submission);
this.submission.setTrackerID(trackerID);
this.submission.setSubmissionDate(submissionDate);
this.loadProcedureResults(submissionFilename);
return this.serializeSubmissionSet();
}
项目:exportlibrary
文件:TrackerSerializer.java
public Long serializeSpecimenSubmissionSet(long trackerID,IOException {
this.submissionset = new SubmissionSet();
this.submission = new Submission();
this.submissionset.getSubmission().add(this.submission);
this.submission.setTrackerID(trackerID);
this.submission.setSubmissionDate(submissionDate);
this.loadSpecimens(submissionFilename);
return this.serializeSubmissionSet();
}
项目:exportlibrary
文件:Serializer.java
public void serialize(T object,Class<T> clazz) throws JAXBException,RuntimeException,Exception {
if (toXml) {
if (Connector.validType(clazz)) {
this.marshall(object);
} else {
logger.error("class {} cannot be serializeda as a xml document");
throw new Exception("class " + clazz.getName() + "cannot be serializeda as a xml document");
}
} else {
this.persist(object);
}
}
项目:fuwesta
文件:UserServiceImplControllerTest.java
/**
* Reset entity-Manager this should fail (no-transaction),but to be sure.
*/
private void resetEntityManager() {
try {
em.clear();
} catch (TransactionrequiredException e) {
// expected.
}
}
项目:xbpm5
文件:EntityManagerSessionImpl.java
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive()) ) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while flushing EntityManager,pe);
}
}
}
项目:camunda-bpm-platform
文件:EntityManagerSessionImpl.java
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive()) ) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ProcessEngineException("Error while flushing EntityManager,ise);
} catch (TransactionrequiredException tre) {
throw new ProcessEngineException("Cannot flush EntityManager,tre);
} catch (PersistenceException pe) {
throw new ProcessEngineException("Error while flushing EntityManager: " + pe.getMessage(),pe);
}
}
}
项目:lams
文件:EntityManagerFactoryUtils.java
/**
* Convert the given runtime exception to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* Return null if no translation is appropriate: any other exception may
* have resulted from user code,and should not be translated.
* <p>The most important cases like object not found or optimistic locking failure
* are covered here. For more fine-granular conversion,JpaTransactionManager etc
* support sophisticated translation of exceptions via a JpaDialect.
* @param ex runtime exception that occurred
* @return the corresponding DataAccessException instance,* or {@code null} if the exception should not be translated
*/
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
// Following the JPA specification,a persistence provider can also
// throw these two exceptions,besides PersistenceException.
if (ex instanceof IllegalStateException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
if (ex instanceof IllegalArgumentException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
// Check for well-kNown PersistenceException subclasses.
if (ex instanceof EntityNotFoundException) {
return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
}
if (ex instanceof noresultException) {
return new EmptyResultDataAccessException(ex.getMessage(),1,ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(),ex);
}
if (ex instanceof QueryTimeoutException) {
return new org.springframework.dao.QueryTimeoutException(ex.getMessage(),ex);
}
if (ex instanceof LockTimeoutException) {
return new CannotAcquireLockException(ex.getMessage(),ex);
}
if (ex instanceof pessimisticLockException) {
return new pessimisticLockingFailureException(ex.getMessage(),ex);
}
if (ex instanceof OptimisticLockException) {
return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
}
if (ex instanceof EntityExistsException) {
return new DataIntegrityViolationException(ex.getMessage(),ex);
}
if (ex instanceof TransactionrequiredException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
// If we have another kind of PersistenceException,throw it.
if (ex instanceof PersistenceException) {
return new JpaSystemException((PersistenceException) ex);
}
// If we get here,we have an exception that resulted from user code,// rather than the persistence provider,so we return null to indicate
// that translation should not occur.
return null;
}
项目:spring4-understanding
文件:EntityManagerFactoryUtils.java
/**
* Convert the given runtime exception to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* Return null if no translation is appropriate: any other exception may
* have resulted from user code,so we return null to indicate
// that translation should not occur.
return null;
}
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:spring4-understanding
文件:SharedEntityManagerCreatorTests.java
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactory.java
@Override
public Object invoke(Object proxy,Method method,Object[] args) throws Throwable {
switch (method.getName()) {
case "equals":
// Only consider equal when proxies are identical.
return (proxy == args[0]);
case "hashCode":
// Use hashCode of EntityManager proxy.
return hashCode();
case "unwrap":
// JPA 2.0: handle unwrap method - Could be a proxy match.
Class<?> targetClass = (Class<?>) args[0];
if (targetClass == null) {
return currentEntityManager();
} else if (targetClass.isinstance(proxy)) {
return proxy;
}
break;
case "isOpen":
// Handle isOpen method: always return true.
return true;
case "close":
// Handle close method: suppress,not valid.
return null;
case "getTransaction":
throw new IllegalStateException(
"Not allowed to create transaction on shared EntityManager - " +
"use @UnitOfWork instead");
}
// Retrieve the EntityManager bound to the current execution context
EntityManager target = currentEntityManager();
if (transactionRequiringMethods.contains(method.getName())) {
// We need a transactional target Now,according to the JPA spec.
// Otherwise,the operation would get accepted but remain un-flushed...
if (!hasActiveTransaction(target)) {
throw new TransactionrequiredException("No EntityManager with actual transaction available " +
"for current thread - cannot reliably process '" + method.getName() + "' call");
}
}
// Invoke method on current EntityManager.
try {
return method.invoke(target,args);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForPersist() {
createProxy().persist(new Object());
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForMerge() {
createProxy().merge(new Object());
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForRemove() {
createProxy().remove(new Object());
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForFlush() {
createProxy().flush();
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForRefresh() {
createProxy().refresh(new Object());
}
项目:dropwizard-entitymanager
文件:SharedEntityManagerFactoryTest.java
@Test(expected = TransactionrequiredException.class)
public void requiresTransactionForRefreshWithProperties() {
createProxy().refresh(new Object(),new HashMap<>());
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。