use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest3 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select count(*) from t";
DbType dbType = JdbcConstants.MYSQL;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(visitor);
System.out.println(visitor.getColumns());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertTrue(visitor.containsColumn("t", "*"));
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest5 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "create table t_org (fid int, name varchar(256))";
DbType dbType = JdbcConstants.MYSQL;
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
SQLStatement stmt = stmtList.get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
System.out.println(statVisitor.getColumns());
System.out.println(statVisitor.getTables());
System.out.println(statVisitor.getConditions());
Assert.assertEquals(2, statVisitor.getColumns().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest_odps method test_schemaStat.
public void test_schemaStat() throws Exception {
File file = new File("/Users/wenshao/Downloads/odps_sql_1.txt");
String sql = FileUtils.readFileToString(file);
DbType dbType = DbType.odps;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
System.out.println("stmtList size : " + stmtList.size());
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
for (SQLStatement stmt : stmtList) {
stmt.accept(statVisitor);
}
Set<TableStat.Relationship> relationships = statVisitor.getRelationships();
for (TableStat.Relationship relationship : relationships) {
// table1.id = table2.id
System.out.println(relationship);
}
// System.out.println(statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println(statVisitor.getConditions());
// assertEquals(3, relationships.size());
//
// Assert.assertEquals(21, statVisitor.getColumns().size());
// Assert.assertEquals(20, statVisitor.getConditions().size());
// assertEquals(1, statVisitor.getFunctions().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class DruidDataSource method initCheck.
protected void initCheck() throws SQLException {
DbType dbType = DbType.of(this.dbTypeName);
if (dbType == DbType.oracle) {
isOracle = true;
if (driver.getMajorVersion() < 10) {
throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "." + driver.getMinorVersion());
}
if (driver.getMajorVersion() == 10 && isUseOracleImplicitCache()) {
this.getConnectProperties().setProperty("oracle.jdbc.FreeMemoryOnEnterImplicitCache", "true");
}
oracleValidationQueryCheck();
} else if (dbType == DbType.db2) {
db2ValidationQueryCheck();
} else if (dbType == DbType.mysql || JdbcUtils.MYSQL_DRIVER_6.equals(this.driverClass)) {
isMySql = true;
}
if (removeAbandoned) {
LOG.warn("removeAbandoned is true, not use in production.");
}
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaRepository method findTable.
public SchemaObject findTable(String tableName) {
if (tableName.indexOf('.') != -1) {
SQLExpr expr = SQLUtils.toSQLExpr(tableName, dbType);
if (!(expr instanceof SQLIdentifierExpr)) {
return findTable((SQLName) expr);
}
}
SchemaObject object = getDefaultSchema().findTable(tableName);
if (object != null) {
return object;
}
String ddl = loadDDL(tableName);
if (ddl == null) {
return null;
}
DbType schemaDbType = this.schemaDbType;
if (schemaDbType == null) {
schemaDbType = dbType;
}
SchemaObject schemaObject = acceptDDL(ddl, schemaDbType);
if (schemaObject != null) {
return schemaObject;
}
return getDefaultSchema().findTable(tableName);
}
Aggregations