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


Java EntityManager.isOpen方法代码示例

本文整理汇总了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;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:20,代码来源:ConversationDataAccessObject.java

示例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;
}
 
开发者ID:mcarleio,项目名称:strix,代码行数:31,代码来源:StrixManager.java

示例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();
        }
    }
}
 
开发者ID:mcarleio,项目名称:strix,代码行数:28,代码来源:StrixManager.java

示例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();
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:9,代码来源:JpaInjectionServicesTest.java

示例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);
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:10,代码来源:EMSupplierImpl.java

示例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);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:CloseUtils.java

示例7: close

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void close(@Disposes EntityManager em) {
	if (em.isOpen()) {
		em.close();
	}
}
 
开发者ID:redhat-developer-demos,项目名称:kubernetes-lab,代码行数:6,代码来源:Resources.java

示例8: dispose

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void dispose(@Disposes @Default EntityManager entityManager) {
    if (entityManager.isOpen()) {
        entityManager.close();
    }
}
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:6,代码来源:EntityManagerProducer.java

示例9: closeEntityManager

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void closeEntityManager(@Disposes EntityManager entityManager) {
    if (entityManager.isOpen()) {
        entityManager.close();
    }
}
 
开发者ID:cassiomolin,项目名称:jersey-jwt,代码行数:6,代码来源:EntityManagerProducer.java

示例10: closeEntityManager

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void closeEntityManager(@Disposes EntityManager manager) {
	if (manager.isOpen()) {
		manager.close();
	}
}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:6,代码来源:EntityManagerProducer.java


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