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


Java EntityManagerFactory.close方法代码示例

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


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

示例1: jpaWithActiveSpanOnlyWithParent

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void jpaWithActiveSpanOnlyWithParent() {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory =
        Persistence.createEntityManagerFactory("jpa_active_span_only");

    Employee employee = new Employee();
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.getTransaction().begin();
    entityManager.persist(employee);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();

    assertNotNull(employee.id);
  }

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

示例2: jpa_with_parent_and_active_span_only

import javax.persistence.EntityManagerFactory; //导入方法依赖的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

示例3: main

import javax.persistence.EntityManagerFactory; //导入方法依赖的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

示例4: jpa_with_active_span_only

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void jpa_with_active_span_only() {
  EntityManagerFactory entityManagerFactory = Persistence
      .createEntityManagerFactory("jpa_active_span_only");

  Employee employee = new Employee();
  EntityManager entityManager = entityManagerFactory.createEntityManager();
  entityManager.getTransaction().begin();
  entityManager.persist(employee);
  entityManager.getTransaction().commit();
  entityManager.close();
  entityManagerFactory.close();

  assertNotNull(employee.id);

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());

  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:21,代码来源:HibernateTest.java

示例5: deleteTest

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void deleteTest() {
	EntityManagerFactory factory = Persistence.createEntityManagerFactory("db1start");
	EntityManager manager = factory.createEntityManager();

	Cidade cidade = manager.find(Cidade.class, 3L);
	manager.getTransaction().begin();
	manager.remove(cidade);
	manager.getTransaction().commit();

	factory.close();

}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:14,代码来源:CidadeTest.java

示例6: createAndCloseDummyEMF

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
 * Create and close a dummy EMF to give the PersistenceProvider a chance to call
 * punit.addTransformer(). This has to occur as early as possible as weaving needs
 * to be done before the first entity class is loaded. So we can not wait till the
 * real DataSource is found.
 */
private void createAndCloseDummyEMF(PersistenceProvider provider) {
    DataSource dummyDataSource = new DummyDataSource();
    punit.setJtaDataSource(dummyDataSource);
    punit.setNonJtaDataSource(dummyDataSource);
    try {
        EntityManagerFactory emf = provider.createContainerEntityManagerFactory(punit, null);
        emf.close();
    } catch (Exception e) {
        LOGGER.debug("Error while creating the Dummy EntityManagerFactory to allow weaving.", e);
    }
    punit.setJtaDataSource(null);
    punit.setNonJtaDataSource(null);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:20,代码来源:PersistenceProviderTracker.java

示例7: replaceDefaultDBPassword

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
public  void replaceDefaultDBPassword() throws Exception {
    try (Connection connection = getSQLConnection();
            PreparedStatement changePasswordStatement = connection.prepareStatement("ALTER USER " + this.connectionParams.getLogin().toUpperCase() + " SET PASSWORD ?")) {

        connection.setAutoCommit(false);

        String newPassword = RandomStringUtils.randomAscii(32);

        try {
            // change password in DB
            changePasswordStatement.setString(1, newPassword);
            changePasswordStatement.execute();

            // put password in keystore
            this.connectionParams.updatePassword(newPassword);

            connection.commit();
        } catch (Exception ex) {
            log.error("Error while changing DB password.", ex);

            try {
                connection.rollback();
            } catch (Exception he) {
                log.error("Error rolling back transaction", he);
            }

            throw ex;
        }
        EntityManagerFactory oldEmf = this.emf;
        // reinitialize session factory
        start(this.properties);

        try {
            oldEmf.close();
        } catch (PersistenceException pe) {
            // Ignore this
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:40,代码来源:DBConnectionManager.java

示例8: selectSqlNativoTest

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void selectSqlNativoTest() {
	EntityManagerFactory factory = Persistence.createEntityManagerFactory("db1start");
	EntityManager manager = factory.createEntityManager();

	Query query = manager.createNativeQuery("Select * from cidade c");
	List<Cidade> cidades = query.getResultList();

	factory.close();

}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:12,代码来源:CidadeTest.java

示例9: main

import javax.persistence.EntityManagerFactory; //导入方法依赖的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();

	// Object used to create more sophisticated conditions
	CriteriaBuilder cb = em.getCriteriaBuilder();
	
	// this object is used to create query object
	CriteriaQuery<Role> cq = cb.createQuery(Role.class);
	
	// We set the root of query (we will use this root to getting values of columns)
	Root<Role> from = cq.from(Role.class);
	
	// we composing query using cb object
	cq.where(cb.equal(from.get("name"), "ordinary"));
	
	// creating query and executing it
	TypedQuery<Role> tq = em.createQuery(cq);
	List<Role> roles = tq.getResultList();
	
	
	for (Role role : roles) {
		System.out.println(role.getName());
	}

	em.getTransaction().commit();
	em.close();
	entityManagerFactory.close();
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:34,代码来源:App5.java

示例10: main

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
	EntityManagerFactory entityManagerFactory 
	= Persistence.createEntityManagerFactory("pl.edu.bogdan.training.db.entity");
	EntityManager em = entityManagerFactory.createEntityManager();
	
	em.getTransaction().begin();
	
	User user = new User("Paweł", "Bogdan", 28, null);
	em.persist(user);
	em.getTransaction().commit();
	em.close();
	entityManagerFactory.close();
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:14,代码来源:App2.java

示例11: metodoTest

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
@Test
public void metodoTest() {
	EntityManagerFactory factory = Persistence.createEntityManagerFactory("db1start");
	EntityManager manager = factory.createEntityManager();

	Cidade cidade = new Cidade();
	cidade.setNome("Maringa");
	
	manager.getTransaction().begin();
	manager.persist(cidade);
	manager.getTransaction().commit();

	factory.close();

}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:16,代码来源:CidadeTest.java

示例12: closeQuietly

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
static void closeQuietly(final EntityManagerFactory emf) {
    if (emf != null) {
        try {
            emf.close();
        } catch (final Exception ex) {
            LOG.warn("Error closing entity manager factory: {}", ex.getMessage(), ex);
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:LiquibaseHelper.java

示例13: closeEntityManagerFactory

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
private static void closeEntityManagerFactory(final EntityManagerFactory emf) {
    try {
        if (emf != null && emf.isOpen()) {
            emf.close();
        }
    } catch (final Exception ex) {
        LOG.warn(ex.getMessage(), ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:CloseUtils.java

示例14: contextDestroyed

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void contextDestroyed(ServletContextEvent sce) {
    JPAEMFProvider.setEmf(null);
    EntityManagerFactory emf = (EntityManagerFactory) sce
            .getServletContext().getAttribute("my.application.emf");
    if (emf != null) {
        emf.close();
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:13,代码来源:Initialization.java

示例15: main

import javax.persistence.EntityManagerFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("mysql-testdb");
	emf.close();
}
 
开发者ID:appNG,项目名称:appng-examples,代码行数:5,代码来源:SchemaExport.java


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