# HG changeset patch # User Sascha L. Teichmann # Date 1300200596 0 # Node ID 249390dd24e7891db60c460a2a5a6a8923ae3e2f # Parent 8e2f2ddc507ff71b570d8e7be4d9323725c8de21 Added foreign key constraint annotations to model classes. flys-backend/trunk@1473 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/ChangeLog Tue Mar 15 14:49:56 2011 +0000 @@ -1,3 +1,16 @@ +2011-03-15 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/App.java: Wire all POJOs + to corresponding factory. + + * src/main/java/de/intevation/flys/model/*.java: Generate + all foreign key constraints. TODO: name them correctly + because the machine generated names are ugly and do + not fit the PostgreSQL names. + + * doc/schema/postgresql.sql: Small quantifier fix in descriptions + of wst columns. + 2011-03-14 Sascha L. Teichmann * doc/schema/postgresql.sql: Fixed wrong spelled diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/doc/schema/postgresql.sql --- a/flys-backend/doc/schema/postgresql.sql Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/doc/schema/postgresql.sql Tue Mar 15 14:49:56 2011 +0000 @@ -151,7 +151,7 @@ id int PRIMARY KEY NOT NULL, wst_id int NOT NULL REFERENCES wsts(id), name VARCHAR(256) NOT NULL, - description VARCHAR, + description VARCHAR(256), time_interval_id int REFERENCES time_intervals(id), diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/App.java --- a/flys-backend/src/main/java/de/intevation/flys/App.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/App.java Tue Mar 15 14:49:56 2011 +0000 @@ -4,7 +4,22 @@ import org.hibernate.SessionFactory; +import de.intevation.flys.model.Annotation; +import de.intevation.flys.model.Attribute; +import de.intevation.flys.model.DischargeTable; +import de.intevation.flys.model.DischargeTableValue; +import de.intevation.flys.model.Gauge; +import de.intevation.flys.model.MainValueType; +import de.intevation.flys.model.NamedMainValues; +import de.intevation.flys.model.Position; +import de.intevation.flys.model.Range; import de.intevation.flys.model.River; +import de.intevation.flys.model.TimeInterval; +import de.intevation.flys.model.WstColumn; +import de.intevation.flys.model.WstColumnQRange; +import de.intevation.flys.model.WstColumnValue; +import de.intevation.flys.model.Wst; +import de.intevation.flys.model.WstQRange; import org.hibernate.dialect.resolver.DialectFactory; @@ -22,23 +37,45 @@ private static final String PASS = System.getProperty("flys.pass", "flys"); - public static void main(String [] args) - throws Exception - { - Configuration cfg = new Configuration(); - - cfg.addAnnotatedClass(River.class); + public static void dumpSchema(Configuration cfg) { + System.out.println("BEGIN;"); String [] setupScript = cfg.generateSchemaCreationScript( DialectFactory.constructDialect( "org.hibernate.dialect.PostgreSQLDialect")); for (String line: setupScript) { - System.out.println(line); + System.out.println(line + ";"); } + System.out.println("COMMIT;"); + } + + public static void main(String [] args) + throws Exception + { + Configuration cfg = new Configuration(); + + cfg.addAnnotatedClass(Annotation.class); + cfg.addAnnotatedClass(Attribute.class); + cfg.addAnnotatedClass(DischargeTable.class); + cfg.addAnnotatedClass(DischargeTableValue.class); + cfg.addAnnotatedClass(Gauge.class); + cfg.addAnnotatedClass(MainValueType.class); + cfg.addAnnotatedClass(NamedMainValues.class); + cfg.addAnnotatedClass(Position.class); + cfg.addAnnotatedClass(Range.class); + cfg.addAnnotatedClass(River.class); + cfg.addAnnotatedClass(TimeInterval.class); + cfg.addAnnotatedClass(WstColumn.class); + cfg.addAnnotatedClass(WstColumnQRange.class); + cfg.addAnnotatedClass(WstColumnValue.class); + cfg.addAnnotatedClass(Wst.class); + cfg.addAnnotatedClass(WstQRange.class); Properties props = new Properties(); + dumpSchema(cfg); + props.setProperty( Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect"); diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/Annotation.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Annotation.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Annotation.java Tue Mar 15 14:49:56 2011 +0000 @@ -9,13 +9,15 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "annotations") public class Annotation implements Serializable { - private Integer id; + private Integer id; private Range range; private Attribute attribute; private Position position; @@ -40,28 +42,34 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "range_id") + public Range getRange() { + return range; + } + public void setRange(Range range) { this.range = range; } - public Range getRange() { - return range; + @OneToOne + @JoinColumn(name = "attribute_id") + public Attribute getAttribute() { + return attribute; } public void setAttribute(Attribute attribute) { this.attribute = attribute; } - public Attribute getAttribute() { - return attribute; + @OneToOne + @JoinColumn(name = "position_id") + public Position getPosition() { + return position; } public void setPosition(Position position) { this.position = position; } - - public Position getPosition() { - return position; - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java --- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Tue Mar 15 14:49:56 2011 +0000 @@ -9,6 +9,11 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; + +import java.util.List; @Entity @Table(name = "discharge_tables") @@ -19,6 +24,8 @@ private Gauge gauge; private TimeInterval timeInterval; + private List dischargeTableValues; + public DischargeTable() { } @@ -39,20 +46,36 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "time_interval_id" ) + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { this.timeInterval = timeInterval; } - public TimeInterval getTimeInterval() { - return timeInterval; + @OneToOne + @JoinColumn(name = "gauge_id" ) + public Gauge getGauge() { + return gauge; } public void setGauge(Gauge gauge) { this.gauge = gauge; } - public Gauge getGauge() { - return gauge; + @OneToMany + @JoinColumn(name = "table_id") + public List getDischargeTableValues() { + return dischargeTableValues; + } + + public void setDischargeTableValues( + List dischargeTableValues + ) { + this.dischargeTableValues = dischargeTableValues; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/DischargeTableValue.java --- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeTableValue.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeTableValue.java Tue Mar 15 14:49:56 2011 +0000 @@ -11,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "discharge_table_values") @@ -42,13 +44,16 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "table_id" ) + public DischargeTable getDischargeTable() { + return dischargeTable; + } + public void setDischargeTable(DischargeTable dischargeTable) { this.dischargeTable = dischargeTable; } - public DischargeTable getDischargeTable() { - return dischargeTable; - } @Column(name = "q") public BigDecimal getQ() { diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/Gauge.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Tue Mar 15 14:49:56 2011 +0000 @@ -11,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; @Entity @Table(name = "gauges") @@ -81,6 +83,8 @@ this.datum = datum; } + @OneToOne + @JoinColumn(name = "range_id" ) public Range getRange() { return range; } diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/MainValueType.java --- a/flys-backend/src/main/java/de/intevation/flys/model/MainValueType.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/MainValueType.java Tue Mar 15 14:49:56 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.model; +import java.math.BigDecimal; + import java.io.Serializable; import javax.persistence.Entity; @@ -15,9 +17,8 @@ public class MainValueType implements Serializable { - private Integer id; - - private String value; + private Integer id; + private BigDecimal value; public MainValueType() { } @@ -39,12 +40,12 @@ this.id = id; } - @Column(name = "value") - public String getValue() { + @Column(name = "value") // FIXME: Type conversion needed? + public BigDecimal getValue() { return value; } - public void setValue(String value) { + public void setValue(BigDecimal value) { this.value = value; } } diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/NamedMainValues.java --- a/flys-backend/src/main/java/de/intevation/flys/model/NamedMainValues.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/NamedMainValues.java Tue Mar 15 14:49:56 2011 +0000 @@ -9,6 +9,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "named_main_values") @@ -48,12 +50,14 @@ this.name = name; } + @OneToOne + @JoinColumn(name = "type_id" ) + public MainValueType getType() { + return type; + } + public void setType(MainValueType type) { this.type = type; } - - public MainValueType getType() { - return type; - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/Position.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Position.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Position.java Tue Mar 15 14:49:56 2011 +0000 @@ -8,8 +8,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Column; import javax.persistence.SequenceGenerator; +import javax.persistence.OneToMany; +import javax.persistence.JoinColumn; import javax.persistence.GenerationType; +import java.util.List; + @Entity @Table(name = "positions") public class Position @@ -19,6 +23,8 @@ private String value; + private List annotations; + public Position() { } @@ -47,5 +53,15 @@ public void setValue(String value) { this.value = value; } + + @OneToMany + @JoinColumn(name="position_id") + public List getAnnotations() { + return annotations; + } + + public void setAnnotations(List annotations) { + this.annotations = annotations; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/Range.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Range.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Range.java Tue Mar 15 14:49:56 2011 +0000 @@ -11,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; @Entity @Table(name = "ranges") @@ -65,6 +67,8 @@ this.river = river; } + @OneToOne + @JoinColumn(name = "id") public River getRiver() { return river; } diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/River.java --- a/flys-backend/src/main/java/de/intevation/flys/model/River.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java Tue Mar 15 14:49:56 2011 +0000 @@ -8,8 +8,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Column; import javax.persistence.SequenceGenerator; +import javax.persistence.OneToMany; +import javax.persistence.JoinColumn; import javax.persistence.GenerationType; +import java.util.List; + @Entity @Table(name = "rivers") public class River @@ -19,6 +23,8 @@ private String name; + private List gauges; + @Id @SequenceGenerator( name = "SEQUENCE_RIVERS_ID_SEQ", @@ -51,5 +57,15 @@ public River(String name) { this.name = name; } + + @OneToMany + @JoinColumn(name="river_id") + public List getGauges() { + return gauges; + } + + public void setGauges(List gauges) { + this.gauges = gauges; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/Wst.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Tue Mar 15 14:49:56 2011 +0000 @@ -9,6 +9,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; @Entity @Table(name = "wsts") @@ -39,14 +41,16 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "river_id" ) + public River getRiver() { + return river; + } + public void setRiver(River river) { this.river = river; } - public River getRiver() { - return river; - } - @Column(name = "description") public String getDescription() { return description; diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java --- a/flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java Tue Mar 15 14:49:56 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.model; +import java.util.List; + import java.io.Serializable; import javax.persistence.Entity; @@ -9,17 +11,22 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.OneToMany; @Entity @Table(name = "wst_columns") public class WstColumn implements Serializable { - private Integer id; - private Wst wst; - private String name; - private String description; - private TimeInterval timeInterval; + private Integer id; + private Wst wst; + private String name; + private String description; + private TimeInterval timeInterval; + private List columnQRanges; + private List columnValues; public WstColumn() { } @@ -41,6 +48,8 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "wst_id" ) public Wst getWst() { return wst; } @@ -67,12 +76,34 @@ this.description = description; } + @OneToOne + @JoinColumn(name = "time_interval_id" ) + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { this.timeInterval = timeInterval; } - public TimeInterval getTimeInterval() { - return timeInterval; + @OneToMany + @JoinColumn(name="wst_column_id") + public List getColumnQRanges() { + return columnQRanges; + } + + public void setColumnQRanges(List columnQRanges) { + this.columnQRanges = columnQRanges; + } + + @OneToMany + @JoinColumn(name="wst_column_id") + public List getColumnValues() { + return columnValues; + } + + public void setColumnValues(List columnValues) { + this.columnValues = columnValues; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/WstColumnQRange.java --- a/flys-backend/src/main/java/de/intevation/flys/model/WstColumnQRange.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/WstColumnQRange.java Tue Mar 15 14:49:56 2011 +0000 @@ -9,6 +9,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "wst_column_q_ranges") @@ -39,6 +41,8 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "wst_column_id" ) public WstColumn getWstColumn() { return wstColumn; } @@ -47,6 +51,8 @@ this.wstColumn = wstColumn; } + @OneToOne + @JoinColumn(name = "wst_q_range_id" ) public WstQRange getWstQRange() { return wstQRange; } diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java --- a/flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java Tue Mar 15 14:49:56 2011 +0000 @@ -11,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "wst_column_values") @@ -19,7 +21,7 @@ { private Integer id; private WstColumn wstColumn; - private Position position; + private BigDecimal position; private BigDecimal w; public WstColumnValue() { @@ -42,6 +44,8 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "wst_column_id") public WstColumn getWstColumn() { return wstColumn; } @@ -50,11 +54,12 @@ this.wstColumn = wstColumn; } - public Position getPosition() { + @Column(name = "position") // FIXME: type mapping needed? + public BigDecimal getPosition() { return position; } - public void setPosition(Position position) { + public void setPosition(BigDecimal position) { this.position = position; } diff -r 8e2f2ddc507f -r 249390dd24e7 flys-backend/src/main/java/de/intevation/flys/model/WstQRange.java --- a/flys-backend/src/main/java/de/intevation/flys/model/WstQRange.java Mon Mar 14 15:40:14 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/WstQRange.java Tue Mar 15 14:49:56 2011 +0000 @@ -11,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.SequenceGenerator; import javax.persistence.GenerationType; +import javax.persistence.OneToOne; +import javax.persistence.JoinColumn; @Entity @Table(name = "wst_q_ranges") @@ -41,6 +43,8 @@ this.id = id; } + @OneToOne + @JoinColumn(name = "range_id" ) public Range getRange() { return range; }