Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/App.java @ 182:1c0afb01bc93
Importer: Fixed error in HQL statement.
flys-backend/trunk@1493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 10:29:18 +0000 |
parents | 249390dd24e7 |
children | bc3747a371cc |
line wrap: on
line source
package de.intevation.flys; import org.hibernate.cfg.Configuration; import org.hibernate.SessionFactory; 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.NamedMainValues; 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; 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 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(NamedMainValues.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 :