當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。