Example usage for javax.persistence EntityManager remove

List of usage examples for javax.persistence EntityManager remove

Introduction

In this page you can find the example usage for javax.persistence EntityManager remove.

Prototype

public void remove(Object entity);

Source Link

Document

Remove the entity instance.

Usage

From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java

/**
 * Remove object from persistence storage.
 * @param clazz the class of object to remove
 * @param id the id of the object to remove
 * @throws SocialSiteException on any error deleting object
 *//*from  ww  w  . j a va  2s.  c  o m*/
public void remove(Class<?> clazz, String id) throws SocialSiteException {
    EntityManager em = getEntityManager(true);
    Object po = em.find(clazz, id);
    em.remove(po);
}

From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java

/**
 * Remove object from persistence storage.
 * @param clazz the class of object to remove
 * @param id the id of the object to remove
 * @throws SocialSiteException on any error deleting object
 */// ww w .  j  av  a  2 s.co  m
public void remove(Class<?> clazz, int id) throws SocialSiteException {
    EntityManager em = getEntityManager(true);
    Object po = em.find(clazz, id);
    em.remove(po);
}

From source file:org.apereo.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupTestDefinitionDao.java

@PortalTransactional
@Override// ww  w  .  ja  v  a 2s  .co m
public void deletePersonAttributesGroupTestDefinition(IPersonAttributesGroupTestDefinition definition) {
    Validate.notNull(definition, "definition can not be null");

    final IPersonAttributesGroupTestDefinition persistentDefinition;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(definition)) {
        persistentDefinition = definition;
    } else {
        persistentDefinition = entityManager.merge(definition);
    }
    entityManager.remove(persistentDefinition);
}

From source file:org.apereo.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupTestGroupDefinitionDao.java

@PortalTransactional
@Override//from  w ww .  j ava 2  s. co  m
public void deletePersonAttributesGroupTestGroupDefinition(
        IPersonAttributesGroupTestGroupDefinition definition) {
    Validate.notNull(definition, "definition can not be null");

    final IPersonAttributesGroupTestGroupDefinition persistentDefinition;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(definition)) {
        persistentDefinition = definition;
    } else {
        persistentDefinition = entityManager.merge(definition);
    }
    entityManager.remove(persistentDefinition);
}

From source file:org.nuxeo.ecm.platform.ec.placeful.PlacefulServiceImpl.java

public void removeAnnotation(EntityManager em, Annotation annotation) {
    em.remove(annotation);
}

From source file:net.anthonychaves.bookmarks.service.TokenService.java

public User loginWithToken(String tokenId) {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();//from w w w .  j a v a  2  s.c o  m
    PersistentLoginToken token = (PersistentLoginToken) em.find(PersistentLoginToken.class, tokenId);

    User user = null;
    if (token != null) {
        user = token.getUser();
        em.remove(token);
        em.getTransaction().commit();
    } else {
        em.getTransaction().rollback();
        //TODO this is a forgery attempt
        throw new RuntimeException("Attempted login token cookie forgery");
    }
    return user;
}

From source file:org.apereo.portal.portlet.dao.jpa.JpaPortletTypeDao.java

@Override
@PortalTransactional//from  w w w .j a v a2 s. c  om
public void deletePortletType(IPortletType type) {
    Validate.notNull(type, "definition can not be null");

    final IPortletType persistentChanneltype;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(type)) {
        persistentChanneltype = type;
    } else {
        persistentChanneltype = entityManager.merge(type);
    }
    entityManager.remove(persistentChanneltype);
}

From source file:org.apache.roller.weblogger.business.jpa.JPAPersistenceStrategy.java

/**
 * Remove object from persistence storage.
 * @param po the persistent object to remove
 * @throws org.apache.roller.weblogger.WebloggerException on any error
 *//*from w  w w.j  a va2 s .com*/
public void remove(Object po) throws WebloggerException {
    EntityManager em = getEntityManager(true);
    em.remove(po);
}

From source file:org.apache.roller.planet.business.jpa.JPAPersistenceStrategy.java

/**
 * Remove object from persistence storage.
 * @param po the persistent object to remove
 * @throws org.apache.roller.planet.PlanetException on any error
 *//*from w  w  w . j  av  a 2 s  . c o m*/
public void remove(Object po) throws PlanetException {
    EntityManager em = getEntityManager(true);
    em.remove(po);
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.UserSkillRepositoryImplementation.java

@Override
public boolean delete(UserSkill userSkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    UserSkill managedUserSkill = null;//www .  j  ava2  s. co  m
    try {
        em.getTransaction().begin();
        managedUserSkill = em.merge(userSkill);
        em.remove(managedUserSkill);
        em.getTransaction().commit();

        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}