Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/App.java @ 170:88c14d5d45be
Added missing sequences. Deleted unsupported sqlite schema.
flys-backend/trunk@1460 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 14 Mar 2011 11:31:00 +0000 |
parents | 7929f4144d2f |
children | 249390dd24e7 |
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 |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
7 import de.intevation.flys.model.River; |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
8 |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
9 import org.hibernate.dialect.resolver.DialectFactory; |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
10 |
169
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
11 import java.util.Properties; |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
12 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
13 import org.hibernate.cfg.Environment; |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
14 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
15 import org.hibernate.Session; |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
16 |
165
a69b8494fcac
Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public class App |
a69b8494fcac
Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 { |
169
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
19 private static final String USER = |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
20 System.getProperty("flys.user", "flys"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
21 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
22 private static final String PASS = |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
23 System.getProperty("flys.pass", "flys"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
24 |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
25 public static void main(String [] args) |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
26 throws Exception |
165
a69b8494fcac
Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 { |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
28 Configuration cfg = new Configuration(); |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
29 |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
30 cfg.addAnnotatedClass(River.class); |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
31 |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
32 String [] setupScript = cfg.generateSchemaCreationScript( |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
33 DialectFactory.constructDialect( |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
34 "org.hibernate.dialect.PostgreSQLDialect")); |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
35 |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
36 for (String line: setupScript) { |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
37 System.out.println(line); |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
38 } |
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
39 |
169
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
40 Properties props = new Properties(); |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
41 |
169
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
42 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
43 Environment.DIALECT, |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
44 "org.hibernate.dialect.PostgreSQLDialect"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
45 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
46 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
47 "hibernate.connection.provider_class", |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
48 "org.hibernate.connection.DBCPConnectionProvider"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
49 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
50 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
51 Environment.USER, |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
52 USER); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
53 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
54 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
55 Environment.PASS, |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
56 PASS); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
57 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
58 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
59 Environment.DRIVER, |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
60 "org.postgresql.Driver"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
61 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
62 props.setProperty( |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
63 Environment.URL, |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
64 "jdbc:postgresql://localhost:54321/flystest1"); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
65 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
66 cfg.mergeProperties(props); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
67 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
68 SessionFactory sessionFactory = cfg.buildSessionFactory(); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
69 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
70 Session session = sessionFactory.openSession(); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
71 session.beginTransaction(); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
72 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
73 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
|
74 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
75 session.save(river); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
76 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
77 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
|
78 |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
79 session.getTransaction().commit(); |
7929f4144d2f
Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
80 session.close(); |
165
a69b8494fcac
Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
a69b8494fcac
Created a new empty maven project
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 } |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
165
diff
changeset
|
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |