本文整理汇总了Java中javax.persistence.EntityManager.remove方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.remove方法的具体用法?Java EntityManager.remove怎么用?Java EntityManager.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanUp
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@AfterClass
public void cleanUp() {
// Delete S3 bucket
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(ContentHelper.getInstance().getConfiguredBucketName());
s3Client.deleteBucket(deleteBucketRequest);
EntityManager _em = Persistence.createEntityManager();
TypedQuery<User> query =_em.createQuery("select u from User u where u.userName=:userName", User.class);
query.setParameter("userName", _user.getUserName());
_user = query.getSingleResult();
query.setParameter("userName", sharedUser.getUserName());
sharedUser = query.getSingleResult();
_em.getTransaction().begin();
_em.remove(_user);
_em.remove(sharedUser);
_em.getTransaction().commit();
}
示例2: delete
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static boolean delete(int conversationID) {
if (conversationID > 0) {
EntityManager em = EMFUtil.getEMFactory().createEntityManager();
Conversations conversation = em.find(Conversations.class, conversationID);
if (conversation != null) {
EntityTransaction trans = em.getTransaction();
try {
trans.begin();
em.remove(conversation);
trans.commit();
return true;
} catch (Exception e) {
e.printStackTrace();
trans.rollback();
} finally {
em.close();
}
}
}
return false;
}
示例3: run
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void run() {
EntityManager em = _emFactory.get();
Media m = em.find(Media.class, _media_id);
if (m == null) {
_logger.info("Media is null");
return;
}
else {
try {
em.getTransaction().begin();
em.remove(m);
em.getTransaction().commit();
ContentHelper.getInstance().deleteContent(m.getS3Bucket(), m.getS3FileName());
ContentHelper.getInstance().deleteContent(m.getS3Bucket(), m.getS3ThumbFileName());
} catch (Exception ex) {
_logger.error(ex.getMessage(), ex);
} finally {
em.close();
em = null;
}
}
}
示例4: delete
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static boolean delete(int candidateID) {
if (candidateID > 0) {
EntityManager em = EMFUtil.getEMFactory().createEntityManager();
Candidates candidate = em.find(Candidates.class, candidateID);
if (candidate != null) {
EntityTransaction trans = em.getTransaction();
try {
trans.begin();
em.remove(candidate);
trans.commit();
return true;
} catch (Exception e) {
e.printStackTrace();
trans.rollback();
} finally {
em.close();
}
}
}
return false;
}
示例5: destroy
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void destroy(String _id) throws NonexistentEntityException, RollbackFailureException, Exception {
EntityManager em = null;
try {
utx.begin();
em = getEntityManager();
Usuario user;
try {
user = em.getReference(Usuario.class, _id);
user.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The persona with id " + _id + " no longer exists.", enfe);
}
em.remove(user);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}
示例6: cleanUp
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@AfterClass
public void cleanUp() {
_logger.info("Clean up after test");
EntityManager _em = Persistence.createEntityManager();
TypedQuery<User> query =_em.createQuery("select u from User u where u.userName=:userName", User.class);
query.setParameter("userName", registeredUser.getUserName());
User _user = query.getSingleResult();
_em.getTransaction().begin();
_em.remove(_user);
_em.getTransaction().commit();
}
示例7: 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();
}
示例8: tearDown
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
EntityManager em = emf.createEntityManager();
Utente daRimuovere = em.find(Utente.class, TEST_USER);
if (daRimuovere != null) {
em.getTransaction().begin();
em.remove(daRimuovere);
em.getTransaction().commit();
}
}
示例9: delete
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void delete(I id) {
EntityManager em = module.getEntityManager();
Object object = em.find(repositoryConfig.getEntityClass(), id);
if (object != null) {
em.remove(object);
}
}
示例10: deleteTest
import javax.persistence.EntityManager; //导入方法依赖的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();
}
示例11: doDelete
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void doDelete(EntityManager em, RouterObjectRef routerObjectRef)
throws NotFoundException, InvalidStateException {
Task task = app.db.task.get(em, routerObjectRef);
if (!task.getState().isDeleteAllowed()) {
throw new InvalidStateException("Deleting task in state " + task.getState() + " not allowed");
}
em.remove(task);
}
示例12: delete
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void delete(EntityManager em, RouterObjectRef routerObjectRef)
throws CommsRouterException {
ENTITYT entity = getNoThrow(em, routerObjectRef);
if (entity != null) {
em.remove(entity);
}
}
示例13: checkHandlePart
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void checkHandlePart(File file, String content, int results, String name, int id, String version) throws Exception {
EntityManager manager = new PersistenceProvider().get();
file.getParentFile().mkdirs();
FileUtils.writeStringToFile(file, content, "utf-8");
List<ProcessTask> result = get(file).handle(manager);
Assert.assertTrue(
file.getName() + ": Wrong type returned",
result instanceof List<?>
);
Assert.assertEquals(
file.getName() + ": Wrong number of tasks returned",
results,
result.size()
);
Modification mod = manager.createNamedQuery("modifications.config", Modification.class)
.setParameter("configPath", file.getName())
.getSingleResult();
Assert.assertEquals(
file.getName() + ": Mod has wrong id",
id,
mod.getId()
);
Assert.assertEquals(
file.getName() + ": Mod has wrong name",
name,
mod.getName()
);
Assert.assertEquals(
file.getName() + ": Mod has wrong version",
version,
mod.getVersion()
);
manager.remove(mod);
}
示例14: getDB
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static org.jpos.ee.DB getDB(EntityManager entityManager, Context ctx)
{
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(org.jpos.ee.DB.class);
Class aClass = factory.createClass();
final org.jpos.ee.DB newInstance;
try
{
newInstance = (org.jpos.ee.DB) aClass.newInstance();
}
catch (InstantiationException | IllegalAccessException e)
{
throw new IllegalStateException("Could not create proxy", e);
}
MethodHandler methodHandler = (self, overridden, proceed, args) ->
{
if (overridden.getName().equals("session"))
{
return entityManager.unwrap(Session.class);
}
if (overridden.getName().equals("save"))
{
entityManager.persist(args[0]);
return null;
}
if (overridden.getName().equals("saveOrUpdate"))
{
return entityManager.merge(args[0]);
}
if (overridden.getName().equals("delete"))
{
entityManager.remove(args[0]);
return null;
}
else if (Arrays.asList(validMethods).contains(overridden.getName()))
{
return proceed.invoke(newInstance, args);
}
else
{
throw new IllegalStateException(
"Method " + overridden.getName() + " cannot be accessed from Transaction " +
"Participant");
}
};
((ProxyObject) newInstance).setHandler(methodHandler);
return newInstance;
}
示例15: deleteCar
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void deleteCar(String id) {
EntityManager em = emf.createEntityManager();
em.remove(em.find(Car.class, id));
em.close();
}