changeset 1229:8b12b338a3f6

Re-enabled Hibernate schema dumps. flys-backend/trunk@2485 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 11 Aug 2011 10:47:43 +0000
parents a964636a0be3
children e2deda3b77a7
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/App.java flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java
diffstat 3 files changed, 39 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Sun Jul 31 18:46:14 2011 +0000
+++ b/flys-backend/ChangeLog	Thu Aug 11 10:47:43 2011 +0000
@@ -1,3 +1,14 @@
+2011-07-31	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	Re-enabled Hibernate schema dumps.
+
+	* src/main/java/de/intevation/flys/App.java: Removed old code
+	  and use new SessionFactoryProvider infrastructure.
+
+	* src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java:
+	  Added methods to create db configurations without opening them.
+	  Useful for introspection only purposes.
+
 2011-07-31	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* pom.xml: Bumped Apache DBCP up to 1.4 to use the same version
--- a/flys-backend/src/main/java/de/intevation/flys/App.java	Sun Jul 31 18:46:14 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/App.java	Thu Aug 11 10:47:43 2011 +0000
@@ -1,45 +1,19 @@
 package de.intevation.flys;
 
+import de.intevation.flys.backend.SessionFactoryProvider;
+
 import org.hibernate.cfg.Configuration;
 
-import de.intevation.flys.model.Annotation;
-import de.intevation.flys.model.Attribute;
-import de.intevation.flys.model.DischargeTable;
-import de.intevation.flys.model.DischargeTableValue;
-import de.intevation.flys.model.Gauge;
-import de.intevation.flys.model.MainValueType;
-import de.intevation.flys.model.NamedMainValue;
-import de.intevation.flys.model.MainValue;
-import de.intevation.flys.model.Position;
-import de.intevation.flys.model.Range;
-import de.intevation.flys.model.River;
-import de.intevation.flys.model.TimeInterval;
-import de.intevation.flys.model.WstColumn;
-import de.intevation.flys.model.WstColumnQRange;
-import de.intevation.flys.model.WstColumnValue;
-import de.intevation.flys.model.Wst;
-import de.intevation.flys.model.WstQRange;
-
 import org.hibernate.dialect.resolver.DialectFactory;
 
-import java.util.Properties;
-
-import org.hibernate.cfg.Environment;
-
 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 dumpSchema(Configuration cfg) {
         System.out.println("BEGIN;");
 
         String [] setupScript = cfg.generateSchemaCreationScript(
             DialectFactory.constructDialect(
-                "org.hibernate.dialect.PostgreSQLDialect"));
+                SessionFactoryProvider.DEFAULT_DIALECT));
 
         for (String line: setupScript) {
             System.out.println(line + ";");
@@ -48,74 +22,8 @@
         System.out.println("COMMIT;");
     }
 
-    public static void main(String [] args)
-    throws Exception
-    {
-        Configuration cfg = new Configuration();
-
-        cfg.addAnnotatedClass(Annotation.class);
-        cfg.addAnnotatedClass(Attribute.class);
-        cfg.addAnnotatedClass(DischargeTable.class);
-        cfg.addAnnotatedClass(DischargeTableValue.class);
-        cfg.addAnnotatedClass(Gauge.class);
-        cfg.addAnnotatedClass(MainValueType.class);
-        cfg.addAnnotatedClass(NamedMainValue.class);
-        cfg.addAnnotatedClass(MainValue.class);
-        cfg.addAnnotatedClass(Position.class);
-        cfg.addAnnotatedClass(Range.class);
-        cfg.addAnnotatedClass(River.class);
-        cfg.addAnnotatedClass(TimeInterval.class);
-        cfg.addAnnotatedClass(WstColumn.class);
-        cfg.addAnnotatedClass(WstColumnQRange.class);
-        cfg.addAnnotatedClass(WstColumnValue.class);
-        cfg.addAnnotatedClass(Wst.class);
-        cfg.addAnnotatedClass(WstQRange.class);
-        Properties props = new Properties();
-
-        dumpSchema(cfg);
-
-        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();
-        */
+    public static void main(String [] args) {
+        dumpSchema(SessionFactoryProvider.createConfiguration());
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Sun Jul 31 18:46:14 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Thu Aug 11 10:47:43 2011 +0000
@@ -119,6 +119,28 @@
         String driver,
         String url
     ) {
+        Configuration cfg = createConfiguration(
+            user, password, dialect, driver, url);
+
+        return cfg.buildSessionFactory();
+    }
+
+    public static Configuration createConfiguration() {
+        return createConfiguration(
+            DEFAULT_USER,
+            DEFAULT_PASSWORD,
+            DEFAULT_DIALECT,
+            DEFAULT_DRIVER,
+            DEFAULT_URL);
+    }
+
+    public static Configuration createConfiguration(
+        String user,
+        String password,
+        String dialect,
+        String driver,
+        String url
+    ) {
         Configuration cfg = new Configuration();
 
         // TODO: Use package reflection here.
@@ -172,7 +194,7 @@
 
         cfg.mergeProperties(props);
 
-        return cfg.buildSessionFactory();
+        return cfg;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org