changeset 56:9f3e902ce778

Added new entity, repository and service for 'LKommentarP'.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 27 May 2013 15:23:41 +0200
parents ddcf13f7b6a0
children d57f2aba50e0
files src/main/java/de/intevation/lada/data/LKommentarPRepository.java src/main/java/de/intevation/lada/manage/LKommentarPManager.java src/main/java/de/intevation/lada/model/LKommentarP.java src/main/java/de/intevation/lada/model/LKommentarPId.java src/main/java/de/intevation/lada/rest/LKommentarService.java
diffstat 5 files changed, 370 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/LKommentarPRepository.java	Mon May 27 15:23:41 2013 +0200
@@ -0,0 +1,67 @@
+package de.intevation.lada.data;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+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;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+import de.intevation.lada.manage.LKommentarPManager;
+import de.intevation.lada.model.LKommentarP;
+
+
+@Named("lkommentarRepository")
+public class LKommentarPRepository
+extends Repository
+{
+    /**
+     * The entitymanager managing the data.
+     */
+    @Inject
+    private EntityManager em;
+
+    @Inject
+    private LKommentarPManager manager;
+
+    @Inject
+    private Logger logger;
+
+    public List<LKommentarP> filter(String probeId) {
+        if (probeId.isEmpty()) {
+            return new ArrayList<LKommentarP>(0);
+        }
+        CriteriaBuilder cb = em.getCriteriaBuilder();
+        CriteriaQuery<LKommentarP> criteria = cb.createQuery(LKommentarP.class);
+        Root<LKommentarP> member = criteria.from(LKommentarP.class);
+        criteria.where(cb.equal(member.get("probeId"), probeId));
+
+        return em.createQuery(criteria).getResultList();
+    }
+
+    public String create(LKommentarP kommentar) {
+        try {
+            manager.create(kommentar);
+            return "";
+        }
+        catch(EntityExistsException eee) {
+            return "Entity already exists.";
+        }
+        catch(IllegalArgumentException iae) {
+            return "Object is not an entity.";
+        }
+        catch(TransactionRequiredException tre) {
+            logger.log(Level.INFO, "exception: " + tre);
+            return "Transaction failed.";
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/manage/LKommentarPManager.java	Mon May 27 15:23:41 2013 +0200
@@ -0,0 +1,36 @@
+package de.intevation.lada.manage;
+
+import java.util.logging.Logger;
+
+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.TransactionRequiredException;
+
+import de.intevation.lada.model.LKommentarP;
+import de.intevation.lada.model.LKommentarPId;
+
+@Stateless
+public class LKommentarPManager
+{
+    @Inject
+    private EntityManager em;
+
+    @Inject
+    private Logger logger;
+
+    @TransactionAttribute(TransactionAttributeType.REQUIRED)
+    public void create(LKommentarP kommentar)
+    throws EntityExistsException,
+        IllegalArgumentException,
+        TransactionRequiredException
+    {
+        LKommentarPId id = new LKommentarPId();
+        id.setProbeId(kommentar.getProbeId());
+        kommentar.setId(id);
+        em.persist(kommentar);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/model/LKommentarP.java	Mon May 27 15:23:41 2013 +0200
@@ -0,0 +1,101 @@
+package de.intevation.lada.model;
+
+// Generated 21.05.2013 16:58:30 by Hibernate Tools 3.4.0.CR1
+
+import java.util.Date;
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ * LKommentarP generated by hbm2java
+ */
+@Entity
+@Table(name = "l_kommentar_p", schema = "public")
+public class LKommentarP implements java.io.Serializable {
+
+	private LKommentarPId id;
+	private String probeId;
+	private String erzeuger;
+	private Date KDatum;
+	private String KText;
+
+	public LKommentarP() {
+	}
+
+	public LKommentarP(LKommentarPId id, String probeId, String erzeuger,
+			Date KDatum) {
+		this.id = id;
+		this.probeId = probeId;
+		this.erzeuger = erzeuger;
+		this.KDatum = KDatum;
+	}
+
+	public LKommentarP(LKommentarPId id, String probeId, String erzeuger,
+			Date KDatum, String KText) {
+		this.id = id;
+		this.probeId = probeId;
+		this.erzeuger = erzeuger;
+		this.KDatum = KDatum;
+		this.KText = KText;
+	}
+
+	@EmbeddedId
+	@AttributeOverrides({
+			@AttributeOverride(name = "probeId", column = @Column(name = "probe_id", nullable = false, length = 20)),
+			@AttributeOverride(name = "KId", column = @Column(name = "k_id", nullable = false)) })
+	public LKommentarPId getId() {
+		return this.id;
+	}
+
+	public void setId(LKommentarPId id) {
+		this.id = id;
+	}
+
+	@Column(name = "probe_id", nullable = false, insertable = false, updatable = false)
+	public String getProbeId() {
+		return this.probeId;
+	}
+
+	public void setProbeId(String probeId) {
+		this.probeId = probeId;
+	}
+
+	@Column(name = "erzeuger", nullable = false, length = 5)
+	public String getErzeuger() {
+		return this.erzeuger;
+	}
+
+	public void setErzeuger(String erzeuger) {
+		this.erzeuger = erzeuger;
+	}
+
+	@Temporal(TemporalType.TIMESTAMP)
+	@Column(name = "k_datum", nullable = false, length = 35)
+	public Date getKDatum() {
+		return this.KDatum;
+	}
+
+	public void setKDatum(Date KDatum) {
+		this.KDatum = KDatum;
+	}
+
+	@Column(name = "k_text", length = 1024)
+	public String getKText() {
+		return this.KText;
+	}
+
+	public void setKText(String KText) {
+		this.KText = KText;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/model/LKommentarPId.java	Mon May 27 15:23:41 2013 +0200
@@ -0,0 +1,73 @@
+package de.intevation.lada.model;
+
+// Generated 21.05.2013 16:58:30 by Hibernate Tools 3.4.0.CR1
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+
+/**
+ * LKommentarPId generated by hbm2java
+ */
+@Embeddable
+public class LKommentarPId implements java.io.Serializable {
+
+	private String probeId;
+	private int KId;
+
+	public LKommentarPId() {
+	}
+
+	public LKommentarPId(String probeId, int KId) {
+		this.probeId = probeId;
+		this.KId = KId;
+	}
+
+	@Column(name = "probe_id", nullable = false, length = 20)
+	public String getProbeId() {
+		return this.probeId;
+	}
+
+	public void setProbeId(String probeId) {
+		this.probeId = probeId;
+	}
+
+	@Column(name = "k_id", nullable = false)
+	@GeneratedValue(strategy= GenerationType.AUTO, generator = "SEQ_Store")
+	@SequenceGenerator(name = "SEQ_Store", sequenceName="lkommentarp_sequence")
+	public int getKId() {
+		return this.KId;
+	}
+
+	public void setKId(int KId) {
+		this.KId = KId;
+	}
+
+	public boolean equals(Object other) {
+		if ((this == other))
+			return true;
+		if ((other == null))
+			return false;
+		if (!(other instanceof LKommentarPId))
+			return false;
+		LKommentarPId castOther = (LKommentarPId) other;
+
+		return ((this.getProbeId() == castOther.getProbeId()) || (this
+				.getProbeId() != null && castOther.getProbeId() != null && this
+				.getProbeId().equals(castOther.getProbeId())))
+				&& (this.getKId() == castOther.getKId());
+	}
+
+	public int hashCode() {
+		int result = 17;
+
+		result = 37 * result
+				+ (getProbeId() == null ? 0 : this.getProbeId().hashCode());
+		result = 37 * result + this.getKId();
+		return result;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/LKommentarService.java	Mon May 27 15:23:41 2013 +0200
@@ -0,0 +1,93 @@
+package de.intevation.lada.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.data.LKommentarPRepository;
+import de.intevation.lada.model.LKommentarP;
+
+/**
+ * This class produces a RESTful service to read the contents of LKommentarP table.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
+@Path("/kommentar")
+@RequestScoped
+public class LKommentarService
+{
+    /**
+     * The Repository.
+     */
+    @Inject @Named("lkommentarRepository")
+    private LKommentarPRepository repository;
+
+    /**
+     * The logger for this class
+     */
+    @Inject
+    private Logger logger;
+
+    /**
+     * Request a single SKommentarP via its id.
+     *
+     * @param id The mst_id
+     * @return JSON Object via REST service.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces("text/json")
+    public LKommentarP findById(@PathParam("id") String id) {
+        return repository.findById(LKommentarP.class, id);
+    }
+
+    /**
+     * Request a list of LKommentarP objects filtered by LProbe id.
+     *
+     * @param info The query parameters
+     * @return JSON object via REST service.
+     */
+    @GET
+    @Produces("text/json")
+    public List<LKommentarP> filter(@Context UriInfo info) {
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        if (params.isEmpty()) {
+            return new ArrayList<LKommentarP>(0);
+        }
+        if (params.containsKey("probe")) {
+            String probe = params.getFirst("probe");
+            return repository.filter(probe);
+        }
+        else {
+            return new ArrayList<LKommentarP>(0);
+        }
+    }
+
+    @POST
+    @Path("/create")
+    @Consumes("application/json")
+    public String create(LKommentarP kommentar) {
+        String response = repository.create(kommentar);
+        if (response.isEmpty()) {
+            return "[{success: true}]";
+        }
+        else {
+            return "[{success: false," +
+                " error: " + response + "}]";
+        }
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)