Search in sources :

Example 96 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project nifi by apache.

the class HiveConnectionPoolTest method setup.

@Before
public void setup() throws Exception {
    userGroupInformation = mock(UserGroupInformation.class);
    basicDataSource = mock(BasicDataSource.class);
    componentLog = mock(ComponentLog.class);
    when(userGroupInformation.doAs(isA(PrivilegedExceptionAction.class))).thenAnswer(invocation -> {
        try {
            return ((PrivilegedExceptionAction) invocation.getArguments()[0]).run();
        } catch (IOException | Error | RuntimeException | InterruptedException e) {
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        }
    });
    initPool();
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) ComponentLog(org.apache.nifi.logging.ComponentLog) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Before(org.junit.Before)

Example 97 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project uavstack by uavorg.

the class TestRestService method testDBCP.

@GET
@Path("testDBCP")
public void testDBCP() {
    if (bds == null) {
        bds = new BasicDataSource();
        bds.setUrl("jdbc:mysql://127.0.0.1:3306/testdb");
        bds.setUsername("root");
        bds.setPassword("root");
        bds.setDriverClassName("com.mysql.jdbc.Driver");
        bds.setInitialSize(2);
        bds.setMaxActive(10);
        bds.setMinIdle(0);
        bds.setMaxIdle(1);
        bds.setMaxWait(30000);
        bds.setMaxOpenPreparedStatements(20);
    }
    try {
        Connection c = bds.getConnection();
        Statement st = c.createStatement();
        st.execute("insert into mytest values (1,'zz',23)");
        st.executeQuery("select name from mytest where id=1");
        st.executeUpdate("update mytest set age=24 where id=1");
        st.executeUpdate("delete from mytest where id=1");
        st.close();
        c.close();
    } catch (Exception e) {
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) RedisAsyncConnection(com.lambdaworks.redis.RedisAsyncConnection) RedisConnection(com.lambdaworks.redis.RedisConnection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) TimeoutException(java.util.concurrent.TimeoutException) MQBrokerException(com.alibaba.rocketmq.client.exception.MQBrokerException) ClientProtocolException(org.apache.http.client.ClientProtocolException) RemotingException(com.alibaba.rocketmq.remoting.exception.RemotingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 98 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project opentheso by miledrousset.

the class BaseHelper method buildDataSource.

/**
 * @param user
 * @param passwd
 * @param url
 * @return
 */
public static BasicDataSource buildDataSource(String user, String passwd, String url) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.postgresql.Driver");
    ds.setUsername(user);
    ds.setPassword(passwd);
    ds.setUrl(url);
    return ds;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 99 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project oozie by apache.

the class JPAService method instrument.

@Override
public void instrument(final Instrumentation instr) {
    this.instr = instr;
    final BasicDataSource dataSource = getBasicDataSource();
    if (dataSource != null) {
        instr.addSampler("jdbc", "connections.active", 60, 1, new Instrumentation.Variable<Long>() {

            @Override
            public Long getValue() {
                return (long) dataSource.getNumActive();
            }
        });
        instr.addSampler("jdbc", "connections.idle", 60, 1, new Instrumentation.Variable<Long>() {

            @Override
            public Long getValue() {
                return (long) dataSource.getNumIdle();
            }
        });
    }
}
Also used : Instrumentation(org.apache.oozie.util.Instrumentation) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 100 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project oozie by apache.

the class JPAService method getBasicDataSource.

private BasicDataSource getBasicDataSource() {
    // Get the BasicDataSource object; it could be wrapped in a DecoratingDataSource
    // It might also not be a BasicDataSource if the user configured something different
    BasicDataSource basicDataSource = null;
    final OpenJPAEntityManagerFactorySPI spi = (OpenJPAEntityManagerFactorySPI) factory;
    final Object connectionFactory = spi.getConfiguration().getConnectionFactory();
    if (connectionFactory instanceof DecoratingDataSource) {
        final DecoratingDataSource decoratingDataSource = (DecoratingDataSource) connectionFactory;
        basicDataSource = (BasicDataSource) decoratingDataSource.getInnermostDelegate();
    } else if (connectionFactory instanceof BasicDataSource) {
        basicDataSource = (BasicDataSource) connectionFactory;
    }
    return basicDataSource;
}
Also used : DecoratingDataSource(org.apache.openjpa.lib.jdbc.DecoratingDataSource) OpenJPAEntityManagerFactorySPI(org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI) 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