本文整理汇总了Java中javax.persistence.EntityManager.clear方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.clear方法的具体用法?Java EntityManager.clear怎么用?Java EntityManager.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clear
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static void clear(final EntityManager em, JpaQueryFactory factory) {
factory.initalize(new JpaQueryFactoryContext() {
@Override
public MetaPartition getMetaPartition() {
MetaLookup metaLookup = new MetaLookup();
JpaMetaProvider metaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
metaLookup.addProvider(metaProvider);
metaLookup.initialize();
return metaProvider.getPartition();
}
@Override
public EntityManager getEntityManager() {
return em;
}
});
clear(em, factory.query(MovieEntity.class).buildExecutor().getResultList());
clear(em, factory.query(PersonEntity.class).buildExecutor().getResultList());
em.flush();
em.clear();
}
示例2: removeAll
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Removes all entities from database.
*/
public void removeAll() {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
for (T t : findAll()) {
em.remove(em.merge(t));
}
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
}
示例3: clear
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static void clear(final EntityManager em, JpaQueryFactory factory) {
factory.initalize(new JpaQueryFactoryContext() {
@Override
public EntityManager getEntityManager() {
return em;
}
@Override
public MetaPartition getMetaPartition() {
JpaMetaProvider jpaMetaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
MetaLookup metaLookup = new MetaLookup();
metaLookup.addProvider(jpaMetaProvider);
metaLookup.initialize();
return jpaMetaProvider.getPartition();
}
});
clear(em, factory.query(OneToOneTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(ManyToManyTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(ManyToManyOppositeEntity.class).buildExecutor().getResultList());
clear(em, factory.query(TestSubclassWithSuperclassPk.class).buildExecutor().getResultList());
clear(em, factory.query(RelatedEntity.class).buildExecutor().getResultList());
clear(em, factory.query(TestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(OtherRelatedEntity.class).buildExecutor().getResultList());
clear(em, factory.query(CountryTranslationEntity.class).buildExecutor().getResultList());
clear(em, factory.query(CountryEntity.class).buildExecutor().getResultList());
clear(em, factory.query(LangEntity.class).buildExecutor().getResultList());
clear(em, factory.query(BasicAttributesTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(RenamedTestEntity.class).buildExecutor().getResultList());
clear(em, factory.query(UuidTestEntity.class).buildExecutor().getResultList());
em.flush();
em.clear();
}
示例4: remove
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Removes an existing entity from database.
*
* @param entity Entity to remove.
*/
public void remove(T entity) {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
em.remove(em.merge(entity));
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
}
示例5: save
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Inserts an entity in database.
*
* @param entity new entity.
* @return entity inserted
*/
public T save(T entity) {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
em.persist(entity);
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
return entity;
}
示例6: update
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Updates an entity in database
*
* @param entity entity to update
* @return entity updated
*/
public T update(T entity) {
EntityManager em = HibernateUtil.getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
em.persist(em.merge(entity));
em.flush();
em.clear();
em.getTransaction().commit();
em.close();
return entity;
}
示例7: testHandle
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Test of handle method, of class Task.
*/
@Test
public void testHandle() {
System.out.println("basics");
EntityManager manager = new PersistenceProvider().get();
try {
manager.getTransaction().begin();
// creating data
Modification mod1 = new Modification("",1);
Modification mod2 = new Modification("",2);
Modification mod3 = new Modification("",3);
mod1.setName("Test 1");
mod2.setName("Test 2");
mod3.setName("Test 3");
manager.persist(mod1);
manager.persist(mod2);
manager.persist(mod3);
mod2.getOverwrite().add(mod1);
Original original = new Original("commons/test");
manager.persist(original);
manager.persist(new Patch(mod1, original));
manager.persist(new Patch(mod2, original));
manager.persist(new Patch(mod3, original));
// storing data
manager.getTransaction().commit();
manager.clear();
//testing
List<?> result = new RemoveOverwrittenFilePatch(original.getAid()).handle(manager);
Assert.assertTrue(
"handle didn't run properly",
result instanceof List<?>
);
Assert.assertEquals(
"handle didn't run properly",
1,
result.size()
);
Assert.assertEquals(
"Patch wasn't removed correctly",
2,
manager.find(Original.class, original.getAid()).getPatches().size()
);
} catch(Exception e) {
manager.getTransaction().rollback();
Assert.fail(e.getMessage());
}
}