[Dive4elements-commits] [PATCH 1 of 2] Use lookup table from bedd_height from database in importer
Wald Commits
scm-commit at wald.intevation.org
Wed Mar 13 16:39:39 CET 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1363189148 -3600
# Node ID db196abd16ca362ca0f178ef1a1de246a4915375
# Parent 731030b69c7e2c879dbe4392cd915ad0bb3f9ddf
Use lookup table from bedd_height from database in importer.
diff -r 731030b69c7e -r db196abd16ca flys-backend/doc/schema/oracle-minfo.sql
--- a/flys-backend/doc/schema/oracle-minfo.sql Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/doc/schema/oracle-minfo.sql Wed Mar 13 16:39:08 2013 +0100
@@ -24,7 +24,7 @@
-- lookup table for bedheight types
CREATE TABLE bed_height_type (
id NUMBER(38,0) NOT NULL,
- type VARCHAR(65) NOT NULL,
+ name VARCHAR(65) NOT NULL,
PRIMARY KEY(id)
);
INSERT INTO bed_height_type VALUES (1, 'Querprofil')
diff -r 731030b69c7e -r db196abd16ca flys-backend/doc/schema/postgresql-minfo.sql
--- a/flys-backend/doc/schema/postgresql-minfo.sql Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-minfo.sql Wed Mar 13 16:39:08 2013 +0100
@@ -24,7 +24,7 @@
-- lookup table for bedheight types
CREATE TABLE bed_height_type (
id int NOT NULL,
- type VARCHAR(64) NOT NULL,
+ name VARCHAR(64) NOT NULL,
PRIMARY KEY(id)
);
INSERT INTO bed_height_type VALUES (1, 'Querprofil')
diff -r 731030b69c7e -r db196abd16ca flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java Wed Mar 13 16:39:08 2013 +0100
@@ -16,19 +16,22 @@
Logger.getLogger(ImportBedHeightType.class);
protected String name;
- protected String description;
protected BedHeightType peer;
-
- public ImportBedHeightType(String name, String description) {
- this.name = name;
- this.description = description;
+ public ImportBedHeightType(BedHeightType peer) {
+ this.peer = peer;
+ name = peer.getName();
}
+ public ImportBedHeightType(String name) {
+ this.name = name;
+ }
+
+
public void storeDependencies() {
- BedHeightType type = getPeer();
+ getPeer();
}
@@ -37,16 +40,14 @@
Session session = ImporterSession.getInstance().getDatabaseSession();
Query query = session.createQuery(
- "from BedHeightType where " +
- "name=:name and description=:description");
+ "from BedHeightType where name=:name and description=:description");
query.setParameter("name", name);
- query.setParameter("description", description);
List<BedHeightType> types = query.list();
if (types.isEmpty()) {
- peer = new BedHeightType(name, description);
+ peer = new BedHeightType(name);
session.save(peer);
}
else {
diff -r 731030b69c7e -r db196abd16ca flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java Wed Mar 13 16:39:08 2013 +0100
@@ -331,15 +331,14 @@
if (m.matches()) {
String tmp = m.group(1).replace(";", "");
- String name = BedHeightType.getBedHeightName(tmp);
+ BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(tmp);
- if (name != null) {
- obj.setType(new ImportBedHeightType(name, tmp));
+ if (bht != null) {
+ obj.setType(new ImportBedHeightType(bht));
return true;
}
- else {
- log.warn("Unknown bed height type: '" + tmp + "'");
- }
+
+ log.warn("Unknown bed height type: '" + tmp + "'");
}
return false;
diff -r 731030b69c7e -r db196abd16ca flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java Wed Mar 13 16:39:08 2013 +0100
@@ -2,6 +2,8 @@
import java.io.Serializable;
+import java.util.List;
+
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@@ -12,6 +14,10 @@
import org.apache.log4j.Logger;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import de.intevation.flys.backend.SessionHolder;
@Entity
@Table(name = "bed_height_type")
@@ -22,15 +28,13 @@
private Integer id;
private String name;
- private String description;
public BedHeightType() {
}
- public BedHeightType(String name, String description) {
- this.name = name;
- this.description = description;
+ public BedHeightType(String name) {
+ this.name = name;
}
@Id
@@ -59,36 +63,17 @@
this.name = name;
}
- @Column(name = "description")
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
+ public static BedHeightType fetchBedHeightTypeForType(String type) {
+ Session session = SessionHolder.HOLDER.get();
+ Query query = session.createQuery(
+ "from BedHeightType where type=:type");
+ query.setParameter("type", type);
- public static String getBedHeightName(String description) {
- if (description.equals("Flächenpeilung")) {
- return "FP";
- }
- else if ("Querprofile".equals(description)) {
- return "QP";
- }
- else if ("Querprofil".equals(description)) {
- return "QP";
- }
- else if ("TIN".equals(description)) {
- return "TIN";
- }
- else if ("Flächen- u. Querprofilpeilungen".equals(description)) {
- return "FP-QP";
- }
- else {
- log.warn("Unknown bed height type: " + description);
- return null;
- }
+ List<Object> results = query.list();
+
+ return results.isEmpty() ? null : (BedHeightType)results.get(0);
}
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4elements-commits
mailing list