Mercurial > dive4elements > river
changeset 471:3570e4af8cb2
Added 'position' column to wst_columns to allow order them by there column position in the original wst file.
flys-backend/trunk@1710 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 15 Apr 2011 16:06:15 +0000 (2011-04-15) |
parents | f4afea9b7537 |
children | 1e196c75563b |
files | flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java |
diffstat | 5 files changed, 57 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri Apr 15 15:28:35 2011 +0000 +++ b/flys-backend/ChangeLog Fri Apr 15 16:06:15 2011 +0000 @@ -1,3 +1,27 @@ +2011-04-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * doc/schema/postgresql.sql: Added 'position' column to wst_columns + to allow order them by there column position in the original + wst file. + + Update existing database with: + + BEGIN; + ALTER TABLE wst_columns ADD COLUMN position int; + UPDATE wst_columns w SET + position = id - (SELECT min(id) FROM wst_columns WHERE wst_id = w.wst_id); + ALTER TABLE wst_columns ADD CONSTRAINT wst_columns_wst_id_position_key + UNIQUE (wst_id, position); + COMMIT; + + * src/main/java/de/intevation/flys/model/Wst.java, + src/main/java/de/intevation/flys/model/WstColumn.java: + Adjusted models. + + * src/main/java/de/intevation/flys/importer/ImportWst.java, + src/main/java/de/intevation/flys/importer/ImportWstColumn.java: + Adjusted importer. + 2011-04-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * doc/schema/postgresql.sql: Forget ',' in schema.
--- a/flys-backend/doc/schema/postgresql.sql Fri Apr 15 15:28:35 2011 +0000 +++ b/flys-backend/doc/schema/postgresql.sql Fri Apr 15 16:06:15 2011 +0000 @@ -153,10 +153,12 @@ wst_id int NOT NULL REFERENCES wsts(id), name VARCHAR(256) NOT NULL, description VARCHAR(256), + position int NOT NULL DEFAULT 0, time_interval_id int REFERENCES time_intervals(id), - UNIQUE (wst_id, name) + UNIQUE (wst_id, name), + UNIQUE (wst_id, position) ); -- w values in WST file column
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java Fri Apr 15 15:28:35 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java Fri Apr 15 16:06:15 2011 +0000 @@ -41,7 +41,7 @@ public ImportWstColumn getColumn(String name) { ImportWstColumn column = columns.get(name); if (column == null) { - column = new ImportWstColumn(this, name, null); + column = new ImportWstColumn(this, name, null, columns.size()); columns.put(name, column); } return column;
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java Fri Apr 15 15:28:35 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java Fri Apr 15 16:06:15 2011 +0000 @@ -17,6 +17,7 @@ protected ImportWst wst; protected String name; protected String description; + protected Integer position; protected List<ImportWstColumnQRange> columnQRanges; protected List<ImportWstColumnValue> columnValues; @@ -31,12 +32,14 @@ public ImportWstColumn( ImportWst wst, String name, - String description + String description, + Integer position ) { this(); this.wst = wst; this.name = name; this.description = description; + this.position = position; } public ImportWst getWst() { @@ -63,6 +66,14 @@ this.description = description; } + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + public void addColumnValue(BigDecimal position, BigDecimal w) { columnValues.add( new ImportWstColumnValue(this, position, w)); @@ -89,13 +100,15 @@ Session session = Importer.sessionHolder.get(); Query query = session.createQuery( "from WstColumn where " + - "wst=:wst and name=:name and description=:description"); + "wst=:wst and name=:name and description=:description" + + " and position=:position"); query.setParameter("wst", w); query.setParameter("name", name); query.setParameter("description", description); + query.setParameter("position", position); List<WstColumn> columns = query.list(); if (columns.isEmpty()) { - peer = new WstColumn(w, name, description, null); + peer = new WstColumn(w, name, description, position, null); session.save(peer); } else {
--- a/flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java Fri Apr 15 15:28:35 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/WstColumn.java Fri Apr 15 16:06:15 2011 +0000 @@ -24,7 +24,9 @@ private Wst wst; private String name; private String description; + private Integer position; private TimeInterval timeInterval; + private List<WstColumnQRange> columnQRanges; private List<WstColumnValue> columnValues; @@ -35,11 +37,13 @@ Wst wst, String name, String description, + Integer position, TimeInterval timeInterval ) { this.wst = wst; this.name = name; this.description = description; + this.position = position; this.timeInterval = timeInterval; } @@ -88,6 +92,15 @@ this.description = description; } + @Column(name = "position") + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + @OneToOne @JoinColumn(name = "time_interval_id" ) public TimeInterval getTimeInterval() {