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


Java EntityManager.close方法代码示例

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


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

示例1: getCandidateByEmail

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Candidates getCandidateByEmail(String email) {
    if (email != null && !email.isEmpty() && CustomUtilities.isValidEmail(email)) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        String query = "SELECT candidate FROM Candidates candidate WHERE candidate.email =:email";
        try {
            TypedQuery<Candidates> q = em.createQuery(query, Candidates.class);
            q.setParameter("email", email);
            return q.getSingleResult();
        } catch (Exception e) {

        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:17,代码来源:CandidatePersistence.java

示例2: findApplyAndMerge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * So you want to load an entity, set some data, and save it again, without detaching it from the persistence
 * context and without bothering with the EntityManager?
 * Look no further! Functional programming to the rescue, just pass a function that does the required transformation
 * on the entity.
 * <p>
 * NOTE that this will create a new instance of the entity if it does not exist yet.
 *
 */
@Nonnull
public <E extends SaucedEntity<I, E>, I extends Serializable> E findApplyAndMerge(@Nonnull final Transfiguration<I, E> transfiguration)
        throws DatabaseException {
    final EntityManager em = this.databaseConnection.getEntityManager();
    try {
        return this.lockedWrappedTransformFunc(transfiguration).apply(em);
    } catch (final PersistenceException e) {
        final String message = String.format("Failed to find, apply and merge entity id %s of class %s on DB %s",
                transfiguration.key.id.toString(), transfiguration.key.clazz.getName(),
                this.databaseConnection.getName());
        throw new DatabaseException(message, e);
    } finally {
        em.close();
    }
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:25,代码来源:DatabaseWrapper.java

示例3: createEntity

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public long createEntity(Product entity) {
	PersistenceProduct product = new PersistenceProduct();
	product.setName(entity.getName());
	product.setDescription(entity.getDescription());
	product.setListPriceInCents(entity.getListPriceInCents());
	
	EntityManager em = getEM();
    try {
        em.getTransaction().begin();
        PersistenceCategory cat = em.find(PersistenceCategory.class, entity.getCategoryId());
        if (cat != null) {
        	product.setCategory(cat);
        	em.persist(product);
        } else {
        	product.setId(-1L);
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
    return product.getId();
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:27,代码来源:ProductRepository.java

示例4: main

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static void main(String[] args) {
	EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("pl.edu.bogdan.training.db.entity");
	EntityManager em = entityManagerFactory.createEntityManager();
	
	// begining of transaction
	em.getTransaction().begin();
	
	// Creating query in the way very similar to SQL
	Query query = em.createQuery("Select r from Role r where r.name = :name");
	query.setParameter("name", "ordinary");
	
	// We obtaining result as a list of entities
	List<Role> roles = query.getResultList();
	
	for (Role role : roles) {
		System.out.println(role.getName());
		for (User u : role.getUsers()) {
			System.out.println("     " + u.getLastName());
		}
	}
	
	em.getTransaction().commit();
	em.close();
	entityManagerFactory.close();
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:26,代码来源:App4.java

示例5: jpa_with_parent_and_active_span_only

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Test
public void jpa_with_parent_and_active_span_only() {

  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory = Persistence
        .createEntityManagerFactory("jpa_active_span_only");

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();
    entityManager.persist(new Employee());
    entityManager.persist(new Employee());
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:23,代码来源:HibernateTest.java

示例6: persist

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Conversations persist (Conversations conversation) {
    if (conversation != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            em.persist(conversation);
            trans.commit();
            return conversation;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:19,代码来源:ConversationDataAccessObject.java

示例7: getByClientAndCandidateID

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static ClientPipelines getByClientAndCandidateID (int clientID, int candidateID) {
    if (clientID > 0 && candidateID > 0) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        try {
            String query = "SELECT elt FROM ClientPipelines elt WHERE elt.clientID = :clientID AND elt.candidateID = :candidateID";
            TypedQuery<ClientPipelines> q = em.createQuery(query, ClientPipelines.class);
            q.setParameter("clientID", clientID);
            q.setParameter("candidateID", candidateID);
            return q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:18,代码来源:ClientPipelineDataAccessObject.java

示例8: getCar

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public Car getCar(String id) {
    EntityManager em = emf.createEntityManager();
    try {
        return em.find(Car.class, id);
    } finally {
        em.close();
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:10,代码来源:CarServiceWithEmfImpl.java

示例9: getDailyRegistry

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * Returns the list of bookings that should be displayed in the daily registry for today's
 * date.
 */
public List<Booking> getDailyRegistry() {
    List<Booking> results;
    EntityManager entityManager = HibernateUtil.getEntityManager();
    String queryString = "FROM Booking WHERE isCheckedIn = true "
            + "OR trunc(sysdate) BETWEEN checkInDate and checkOutDate";
    Query q = entityManager.createQuery(queryString);
    results = q.getResultList();
    entityManager.close();
    return results;
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:15,代码来源:BookingService.java

示例10: registrate

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void registrate(User user, String plainTextPassword) {		  
  generatePassword(user, plainTextPassword);
  LOGGER.info("persisting user " + user.getUsername() + " with password " + user.getPassword() + " and salt " + user.getSalt());
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
  EntityManager em = emf.createEntityManager();
  EntityTransaction tx = em.getTransaction();
  tx.begin();
  em.persist(user);
  LOGGER.info("user persisted");
  tx.commit();
  em.close();
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:13,代码来源:UserRegistrationServlet.java

示例11: carLifecycleRL

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * Create, find and delete car using resource local transactions
 * @param emf
 * @throws BundleException
 */
protected void carLifecycleRL(EntityManager em) throws BundleException {
    em.getTransaction().begin();
    Car car = createBlueCar();
    em.persist(car);
    em.getTransaction().commit();

    Car car2 = em.find(Car.class, BLUE_PLATE);
    assertBlueCar(car2);
    em.getTransaction().begin();
    em.remove(car2);
    em.getTransaction().commit();
    em.close();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:19,代码来源:AbstractCarJPAITest.java

示例12: addCar

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void addCar(Car car) {
    EntityManager localEm = emf.createEntityManager();
    localEm.persist(car);
    localEm.flush();
    localEm.close();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:8,代码来源:CarServiceWithMultiAnnotationImpl.java

示例13: getCurrentlyCheckedInGuests

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public List<Guest> getCurrentlyCheckedInGuests() {
    EntityManager entityManager = HibernateUtil.getEntityManager();
    String query = "SELECT b.guest FROM Booking AS b WHERE b.isCheckedIn = true";
    Query q = entityManager.createQuery(query);
    List<Guest> results = q.getResultList();
    entityManager.close();
    return results;
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:9,代码来源:GuestService.java

示例14: getByID

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Certifications getByID(int certificationID) {
    if (certificationID > 0) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        Certifications certification = em.find(Certifications.class, certificationID);
        em.close();
        return certification;
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:10,代码来源:CertificationPersistence.java

示例15: jButton1ActionPerformed

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    Object[] selected = inactiveList.getSelectedValues();
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    for (Object plugin : selected) {
        Plugins p = (Plugins) plugin;
        p.setActive(true);
        inactivemodel.removeElement(p);
        activemodel.addElement(p);
        p = em.merge(p);
        em.persist(p);
    }
    em.getTransaction().commit();
    em.close();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:16,代码来源:PluginManagerDialog.java


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