Search in sources :

Example 11 with DdlGenerator

use of siena.jdbc.ddl.DdlGenerator in project siena by mandubian.

the class DrizzleTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.drizzle.jdbc.DrizzleDriver";
        //String username = "root";
        //String password = "";
        String url = "jdbc:mysql://localhost:4427/siena";
        p.setProperty("driver", driver);
        //p.setProperty("user",     username);
        //p.setProperty("password", password);
        p.setProperty("url", url);
        Class.forName(driver);
        BasicDataSource dataSource = new BasicDataSource();
        dataSource = new BasicDataSource();
        dataSource.setUrl(url);
        //dataSource.setUsername(username);
        //dataSource.setPassword(password);
        // 2 seconds max for wait a connection.
        dataSource.setMaxWait(2000);
        DdlGenerator generator = new DdlGenerator();
        for (Class<?> clazz : classes) {
            generator.addTable(clazz);
        }
        // get the Database model
        Database database = generator.getDatabase();
        Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
        Class.forName("org.drizzle.jdbc.DrizzleDriver");
        Connection connection = DriverManager.getConnection(url);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        platform.alterTables(connection, database, true);
        connection.close();
        pm = new JdbcPersistenceManager();
        pm.init(p);
    }
    return pm;
}
Also used : JdbcPersistenceManager(siena.jdbc.JdbcPersistenceManager) Platform(org.apache.ddlutils.Platform) Database(org.apache.ddlutils.model.Database) Connection(java.sql.Connection) DdlGenerator(siena.jdbc.ddl.DdlGenerator) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

Connection (java.sql.Connection)11 Platform (org.apache.ddlutils.Platform)11 Database (org.apache.ddlutils.model.Database)11 DdlGenerator (siena.jdbc.ddl.DdlGenerator)11 Properties (java.util.Properties)10 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)8 JdbcPersistenceManager (siena.jdbc.JdbcPersistenceManager)5 H2PersistenceManager (siena.jdbc.H2PersistenceManager)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3 CreationParameters (org.apache.ddlutils.platform.CreationParameters)2