Search in sources :

Example 11 with SingleConnectionDataSource

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));
        }
    }
}
Also used : ExtensionService(alfio.extension.ExtensionService) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource) Extension(alfio.extension.Extension) ExtensionRepository(alfio.repository.ExtensionRepository) ExtensionLogRepository(alfio.repository.ExtensionLogRepository) ExternalConfiguration(alfio.manager.system.ExternalConfiguration) ScriptingExecutionService(alfio.extension.ScriptingExecutionService) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Example 12 with SingleConnectionDataSource

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);
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 13 with SingleConnectionDataSource

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));
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Example 14 with SingleConnectionDataSource

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();
    }
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) Query(org.sql2o.Query) DbObject(org.simpleflatmapper.test.beans.DbObject) Connection(java.sql.Connection) SfmResultSetHandlerFactoryBuilder(org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder) Sql2o(org.sql2o.Sql2o) Test(org.junit.Test)

Example 15 with SingleConnectionDataSource

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;
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) InputStream(java.io.InputStream) Properties(java.util.Properties) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource)

Aggregations

SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)20 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)7 Connection (java.sql.Connection)6 DataSource (javax.sql.DataSource)4 Before (org.junit.Before)4 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)2 DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)2 DBSchemaParser (com.thinkbiganalytics.schema.DBSchemaParser)2 Nonnull (javax.annotation.Nonnull)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Extension (alfio.extension.Extension)1 ExtensionService (alfio.extension.ExtensionService)1 ScriptingExecutionService (alfio.extension.ScriptingExecutionService)1 ExternalConfiguration (alfio.manager.system.ExternalConfiguration)1 ExtensionLogRepository (alfio.repository.ExtensionLogRepository)1 ExtensionRepository (alfio.repository.ExtensionRepository)1 JdbcDriver (com.consol.citrus.db.driver.JdbcDriver)1