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