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


Java EntityManager.remove方法代码示例

本文整理汇总了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();
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:22,代码来源:ContentFacadeTest.java

示例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;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:22,代码来源:ConversationDataAccessObject.java

示例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;
		}
	}				
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:24,代码来源:ContentFacade.java

示例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;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:22,代码来源:CandidatePersistence.java

示例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();
        }
    }
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:28,代码来源:UsuarioJpaController.java

示例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();
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:16,代码来源:UserFacadeTest.java

示例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();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:19,代码来源:AbstractCarJPAITest.java

示例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();
	}
}
 
开发者ID:andrea-colleoni,项目名称:corso-lutech,代码行数:11,代码来源:UtenteTest.java

示例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);
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:10,代码来源:JpaEntityRepository.java

示例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();

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

示例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);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:10,代码来源:CoreTaskService.java

示例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);
  }
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:9,代码来源:RouterObjectRepository.java

示例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);
}
 
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:35,代码来源:ConfigParserTest.java

示例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;
}
 
开发者ID:vmantek,项目名称:chimera,代码行数:51,代码来源:HibernateUtil.java

示例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();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:7,代码来源:CarServiceWithEmfImpl.java


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