Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/util/data/DataTransaction.java @ 1041:f92c96efa976 schema-update
Organized imports and removed unused logger.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 05 Sep 2016 10:17:32 +0200 |
parents | d74b5b1190ae |
children | 7683c4162746 |
line wrap: on
line source
/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=3) * and comes with ABSOLUTELY NO WARRANTY! Check out * the documentation coming with IMIS-Labordaten-Application for details. */ package de.intevation.lada.util.data; import javax.ejb.EJBTransactionRolledbackException; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import javax.ejb.TransactionAttributeType; import javax.inject.Inject; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; import javax.persistence.Query; import javax.persistence.TransactionRequiredException; /** * Abstract class implementing low level data operations. * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @Stateless public class DataTransaction { @Inject protected EntityManagerProducer emp; protected String jndiPath; /** * Create object in the database. * This operation can not be undone. * * @param object The object to create * * @throws EntityExistsException * @throws IllegalArgumentException * @throws EJBTransactionRolledbackException * @throws TransactionRequiredException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void persistInDatabase(Object object, String dataSource) throws EntityExistsException, IllegalArgumentException, EJBTransactionRolledbackException, TransactionRequiredException { emp.entityManager(dataSource).persist(object); } /** * Create object in the database. * This operation can not be undone. * * @param object The object to create * * @throws EntityExistsException * @throws IllegalArgumentException * @throws EJBTransactionRolledbackException * @throws TransactionRequiredException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void updateInDatabase(Object object, String dataSource) throws EntityExistsException, IllegalArgumentException, EJBTransactionRolledbackException, TransactionRequiredException { emp.entityManager(dataSource).merge(object); } /** * Remove an object from the datebase. * This operation can not be undone. * * @param object The object to remove * * @throws IllegalArgumentException * @throws TransactionRequiredException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void removeFromDatabase(Object object, String dataSource) throws IllegalArgumentException, TransactionRequiredException, EJBTransactionRolledbackException { EntityManager em = emp.entityManager(dataSource); em.remove( em.contains(object) ? object : em.merge(object)); } public Query queryFromString(String sql, String dataSource) { EntityManager em = emp.entityManager(dataSource); return em.createNativeQuery(sql); } public EntityManager entityManager(String dataSource) { return emp.entityManager(dataSource); } }