Search in sources :

Example 41 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project symmetric-ds by JumpMind.

the class AbstractCommandLauncher method testConnection.

protected void testConnection() {
    try {
        BasicDataSource ds = ClientSymmetricEngine.createBasicDataSource(propertiesFile);
        Connection conn = ds.getConnection();
        conn.close();
        ds.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 42 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project siena by mandubian.

the class JdbcModelTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "com.mysql.jdbc.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:mysql://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("mysql");
        Class.forName("com.mysql.jdbc.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 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)

Example 43 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project siena by mandubian.

the class JdbcTest method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "com.mysql.jdbc.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:mysql://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("mysql");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        CreationParameters cp = new CreationParameters();
        // to search, it requires MyISAM
        cp.addParameter(database.findTable("discoveries_search"), "ENGINE", "MyISAM");
        cp.addParameter(database.findTable("discoveries_search2"), "ENGINE", "MyISAM");
        platform.alterTables(connection, database, cp, 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) CreationParameters(org.apache.ddlutils.platform.CreationParameters)

Example 44 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project siena by mandubian.

the class JdbcTestNoAutoInc_4_SPECIALS method createPersistenceManager.

@Override
public PersistenceManager createPersistenceManager(List<Class<?>> classes) throws Exception {
    if (pm == null) {
        Properties p = new Properties();
        String driver = "com.mysql.jdbc.Driver";
        String username = "siena";
        String password = "siena";
        String url = "jdbc:mysql://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("mysql");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(platform.getAlterTablesSql(connection, database));
        // this will perform the database changes
        CreationParameters cp = new CreationParameters();
        // to search, it requires MyISAM
        cp.addParameter(database.findTable("discoveries_search"), "ENGINE", "MyISAM");
        cp.addParameter(database.findTable("discoveries_search2"), "ENGINE", "MyISAM");
        platform.alterTables(connection, database, cp, 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) CreationParameters(org.apache.ddlutils.platform.CreationParameters)

Example 45 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project cobar by alibaba.

the class DataSourceCreator method createDataSource.

@Override
public DataSource createDataSource(String ip, int port, String user, String password) {
    BasicDataSource ds = new BasicDataSource();
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(port).append("/").toString());
    ds.setDriverClassName(driverClassName);
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    return ds;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

BasicDataSource (org.apache.commons.dbcp.BasicDataSource)141 Connection (java.sql.Connection)25 Test (org.junit.Test)13 SQLException (java.sql.SQLException)12 Properties (java.util.Properties)12 DataSource (javax.sql.DataSource)10 Platform (org.apache.ddlutils.Platform)8 Database (org.apache.ddlutils.model.Database)8 DdlGenerator (siena.jdbc.ddl.DdlGenerator)8 Statement (java.sql.Statement)7 Bean (org.springframework.context.annotation.Bean)6 ResultSet (java.sql.ResultSet)5 Before (org.junit.Before)5 JdbcPersistenceManager (siena.jdbc.JdbcPersistenceManager)5 Config (com.typesafe.config.Config)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3