Search in sources :

Example 6 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project spring-security by spring-projects.

the class JdbcTokenRepositoryImplTests method createDataSource.

@BeforeAll
public static void createDataSource() {
    dataSource = new SingleConnectionDataSource("jdbc:hsqldb:mem:tokenrepotest", "sa", "", true);
    dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project symmetric-ds by JumpMind.

the class SqlScriptTest method getDataSource.

private SingleConnectionDataSource getDataSource() throws Exception {
    Class.forName("org.h2.Driver");
    Connection c = DriverManager.getConnection("jdbc:h2:mem:sqlscript");
    return new SingleConnectionDataSource(c, true);
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) Connection(java.sql.Connection)

Example 8 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project symmetric-ds by JumpMind.

the class SqlScriptTest method testSimpleSqlScript.

@Test
public void testSimpleSqlScript() throws Exception {
    SingleConnectionDataSource ds = getDataSource();
    IDatabasePlatform platform = JdbcDatabasePlatformFactory.createNewPlatformInstance(ds, new SqlTemplateSettings(), true);
    SqlScript script = new SqlScript(getClass().getResource("sqlscript-simple.sql"), platform.getSqlTemplate());
    script.execute();
    JdbcTemplate template = new JdbcTemplate(ds);
    assertEquals(2, (int) template.queryForObject("select count(*) from test", Integer.class));
    assertEquals(3, template.queryForObject("select test from test where test_id=2", String.class).split("\r\n|\r|\n").length);
    ds.destroy();
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test)

Example 9 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project kylo by Teradata.

the class DefaultCatalogTableManager method getTableNames.

@Nonnull
@Override
public List<String> getTableNames(@Nonnull final DataSource dataSource, @Nullable final String schemaName, @Nullable final String tableName) throws SQLException {
    final DataSetTemplate template = DataSourceUtil.mergeTemplates(dataSource);
    return isolatedFunction(template, schemaName, (connection, schemaParser) -> {
        final javax.sql.DataSource ds = new SingleConnectionDataSource(connection, true);
        final DBSchemaParser tableSchemaParser = new DBSchemaParser(ds, new KerberosTicketConfiguration());
        return tableSchemaParser.listTables(schemaName, tableName);
    });
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) Nonnull(javax.annotation.Nonnull)

Example 10 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project kylo by Teradata.

the class DefaultCatalogTableManager method describeTable.

@Nonnull
@Override
public CatalogTableSchema describeTable(@Nonnull final DataSource dataSource, @Nullable final String schemaName, @Nullable final String tableName) throws SQLException {
    final DataSetTemplate template = DataSourceUtil.mergeTemplates(dataSource);
    if (Objects.equals("hive", template.getFormat())) {
        final TableSchema tableSchema = hiveMetastoreService.getTable(schemaName, tableName);
        final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
        // Get table metadata
        if (StringUtils.isNotEmpty(tableSchema.getName())) {
            final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
            jdbcTable.setCatalog(tableSchema.getDatabaseName());
            jdbcTable.setCatalog(tableSchema.getDatabaseName());
            jdbcTable.setRemarks(tableSchema.getDescription());
            jdbcTable.setSchema(tableSchema.getSchemaName());
            jdbcTable.setCatalogSeparator(".");
            jdbcTable.setIdentifierQuoteString("`");
            catalogTableSchema.setTable(createTable(jdbcTable));
        }
        return catalogTableSchema;
    } else if (Objects.equals("jdbc", template.getFormat())) {
        return isolatedFunction(template, schemaName, (connection, schemaParser) -> {
            final javax.sql.DataSource ds = new SingleConnectionDataSource(connection, true);
            final DBSchemaParser tableSchemaParser = new DBSchemaParser(ds, new KerberosTicketConfiguration());
            final TableSchema tableSchema = tableSchemaParser.describeTable(schemaName, tableName);
            if (tableSchema != null) {
                // Get table metadata
                final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(tableSchema.getName(), "TABLE");
                jdbcTable.setCatalog(tableSchema.getDatabaseName());
                jdbcTable.setCatalog(tableSchema.getDatabaseName());
                jdbcTable.setRemarks(tableSchema.getDescription());
                jdbcTable.setSchema(tableSchema.getSchemaName());
                jdbcTable.setMetaData(connection.getMetaData());
                // Return table schema
                final CatalogTableSchema catalogTableSchema = new CatalogTableSchema(tableSchema);
                catalogTableSchema.setTable(createTable(jdbcTable));
                return catalogTableSchema;
            } else {
                return null;
            }
        });
    } else {
        throw new IllegalArgumentException("Unsupported format: " + template.getFormat());
    }
}
Also used : PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) LoadingCache(com.google.common.cache.LoadingCache) Connection(java.sql.Connection) DataSourceUtil(com.thinkbiganalytics.kylo.catalog.datasource.DataSourceUtil) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) DataSetUtil(com.thinkbiganalytics.kylo.catalog.dataset.DataSetUtil) StringUtils(org.apache.commons.lang3.StringUtils) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) Value(org.springframework.beans.factory.annotation.Value) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Configuration(org.apache.hadoop.conf.Configuration) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) HiveMetastoreService(com.thinkbiganalytics.hive.service.HiveMetastoreService) DefaultJdbcTable(com.thinkbiganalytics.schema.DefaultJdbcTable) Nonnull(javax.annotation.Nonnull) JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Properties(java.util.Properties) Set(java.util.Set) JdbcCatalog(com.thinkbiganalytics.discovery.schema.JdbcCatalog) HadoopClassLoader(com.thinkbiganalytics.kylo.util.HadoopClassLoader) Collectors(java.util.stream.Collectors) JdbcSchemaParserProvider(com.thinkbiganalytics.schema.JdbcSchemaParserProvider) KerberosUtil(com.thinkbiganalytics.kerberos.KerberosUtil) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) List(java.util.List) JdbcSchema(com.thinkbiganalytics.discovery.schema.JdbcSchema) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) JdbcTable(com.thinkbiganalytics.discovery.schema.JdbcTable) DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) DefaultJdbcTable(com.thinkbiganalytics.schema.DefaultJdbcTable) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Nonnull(javax.annotation.Nonnull)

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