changeset 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 88c14d5d45be
files flys-backend/ChangeLog flys-backend/doc/schema/postgresql-cleanup.sql flys-backend/pom.xml flys-backend/src/main/java/de/intevation/flys/App.java flys-backend/src/main/java/de/intevation/flys/model/River.java
diffstat 5 files changed, 105 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Fri Mar 11 14:41:18 2011 +0000
+++ b/flys-backend/ChangeLog	Fri Mar 11 16:23:42 2011 +0000
@@ -1,3 +1,16 @@
+2011-03-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/schema/postgresql-cleanup.sql: Forgot to add.
+
+	* src/main/java/de/intevation/flys/App.java: Use
+	  Apache Commons DBCP as Hibernate connection provide.
+
+	* src/main/java/de/intevation/flys/model/River.java:
+	  Added a constructor with string argument. Set the
+	  sequence increment to 1 (eat up 100 at a time before).
+
+	* pom.xml: Added PostgreSQL 8.4 driver as runtime dependency.
+
 2011-03-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/schema/postgresql-cleanup.sql: New. Tear down schema
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/doc/schema/postgresql-cleanup.sql	Fri Mar 11 16:23:42 2011 +0000
@@ -0,0 +1,28 @@
+BEGIN;
+
+DROP TABLE wst_column_q_ranges;
+DROP TABLE wst_q_ranges;
+DROP TABLE wst_column_values;
+DROP TABLE wst_column;
+DROP TABLE wst;
+
+DROP TABLE discharge_table_values;
+DROP TABLE discharge_tables;
+
+DROP TABLE main_values CASCADE;
+DROP TABLE time_intervals CASCADE;
+DROP TABLE named_main_values CASCADE;
+DROP TABLE main_value_types CASCADE;
+
+DROP TABLE gauges CASCADE;
+
+DROP TABLE annotations CASCADE;
+DROP TABLE positions CASCADE;
+DROP TABLE ranges CASCADE;
+DROP TABLE attributes CASCADE;
+
+DROP TABLE rivers CASCADE;
+
+DROP SEQUENCE RIVERS_ID_SEQ;
+
+COMMIT;
--- a/flys-backend/pom.xml	Fri Mar 11 14:41:18 2011 +0000
+++ b/flys-backend/pom.xml	Fri Mar 11 16:23:42 2011 +0000
@@ -67,6 +67,12 @@
       <artifactId>commons-dbcp</artifactId>
       <version>1.2.2</version>
     </dependency>
+    <dependency>
+      <groupId>postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+      <version>8.4-702.jdbc4</version>
+      <scope>runtime</scope>
+    </dependency>
   </dependencies>
 
   <repositories>
--- 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 :
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Fri Mar 11 14:41:18 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Fri Mar 11 16:23:42 2011 +0000
@@ -22,8 +22,9 @@
 
     @Id
     @SequenceGenerator(
-        name = "SEQUENCE RIVERS_ID_SEQ",
-        sequenceName = "RIVERS_ID_SEQ")
+        name           = "SEQUENCE RIVERS_ID_SEQ",
+        sequenceName   = "RIVERS_ID_SEQ",
+        allocationSize = 1)
     @GeneratedValue(
         strategy  = GenerationType.SEQUENCE,
         generator = "SEQUENCE RIVERS_ID_SEQ")
@@ -47,5 +48,9 @@
 
     public River() {
     }
+
+    public River(String name) {
+        this.name = name;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org