Search in sources :

Example 1 with H2PersistenceManager

use of siena.jdbc.H2PersistenceManager in project siena by mandubian.

the class H2Test method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.h2.Driver";
        String url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
        String username = "sa";
        String password = "";
        p.setProperty("driver", driver);
        p.setProperty("url", url);
        p.setProperty("user", username);
        p.setProperty("password", password);
        DdlGenerator generator = new DdlGenerator();
        for (Class<?> clazz : classes) {
            generator.addTable(clazz);
        }
        // get the Database model
        Database database = generator.getDatabase();
        Platform platform = PlatformFactory.createNewPlatformInstance("mysql");
        Class.forName(driver);
        // JdbcDataSource ds = new JdbcDataSource();
        // ds.setURL(url);
        // Connection connection = ds.getConnection();
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        platform.alterTables(connection, database, true);
        connection.close();
        pm = new H2PersistenceManager();
        pm.init(p);
    }
    return pm;
}
Also used : Platform(org.apache.ddlutils.Platform) Database(org.apache.ddlutils.model.Database) Connection(java.sql.Connection) DdlGenerator(siena.jdbc.ddl.DdlGenerator) H2PersistenceManager(siena.jdbc.H2PersistenceManager)

Example 2 with H2PersistenceManager

use of siena.jdbc.H2PersistenceManager in project siena by mandubian.

the class H2MultiThreadTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.h2.Driver";
        String url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
        String username = "sa";
        String password = "";
        p.setProperty("driver", driver);
        p.setProperty("url", url);
        p.setProperty("user", username);
        p.setProperty("password", password);
        DdlGenerator generator = new DdlGenerator();
        for (Class<?> clazz : classes) {
            generator.addTable(clazz);
        }
        // get the Database model
        Database database = generator.getDatabase();
        Platform platform = PlatformFactory.createNewPlatformInstance("mysql");
        Class.forName(driver);
        // JdbcDataSource ds = new JdbcDataSource();
        // ds.setURL(url);
        // Connection connection = ds.getConnection();
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        platform.alterTables(connection, database, true);
        connection.close();
        pm = new H2PersistenceManager();
        pm.init(p);
    }
    return pm;
}
Also used : Platform(org.apache.ddlutils.Platform) Database(org.apache.ddlutils.model.Database) Connection(java.sql.Connection) DdlGenerator(siena.jdbc.ddl.DdlGenerator) Properties(java.util.Properties) H2PersistenceManager(siena.jdbc.H2PersistenceManager)

Example 3 with H2PersistenceManager

use of siena.jdbc.H2PersistenceManager in project siena by mandubian.

the class H2TestNoAutoInc_4_SPECIALS method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.h2.Driver";
        String url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
        String username = "sa";
        String password = "";
        p.setProperty("driver", driver);
        p.setProperty("url", url);
        p.setProperty("user", username);
        p.setProperty("password", password);
        DdlGenerator generator = new DdlGenerator();
        for (Class<?> clazz : classes) {
            generator.addTable(clazz);
        }
        // get the Database model
        Database database = generator.getDatabase();
        Platform platform = PlatformFactory.createNewPlatformInstance("mysql");
        Class.forName(driver);
        // JdbcDataSource ds = new JdbcDataSource();
        // ds.setURL(url);
        // Connection connection = ds.getConnection();
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        platform.alterTables(connection, database, true);
        connection.close();
        pm = new H2PersistenceManager();
        pm.init(p);
    }
    return pm;
}
Also used : Platform(org.apache.ddlutils.Platform) Database(org.apache.ddlutils.model.Database) Connection(java.sql.Connection) DdlGenerator(siena.jdbc.ddl.DdlGenerator) Properties(java.util.Properties) H2PersistenceManager(siena.jdbc.H2PersistenceManager)

Aggregations

Connection (java.sql.Connection)3 Platform (org.apache.ddlutils.Platform)3 Database (org.apache.ddlutils.model.Database)3 H2PersistenceManager (siena.jdbc.H2PersistenceManager)3 DdlGenerator (siena.jdbc.ddl.DdlGenerator)3 Properties (java.util.Properties)2