mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #158 from sandzhang/master
new dbtype for alibaba oracle driver
This commit is contained in:
@@ -42,18 +42,19 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class SQLUtils {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(SQLUtils.class);
|
||||
|
||||
public static String toSQLString(SQLObject sqlObject, String dbType) {
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
return toMySqlString(sqlObject);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return toMySqlString(sqlObject);
|
||||
}
|
||||
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
return toOracleString(sqlObject);
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ public class SQLUtils {
|
||||
|
||||
public static SQLASTOutputVisitor createFormatOutputVisitor(Appendable out, List<SQLStatement> statementList,
|
||||
String dbType) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
if (statementList.size() == 1) {
|
||||
return new OracleOutputVisitor(out, false);
|
||||
} else {
|
||||
@@ -191,7 +192,7 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
public static SchemaStatVisitor createSchemaStatVisitor(List<SQLStatement> statementList, String dbType) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
if (statementList.size() == 1) {
|
||||
return new OracleSchemaStatVisitor();
|
||||
} else {
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
public class SQLParserUtils {
|
||||
|
||||
public static SQLStatementParser createSQLStatementParser(String sql, String dbType) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
return new OracleStatementParser(sql);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SQLParserUtils {
|
||||
if (JdbcUtils.SQL_SERVER.equals(dbType)) {
|
||||
return new SQLServerStatementParser(sql);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return new MySqlStatementParser(sql);
|
||||
}
|
||||
@@ -52,14 +52,14 @@ public class SQLParserUtils {
|
||||
}
|
||||
|
||||
public static SQLExprParser createExprParser(String sql, String dbType) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
return new OracleExprParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return new MySqlExprParser(sql);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
return new MySqlExprParser(sql);
|
||||
}
|
||||
|
||||
@@ -48,14 +48,14 @@ public class ParameterizedOutputVisitorUtils {
|
||||
}
|
||||
|
||||
public static SQLASTOutputVisitor createParameterizedOutputVisitor(Appendable out, String dbType) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
return new OracleParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
return new MySqlParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return new MySqlParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SQLEvalVisitorUtils {
|
||||
return new MySqlEvalVisitorImpl();
|
||||
}
|
||||
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
return new OracleEvalVisitor();
|
||||
}
|
||||
|
||||
@@ -623,11 +623,11 @@ public class SQLEvalVisitorUtils {
|
||||
if (a instanceof BigInteger || b instanceof BigInteger) {
|
||||
return _bigInt(a).add(_bigInt(b));
|
||||
}
|
||||
|
||||
|
||||
if (a instanceof Double || b instanceof Double) {
|
||||
return _double(a) + _double(b);
|
||||
}
|
||||
|
||||
|
||||
if (a instanceof Float || b instanceof Float) {
|
||||
return _float(a) + _float(b);
|
||||
}
|
||||
@@ -671,11 +671,11 @@ public class SQLEvalVisitorUtils {
|
||||
if (a instanceof BigInteger || b instanceof BigInteger) {
|
||||
return _bigInt(a).subtract(_bigInt(b));
|
||||
}
|
||||
|
||||
|
||||
if (a instanceof Double || b instanceof Double) {
|
||||
return _double(a) - _double(b);
|
||||
}
|
||||
|
||||
|
||||
if (a instanceof Float || b instanceof Float) {
|
||||
return _float(a) - _float(b);
|
||||
}
|
||||
|
||||
@@ -47,43 +47,46 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
*/
|
||||
public final class JdbcUtils {
|
||||
|
||||
public static final String JTDS = "jtds";
|
||||
public static final String JTDS = "jtds";
|
||||
|
||||
public static final String MOCK = "mock";
|
||||
public static final String MOCK = "mock";
|
||||
|
||||
public static final String HSQL = "hsql";
|
||||
public static final String HSQL = "hsql";
|
||||
|
||||
public static final String DB2 = "db2";
|
||||
public static final String DB2 = "db2";
|
||||
|
||||
private static final String DB2_DRIVER = "COM.ibm.db2.jdbc.app.DB2Driver";
|
||||
private static final String DB2_DRIVER = "COM.ibm.db2.jdbc.app.DB2Driver";
|
||||
|
||||
public static final String POSTGRESQL = "postgresql";
|
||||
public static final String POSTGRESQL = "postgresql";
|
||||
|
||||
public static final String SYBASE = "sybase";
|
||||
public static final String SYBASE = "sybase";
|
||||
|
||||
public static final String SQL_SERVER = "sqlserver";
|
||||
public static final String SQL_SERVER = "sqlserver";
|
||||
|
||||
public static final String ORACLE = "oracle";
|
||||
public static final String ORACLE = "oracle";
|
||||
public static final String ALI_ORACLE = "AliOracle";
|
||||
|
||||
private static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
private static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
public static final String MYSQL = "mysql";
|
||||
private static final String ALI_ORACLE_DRIVER = "com.alibaba.jdbc.AlibabaDriver";
|
||||
|
||||
private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
|
||||
public static final String MYSQL = "mysql";
|
||||
|
||||
public static final String DERBY = "derby";
|
||||
private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
|
||||
|
||||
public static final String HBASE = "hbase";
|
||||
public static final String DERBY = "derby";
|
||||
|
||||
public static final String HIVE = "hive";
|
||||
public static final String HBASE = "hbase";
|
||||
|
||||
public static final String H2 = "h2";
|
||||
public static final String HIVE = "hive";
|
||||
|
||||
private static final String H2_DRIVER = "org.h2.Driver";
|
||||
public static final String H2 = "h2";
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(JdbcUtils.class);
|
||||
private static final String H2_DRIVER = "org.h2.Driver";
|
||||
|
||||
private static final Properties driverUrlMapping = new Properties();
|
||||
private final static Log LOG = LogFactory.getLog(JdbcUtils.class);
|
||||
|
||||
private static final Properties driverUrlMapping = new Properties();
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -376,6 +379,8 @@ public final class JdbcUtils {
|
||||
return MYSQL_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:oracle:")) {
|
||||
return ORACLE_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:alibaba:oracle:")) {
|
||||
return ALI_ORACLE_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:microsoft:")) {
|
||||
return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
|
||||
} else if (rawUrl.startsWith("jdbc:sqlserver:")) {
|
||||
@@ -440,6 +445,8 @@ public final class JdbcUtils {
|
||||
return MYSQL;
|
||||
} else if (rawUrl.startsWith("jdbc:oracle:")) {
|
||||
return ORACLE;
|
||||
} else if (rawUrl.startsWith("jdbc:alibaba:oracle:")) {
|
||||
return ALI_ORACLE;
|
||||
} else if (rawUrl.startsWith("jdbc:microsoft:")) {
|
||||
return SQL_SERVER;
|
||||
} else if (rawUrl.startsWith("jdbc:sybase:Tds:")) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
}
|
||||
|
||||
provider = new MySqlWallProvider(config);
|
||||
} else if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
} else if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
|
||||
if (config == null) {
|
||||
config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
@@ -21,26 +21,30 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
|
||||
public class DistinctTest extends TestCase {
|
||||
|
||||
private String sql = "select count(distinct *) from t";
|
||||
|
||||
|
||||
public void test_mysql() throws Exception {
|
||||
Assert.assertEquals("SELECT COUNT(DISTINCT *)\nFROM t", SQLUtils.format(sql, JdbcUtils.MYSQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Assert.assertEquals("SELECT COUNT(DISTINCT *)\nFROM t", SQLUtils.format(sql, JdbcUtils.ORACLE));
|
||||
Assert.assertEquals("SELECT COUNT(DISTINCT *)\nFROM t", SQLUtils.format(sql, JdbcUtils.ALI_ORACLE));
|
||||
}
|
||||
|
||||
|
||||
public void test_oracle_unique() throws Exception {
|
||||
Assert.assertEquals("SELECT COUNT(UNIQUE *)\nFROM t", SQLUtils.format("select count(unique *) from t", JdbcUtils.ORACLE));
|
||||
Assert.assertEquals("SELECT COUNT(UNIQUE *)\nFROM t",
|
||||
SQLUtils.format("select count(unique *) from t", JdbcUtils.ORACLE));
|
||||
Assert.assertEquals("SELECT COUNT(UNIQUE *)\nFROM t",
|
||||
SQLUtils.format("select count(unique *) from t", JdbcUtils.ALI_ORACLE));
|
||||
}
|
||||
|
||||
|
||||
public void test_postgres() throws Exception {
|
||||
Assert.assertEquals("SELECT COUNT(DISTINCT *)\nFROM t", SQLUtils.format(sql, JdbcUtils.POSTGRESQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_sql92() throws Exception {
|
||||
Assert.assertEquals("SELECT COUNT(DISTINCT *)\nFROM t", SQLUtils.format(sql, null));
|
||||
}
|
||||
|
||||
@@ -21,22 +21,23 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
|
||||
public class MybatisTest extends TestCase {
|
||||
|
||||
private String sql = "select * from t where id = #{id}";
|
||||
|
||||
|
||||
public void test_mysql() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = #{id}", SQLUtils.format(sql, JdbcUtils.MYSQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = #{id}", SQLUtils.format(sql, JdbcUtils.ORACLE));
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = #{id}", SQLUtils.format(sql, JdbcUtils.ALI_ORACLE));
|
||||
}
|
||||
|
||||
|
||||
public void test_postgres() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = #{id}", SQLUtils.format(sql, JdbcUtils.POSTGRESQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_sql92() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = #{id}", SQLUtils.format(sql, null));
|
||||
}
|
||||
|
||||
@@ -21,22 +21,23 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
|
||||
public class MybatisTest2 extends TestCase {
|
||||
|
||||
private String sql = "select * from t where id = ${id}";
|
||||
|
||||
|
||||
public void test_mysql() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = ${id}", SQLUtils.format(sql, JdbcUtils.MYSQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = ${id}", SQLUtils.format(sql, JdbcUtils.ORACLE));
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = ${id}", SQLUtils.format(sql, JdbcUtils.ALI_ORACLE));
|
||||
}
|
||||
|
||||
|
||||
public void test_postgres() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = ${id}", SQLUtils.format(sql, JdbcUtils.POSTGRESQL));
|
||||
}
|
||||
|
||||
|
||||
public void test_sql92() throws Exception {
|
||||
Assert.assertEquals("SELECT *\nFROM t\nWHERE id = ${id}", SQLUtils.format(sql, null));
|
||||
}
|
||||
|
||||
@@ -32,11 +32,12 @@ public class MergeTest extends TestCase {
|
||||
String sql = "{ call INTERFACE_DATA_EXTRACTION.INVOICE_INFO(?,?,?)}";
|
||||
|
||||
ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.ORACLE);
|
||||
ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.ALI_ORACLE);
|
||||
}
|
||||
|
||||
|
||||
public void test_mergeCall_mysql() throws Exception {
|
||||
String sql = "{ call INTERFACE_DATA_EXTRACTION.INVOICE_INFO(?,?,?)}";
|
||||
|
||||
|
||||
ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.MYSQL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,7 @@ public class OracleFormatTest2 extends TestCase {
|
||||
|
||||
String formatedText = SQLUtils.format(text, JdbcUtils.ORACLE);
|
||||
System.out.println(formatedText);
|
||||
String formatedText2 = SQLUtils.format(text, JdbcUtils.ALI_ORACLE);
|
||||
System.out.println(formatedText2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user