use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project alf.io by alfio-event.
the class V22_1_14_8__MigrateMailchimp method migrate.
@Override
public void migrate(Context context) throws Exception {
var jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
Integer enabledCount = jdbcTemplate.queryForObject("select count(*) from plugin_configuration where plugin_id = 'alfio.mailchimp' and conf_name = 'enabled' and conf_value = 'true'", Integer.class);
if (enabledCount == null || enabledCount == 0) {
return;
}
DataSource dataSource = Objects.requireNonNull(jdbcTemplate.getDataSource());
ExtensionRepository extensionRepository = QueryFactory.from(ExtensionRepository.class, "PGSQL", dataSource);
ExtensionLogRepository extensionLogRepository = QueryFactory.from(ExtensionLogRepository.class, "PGSQL", dataSource);
PluginRepository pluginRepository = QueryFactory.from(PluginRepository.class, "PGSQL", dataSource);
ExtensionService extensionService = new ExtensionService(new ScriptingExecutionService(HttpClient.newHttpClient(), null, Executors::newSingleThreadExecutor), extensionRepository, extensionLogRepository, new DataSourceTransactionManager(dataSource), new ExternalConfiguration(), new NamedParameterJdbcTemplate(jdbcTemplate));
extensionService.createOrUpdate(null, null, new Extension("-", "mailchimp", getMailChimpScript(), true));
int extensionId = extensionRepository.getExtensionIdFor("-", "mailchimp");
int apiKeyId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "apiKey", "EVENT");
int listIdId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "listId", "EVENT");
List<ConfValue> confValues = pluginRepository.findAllMailChimpConfigurationValues();
for (ConfValue cv : confValues) {
if (cv.value != null) {
optionally(() -> jdbcTemplate.queryForObject("select org_id from event where id = " + cv.eventId, Integer.class)).ifPresent(orgId -> extensionRepository.insertSettingValue("apiKey".equals(cv.name) ? apiKeyId : listIdId, "-" + orgId + "-" + cv.eventId, cv.value));
}
}
}
use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project spring-security by spring-projects.
the class BasicLookupStrategyTests method createDatabase.
@BeforeClass
public static void createDatabase() throws Exception {
dataSource = new SingleConnectionDataSource("jdbc:hsqldb:mem:lookupstrategytest", "sa", "", true);
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
jdbcTemplate = new JdbcTemplate(dataSource);
Resource resource = new ClassPathResource("createAclSchema.sql");
String sql = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
jdbcTemplate.execute(sql);
}
use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project aries by apache.
the class SpringJdbcTemplateTransactionTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(connection, false));
}
use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project SimpleFlatMapper by arnaudroger.
the class Sql2oIntegrationTest method testSql2O.
@Test
public void testSql2O() throws SQLException, ParseException {
Connection connection = DbHelper.objectDb();
try {
SingleConnectionDataSource scds = new SingleConnectionDataSource(connection, true);
Sql2o sql2o = new Sql2o(scds);
Query query = sql2o.open().createQuery(DbHelper.TEST_DB_OBJECT_QUERY);
query.setAutoDeriveColumnNames(true);
query.setResultSetHandlerFactoryBuilder(new SfmResultSetHandlerFactoryBuilder());
List<DbObject> dbObjects = query.executeAndFetch(DbObject.class);
assertEquals(1, dbObjects.size());
DbHelper.assertDbObjectMapping(dbObjects.get(0));
} finally {
connection.close();
}
}
use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project ovirt-engine by oVirt.
the class BaseDaoTestCase method createDataSource.
private static DataSource createDataSource() throws Exception {
DataSource result = null;
Properties properties = new Properties();
String job = System.getProperty("JOB_NAME", "");
String number = System.getProperty("BUILD_NUMBER", "");
String schemaNamePostfix = job + number;
try (InputStream is = BaseDaoTestCase.class.getResourceAsStream("/test-database.properties")) {
properties.load(is);
ClassLoader.getSystemClassLoader().loadClass(properties.getProperty("database.driver"));
String dbUrl = properties.getProperty("database.url") + schemaNamePostfix;
result = new SingleConnectionDataSource(dbUrl, properties.getProperty("database.username"), properties.getProperty("database.password"), true);
initSql = properties.getProperty("database.initsql");
loadDataFactory(properties.getProperty("database.testing.datafactory"));
if (initSql != null && !initSql.isEmpty()) {
needInitializationSql = true;
}
}
return result;
}
Aggregations