Mercurial > dive4elements > river
changeset 763:8076f6a689d0
First part of flys/issue18
flys-backend/trunk@2124 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 09:22:00 +0000 |
parents | 23fe9ac1c3b4 |
children | e09f00ecb915 |
files | flys-backend/ChangeLog flys-backend/doc/schema/postgresql-cleanup.sql flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java flys-backend/src/main/java/de/intevation/flys/importer/AnnotationsParser.java flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotationType.java flys-backend/src/main/java/de/intevation/flys/model/Annotation.java flys-backend/src/main/java/de/intevation/flys/model/AnnotationType.java |
diffstat | 9 files changed, 218 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/ChangeLog Wed Jun 15 09:22:00 2011 +0000 @@ -1,3 +1,38 @@ +2011-06-14 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + First part of flys/issue18 + + * doc/schema/postgresql.sql: Add new table 'annotation_types'. + To update existing databases: + BEGIN; + CREATE SEQUENCE ANNOTATION_TYPES_ID_SEQ; + CREATE TABLE annotation_types ( + id int PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL UNIQUE + ); + ALTER TABLE annotations ADD COLUMN type_id int REFERENCES annotation_types(id); + COMMIT; + + * doc/schema/postgresql-cleanup.sql: Removed. Hopeless out-dated. + + * src/main/java/de/intevation/flys/model/AnnotationType.java: + New. Hibernate model to access the type. + + * src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java: + Register the new backend type. + + * src/main/java/de/intevation/flys/model/Annotation.java: + References the annotation type. + + * src/main/java/de/intevation/flys/importer/ImportAnnotationType.java: + New. Model to help import the annotation type. + + * src/main/java/de/intevation/flys/importer/ImportAnnotation.java: + Uses the import type. + + * src/main/java/de/intevation/flys/importer/AnnotationsParser.java: + Set the annotation type to 'null'. TODO: Do the classification! + 2011-06-14 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/importer/AtFileParser.java:
--- a/flys-backend/doc/schema/postgresql-cleanup.sql Tue Jun 14 17:30:09 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -BEGIN; - -DROP VIEW wst_value_table; - -DROP TABLE wst_column_q_ranges; -DROP TABLE wst_q_ranges; -DROP TABLE wst_column_values; -DROP TABLE wst_column; -DROP TABLE wst; - -DROP TABLE discharge_table_values; -DROP TABLE discharge_tables; - -DROP TABLE main_values CASCADE; -DROP TABLE time_intervals CASCADE; -DROP TABLE named_main_values CASCADE; -DROP TABLE main_value_types CASCADE; - -DROP TABLE gauges CASCADE; - -DROP TABLE annotations CASCADE; -DROP TABLE positions CASCADE; -DROP TABLE ranges CASCADE; -DROP TABLE attributes CASCADE; - -DROP TABLE rivers CASCADE; - -DROP SEQUENCE WST_COLUMN_Q_RANGES_ID_SEQ; -DROP SEQUENCE WST_Q_RANGES_ID_SEQ; -DROP SEQUENCE WST_COLUMN_VALUES_ID_SEQ; -DROP SEQUENCE WST_COLUMNS_ID_SEQ; -DROP SEQUENCE WSTS_ID_SEQ; -DROP SEQUENCE DISCHARGE_TABLE_VALUES_ID_SEQ; -DROP SEQUENCE DISCHARGE_TABLES_ID_SEQ; -DROP SEQUENCE MAIN_VALUES_ID_SEQ; -DROP SEQUENCE TIME_INTERVALS_ID_SEQ; -DROP SEQUENCE NAMED_MAIN_VALUES_ID_SEQ; -DROP SEQUENCE MAIN_VALUE_TYPES_ID_SEQ; -DROP SEQUENCE GAUGES_ID_SEQ; -DROP SEQUENCE ANNOTATIONS_ID_SEQ; -DROP SEQUENCE POSITIONS_ID_SEQ; -DROP SEQUENCE RANGES_ID_SEQ; -DROP SEQUENCE ATTRIBUTES_ID_SEQ; -DROP SEQUENCE RIVERS_ID_SEQ; - -COMMIT;
--- a/flys-backend/doc/schema/postgresql.sql Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/doc/schema/postgresql.sql Wed Jun 15 09:22:00 2011 +0000 @@ -45,6 +45,14 @@ bottom NUMERIC ); +-- Types of annotatations (Hafen, Bruecke, Zufluss, ...) +CREATE SEQUENCE ANNOTATION_TYPES_ID_SEQ; + +CREATE TABLE annotation_types ( + id int PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL UNIQUE +); + -- Some object (eg. Hafen) at a segment of river -- plus its position. CREATE SEQUENCE ANNOTATIONS_ID_SEQ; @@ -54,7 +62,8 @@ range_id int NOT NULL REFERENCES ranges(id), attribute_id int NOT NULL REFERENCES attributes(id), position_id int REFERENCES positions(id), - edge_id int REFERENCES edges(id) + edge_id int REFERENCES edges(id), + type_id int REFERENCES annotation_types(id) ); -- Pegel
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Wed Jun 15 09:22:00 2011 +0000 @@ -10,6 +10,7 @@ import org.hibernate.cfg.Environment; import de.intevation.flys.model.Annotation; +import de.intevation.flys.model.AnnotationType; import de.intevation.flys.model.Attribute; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.DischargeTableValue; @@ -114,6 +115,7 @@ // TODO: Use package reflection here. cfg.addAnnotatedClass(Annotation.class); + cfg.addAnnotatedClass(AnnotationType.class); cfg.addAnnotatedClass(Attribute.class); cfg.addAnnotatedClass(DischargeTable.class); cfg.addAnnotatedClass(DischargeTableValue.class);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/AnnotationsParser.java Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/AnnotationsParser.java Wed Jun 15 09:22:00 2011 +0000 @@ -124,8 +124,10 @@ ImportRange range = new ImportRange(from, to); + ImportAnnotationType type = null; // TODO: do classification + ImportAnnotation annotation = new ImportAnnotation( - attribute, position, range, edge); + attribute, position, range, edge, type); if (!annotations.add(annotation)) { log.debug("duplicated annotation in line "
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java Wed Jun 15 09:22:00 2011 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.importer; import de.intevation.flys.model.Annotation; +import de.intevation.flys.model.AnnotationType; import de.intevation.flys.model.Range; import de.intevation.flys.model.Position; import de.intevation.flys.model.Attribute; @@ -15,10 +16,11 @@ public class ImportAnnotation implements Comparable<ImportAnnotation> { - protected ImportAttribute attribute; - protected ImportPosition position; - protected ImportRange range; - protected ImportEdge edge; + protected ImportAttribute attribute; + protected ImportPosition position; + protected ImportRange range; + protected ImportEdge edge; + protected ImportAnnotationType type; protected Annotation peer; @@ -26,15 +28,17 @@ } public ImportAnnotation( - ImportAttribute attribute, - ImportPosition position, - ImportRange range, - ImportEdge edge + ImportAttribute attribute, + ImportPosition position, + ImportRange range, + ImportEdge edge, + ImportAnnotationType type ) { this.attribute = attribute; this.position = position; this.range = range; this.edge = edge; + this.type = type; } public int compareTo(ImportAnnotation other) { @@ -55,7 +59,15 @@ if (edge != null && other.edge == null) return +1; if (edge == null && other.edge == null) return 0; - return edge.compareTo(other.edge); + if ((d = edge.compareTo(other.edge)) != 0) { + return d; + } + + if (type == null && other.type != null) return -1; + if (type != null && other.type == null) return +1; + if (type == null && other.type == null) return 0; + + return type.compareTo(other.type); } public ImportAttribute getAttribute() { @@ -82,26 +94,46 @@ this.range = range; } + public ImportEdge getEdge() { + return edge; + } + + public void setEdge(ImportEdge edge) { + this.edge = edge; + } + + public ImportAnnotationType getType() { + return type; + } + + public void setType(ImportAnnotationType type) { + this.type = type; + } + public Annotation getPeer(River river) { if (peer == null) { - Range r = range.getPeer(river); - Attribute a = attribute.getPeer(); - Position p = position.getPeer(); - Edge e = edge != null ? edge.getPeer() : null; + Range r = range.getPeer(river); + Attribute a = attribute.getPeer(); + Position p = position.getPeer(); + Edge e = edge != null ? edge.getPeer() : null; + AnnotationType t = type != null ? type.getPeer() : null; + Session session = ImporterSession.getInstance().getDatabaseSession(); Query query = session.createQuery( "from Annotation where " + "range=:range and " + "attribute=:attribute and " + "position=:position and " + - "edge=:edge"); + "edge=:edge and " + + "type=:type"); query.setParameter("range", r); query.setParameter("attribute", a); query.setParameter("position", p); query.setParameter("edge", e); + query.setParameter("type", t); List<Annotation> annotations = query.list(); if (annotations.isEmpty()) { - peer = new Annotation(r, a, p, e); + peer = new Annotation(r, a, p, e, t); session.save(peer); } else {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotationType.java Wed Jun 15 09:22:00 2011 +0000 @@ -0,0 +1,45 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.AnnotationType; + +import org.hibernate.Session; +import org.hibernate.Query; + +import java.util.List; + +public class ImportAnnotationType +implements Comparable<ImportAnnotationType> +{ + protected String name; + protected AnnotationType peer; + + public ImportAnnotationType() { + } + + public ImportAnnotationType(String name) { + this.name = name; + } + + public int compareTo(ImportAnnotationType other) { + return name.compareTo(other.name); + } + + public AnnotationType getPeer() { + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + Query query = session.createQuery( + "from AnnotationType where name=:name"); + query.setParameter("name", name); + List<AnnotationType> types = query.list(); + if (types.isEmpty()) { + peer = new AnnotationType(name); + session.save(peer); + } + else { + peer = types.get(0); + } + } + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/model/Annotation.java Tue Jun 14 17:30:09 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Annotation.java Wed Jun 15 09:22:00 2011 +0000 @@ -17,29 +17,28 @@ public class Annotation implements Serializable { - private Integer id; - private Range range; - private Attribute attribute; - private Position position; - private Edge edge; + private Integer id; + private Range range; + private Attribute attribute; + private Position position; + private Edge edge; + private AnnotationType type; public Annotation() { } - public Annotation(Range range, Attribute attribute, Position position) { - this(range, attribute, position, null); - } - public Annotation( - Range range, - Attribute attribute, - Position position, - Edge edge + Range range, + Attribute attribute, + Position position, + Edge edge, + AnnotationType type ) { this.range = range; this.attribute = attribute; this.position = position; this.edge = edge; + this.type = type; } @Id @@ -98,5 +97,15 @@ public void setEdge(Edge edge) { this.edge = edge; } + + @OneToOne + @JoinColumn(name = "type_id") + public AnnotationType getType() { + return type; + } + + public void setType(AnnotationType type) { + this.type = type; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/AnnotationType.java Wed Jun 15 09:22:00 2011 +0000 @@ -0,0 +1,54 @@ +package de.intevation.flys.model; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.GeneratedValue; +import javax.persistence.Column; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; + +@Entity +@Table(name = "annotation_types") +public class AnnotationType +implements Serializable +{ + private Integer id; + private String name; + + public AnnotationType() { + } + + public AnnotationType(String name) { + this.name = name; + } + + @Id + @SequenceGenerator( + name = "SEQUENCE_ANNOTATION_TYPES_ID_SEQ", + sequenceName = "ANNOTATION_TYPES_ID_SEQ", + allocationSize = 1) + @GeneratedValue( + strategy = GenerationType.SEQUENCE, + generator = "SEQUENCE_ANNOTATION_TYPES_ID_SEQ") + @Column(name = "id") + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @Column(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :