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();
}
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) {
}
}
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;
}
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();
}
});
}
}
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;
}
Aggregations