annotate flys-backend/src/main/java/de/intevation/flys/App.java @ 189:bc3747a371cc

First part of parsing main values. flys-backend/trunk@1520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 18 Mar 2011 16:12:24 +0000
parents 249390dd24e7
children ed38839a6b08
rev   line source
165
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys;
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
3 import org.hibernate.cfg.Configuration;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
4
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
5 import org.hibernate.SessionFactory;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
6
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
7 import de.intevation.flys.model.Annotation;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
8 import de.intevation.flys.model.Attribute;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
9 import de.intevation.flys.model.DischargeTable;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
10 import de.intevation.flys.model.DischargeTableValue;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
11 import de.intevation.flys.model.Gauge;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
12 import de.intevation.flys.model.MainValueType;
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
13 import de.intevation.flys.model.NamedMainValue;
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
14 import de.intevation.flys.model.MainValue;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
15 import de.intevation.flys.model.Position;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
16 import de.intevation.flys.model.Range;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
17 import de.intevation.flys.model.River;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
18 import de.intevation.flys.model.TimeInterval;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
19 import de.intevation.flys.model.WstColumn;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
20 import de.intevation.flys.model.WstColumnQRange;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
21 import de.intevation.flys.model.WstColumnValue;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
22 import de.intevation.flys.model.Wst;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
23 import de.intevation.flys.model.WstQRange;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
24
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
25 import org.hibernate.dialect.resolver.DialectFactory;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
26
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
27 import java.util.Properties;
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
28
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
29 import org.hibernate.cfg.Environment;
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
30
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
31 import org.hibernate.Session;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
32
165
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public class App
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 {
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
35 private static final String USER =
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
36 System.getProperty("flys.user", "flys");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
37
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
38 private static final String PASS =
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
39 System.getProperty("flys.pass", "flys");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
40
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
41 public static void dumpSchema(Configuration cfg) {
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
42 System.out.println("BEGIN;");
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
43
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
44 String [] setupScript = cfg.generateSchemaCreationScript(
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
45 DialectFactory.constructDialect(
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
46 "org.hibernate.dialect.PostgreSQLDialect"));
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
47
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
48 for (String line: setupScript) {
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
49 System.out.println(line + ";");
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
50 }
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
51
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
52 System.out.println("COMMIT;");
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
53 }
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
54
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
55 public static void main(String [] args)
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
56 throws Exception
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
57 {
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
58 Configuration cfg = new Configuration();
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
59
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
60 cfg.addAnnotatedClass(Annotation.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
61 cfg.addAnnotatedClass(Attribute.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
62 cfg.addAnnotatedClass(DischargeTable.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
63 cfg.addAnnotatedClass(DischargeTableValue.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
64 cfg.addAnnotatedClass(Gauge.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
65 cfg.addAnnotatedClass(MainValueType.class);
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
66 cfg.addAnnotatedClass(NamedMainValue.class);
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
67 cfg.addAnnotatedClass(MainValue.class);
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
68 cfg.addAnnotatedClass(Position.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
69 cfg.addAnnotatedClass(Range.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
70 cfg.addAnnotatedClass(River.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
71 cfg.addAnnotatedClass(TimeInterval.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
72 cfg.addAnnotatedClass(WstColumn.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
73 cfg.addAnnotatedClass(WstColumnQRange.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
74 cfg.addAnnotatedClass(WstColumnValue.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
75 cfg.addAnnotatedClass(Wst.class);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
76 cfg.addAnnotatedClass(WstQRange.class);
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
77 Properties props = new Properties();
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
78
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
79 dumpSchema(cfg);
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
80
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
81 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
82 Environment.DIALECT,
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
83 "org.hibernate.dialect.PostgreSQLDialect");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
84
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
85 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
86 "hibernate.connection.provider_class",
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
87 "org.hibernate.connection.DBCPConnectionProvider");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
88
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
89 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
90 Environment.USER,
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
91 USER);
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
92
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
93 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
94 Environment.PASS,
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
95 PASS);
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
96
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
97 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
98 Environment.DRIVER,
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
99 "org.postgresql.Driver");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
100
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
101 props.setProperty(
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
102 Environment.URL,
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
103 "jdbc:postgresql://localhost:54321/flystest1");
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
104
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
105 cfg.mergeProperties(props);
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
106
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
107 /*
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
108
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
109 SessionFactory sessionFactory = cfg.buildSessionFactory();
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
110
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
111 Session session = sessionFactory.openSession();
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
112 session.beginTransaction();
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
113
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
114 River river = new River("Hase-" + new java.util.Date());
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
115
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
116 session.save(river);
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
117
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
118 System.out.println("river id: " + river.getId());
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
119
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
120 session.getTransaction().commit();
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
121 session.close();
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
122 */
165
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 }
a69b8494fcac Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 }
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 165
diff changeset
125 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org