comparison flys-backend/src/main/java/de/intevation/flys/App.java @ 169:7929f4144d2f

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

http://dive4elements.wald.intevation.org