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:org.jasig.portal.portlet.dao.jpa.JpaMarketplaceRatingDao.java

/**
 * @param entity to delete - can not be null
 *///from  ww w.  j  av a2s  .  c o  m
@Override
@PortalTransactional
public void deleteRating(IMarketplaceRating marketplaceRatingImplementation) {
    Validate.notNull(marketplaceRatingImplementation, "ratingPK can not be null");
    final IMarketplaceRating persistantMarketplaceRatingImpl;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(marketplaceRatingImplementation)) {
        persistantMarketplaceRatingImpl = marketplaceRatingImplementation;
    } else {
        persistantMarketplaceRatingImpl = entityManager.merge(marketplaceRatingImplementation);
    }
    entityManager.remove(persistantMarketplaceRatingImpl);
}

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

@Override
public boolean delete(OfferBid something) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    OfferBid managedManagedOfferBid = null;
    try {/*from  ww w .  j  a v  a 2  s  .  c om*/
        em.getTransaction().begin();
        managedManagedOfferBid = em.merge(something);
        em.remove(managedManagedOfferBid);
        em.getTransaction().commit();

        success = true;
    } catch (RuntimeException e) {
        Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

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

@Override
@Transactional//  w  w  w .ja  va 2  s. com
public void deletePresentation(Presentation presentation) {
    Validate.notNull(presentation, "presentation can not be null");

    final EntityManager entityManager = this.getEntityManager();

    final PresentationImpl presentationImpl = entityManager.find(PresentationImpl.class,
            presentation.getPresentationId());

    final ConferenceUser creator = presentationImpl.getCreator();
    final ConferenceUserImpl creatorImpl = this.conferenceUserDao.getUser(creator.getUserId());
    creatorImpl.getPresentations().remove(presentationImpl);

    entityManager.remove(presentationImpl);
    entityManager.persist(creatorImpl);
}

From source file:de.egore911.opengate.services.GameserverService.java

@GET
@Path("/remove")
@Produces("application/json")
@Documentation("This method removes a gameserver from the list. It is recommend to call this "
        + "method on shutdown of the gameserver. The remote IP will be obtained from the packet "
        + "sent to the server so server behind a NAT will not work. The method will answer using "
        + "a JSON object like {status: 'ok', detail: '...'}.")
public Response removeGameserver(@Context HttpServletRequest req) {
    String remoteAddr = req.getRemoteAddr();
    EntityManager em = EntityManagerFilter.getEntityManager();
    Gameserver gameserver;/*from w ww.  j a va2s.  c  o m*/
    try {
        JSONObject retval = new JSONObject();
        StatusHelper.ok(retval);
        try {
            gameserver = (Gameserver) em
                    .createQuery("select gameserver from Gameserver gameserver where address = :address")
                    .setParameter("address", remoteAddr).getSingleResult();
            em.remove(gameserver);
            retval.put("detail", "Successfully removed");
        } catch (NoResultException e) {
            // Nothing to do
            retval.put("detail", "Already removed");
        }
        return Response.ok(retval.toString()).build();
    } catch (JSONException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:nl.b3p.viewer.admin.stripes.ConfigureSolrActionBean.java

public Resolution delete() {
    removeFromIndex();/* w w  w. j a v a2s .  c om*/
    EntityManager em = Stripersist.getEntityManager();
    solrConfiguration.getIndexAttributes().clear();
    solrConfiguration.getResultAttributes().clear();
    em.remove(solrConfiguration);
    em.getTransaction().commit();
    return new ForwardResolution(EDIT_JSP);
}

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

/**
 * @param entity to delete - can not be null
 *///from   w  ww .  j  av a 2  s  .  c  o m
@Override
@PortalTransactional
public void deleteRating(IMarketplaceRating marketplaceRatingImplementation) {
    Validate.notNull(marketplaceRatingImplementation, "marketplaceRatingImplementation can not be null");
    final IMarketplaceRating persistantMarketplaceRatingImpl;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(marketplaceRatingImplementation)) {
        persistantMarketplaceRatingImpl = marketplaceRatingImplementation;
    } else {
        persistantMarketplaceRatingImpl = entityManager.merge(marketplaceRatingImplementation);
    }
    entityManager.remove(persistantMarketplaceRatingImpl);
}

From source file:org.nuxeo.theme.webwidgets.providers.PersistentProvider.java

@Override
public void destroy() throws ProviderException {
    try {//from   ww  w  .ja  v  a 2s .c o m
        getPersistenceProvider().run(true, new RunVoid() {
            public void runWith(EntityManager em) {
                em.createQuery("DELETE FROM DataEntity data").executeUpdate();
                for (Object w : em.createQuery("FROM WidgetEntity widget").getResultList()) {
                    em.remove(w);
                }
            }
        });
    } catch (ClientException e) {
        throw new ProviderException(e);
    }
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

public void deleteById(Serializable id) throws ServiceException {
    try {//from w ww .j  a va 2s.c  o m
        EntityManager entityManager = currentEntityManager();
        entityManager.getTransaction().begin();
        Object loadedEntity = entityManager.find(getObjectClass(), id);
        if (loadedEntity == null) {
            throw new ServiceException("Entity referenced by id " + id + " does not exist");
        }
        entityManager.remove(loadedEntity);
        commitTransaction();
    } catch (PersistenceException e) {
        logger.error(e.getCause(), e);
        rollbackTransaction();
        throw new ServiceException("Can't delete object", e);
    } finally {
        closeEntityManager();
    }
}

From source file:org.apache.juddi.subscription.SubscriptionNotifier.java

/**
 * Deletes the subscription. i.e. when it is expired.
 * @param subscription//from w  w  w . j a v a  2s .  c o  m
 */
protected void deleteSubscription(Subscription subscription) {
    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        em.remove(subscription);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:uk.ac.edukapp.service.UserAccountService.java

public Message removeFavourite(Useraccount user, Widgetprofile favourite) {
    EntityManager em = this.getEntityManagerFactory().createEntityManager();
    em.getTransaction().begin();/*from  www . ja v  a  2s.com*/
    Query q = em.createNamedQuery("favourite.select");
    q.setParameter("user", user);
    q.setParameter("widgetprofile", favourite);
    WidgetFavourite fav = (WidgetFavourite) q.getSingleResult();
    Message msg = new Message();
    if (fav != null) {
        em.remove(fav);
        msg.setMessage("OK");
    } else {
        msg.setMessage("Favourite could not be removed");
    }
    em.getTransaction().commit();
    em.close();
    return msg;
}