Example usage for javax.persistence EntityManager contains

List of usage examples for javax.persistence EntityManager contains

Introduction

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

Prototype

public boolean contains(Object entity);

Source Link

Document

Check if the instance is a managed entity instance belonging to the current persistence context.

Usage

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

@PortalTransactional
@Override//from  w  w w . ja va  2 s.  c  o  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);
}

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

@PortalTransactional
@Override/* www  .java2 s  . c  om*/
public IPersonAttributesGroupDefinition updatePersonAttributesGroupDefinition(
        IPersonAttributesGroupDefinition personAttributesGroupDefinition) {
    Validate.notNull(personAttributesGroupDefinition, "personAttributesGroupDefinition can not be null");

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

    this.getEntityManager().persist(persistentDefinition);
    return persistentDefinition;
}

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

@Override
@PortalTransactional//from  ww w .  j  av  a  2s  . c o m
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:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java

/**
 * Store object using an existing transaction.
 * @param obj the object to persist//w  w w.  j ava 2s.c  o m
 * @return the object persisted
 * @throws SocialSiteException on any error
 */
public Object store(Object obj) throws SocialSiteException {
    EntityManager em = getEntityManager(true);
    if (!em.contains(obj)) {
        // If entity is not managed we can assume it is new
        em.persist(obj);
    }
    return obj;
}

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

/**
 * @param entity to delete - can not be null
 *//*from   w  w  w.ja va 2  s  .com*/
@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:org.apereo.portal.portlet.dao.jpa.JpaPortletEntityDao.java

@Override
@PortalTransactional/*from  w  ww. j  a va 2  s  . c o m*/
public void deletePortletEntity(IPortletEntity portletEntity) {
    Validate.notNull(portletEntity, "portletEntity can not be null");

    final IPortletEntity persistentPortletEntity;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(portletEntity)) {
        persistentPortletEntity = portletEntity;
    } else {
        persistentPortletEntity = entityManager.merge(portletEntity);
    }

    entityManager.remove(persistentPortletEntity);
}

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

@Override
@Transactional/*from ww w .  j  a  v a 2  s  .  com*/
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.portlet.dao.jpa.JpaPortletDefinitionDao.java

@Override
@PortalTransactional/*  ww w  . j a  v  a  2  s.  c  om*/
public void deletePortletDefinition(IPortletDefinition definition) {
    Validate.notNull(definition, "definition can not be null");

    final IPortletDefinition persistentPortletDefinition;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(definition)) {
        persistentPortletDefinition = definition;
    } else {
        persistentPortletDefinition = entityManager.merge(definition);
    }

    entityManager.remove(persistentPortletDefinition);
}

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

/**
 * @param entity to delete - can not be null
 *///from www  .j  a  v 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.apache.roller.weblogger.business.jpa.JPAPersistenceStrategy.java

/**
 * Store object using an existing transaction.
 * @param obj the object to persist//from  w  ww . j a  va2s  .  c  om
 * @return the object persisted
 * @throws org.apache.roller.weblogger.WebloggerException on any error
 */
public Object store(Object obj) throws WebloggerException {
    EntityManager em = getEntityManager(true);
    if (!em.contains(obj)) {
        // If entity is not managed we can assume it is new
        em.persist(obj);
    }
    return obj;
}