本文整理汇总了Java中javax.persistence.EntityManager.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.isOpen方法的具体用法?Java EntityManager.isOpen怎么用?Java EntityManager.isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.isOpen方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getByClientAndCandidateID
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Conversations getByClientAndCandidateID(int clientID, int candidateID) throws NoResultException {
if (clientID > 0 && candidateID > 0) {
EntityManager em = EMFUtil.getEMFactory().createEntityManager();
String query = "SELECT c FROM Conversations c WHERE c.clientID = :clientID AND c.candidateID = :candidateID";
try {
TypedQuery<Conversations> q = em.createQuery(query, Conversations.class);
q.setParameter("clientID", clientID);
q.setParameter("candidateID", candidateID);
Conversations conversation = q.getSingleResult();
em.close();
return conversation;
} finally {
if (em.isOpen()) {
em.close();
}
}
}
return null;
}
示例2: startTimeoutChecker
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Starts a thread which will close the {@code em} after the specified {@code timeoutTime}.
*
* @param timeoutTime Time in milliseconds
* @param em The {@link EntityManager}, which may be used of the aspected method
* @param transaction The {@link EntityTransaction}, which will be marked as rollback-only if the timeout is reached
* @return The started timeout thread
*/
static Thread startTimeoutChecker(final int timeoutTime, EntityManager em, EntityTransaction transaction) {
LOG.trace("Starts the timeout thread with {}ms", timeoutTime);
Thread thread = new Thread(() -> {
try {
Thread.currentThread().setName("STRIX-TT");
Thread.sleep(timeoutTime);
LOG.trace("Timeout thread reached timeout time ({}ms)", timeoutTime);
if (em.isOpen()) {
if (transaction.isActive()) {
LOG.trace("Mark the transaction to rollbackOnly");
transaction.setRollbackOnly();
}
LOG.trace("Close EntityManager");
em.close();
}
} catch (InterruptedException ex) {
// Ignore InterruptedException
}
});
thread.start();
return thread;
}
示例3: executeWithSession
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Executes the aspected method within a session, i.e. opens and closes an {@link EntityManager} before and after
* execution.
*
* @param function The function, in which the aspected method will be executed
* @param persistenceUnit The persistence unit to identify the {@link EntityManagerFactory} from which the
* {@link EntityManager} will be created.
* @return The result of the aspected method
* @throws Throwable If the aspected method throws an exception
*/
private static Object executeWithSession(
ThrowingFunction<EntityManager, Object, Throwable> function,
String persistenceUnit
) throws Throwable {
LOG.trace("Create new EntityManager from persistence unit {}", persistenceUnit);
EntityManager em = getEntityManagerFactory(persistenceUnit).createEntityManager();
try {
PersistenceManager.setEntityManager(persistenceUnit, em);
return function.apply(em);
} finally {
PersistenceManager.clearEntityManager();
if (em.isOpen()) {
LOG.trace("Close EntityManager");
em.close();
}
}
}
示例4: creates_entity_manager_lazy
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Test
public void creates_entity_manager_lazy() {
final EntityManager em = getEntityManager();
assertNotNull(em);
verify(factory, never()).createEntityManager();
em.isOpen();
verify(factory).createEntityManager();
}
示例5: closeEm
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private static void closeEm(EntityManager em) {
try {
if (em.isOpen()) {
em.close();
}
} catch (Exception e) {
LOG.warn("Error closing EntityManager", e);
}
}
示例6: closeEntityManager
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private static void closeEntityManager(final EntityManager em) {
try {
if (em != null && em.isOpen()) {
em.close();
}
} catch (final Exception ex) {
LOG.warn(ex.getMessage(), ex);
}
}
示例7: close
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void close(@Disposes EntityManager em) {
if (em.isOpen()) {
em.close();
}
}
示例8: dispose
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void dispose(@Disposes @Default EntityManager entityManager) {
if (entityManager.isOpen()) {
entityManager.close();
}
}
示例9: closeEntityManager
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void closeEntityManager(@Disposes EntityManager entityManager) {
if (entityManager.isOpen()) {
entityManager.close();
}
}
示例10: closeEntityManager
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void closeEntityManager(@Disposes EntityManager manager) {
if (manager.isOpen()) {
manager.close();
}
}