Mercurial > lada > lada-server
changeset 245:1963f002e4c0
Use a sequence to generate the id and create an id object in service.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 15 Jul 2013 13:22:55 +0200 |
parents | f3e15ba7c3b7 |
children | 7a1bbd96cecd |
files | src/main/java/de/intevation/lada/model/LMessung.java src/main/java/de/intevation/lada/model/LMessungId.java src/main/java/de/intevation/lada/model/LMesswertId.java src/main/java/de/intevation/lada/rest/LMessungService.java src/main/java/de/intevation/lada/rest/LMesswertService.java |
diffstat | 5 files changed, 32 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 13:22:55 2013 +0200 @@ -11,9 +11,12 @@ import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -23,9 +26,11 @@ */ @Entity @Table(name = "l_messung", schema = "public") +@SequenceGenerator(name = "MESSUNG_ID_STORE", sequenceName = "messung_id_seq") public class LMessung implements java.io.Serializable { private LMessungId id; + private Integer messungsId; private String probeId; private String mmtId; private String nebenprobenNr; @@ -73,7 +78,16 @@ this.id = id; } - @Column(name = "probe_id", nullable = false, insertable = false, updatable = false) + @Column(name = "messungs_id", nullable = false, insertable = false, updatable = false) + public Integer getMessungsId() { + return messungsId; + } + + public void setMessungsId(Integer messungsId) { + this.messungsId = messungsId; + } + + @Column(name = "probe_id", nullable = false, insertable = false, updatable = false) public String getProbeId() { return this.probeId; }
--- a/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 13:22:55 2013 +0200 @@ -4,6 +4,8 @@ import javax.persistence.Column; import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; /** * LMessungId generated by hbm2java @@ -32,6 +34,7 @@ } @Column(name = "messungs_id", nullable = false) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MESSUNG_ID_STORE") public short getMessungsId() { return this.messungsId; }
--- a/src/main/java/de/intevation/lada/model/LMesswertId.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMesswertId.java Mon Jul 15 13:22:55 2013 +0200 @@ -12,13 +12,13 @@ public class LMesswertId implements java.io.Serializable { private String probeId; - private short messungsId; + private Integer messungsId; private int messgroesseId; public LMesswertId() { } - public LMesswertId(String probeId, short messungsId, int messgroesseId) { + public LMesswertId(String probeId, Integer messungsId, int messgroesseId) { this.probeId = probeId; this.messungsId = messungsId; this.messgroesseId = messgroesseId; @@ -34,11 +34,11 @@ } @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; }
--- a/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 13:22:55 2013 +0200 @@ -22,6 +22,7 @@ import de.intevation.lada.data.QueryBuilder; import de.intevation.lada.data.Repository; import de.intevation.lada.model.LMessung; +import de.intevation.lada.model.LMessungId; /** * This class produces a RESTful service to read, write and update @@ -133,6 +134,9 @@ try { String probeId = messung.getProbeId(); if (authentication.hasAccess(headers, probeId)) { + LMessungId id = new LMessungId(); + id.setProbeId(probeId); + messung.setId(id); return repository.create(messung); } return new Response(false, 698, new ArrayList<LMessung>());
--- a/src/main/java/de/intevation/lada/rest/LMesswertService.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMesswertService.java Mon Jul 15 13:22:55 2013 +0200 @@ -23,6 +23,7 @@ import de.intevation.lada.data.Repository; import de.intevation.lada.model.LMessung; import de.intevation.lada.model.LMesswert; +import de.intevation.lada.model.LMesswertId; /** * This class produces a RESTful service to read, write and update @@ -141,6 +142,11 @@ Integer messungsId = messwert.getMessungsId(); if (authentication.hasAccess(headers, probeId) && !isReadOnly(probeId, messungsId)) { + LMesswertId id = new LMesswertId(); + id.setMessgroesseId(messwert.getMessgroesseId()); + id.setMessungsId(messungsId); + id.setProbeId(probeId); + messwert.setId(id); return repository.create(messwert); } return new Response(false, 698, new ArrayList<LMesswert>());