mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge branch 'master' into support_oceanbase_dbtype
This commit is contained in:
@@ -340,7 +340,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
|
||||
public boolean isUseUnfairLock() {
|
||||
return lock.isFair();
|
||||
return !lock.isFair();
|
||||
}
|
||||
|
||||
public void setUseUnfairLock(boolean useUnfairLock) {
|
||||
@@ -795,7 +795,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
LOG.error("maxEvictableIdleTimeMillis should be greater than 30000");
|
||||
}
|
||||
|
||||
if (maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis) {
|
||||
if (inited && maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis) {
|
||||
throw new IllegalArgumentException("maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis");
|
||||
}
|
||||
|
||||
|
||||
@@ -884,24 +884,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
initFromSPIServiceLoader();
|
||||
|
||||
if (this.driver == null) {
|
||||
if (this.driverClass == null || this.driverClass.isEmpty()) {
|
||||
this.driverClass = JdbcUtils.getDriverClassName(this.jdbcUrl);
|
||||
}
|
||||
|
||||
if (MockDriver.class.getName().equals(driverClass)) {
|
||||
driver = MockDriver.instance;
|
||||
} else {
|
||||
if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
|
||||
throw new SQLException("url not set");
|
||||
}
|
||||
driver = JdbcUtils.createDriver(driverClassLoader, driverClass);
|
||||
}
|
||||
} else {
|
||||
if (this.driverClass == null) {
|
||||
this.driverClass = driver.getClass().getName();
|
||||
}
|
||||
}
|
||||
resolveDriver();
|
||||
|
||||
initCheck();
|
||||
|
||||
@@ -1214,6 +1197,27 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
LOG.error(errorMessage + "validationQuery not set");
|
||||
}
|
||||
|
||||
protected void resolveDriver() throws SQLException {
|
||||
if (this.driver == null) {
|
||||
if (this.driverClass == null || this.driverClass.isEmpty()) {
|
||||
this.driverClass = JdbcUtils.getDriverClassName(this.jdbcUrl);
|
||||
}
|
||||
|
||||
if (MockDriver.class.getName().equals(driverClass)) {
|
||||
driver = MockDriver.instance;
|
||||
} else {
|
||||
if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
|
||||
throw new SQLException("url not set");
|
||||
}
|
||||
driver = JdbcUtils.createDriver(driverClassLoader, driverClass);
|
||||
}
|
||||
} else {
|
||||
if (this.driverClass == null) {
|
||||
this.driverClass = driver.getClass().getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initCheck() throws SQLException {
|
||||
if (JdbcUtils.ORACLE.equals(this.dbType)) {
|
||||
isOracle = true;
|
||||
@@ -1317,7 +1321,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.validConnectionChecker = new MSSQLValidConnectionChecker();
|
||||
|
||||
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)) {
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
|
||||
this.validConnectionChecker = new PGValidConnectionChecker();
|
||||
}
|
||||
}
|
||||
@@ -1348,7 +1353,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.exceptionSorter = new SybaseExceptionSorter();
|
||||
|
||||
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)) {
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
|
||||
this.exceptionSorter = new PGExceptionSorter();
|
||||
|
||||
} else if (realDriverClassName.equals("com.alibaba.druid.mock.MockDriver")) {
|
||||
|
||||
@@ -891,7 +891,9 @@ public class SQLUtils {
|
||||
if (MySqlUtils.isKeyword(normalizeName)) {
|
||||
return name;
|
||||
}
|
||||
} else if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
} else if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcConstants.POLARDB.equals(dbType)) {
|
||||
if (PGUtils.isKeyword(normalizeName)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -1585,11 +1585,7 @@ public class SQLExprParser extends SQLParser {
|
||||
throw new ParserException("error, " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token == Token.LITERAL_ALIAS) {
|
||||
name = new SQLPropertyExpr(name, lexer.stringVal());
|
||||
} else {
|
||||
name = new SQLPropertyExpr(name, lexer.stringVal());
|
||||
}
|
||||
name = new SQLPropertyExpr(name, lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
name = nameRest(name);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ public class SQLParserUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGSQLStatementParser(sql);
|
||||
}
|
||||
|
||||
@@ -124,7 +126,9 @@ public class SQLParserUtils {
|
||||
return new MySqlExprParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGExprParser(sql);
|
||||
}
|
||||
|
||||
@@ -156,7 +160,9 @@ public class SQLParserUtils {
|
||||
return new MySqlLexer(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGLexer(sql);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,212 +1,222 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBooleanExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLDateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLTimestampExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.MSSQLServerExportParameterVisitor;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public final class ExportParameterVisitorUtils {
|
||||
|
||||
//private for util class not need new instance
|
||||
private ExportParameterVisitorUtils() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static ExportParameterVisitor createExportParameterVisitor(final Appendable out ,final String dbType) {
|
||||
|
||||
if (JdbcUtils.isMysqlDbType(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isOracleDbType(dbType)) {
|
||||
return new OracleExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
return new PGExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isSqlserverDbType(dbType)) {
|
||||
return new MSSQLServerExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.DB2.equals(dbType)) {
|
||||
return new DB2ExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.MARIADB.equals(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
return new ExportParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean exportParamterAndAccept(final List<Object> parameters, List<SQLExpr> list) {
|
||||
for (int i = 0, size = list.size(); i < size; ++i) {
|
||||
SQLExpr param = list.get(i);
|
||||
|
||||
SQLExpr result = exportParameter(parameters, param);
|
||||
if (result != param) {
|
||||
list.set(i, result);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SQLExpr exportParameter(final List<Object> parameters, final SQLExpr param) {
|
||||
Object value = null;
|
||||
boolean replace = false;
|
||||
|
||||
if (param instanceof SQLCharExpr) {
|
||||
value = ((SQLCharExpr) param).getText();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLBooleanExpr) {
|
||||
value = ((SQLBooleanExpr) param).getBooleanValue();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLNumericLiteralExpr) {
|
||||
value = ((SQLNumericLiteralExpr) param).getNumber();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
value = ((SQLHexExpr) param).toBytes();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLTimestampExpr || param instanceof SQLDateExpr) {
|
||||
value = ((SQLTimestampExpr) param).getValue();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLListExpr) {
|
||||
SQLListExpr list = ((SQLListExpr) param);
|
||||
|
||||
List<Object> listValues = new ArrayList<Object>();
|
||||
for (int i = 0; i < list.getItems().size(); i++) {
|
||||
SQLExpr listItem = list.getItems().get(i);
|
||||
|
||||
if (listItem instanceof SQLCharExpr) {
|
||||
Object listValue = ((SQLCharExpr) listItem).getText();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLBooleanExpr) {
|
||||
Object listValue = ((SQLBooleanExpr) listItem).getBooleanValue();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLNumericLiteralExpr) {
|
||||
Object listValue = ((SQLNumericLiteralExpr) listItem).getNumber();
|
||||
listValues.add(listValue);
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
Object listValue = ((SQLHexExpr) listItem).toBytes();
|
||||
listValues.add(listValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (listValues.size() == list.getItems().size()) {
|
||||
value = listValues;
|
||||
replace = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
SQLObject parent = param.getParent();
|
||||
if (parent != null) {
|
||||
List<SQLObject> mergedList = null;
|
||||
if (parent instanceof SQLBinaryOpExpr) {
|
||||
mergedList = ((SQLBinaryOpExpr) parent).getMergedList();
|
||||
}
|
||||
if (mergedList != null) {
|
||||
List<Object> mergedListParams = new ArrayList<Object>(mergedList.size() + 1);
|
||||
for (int i = 0; i < mergedList.size(); ++i) {
|
||||
SQLObject item = mergedList.get(i);
|
||||
if (item instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpItem = (SQLBinaryOpExpr) item;
|
||||
exportParameter(mergedListParams, binaryOpItem.getRight());
|
||||
}
|
||||
}
|
||||
if (mergedListParams.size() > 0) {
|
||||
mergedListParams.add(0, value);
|
||||
value = mergedListParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameters.add(value);
|
||||
|
||||
return new SQLVariantRefExpr("?");
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
public static void exportParameter(final List<Object> parameters, SQLBinaryOpExpr x) {
|
||||
if (x.getLeft() instanceof SQLLiteralExpr
|
||||
&& x.getRight() instanceof SQLLiteralExpr
|
||||
&& x.getOperator().isRelational()) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr leftResult = ExportParameterVisitorUtils.exportParameter(parameters, x.getLeft());
|
||||
if (leftResult != x.getLeft()) {
|
||||
x.setLeft(leftResult);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr rightResult = exportParameter(parameters, x.getRight());
|
||||
if (rightResult != x.getRight()) {
|
||||
x.setRight(rightResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportParameter(final List<Object> parameters, SQLBetweenExpr x) {
|
||||
{
|
||||
SQLExpr result = exportParameter(parameters, x.getBeginExpr());
|
||||
if (result != x.getBeginExpr()) {
|
||||
x.setBeginExpr(result);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr result = exportParameter(parameters, x.getEndExpr());
|
||||
if (result != x.getBeginExpr()) {
|
||||
x.setEndExpr(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBooleanExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLDateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLTimestampExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.MSSQLServerExportParameterVisitor;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public final class ExportParameterVisitorUtils {
|
||||
|
||||
//private for util class not need new instance
|
||||
private ExportParameterVisitorUtils() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static ExportParameterVisitor createExportParameterVisitor(final Appendable out ,final String dbType) {
|
||||
|
||||
if (JdbcUtils.isMysqlDbType(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isOracleDbType(dbType)) {
|
||||
return new OracleExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
return new PGExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isSqlserverDbType(dbType)) {
|
||||
return new MSSQLServerExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.DB2.equals(dbType)) {
|
||||
return new DB2ExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.MARIADB.equals(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.H2.equals(dbType)) {
|
||||
return new MySqlExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) {
|
||||
return new MSSQLServerExportParameterVisitor(out);
|
||||
}
|
||||
return new ExportParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean exportParamterAndAccept(final List<Object> parameters, List<SQLExpr> list) {
|
||||
for (int i = 0, size = list.size(); i < size; ++i) {
|
||||
SQLExpr param = list.get(i);
|
||||
|
||||
SQLExpr result = exportParameter(parameters, param);
|
||||
if (result != param) {
|
||||
list.set(i, result);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SQLExpr exportParameter(final List<Object> parameters, final SQLExpr param) {
|
||||
Object value = null;
|
||||
boolean replace = false;
|
||||
|
||||
if (param instanceof SQLCharExpr) {
|
||||
value = ((SQLCharExpr) param).getText();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLBooleanExpr) {
|
||||
value = ((SQLBooleanExpr) param).getBooleanValue();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLNumericLiteralExpr) {
|
||||
value = ((SQLNumericLiteralExpr) param).getNumber();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
value = ((SQLHexExpr) param).toBytes();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLTimestampExpr || param instanceof SQLDateExpr) {
|
||||
value = ((SQLTimestampExpr) param).getValue();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLListExpr) {
|
||||
SQLListExpr list = ((SQLListExpr) param);
|
||||
|
||||
List<Object> listValues = new ArrayList<Object>();
|
||||
for (int i = 0; i < list.getItems().size(); i++) {
|
||||
SQLExpr listItem = list.getItems().get(i);
|
||||
|
||||
if (listItem instanceof SQLCharExpr) {
|
||||
Object listValue = ((SQLCharExpr) listItem).getText();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLBooleanExpr) {
|
||||
Object listValue = ((SQLBooleanExpr) listItem).getBooleanValue();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLNumericLiteralExpr) {
|
||||
Object listValue = ((SQLNumericLiteralExpr) listItem).getNumber();
|
||||
listValues.add(listValue);
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
Object listValue = ((SQLHexExpr) listItem).toBytes();
|
||||
listValues.add(listValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (listValues.size() == list.getItems().size()) {
|
||||
value = listValues;
|
||||
replace = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
SQLObject parent = param.getParent();
|
||||
if (parent != null) {
|
||||
List<SQLObject> mergedList = null;
|
||||
if (parent instanceof SQLBinaryOpExpr) {
|
||||
mergedList = ((SQLBinaryOpExpr) parent).getMergedList();
|
||||
}
|
||||
if (mergedList != null) {
|
||||
List<Object> mergedListParams = new ArrayList<Object>(mergedList.size() + 1);
|
||||
for (int i = 0; i < mergedList.size(); ++i) {
|
||||
SQLObject item = mergedList.get(i);
|
||||
if (item instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpItem = (SQLBinaryOpExpr) item;
|
||||
exportParameter(mergedListParams, binaryOpItem.getRight());
|
||||
}
|
||||
}
|
||||
if (mergedListParams.size() > 0) {
|
||||
mergedListParams.add(0, value);
|
||||
value = mergedListParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameters.add(value);
|
||||
|
||||
return new SQLVariantRefExpr("?");
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
public static void exportParameter(final List<Object> parameters, SQLBinaryOpExpr x) {
|
||||
if (x.getLeft() instanceof SQLLiteralExpr
|
||||
&& x.getRight() instanceof SQLLiteralExpr
|
||||
&& x.getOperator().isRelational()) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr leftResult = ExportParameterVisitorUtils.exportParameter(parameters, x.getLeft());
|
||||
if (leftResult != x.getLeft()) {
|
||||
x.setLeft(leftResult);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr rightResult = exportParameter(parameters, x.getRight());
|
||||
if (rightResult != x.getRight()) {
|
||||
x.setRight(rightResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportParameter(final List<Object> parameters, SQLBetweenExpr x) {
|
||||
{
|
||||
SQLExpr result = exportParameter(parameters, x.getBeginExpr());
|
||||
if (result != x.getBeginExpr()) {
|
||||
x.setBeginExpr(result);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
SQLExpr result = exportParameter(parameters, x.getEndExpr());
|
||||
if (result != x.getBeginExpr()) {
|
||||
x.setEndExpr(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +273,10 @@ public class ParameterizedOutputVisitorUtils {
|
||||
return new MySqlOutputVisitor(out, true);
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGOutputVisitor(out, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -2552,7 +2552,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
boolean newLine = item instanceof SQLForeignKeyConstraint //
|
||||
|| item instanceof SQLPrimaryKey //
|
||||
|| item instanceof SQLColumnCheck //
|
||||
|| item instanceof SQLColumnCheck //
|
||||
|| item.getName() != null;
|
||||
if (newLine) {
|
||||
this.indentCount++;
|
||||
|
||||
@@ -168,7 +168,9 @@ public class SQLEvalVisitorUtils {
|
||||
return new OracleEvalVisitor();
|
||||
}
|
||||
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcConstants.POLARDB.equals(dbType)) {
|
||||
return new PGEvalVisitor();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ public interface JdbcConstants {
|
||||
|
||||
String DB2 = "db2";
|
||||
|
||||
String DB2_DRIVER = "com.ibm.db2.jcc.DB2Driver";
|
||||
String DB2_DRIVER = "com.ibm.db2.jcc.DB2Driver"; // Type4
|
||||
String DB2_DRIVER2 = "COM.ibm.db2.jdbc.app.DB2Driver"; // Type2
|
||||
String DB2_DRIVER3 = "COM.ibm.db2.jdbc.net.DB2Driver"; // Type3
|
||||
|
||||
String POSTGRESQL = "postgresql";
|
||||
String POSTGRESQL_DRIVER = "org.postgresql.Driver";
|
||||
@@ -119,4 +121,13 @@ public interface JdbcConstants {
|
||||
|
||||
String CLICKHOUSE = "clickhouse";
|
||||
String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
|
||||
|
||||
String KDB = "kdb";
|
||||
String KDB_DRIVER = "com.inspur.jdbc.KdDriver";
|
||||
|
||||
/**
|
||||
* Aliyun PolarDB
|
||||
*/
|
||||
String POLARDB = "polardb";
|
||||
String POLARDB_DRIVER = "com.aliyun.polardb.Driver";
|
||||
}
|
||||
|
||||
@@ -438,7 +438,21 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
} else if (rawUrl.startsWith("jdbc:hsqldb:")) {
|
||||
return "org.hsqldb.jdbcDriver";
|
||||
} else if (rawUrl.startsWith("jdbc:db2:")) {
|
||||
return DB2_DRIVER;
|
||||
// Resolve the DB2 driver from JDBC URL
|
||||
// Type2 COM.ibm.db2.jdbc.app.DB2Driver, url = jdbc:db2:databasename
|
||||
// Type3 COM.ibm.db2.jdbc.net.DB2Driver, url = jdbc:db2:ServerIP:6789:databasename
|
||||
// Type4 8.1+ com.ibm.db2.jcc.DB2Driver, url = jdbc:db2://ServerIP:50000/databasename
|
||||
String prefix = "jdbc:db2:";
|
||||
if (rawUrl.startsWith(prefix + "//")) { // Type4
|
||||
return DB2_DRIVER; // "com.ibm.db2.jcc.DB2Driver";
|
||||
} else {
|
||||
String suffix = rawUrl.substring(prefix.length());
|
||||
if (suffix.indexOf(':') > 0) { // Type3
|
||||
return DB2_DRIVER3; // COM.ibm.db2.jdbc.net.DB2Driver
|
||||
} else { // Type2
|
||||
return DB2_DRIVER2; // COM.ibm.db2.jdbc.app.DB2Driver
|
||||
}
|
||||
}
|
||||
} else if (rawUrl.startsWith("jdbc:sqlite:")) {
|
||||
return SQLITE_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:ingres:")) {
|
||||
@@ -495,7 +509,11 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return JdbcConstants.CLICKHOUSE_DRIVER;
|
||||
} else if(rawUrl.startsWith("jdbc:presto:")) {
|
||||
return JdbcConstants.PRESTO_DRIVER;
|
||||
}else {
|
||||
} else if (rawUrl.startsWith("jdbc:inspur:")) {
|
||||
return JdbcConstants.KDB_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:polardb")) {
|
||||
return JdbcConstants.POLARDB_DRIVER;
|
||||
} else {
|
||||
throw new SQLException("unknown jdbc driver : " + rawUrl);
|
||||
}
|
||||
}
|
||||
@@ -594,6 +612,10 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return CLICKHOUSE;
|
||||
} else if (rawUrl.startsWith("jdbc:presto:")) {
|
||||
return PRESTO;
|
||||
} else if (rawUrl.startsWith("jdbc:inspur:")) {
|
||||
return JdbcConstants.KDB;
|
||||
} else if (rawUrl.startsWith("jdbc:polardb")) {
|
||||
return POLARDB;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,9 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
}
|
||||
|
||||
provider = new SQLServerWallProvider(config);
|
||||
} else if (JdbcUtils.isPgsqlDbType(dbType)) {
|
||||
} else if (JdbcUtils.isPgsqlDbType(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
if (config == null) {
|
||||
config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user