changeset 244:f3e15ba7c3b7

Use a sequence for pk in LStatusId and create a new ID object.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 15 Jul 2013 13:22:00 +0200
parents 6a85146d76f5
children 1963f002e4c0
files src/main/java/de/intevation/lada/model/LStatus.java src/main/java/de/intevation/lada/model/LStatusId.java src/main/java/de/intevation/lada/rest/LStatusService.java
diffstat 3 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/LStatus.java	Mon Jul 15 13:20:42 2013 +0200
+++ b/src/main/java/de/intevation/lada/model/LStatus.java	Mon Jul 15 13:22:00 2013 +0200
@@ -12,6 +12,7 @@
 import javax.persistence.JoinColumn;
 import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
+import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
@@ -21,9 +22,11 @@
  */
 @Entity
 @Table(name = "l_status", schema = "public")
+@SequenceGenerator(name = "STATUS_ID_STORE", sequenceName = "status_id_seq")
 public class LStatus implements java.io.Serializable {
 
 	private LStatusId id;
+	private Integer sId;
 	private String probeId;
 	private String erzeuger;
 	private Integer messungsId;
@@ -68,7 +71,16 @@
 		this.id = id;
 	}
 
-	@Column(name = "probe_id", nullable = false, insertable = false, updatable = false)
+    @Column(name = "s_id", nullable = false, insertable = false, updatable = false)
+	public Integer getSId() {
+        return sId;
+    }
+
+    public void setSId(Integer sId) {
+        this.sId = sId;
+    }
+
+    @Column(name = "probe_id", nullable = false, insertable = false, updatable = false)
 	public String getProbeId() {
         return probeId;
     }
--- a/src/main/java/de/intevation/lada/model/LStatusId.java	Mon Jul 15 13:20:42 2013 +0200
+++ b/src/main/java/de/intevation/lada/model/LStatusId.java	Mon Jul 15 13:22:00 2013 +0200
@@ -4,6 +4,8 @@
 
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 
 /**
  * LStatusId generated by hbm2java
@@ -12,13 +14,13 @@
 public class LStatusId implements java.io.Serializable {
 
 	private String probeId;
-	private short messungsId;
+	private Integer messungsId;
 	private short SId;
 
 	public LStatusId() {
 	}
 
-	public LStatusId(String probeId, short messungsId, short SId) {
+	public LStatusId(String probeId, Integer messungsId, short SId) {
 		this.probeId = probeId;
 		this.messungsId = messungsId;
 		this.SId = SId;
@@ -34,15 +36,16 @@
 	}
 
 	@Column(name = "messungs_id", nullable = false)
-	public short getMessungsId() {
+	public Integer getMessungsId() {
 		return this.messungsId;
 	}
 
-	public void setMessungsId(short messungsId) {
+	public void setMessungsId(Integer messungsId) {
 		this.messungsId = messungsId;
 	}
 
 	@Column(name = "s_id", nullable = false)
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "STATUS_ID_STORE")
 	public short getSId() {
 		return this.SId;
 	}
--- a/src/main/java/de/intevation/lada/rest/LStatusService.java	Mon Jul 15 13:20:42 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LStatusService.java	Mon Jul 15 13:22:00 2013 +0200
@@ -21,6 +21,7 @@
 import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LStatus;
+import de.intevation.lada.model.LStatusId;
 
 /**
  * This class produces a RESTful service to read, write and update
@@ -130,6 +131,10 @@
         try {
             String probeId = status.getProbeId();
             if (authentication.hasAccess(headers, probeId)) {
+                LStatusId id = new LStatusId();
+                id.setMessungsId(status.getMessungsId());
+                id.setProbeId(probeId);
+                status.setId(id);
                 return repository.create(status);
             }
             return new Response(false, 698, new ArrayList<LStatus>());
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)