use of java.sql.DatabaseMetaData in project druid by druid-io.
the class DruidAvaticaHandlerTest method testDatabaseMetaDataColumns.
@Test
public void testDatabaseMetaDataColumns() throws Exception {
final DatabaseMetaData metaData = client.getMetaData();
Assert.assertEquals(ImmutableList.of(ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "__time"), Pair.of("DATA_TYPE", Types.TIMESTAMP), Pair.of("TYPE_NAME", "TIMESTAMP"), Pair.of("IS_NULLABLE", "NO")), ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "cnt"), Pair.of("DATA_TYPE", Types.BIGINT), Pair.of("TYPE_NAME", "BIGINT"), Pair.of("IS_NULLABLE", "NO")), ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "dim1"), Pair.of("DATA_TYPE", Types.VARCHAR), Pair.of("TYPE_NAME", "VARCHAR"), Pair.of("IS_NULLABLE", "NO")), ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "dim2"), Pair.of("DATA_TYPE", Types.VARCHAR), Pair.of("TYPE_NAME", "VARCHAR"), Pair.of("IS_NULLABLE", "NO")), ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "m1"), Pair.of("DATA_TYPE", Types.FLOAT), Pair.of("TYPE_NAME", "FLOAT"), Pair.of("IS_NULLABLE", "NO")), ROW(Pair.of("TABLE_SCHEM", "druid"), Pair.of("TABLE_NAME", "foo"), Pair.of("COLUMN_NAME", "unique_dim1"), Pair.of("DATA_TYPE", Types.OTHER), Pair.of("TYPE_NAME", "OTHER"), Pair.of("IS_NULLABLE", "NO"))), getRows(metaData.getColumns(null, "dr_id", "foo", null), ImmutableSet.of("IS_NULLABLE", "TABLE_NAME", "TABLE_SCHEM", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME")));
}
use of java.sql.DatabaseMetaData in project druid by druid-io.
the class DruidAvaticaHandlerTest method testDatabaseMetaDataCatalogs.
@Test
public void testDatabaseMetaDataCatalogs() throws Exception {
final DatabaseMetaData metaData = client.getMetaData();
Assert.assertEquals(ImmutableList.of(ROW(Pair.of("TABLE_CAT", ""))), getRows(metaData.getCatalogs()));
}
use of java.sql.DatabaseMetaData in project druid by druid-io.
the class DruidAvaticaHandlerTest method testDatabaseMetaDataSchemas.
@Test
public void testDatabaseMetaDataSchemas() throws Exception {
final DatabaseMetaData metaData = client.getMetaData();
Assert.assertEquals(ImmutableList.of(ROW(Pair.of("TABLE_CATALOG", ""), Pair.of("TABLE_SCHEM", "druid"))), getRows(metaData.getSchemas(null, "druid")));
}
use of java.sql.DatabaseMetaData in project sharding-jdbc by dangdangdotcom.
the class ShardingDataSourceFactoryTest method createShardingRule.
private ShardingRule createShardingRule() throws SQLException {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
Map<String, DataSource> dataSourceMap = new HashMap<>(1);
dataSourceMap.put("ds", dataSource);
DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
TableRule tableRule = TableRule.builder("logicTable").actualTables(Arrays.asList("table_0", "table_1", "table_2")).dataSourceRule(dataSourceRule).build();
return ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Collections.singletonList(tableRule)).build();
}
use of java.sql.DatabaseMetaData in project nutz by nutzam.
the class DaoSupport method setDataSource.
public void setDataSource(DataSource ds, boolean isLazy) {
if (null != dataSource)
if (log.isWarnEnabled())
log.warn("Replaced a running dataSource!");
dataSource = ds;
if (expert == null)
expert = Jdbcs.getExpert(ds);
log.debug("select expert : " + expert.getClass().getName());
pojoMaker = new NutPojoMaker(expert);
meta = new DatabaseMeta();
final Set<String> keywords = new HashSet<String>(Daos.sql2003Keywords());
run(new ConnCallback() {
public void invoke(Connection conn) throws Exception {
try {
DatabaseMetaData dmd = conn.getMetaData();
meta.setProductName(dmd.getDatabaseProductName());
meta.setVersion(dmd.getDatabaseProductVersion());
log.debug("JDBC Driver --> " + dmd.getDriverVersion());
log.debug("JDBC Name --> " + dmd.getDriverName());
if (!Strings.isBlank(dmd.getURL()))
log.debug("JDBC URL --> " + dmd.getURL());
if (dmd.getDriverName().contains("mariadb") || dmd.getDriverName().contains("sqlite")) {
log.warn("Auto-select fetch size to Integer.MIN_VALUE, enable for ResultSet Streaming");
SqlContext.DEFAULT_FETCH_SIZE = Integer.MIN_VALUE;
}
String tmp = dmd.getSQLKeywords();
if (tmp != null) {
for (String keyword : tmp.split(",")) {
keywords.add(keyword.toUpperCase());
}
}
expert.checkDataSource(conn);
} catch (Exception e) {
log.info("something wrong when checking DataSource", e);
}
}
});
if (log.isDebugEnabled())
log.debug("Database info --> " + meta);
expert.setKeywords(keywords);
if (!isLazy) {
holder = new EntityHolder(this.expert, new Callback<ConnCallback>() {
public void invoke(ConnCallback obj) {
run(obj);
}
});
holder.maker = createEntityMaker();
}
setRunner(runner);
setExecutor(executor);
}
Aggregations