Search in sources :

Example 1 with PostgresqlPersistenceManager

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

the class PostgresMultiThreadTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.postgresql.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:postgresql://localhost/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("postgresql");
        Class.forName(driver);
        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 PostgresqlPersistenceManager();
        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) PostgresqlPersistenceManager(siena.jdbc.PostgresqlPersistenceManager) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 2 with PostgresqlPersistenceManager

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

the class PostgresqlTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.postgresql.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:postgresql://localhost/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("postgresql");
        Class.forName(driver);
        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 PostgresqlPersistenceManager();
        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) PostgresqlPersistenceManager(siena.jdbc.PostgresqlPersistenceManager) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 3 with PostgresqlPersistenceManager

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

the class PostgresTestNoAutoInc_4_SPECIALS method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "org.postgresql.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:postgresql://localhost/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("postgresql");
        Class.forName(driver);
        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 PostgresqlPersistenceManager();
        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) PostgresqlPersistenceManager(siena.jdbc.PostgresqlPersistenceManager) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

Connection (java.sql.Connection)3 Properties (java.util.Properties)3 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)3 Platform (org.apache.ddlutils.Platform)3 Database (org.apache.ddlutils.model.Database)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3 DdlGenerator (siena.jdbc.ddl.DdlGenerator)3