view flys-backend/src/main/java/de/intevation/flys/App.java @ 507:730f8500a73a

Tagged release 2.3.1 of flys-backend. flys-backend/tags/2.3.1@1970 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 20 May 2011 09:30:08 +0000
parents d37ccb04ab5d
children 8b12b338a3f6
line wrap: on
line source
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 :

http://dive4elements.wald.intevation.org