Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/App.java @ 207:2b745b5e731c 0.1
merged flys-backend/0.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:07 +0200 |
parents | ed38839a6b08 |
children | d37ccb04ab5d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/App.java Fri Sep 28 12:14:07 2012 +0200 @@ -0,0 +1,121 @@ +package de.intevation.flys; + +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")); + + for (String line: setupScript) { + System.out.println(line + ";"); + } + + 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(); + */ + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :