use of javax.sql.DataSource in project qi4j-sdk by Qi4j.
the class DataSources method wrapWithCircuitBreaker.
public static DataSource wrapWithCircuitBreaker(final String dataSourceIdentity, final DataSource pool, final CircuitBreaker circuitBreaker) {
// Create wrapper
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (!circuitBreaker.isOn()) {
Throwable throwable = circuitBreaker.lastThrowable();
if (throwable != null) {
throw throwable;
} else {
throw new ServiceImporterException("Circuit breaker for DataSource " + dataSourceIdentity + " is not on");
}
}
try {
Object result = method.invoke(pool, args);
circuitBreaker.success();
return result;
} catch (IllegalAccessException e) {
circuitBreaker.throwable(e);
throw e;
} catch (IllegalArgumentException e) {
circuitBreaker.throwable(e);
throw e;
} catch (InvocationTargetException e) {
circuitBreaker.throwable(e.getCause());
throw e.getCause();
}
}
};
// Create proxy with circuit breaker
return (DataSource) Proxy.newProxyInstance(DataSource.class.getClassLoader(), new Class[] { DataSource.class }, handler);
}
use of javax.sql.DataSource in project qi4j-sdk by Qi4j.
the class ExternalDataSourceTest method test.
@Test
public void test() throws SQLException {
DataSource dataSource = module.findService(DataSource.class).get();
Connection connection = dataSource.getConnection();
try {
connection.getMetaData();
} finally {
SQLUtil.closeQuietly(connection);
}
}
use of javax.sql.DataSource in project sonarqube by SonarSource.
the class Migration1223Test method setUp.
@Before
public void setUp() throws Exception {
DataSource dataSource = mock(DataSource.class);
when(database.getDataSource()).thenReturn(dataSource);
Connection connection = mock(Connection.class);
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(mock(DatabaseMetaData.class));
}
use of javax.sql.DataSource in project archaius by Netflix.
the class JDBCConfigurationSourceTest method testSimpleInMemoryJDBCDynamicPropertySource.
@Test
public void testSimpleInMemoryJDBCDynamicPropertySource() throws Throwable {
final String dbName = "MySiteConfiguration";
DataSource ds = createDataConfigSource(dbName);
try {
JDBCConfigurationSource source = new JDBCConfigurationSource(ds, "select distinct property_key, property_value from MySiteProperties", "property_key", "property_value");
FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
DynamicPropertyFactory.initWithConfigurationSource(configuration);
DynamicStringProperty defaultProp = DynamicPropertyFactory.getInstance().getStringProperty("this.prop.does.not.exist.use.default", "default");
assertEquals("default", defaultProp.get());
DynamicStringProperty prop1 = DynamicPropertyFactory.getInstance().getStringProperty("prop1", "default");
assertEquals("value1", prop1.get());
} finally {
//Clean up the data files generated by the embedded DB.
FileUtils.deleteDirectory(new File(".", dbName));
}
}
use of javax.sql.DataSource in project OpenAttestation by OpenAttestation.
the class CreateDatabase method createTables.
/*
private <T extends GenericDAO> void createTable(String name, Class<T> daoClass, DBI dbi) {
T dao = dbi.open(daoClass);
if( !Derby.tableExists(name) ) { dao.create(); }
dao.close();
}
*/
public void createTables() throws SQLException {
DataSource ds = Derby.getDataSource();
DBI dbi = new DBI(ds);
// tag
KvAttributeDAO tagDao = dbi.open(KvAttributeDAO.class);
if (!Derby.tableExists("mw_tag_kvattribute")) {
tagDao.create();
}
tagDao.close();
// tag value
//SelectionKvAttributeDAO tagValueDao = dbi.open(SelectionKvAttributeDAO.class);
//if( !Derby.tableExists("mw_tag_selection_kvattribute") ) { tagValueDao.create(); }
//tagValueDao.close();
// certificate request
CertificateRequestDAO certificateRequestDao = dbi.open(CertificateRequestDAO.class);
if (!Derby.tableExists("mw_tag_certificate_request")) {
certificateRequestDao.create();
}
certificateRequestDao.close();
// certificate
CertificateDAO certificateDao = dbi.open(CertificateDAO.class);
if (!Derby.tableExists("mw_tag_certificate")) {
certificateDao.create();
}
certificateDao.close();
// certificate request
SelectionDAO selectionDao = dbi.open(SelectionDAO.class);
if (!Derby.tableExists("mw_tag_selection")) {
selectionDao.create();
}
selectionDao.close();
// configuration
ConfigurationDAO configurationDao = dbi.open(ConfigurationDAO.class);
if (!Derby.tableExists("mw_configuration")) {
configurationDao.create();
}
configurationDao.close();
// file
FileDAO fileDao = dbi.open(FileDAO.class);
if (!Derby.tableExists("mw_file")) {
fileDao.create();
}
fileDao.close();
//TpmPasswordDAO tpmPasswordDao = dbi.open(TpmPasswordDAO.class);
//if( !Derby.tableExists("mw_host_tpm_password")) { tpmPasswordDao.create();}
//tpmPasswordDao.close();
}
Aggregations