annotate flys-backend/src/main/java/de/intevation/flys/App.java @ 1202:44581b40b968

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

http://dive4elements.wald.intevation.org