diff 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
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/App.java	Fri Mar 11 14:41:18 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/App.java	Fri Mar 11 16:23:42 2011 +0000
@@ -8,17 +8,25 @@
 
 import org.hibernate.dialect.resolver.DialectFactory;
 
-import org.hibernate.dialect.Dialect;
+import java.util.Properties;
+
+import org.hibernate.cfg.Environment;
+
+import org.hibernate.Session;
 
 public class App 
 {
+    private static final String USER =
+        System.getProperty("flys.user", "flys");
+
+    private static final String PASS =
+        System.getProperty("flys.pass", "flys");
+
     public static void main(String [] args)
     throws Exception
     {
         Configuration cfg = new Configuration();
 
-        System.err.println(cfg);
-
         cfg.addAnnotatedClass(River.class);
 
         String [] setupScript = cfg.generateSchemaCreationScript(
@@ -28,10 +36,48 @@
         for (String line: setupScript) {
             System.out.println(line);
         }
-            
 
-        //SessionFactory sessionFactory = cfg.buildSessionFactory();
+        Properties props = new Properties();
 
+        props.setProperty(
+            Environment.DIALECT,
+            "org.hibernate.dialect.PostgreSQLDialect");
+
+        props.setProperty(
+            "hibernate.connection.provider_class",
+            "org.hibernate.connection.DBCPConnectionProvider");
+
+        props.setProperty(
+            Environment.USER,
+            USER);
+
+        props.setProperty(
+            Environment.PASS,
+            PASS);
+
+        props.setProperty(
+            Environment.DRIVER,
+            "org.postgresql.Driver");
+
+        props.setProperty(
+            Environment.URL,
+            "jdbc:postgresql://localhost:54321/flystest1");
+
+        cfg.mergeProperties(props);
+
+        SessionFactory sessionFactory = cfg.buildSessionFactory();
+
+        Session session = sessionFactory.openSession();
+        session.beginTransaction();
+
+        River river = new River("Hase-" + new java.util.Date());
+
+        session.save(river);
+
+        System.out.println("river id: " + river.getId());
+
+        session.getTransaction().commit();
+        session.close();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org