view src/main/java/de/intevation/lada/manage/DataManager.java @ 320:6621f7345c06

Use 'merge' instead of 'persist' since it saves detached objects, too.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 23 Aug 2013 11:32:21 +0200
parents a305412206a3
children 9d5e4d4eb90f
line wrap: on
line source
package de.intevation.lada.manage;

import javax.ejb.EJBTransactionRolledbackException;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.TransactionRequiredException;


/**
 * This data manager provides the interface to persist, remove and update
 * database objects.
 *
 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
 */
@Stateless
@Named("datamanager")
public class DataManager
implements Manager
{
    @Inject
    private EntityManager em;

    /**
     * Create a new database object.
     *
     * @param object    The new object.
     */
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void create(Object object)
    throws EntityExistsException,
        IllegalArgumentException,
        EJBTransactionRolledbackException,
        TransactionRequiredException {
        em.merge(object);
        //em.persist(object);
    }

    /**
     * Update a database object.
     *
     * @param object    The object to update.
     */
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void update(Object object)
    throws EntityExistsException,
        IllegalArgumentException,
        EJBTransactionRolledbackException,
        TransactionRequiredException {
        em.merge(object);
    }

    /**
     * Delete a database object.
     *
     * @param object    The object to delete.
     */
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void delete(Object object)
    throws IllegalArgumentException,
        TransactionRequiredException {
        em.remove(em.contains(object) ? object : em.merge(object));
    }
}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)