changeset 151:7b1235c852a9

New repository for LZusatzWert objects.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 14 Jun 2013 14:10:13 +0200
parents 301260b80acb
children 53f6d290a559
files src/main/java/de/intevation/lada/data/LZusatzwertRepository.java
diffstat 1 files changed, 118 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/data/LZusatzwertRepository.java	Fri Jun 14 14:10:13 2013 +0200
@@ -0,0 +1,118 @@
+package de.intevation.lada.data;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.EJBTransactionRolledbackException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityExistsException;
+import javax.persistence.EntityManager;
+import javax.persistence.TransactionRequiredException;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import de.intevation.lada.manage.LZusatzwertManager;
+import de.intevation.lada.model.LZusatzWert;
+import de.intevation.lada.rest.Response;
+
+/**
+ * This Container is an interface to request, filter and select LZusatzWert
+ * obejcts from the connected database.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
+@Named("lzusatzwertrepository")
+public class LZusatzwertRepository
+extends Repository
+{
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
+
+    /**
+     * Manager class for LPRobe. Used to manipulate data objects.
+     */
+    @Inject
+    private LZusatzwertManager manager;
+
+    @Override
+    public Response create(Object object) {
+        if (!(object instanceof LZusatzWert)) {
+            return new Response(false, 602, object);
+        }
+        LZusatzWert zusatzwert = (LZusatzWert)object;
+        Response response = new Response(true, 200, zusatzwert);
+        // Try to save the new LProbe.
+        try {
+            manager.create(zusatzwert);
+            return response;
+        }
+        catch (EntityExistsException eee) {
+            response.setSuccess(false);
+            response.setMessage(601);
+        }
+        catch (IllegalArgumentException iae) {
+            response.setSuccess(false);
+            response.setMessage(602);
+        }
+        catch (TransactionRequiredException tre) {
+            response.setSuccess(false);
+            response.setMessage(603);
+        }
+        catch (EJBTransactionRolledbackException te) {
+            response.setSuccess(false);
+            response.setMessage(604);
+        }
+        return response;
+    }
+
+    @Override
+    public Response update(Object object) {
+        if (!(object instanceof LZusatzWert)) {
+            return new Response(false, 602, object);
+        }
+        LZusatzWert messwert = (LZusatzWert)object;
+        Response response = new Response(true, 200, messwert);
+        // Try to save the new LProbe.
+        try {
+            manager.update(messwert);
+            return response;
+        }
+        catch (EntityExistsException eee) {
+            response.setSuccess(false);
+            response.setMessage(601);
+        }
+        catch (IllegalArgumentException iae) {
+            response.setSuccess(false);
+            response.setMessage(602);
+        }
+        catch (TransactionRequiredException tre) {
+            response.setSuccess(false);
+            response.setMessage(603);
+        }
+        catch (EJBTransactionRolledbackException te) {
+            response.setSuccess(false);
+            response.setMessage(604);
+        }
+        return response;
+    }
+
+    @Override
+    public Response filter(Map<String, String> filter) {
+        CriteriaBuilder cb = em.getCriteriaBuilder();
+        CriteriaQuery<LZusatzWert> criteria = cb.createQuery(LZusatzWert.class);
+        Root<LZusatzWert> member = criteria.from(LZusatzWert.class);
+        if (filter.containsKey("probe")) {
+            criteria.where(cb.equal(member.get("probeId"), filter.get("probe")));
+        }
+        List<LZusatzWert> result = filter(criteria);
+        return new Response(true, 200, result);
+    }
+
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)