当前位置: 首页>>代码示例>>Java>>正文


Java TransactionRequiredException类代码示例

本文整理汇总了Java中javax.persistence.TransactionRequiredException的典型用法代码示例。如果您正苦于以下问题:Java TransactionRequiredException类的具体用法?Java TransactionRequiredException怎么用?Java TransactionRequiredException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransactionRequiredException类属于javax.persistence包,在下文中一共展示了TransactionRequiredException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCannotFlushWithoutGettingTransaction

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ApplicationManagedEntityManagerIntegrationTests.java

示例2: release

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:33,代码来源:Controllable.java

示例3: releasepersistNoTransaction

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@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) {
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:26,代码来源:ActuatorIT.java

示例4: releasePersistNoTransaction

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@Test
public void releasePersistNoTransaction() throws Exception {
   log.info("start releasePersistNoTransaction()");

   registerSetpoint(TEntity.class, FourEyesActuator.DEFAULTNAME, ControlEvent.INSERT, ControlEvent.RELEASE);
   Context.requestScope().setRemark("created");

   TEntity ent = persistTEntity();
   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("test2");

   applEman.getTransaction().commit();

   try {
      co.release(applEman, null);
      Assert.fail();
   } catch (TransactionRequiredException e) {
   }

   applEman.getTransaction().begin();
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:27,代码来源:DcManagerImplIntegrationTest.java

示例5: transactionStarted

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:25,代码来源:JtaEntityManagerRegistry.java

示例6: doJoinTransaction

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
/**
 * 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");
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:ExtendedEntityManagerCreator.java

示例7: testConvertJpaPersistenceException

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:EntityManagerFactoryUtilsTests.java

示例8: testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
	try {
		createContainerManagedEntityManager().joinTransaction();
		fail("Should have thrown a TransactionRequiredException");
	}
	catch (TransactionRequiredException e) {
		/* expected */
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:ContainerManagedEntityManagerIntegrationTests.java

示例9: getOrCreateEntityManager

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:37,代码来源:RequestScopeContext.java

示例10: flush

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@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);
        }
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:15,代码来源:EntityManagerSessionImpl.java

示例11: flush

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
@Override
public void flush() {
    if (entityManager != null && (!handleTransactions || isTransactionActive())) {
        try {
            entityManager.flush();
        } catch (IllegalStateException ise) {
            throw new ActivitiException("Error while flushing EntityManager, illegal state", ise);
        } catch (TransactionRequiredException tre) {
            throw new ActivitiException("Cannot flush EntityManager, an active transaction is required", tre);
        } catch (PersistenceException pe) {
            throw new ActivitiException("Error while flushing EntityManager: " + pe.getMessage(), pe);
        }
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:15,代码来源:EntityManagerSessionImpl.java

示例12: updateStatus

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
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");
  }
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:9,代码来源:UsersController.java

示例13: flush

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
public void flush() {
  if (entityManager != null && (!handleTransactions || isTransactionActive()) ) {
    try {
      entityManager.flush();
    } catch (IllegalStateException ise) {
      throw new ActivitiException("Error while flushing EntityManager, illegal state", ise);
    } catch (TransactionRequiredException tre) {
      throw new ActivitiException("Cannot flush EntityManager, an active transaction is required", tre);
    } catch (PersistenceException pe) {
      throw new ActivitiException("Error while flushing EntityManager: " + pe.getMessage(), pe);
    }
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:14,代码来源:EntityManagerSessionImpl.java

示例14: registerEntityManagerUnknown

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:18,代码来源:EntityProxyInvocationHandler.java

示例15: serializeProcedureSubmissionSet

import javax.persistence.TransactionRequiredException; //导入依赖的package包/类
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();
}
 
开发者ID:mpi2,项目名称:exportlibrary,代码行数:10,代码来源:TrackerSerializer.java


注:本文中的javax.persistence.TransactionRequiredException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。