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.epam.training.taranovski.web.project.repository.implementation.VacancySkillRepositoryImplementation.java

@Override
public boolean delete(VacancySkill vacancySkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    VacancySkill managedVacancySkill = null;
    try {/*from w w w .java  2s  .c om*/
        em.getTransaction().begin();
        managedVacancySkill = em.merge(vacancySkill);
        em.remove(managedVacancySkill);
        em.getTransaction().commit();

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

    return success;
}

From source file:org.apereo.portal.layout.dlm.FragmentDefinitionDao.java

@Override
@PortalTransactional//from  www .  jav  a 2s.  c o m
public void removeFragmentDefinition(FragmentDefinition fd) {

    Validate.notNull(fd, "FragmentDefinition can not be null");
    final FragmentDefinition persistentFragmentDefinition;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(fd)) {
        persistentFragmentDefinition = fd;
    } else {
        persistentFragmentDefinition = entityManager.merge(fd);
    }

    entityManager.remove(persistentFragmentDefinition);
}

From source file:org.apereo.portal.i18n.dao.jpa.JpaMessageDao.java

@Override
@PortalTransactional/*from  w  ww .  j a v  a  2  s  .com*/
public void deleteMessage(Message message) {
    Validate.notNull(message, "message can not be null");

    final Message msg;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(message)) {
        msg = message;
    } else {
        msg = entityManager.merge(message);
    }
    entityManager.remove(msg);
}

From source file:org.apache.roller.weblogger.business.jpa.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 WebloggerException on any error deleting object
 *//*from   www  .  ja  v  a2  s . c om*/
public void remove(Class clazz, String id) throws WebloggerException {
    EntityManager em = getEntityManager(true);
    Object po = em.find(clazz, id);
    em.remove(po);
}

From source file:org.ejbca.extra.db.MessageHome.java

/**
 * Method that removes a message from the database.
 * /*  w  w w.j a  va  2s.c  om*/
 * @param Messageid, the unique message id.
 */
public void remove(String messageId) {
    log.trace(">remove : Message, Messageid : " + messageId);
    EntityManager entityManager = getNewEntityManager();
    try {
        Message msg = Message.findByUniqueId(entityManager, Message.createUniqueIdString(messageId, type));
        if (msg != null) {
            entityManager.remove(msg);
        }
    } finally {
        closeEntityManager(entityManager);
    }
    log.trace("<remove : Message, Messageid : " + messageId);
}

From source file:org.apache.roller.planet.business.jpa.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 PlanetException on any error deleting object
 *///from w  ww . jav a 2  s .  c om
public void remove(Class clazz, String id) throws PlanetException {
    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 pos the persistent objects to remove
 * @throws SocialSiteException on any error
 */// w  w w . j a v  a 2s. c  o  m
public void removeAll(Collection pos) throws SocialSiteException {
    EntityManager em = getEntityManager(true);
    for (Iterator iterator = pos.iterator(); iterator.hasNext();) {
        Object obj = iterator.next();
        em.remove(obj);
    }
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.ConferenceUserDaoImpl.java

@Override
@Transactional//from   w  w  w. j a  v a 2  s .  c  o m
public void deleteUser(ConferenceUser user) {
    Validate.notNull(user, "user can not be null");

    final EntityManager entityManager = this.getEntityManager();
    if (!entityManager.contains(user)) {
        user = entityManager.merge(user);
    }
    entityManager.remove(user);
}

From source file:org.apereo.portal.layout.dao.jpa.JpaStylesheetDescriptorDao.java

@PortalTransactional
@Override//  w  ww .j  a va  2s  .  c o  m
public void deleteStylesheetDescriptor(IStylesheetDescriptor stylesheetDescriptor) {
    Validate.notNull(stylesheetDescriptor, "definition can not be null");

    final IStylesheetDescriptor persistentStylesheetDescriptor;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(stylesheetDescriptor)) {
        persistentStylesheetDescriptor = stylesheetDescriptor;
    } else {
        persistentStylesheetDescriptor = entityManager.merge(stylesheetDescriptor);
    }

    entityManager.remove(persistentStylesheetDescriptor);
}

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

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

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