mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser, support apache phoenix.
This commit is contained in:
@@ -87,9 +87,9 @@ public final class DruidConnectionHolder {
|
||||
|
||||
{
|
||||
boolean initUnderlyHoldability = !holdabilityUnsupported;
|
||||
if (JdbcConstants.SYBASE.equals(dataSource.getDbType()) //
|
||||
|| JdbcConstants.DB2.equals(dataSource.getDbType()) //
|
||||
|| JdbcConstants.HIVE.equals(dataSource.getDbType()) //
|
||||
if (JdbcConstants.SYBASE.equals(dataSource.dbType) //
|
||||
|| JdbcConstants.DB2.equals(dataSource.dbType) //
|
||||
|| JdbcConstants.HIVE.equals(dataSource.dbType) //
|
||||
) {
|
||||
initUnderlyHoldability = false;
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
JdbcDataSourceStat.setGlobal(dataSourceStat);
|
||||
}
|
||||
if (dataSourceStat.getDbType() == null) {
|
||||
dataSourceStat.setDbType(this.getDbType());
|
||||
dataSourceStat.setDbType(this.dbType);
|
||||
}
|
||||
} else {
|
||||
dataSourceStat = new JdbcDataSourceStat(this.name, this.jdbcUrl, this.dbType, this.connectProperties);
|
||||
@@ -1732,7 +1732,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
value.setName(this.getName());
|
||||
value.setDbType(this.getDbType());
|
||||
value.setDbType(this.dbType);
|
||||
value.setDriverClassName(this.getDriverClassName());
|
||||
|
||||
value.setUrl(this.getUrl());
|
||||
@@ -2578,7 +2578,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
map.put("MinEvictableIdleTimeMillis", this.getMinEvictableIdleTimeMillis());
|
||||
map.put("ConnectErrorCount", this.getConnectErrorCount());
|
||||
map.put("CreateTimespanMillis", this.getCreateTimespanMillis());
|
||||
map.put("DbType", this.getDbType());
|
||||
map.put("DbType", this.dbType);
|
||||
|
||||
// 20 - 24
|
||||
map.put("ValidationQuery", this.getValidationQuery());
|
||||
@@ -2651,7 +2651,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
dataMap.put("Identity", System.identityHashCode(this));
|
||||
dataMap.put("Name", this.getName());
|
||||
dataMap.put("DbType", this.getDbType());
|
||||
dataMap.put("DbType", this.dbType);
|
||||
dataMap.put("DriverClassName", this.getDriverClassName());
|
||||
|
||||
dataMap.put("URL", this.getUrl());
|
||||
|
||||
+118
-129
@@ -1,129 +1,118 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.oracle.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
public class OracleCreateSequenceStatement extends OracleStatementImpl {
|
||||
|
||||
private SQLName name;
|
||||
|
||||
private SQLExpr startWith;
|
||||
private SQLExpr incrementBy;
|
||||
private SQLExpr minValue;
|
||||
private SQLExpr maxValue;
|
||||
private boolean noMaxValue;
|
||||
private boolean noMinValue;
|
||||
|
||||
private Boolean cycle;
|
||||
private Boolean cache;
|
||||
private Boolean order;
|
||||
|
||||
@Override
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
acceptChild(visitor, startWith);
|
||||
acceptChild(visitor, incrementBy);
|
||||
acceptChild(visitor, minValue);
|
||||
acceptChild(visitor, maxValue);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLExpr getStartWith() {
|
||||
return startWith;
|
||||
}
|
||||
|
||||
public void setStartWith(SQLExpr startWith) {
|
||||
this.startWith = startWith;
|
||||
}
|
||||
|
||||
public SQLExpr getIncrementBy() {
|
||||
return incrementBy;
|
||||
}
|
||||
|
||||
public void setIncrementBy(SQLExpr incrementBy) {
|
||||
this.incrementBy = incrementBy;
|
||||
}
|
||||
|
||||
public SQLExpr getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(SQLExpr maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public Boolean getCycle() {
|
||||
return cycle;
|
||||
}
|
||||
|
||||
public void setCycle(Boolean cycle) {
|
||||
this.cycle = cycle;
|
||||
}
|
||||
|
||||
public Boolean getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void setCache(Boolean cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public Boolean getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Boolean order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public SQLExpr getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(SQLExpr minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public boolean isNoMaxValue() {
|
||||
return noMaxValue;
|
||||
}
|
||||
|
||||
public void setNoMaxValue(boolean noMaxValue) {
|
||||
this.noMaxValue = noMaxValue;
|
||||
}
|
||||
|
||||
public boolean isNoMinValue() {
|
||||
return noMinValue;
|
||||
}
|
||||
|
||||
public void setNoMinValue(boolean noMinValue) {
|
||||
this.noMinValue = noMinValue;
|
||||
}
|
||||
|
||||
}
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/14.
|
||||
*/
|
||||
public class SQLCreateSequenceStatement extends SQLStatementImpl {
|
||||
private SQLName name;
|
||||
|
||||
private SQLExpr startWith;
|
||||
private SQLExpr incrementBy;
|
||||
private SQLExpr minValue;
|
||||
private SQLExpr maxValue;
|
||||
private boolean noMaxValue;
|
||||
private boolean noMinValue;
|
||||
|
||||
private Boolean cycle;
|
||||
private Boolean cache;
|
||||
private Boolean order;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
acceptChild(visitor, startWith);
|
||||
acceptChild(visitor, incrementBy);
|
||||
acceptChild(visitor, minValue);
|
||||
acceptChild(visitor, maxValue);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLExpr getStartWith() {
|
||||
return startWith;
|
||||
}
|
||||
|
||||
public void setStartWith(SQLExpr startWith) {
|
||||
this.startWith = startWith;
|
||||
}
|
||||
|
||||
public SQLExpr getIncrementBy() {
|
||||
return incrementBy;
|
||||
}
|
||||
|
||||
public void setIncrementBy(SQLExpr incrementBy) {
|
||||
this.incrementBy = incrementBy;
|
||||
}
|
||||
|
||||
public SQLExpr getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(SQLExpr maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public Boolean getCycle() {
|
||||
return cycle;
|
||||
}
|
||||
|
||||
public void setCycle(Boolean cycle) {
|
||||
this.cycle = cycle;
|
||||
}
|
||||
|
||||
public Boolean getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void setCache(Boolean cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public Boolean getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Boolean order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public SQLExpr getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(SQLExpr minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public boolean isNoMaxValue() {
|
||||
return noMaxValue;
|
||||
}
|
||||
|
||||
public void setNoMaxValue(boolean noMaxValue) {
|
||||
this.noMaxValue = noMaxValue;
|
||||
}
|
||||
|
||||
public boolean isNoMinValue() {
|
||||
return noMinValue;
|
||||
}
|
||||
|
||||
public void setNoMinValue(boolean noMinValue) {
|
||||
this.noMinValue = noMinValue;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
private String dbType;
|
||||
|
||||
protected boolean upsert = false; // for phoenix
|
||||
|
||||
public SQLInsertStatement(){
|
||||
|
||||
}
|
||||
@@ -42,6 +44,14 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public boolean isUpsert() {
|
||||
return upsert;
|
||||
}
|
||||
|
||||
public void setUpsert(boolean upsert) {
|
||||
this.upsert = upsert;
|
||||
}
|
||||
|
||||
public static class ValuesClause extends SQLObjectImpl {
|
||||
|
||||
private final List<SQLExpr> values;
|
||||
|
||||
+3
-3
@@ -51,7 +51,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateDatabaseDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExceptionStatement;
|
||||
@@ -1439,14 +1438,15 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public OracleCreateSequenceStatement parseCreateSequence(boolean acceptCreate) {
|
||||
public SQLCreateSequenceStatement parseCreateSequence(boolean acceptCreate) {
|
||||
if (acceptCreate) {
|
||||
accept(Token.CREATE);
|
||||
}
|
||||
|
||||
accept(Token.SEQUENCE);
|
||||
|
||||
OracleCreateSequenceStatement stmt = new OracleCreateSequenceStatement();
|
||||
SQLCreateSequenceStatement stmt = new SQLCreateSequenceStatement();
|
||||
stmt.setDbType(JdbcConstants.ORACLE);
|
||||
stmt.setName(this.exprParser.name());
|
||||
|
||||
for (;;) {
|
||||
|
||||
@@ -63,7 +63,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCheck;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateDatabaseDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
@@ -447,10 +446,6 @@ public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OracleAlterTablespaceStatement x);
|
||||
|
||||
boolean visit(OracleCreateSequenceStatement x);
|
||||
|
||||
void endVisit(OracleCreateSequenceStatement x);
|
||||
|
||||
boolean visit(OracleExitStatement x);
|
||||
|
||||
void endVisit(OracleExitStatement x);
|
||||
|
||||
-11
@@ -73,7 +73,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCheck;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateDatabaseDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
@@ -1021,16 +1020,6 @@ public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements Ora
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCreateSequenceStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCreateSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExitStatement x) {
|
||||
return true;
|
||||
|
||||
@@ -94,7 +94,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateDatabaseDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
@@ -2567,63 +2566,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCreateSequenceStatement x) {
|
||||
print0(ucase ? "CREATE SEQUENCE " : "create sequence ");
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getStartWith() != null) {
|
||||
print0(ucase ? " START WITH " : " start with ");
|
||||
x.getStartWith().accept(this);
|
||||
}
|
||||
|
||||
if (x.getIncrementBy() != null) {
|
||||
print0(ucase ? " INCREMENT BY " : " increment by ");
|
||||
x.getIncrementBy().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxValue() != null) {
|
||||
print0(ucase ? " MAXVALUE " : " maxvalue ");
|
||||
x.getMaxValue().accept(this);
|
||||
}
|
||||
|
||||
if (x.isNoMaxValue()) {
|
||||
print0(ucase ? " NOMAXVALUE" : " nomaxvalue");
|
||||
}
|
||||
|
||||
if (x.getMinValue() != null) {
|
||||
print0(ucase ? " MINVALUE " : " minvalue ");
|
||||
x.getMinValue().accept(this);
|
||||
}
|
||||
|
||||
if (x.isNoMinValue()) {
|
||||
print0(ucase ? " NOMINVALUE" : " nominvalue");
|
||||
}
|
||||
|
||||
if (x.getCycle() != null) {
|
||||
if (x.getCycle().booleanValue()) {
|
||||
print0(ucase ? " CYCLE" : " cycle");
|
||||
} else {
|
||||
print0(ucase ? " NOCYCLE" : " nocycle");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getCache() != null) {
|
||||
if (x.getCache().booleanValue()) {
|
||||
print0(ucase ? " CACHE" : " cache");
|
||||
} else {
|
||||
print0(ucase ? " NOCACHE" : " nocache");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCreateSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExitStatement x) {
|
||||
print0(ucase ? "EXIT" : "exit");
|
||||
|
||||
-11
@@ -96,7 +96,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCheck;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateDatabaseDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
@@ -1354,16 +1353,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCreateSequenceStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCreateSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExitStatement x) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/14.
|
||||
*/
|
||||
public interface PhoenixObject extends SQLObject {
|
||||
void accept0(PhoenixASTVisitor visitor);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.DB2Object;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/14.
|
||||
*/
|
||||
public abstract class PhoenixStatementImpl extends SQLStatementImpl implements PhoenixObject {
|
||||
|
||||
public PhoenixStatementImpl() {
|
||||
super(JdbcConstants.PHOENIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof PhoenixASTVisitor) {
|
||||
accept0((PhoenixASTVisitor) visitor);
|
||||
return;
|
||||
}
|
||||
|
||||
super.accept0(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void accept0(PhoenixASTVisitor visitor);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.ast;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/14.
|
||||
*/
|
||||
public class PhoenixUpsertStatement extends PhoenixStatementImpl {
|
||||
|
||||
@Override
|
||||
public void accept0(PhoenixASTVisitor visitor) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.parser;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixExprParser extends SQLExprParser {
|
||||
public PhoenixExprParser(String sql){
|
||||
this(new PhoenixLexer(sql));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public PhoenixExprParser(Lexer lexer){
|
||||
super(lexer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.parser;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixLexer extends Lexer {
|
||||
public final static Keywords DEFAULT_PHOENIX_KEYWORDS;
|
||||
|
||||
static {
|
||||
Map<String, Token> map = new HashMap<String, Token>();
|
||||
|
||||
map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords());
|
||||
|
||||
map.put("FETCH", Token.FETCH);
|
||||
map.put("FIRST", Token.FIRST);
|
||||
map.put("ONLY", Token.ONLY);
|
||||
map.put("OPTIMIZE", Token.OPTIMIZE);
|
||||
map.put("OF", Token.OF);
|
||||
map.put("CONCAT", Token.CONCAT);
|
||||
map.put("CONTINUE", Token.CONTINUE);
|
||||
map.put("IDENTITY", Token.IDENTITY);
|
||||
map.put("MERGE", Token.MERGE);
|
||||
map.put("USING", Token.USING);
|
||||
map.put("MATCHED", Token.MATCHED);
|
||||
map.put("UPSERT", Token.UPSERT);
|
||||
|
||||
DEFAULT_PHOENIX_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
public PhoenixLexer(String input){
|
||||
super(input);
|
||||
super.keywods = DEFAULT_PHOENIX_KEYWORDS;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixStatementParser extends SQLStatementParser {
|
||||
public PhoenixStatementParser(String sql) {
|
||||
super (new PhoenixExprParser(sql));
|
||||
}
|
||||
|
||||
public PhoenixStatementParser(Lexer lexer){
|
||||
super(new PhoenixExprParser(lexer));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public interface PhoenixASTVisitor extends SQLASTVisitor {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixOutputVisitor extends SQLASTOutputVisitor implements PhoenixASTVisitor {
|
||||
public PhoenixOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixParameterizedOutputVisitor extends PhoenixOutputVisitor implements ParameterizedVisitor {
|
||||
private int replaceCount;
|
||||
|
||||
public PhoenixParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public PhoenixParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.dialect.phoenix.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixSchemaStatVisitor extends SchemaStatVisitor implements PhoenixASTVisitor {
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import com.alibaba.druid.sql.dialect.odps.parser.OdpsExprParser;
|
||||
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.phoenix.parser.PhoenixExprParser;
|
||||
import com.alibaba.druid.sql.dialect.phoenix.parser.PhoenixStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGExprParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerExprParser;
|
||||
@@ -64,6 +66,10 @@ public class SQLParserUtils {
|
||||
return new OdpsStatementParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.PHOENIX.equals(dbType)) {
|
||||
return new PhoenixStatementParser(sql);
|
||||
}
|
||||
|
||||
return new SQLStatementParser(sql);
|
||||
}
|
||||
|
||||
@@ -94,6 +100,10 @@ public class SQLParserUtils {
|
||||
return new OdpsExprParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.PHOENIX.equals(dbType)) {
|
||||
return new PhoenixExprParser(sql);
|
||||
}
|
||||
|
||||
return new SQLExprParser(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUseStatement;
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
|
||||
public class SQLStatementParser extends SQLParser {
|
||||
|
||||
@@ -418,6 +419,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.UPSERT || identifierEquals("UPSERT")) {
|
||||
SQLStatement stmt = parseUpsert();
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
// throw new ParserException("syntax error, " + lexer.token() + " "
|
||||
// + lexer.stringVal() + ", pos "
|
||||
// + lexer.pos());
|
||||
@@ -425,6 +432,18 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
public SQLStatement parseUpsert() {
|
||||
SQLInsertStatement insertStatement = new SQLInsertStatement();
|
||||
|
||||
if (lexer.token() == Token.UPSERT || identifierEquals("UPSERT")) {
|
||||
lexer.nextToken();
|
||||
insertStatement.setUpsert(true);
|
||||
}
|
||||
|
||||
parseInsert0(insertStatement);
|
||||
return insertStatement;
|
||||
}
|
||||
|
||||
public SQLRollbackStatement parseRollback() {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
@@ -280,6 +280,8 @@ public enum Token {
|
||||
|
||||
CONCAT("CONCAT"), // DB2
|
||||
|
||||
UPSERT("UPSERT"), // Phoenix
|
||||
|
||||
LPAREN("("),
|
||||
RPAREN(")"),
|
||||
LBRACE("{"),
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.phoenix.visitor.PhoenixParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerParameterizedOutputVisitor;
|
||||
@@ -102,6 +103,10 @@ public class ParameterizedOutputVisitorUtils {
|
||||
return new DB2ParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
if (JdbcUtils.PHOENIX.equals(dbType)) {
|
||||
return new PhoenixParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
return new ParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
@@ -1058,7 +1058,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLInsertStatement x) {
|
||||
print0(ucase ? "INSERT INTO " : "insert into ");
|
||||
if (x.isUpsert()) {
|
||||
print0(ucase ? "UPSERT INTO " : "upsert into ");
|
||||
} else {
|
||||
print0(ucase ? "INSERT INTO " : "insert into ");
|
||||
}
|
||||
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
@@ -3231,5 +3235,57 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateSequenceStatement x) {
|
||||
print0(ucase ? "CREATE SEQUENCE " : "create sequence ");
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getStartWith() != null) {
|
||||
print0(ucase ? " START WITH " : " start with ");
|
||||
x.getStartWith().accept(this);
|
||||
}
|
||||
|
||||
if (x.getIncrementBy() != null) {
|
||||
print0(ucase ? " INCREMENT BY " : " increment by ");
|
||||
x.getIncrementBy().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxValue() != null) {
|
||||
print0(ucase ? " MAXVALUE " : " maxvalue ");
|
||||
x.getMaxValue().accept(this);
|
||||
}
|
||||
|
||||
if (x.isNoMaxValue()) {
|
||||
print0(ucase ? " NOMAXVALUE" : " nomaxvalue");
|
||||
}
|
||||
|
||||
if (x.getMinValue() != null) {
|
||||
print0(ucase ? " MINVALUE " : " minvalue ");
|
||||
x.getMinValue().accept(this);
|
||||
}
|
||||
|
||||
if (x.isNoMinValue()) {
|
||||
print0(ucase ? " NOMINVALUE" : " nominvalue");
|
||||
}
|
||||
|
||||
if (x.getCycle() != null) {
|
||||
if (x.getCycle().booleanValue()) {
|
||||
print0(ucase ? " CYCLE" : " cycle");
|
||||
} else {
|
||||
print0(ucase ? " NOCYCLE" : " nocycle");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getCache() != null) {
|
||||
if (x.getCache().booleanValue()) {
|
||||
print0(ucase ? " CACHE" : " cache");
|
||||
} else {
|
||||
print0(ucase ? " NOCACHE" : " nocache");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,56 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLKeep;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOver;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByList;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByRange;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionByList;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAnyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBooleanExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCaseExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCastExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLDefaultExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLExistsExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLGroupingSetExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNotExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSequenceExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSomeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLTimestampExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
|
||||
public interface SQLASTVisitor {
|
||||
@@ -721,4 +673,7 @@ public interface SQLASTVisitor {
|
||||
|
||||
void endVisit(SQLNullConstraint x);
|
||||
|
||||
boolean visit(SQLCreateSequenceStatement x);
|
||||
|
||||
void endVisit(SQLCreateSequenceStatement x);
|
||||
}
|
||||
|
||||
@@ -1574,4 +1574,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
@Override
|
||||
public void endVisit(SQLNullConstraint x) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateSequenceStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLCreateSequenceStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,77 +51,7 @@ import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSequenceExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAnalyzePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCheckPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDiscardPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeignKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableImportPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableOptimizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRebuildPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRename;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRepairPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableTruncatePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCheck;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCloseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommentStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropFunctionStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropProcedureStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableSpaceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLFetchStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLObjectType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLOpenStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLRevokeStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLShowTablesStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import com.alibaba.druid.stat.TableStat.Condition;
|
||||
@@ -1758,4 +1688,8 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public List<SQLMethodInvokeExpr> getFunctions() {
|
||||
return this.functions;
|
||||
}
|
||||
|
||||
public boolean visit(SQLCreateSequenceStatement x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +83,7 @@ public interface JdbcConstants {
|
||||
*/
|
||||
public static final String LOG4JDBC = "log4jdbc";
|
||||
public static final String LOG4JDBC_DRIVER = "net.sf.log4jdbc.DriverSpy";
|
||||
|
||||
public static final String PHOENIX = "phoenix";
|
||||
public static final String PHOENIX_DRIVER = "org.apache.phoenix.jdbc.PhoenixDriver";
|
||||
}
|
||||
|
||||
@@ -442,6 +442,10 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return JdbcConstants.HIVE_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:hive2:")) {
|
||||
return JdbcConstants.HIVE_DRIVER;
|
||||
} else if (rawUrl.startsWith("jdbc:phoenix:thin:")) {
|
||||
return "org.apache.phoenix.queryserver.client.Driver";
|
||||
} else if (rawUrl.startsWith("jdbc:phoenix://")) {
|
||||
return JdbcConstants.PHOENIX_DRIVER;
|
||||
} else {
|
||||
throw new SQLException("unkow jdbc driver : " + rawUrl);
|
||||
}
|
||||
@@ -523,6 +527,8 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return HIVE;
|
||||
} else if (rawUrl.startsWith("jdbc:hive2:")) {
|
||||
return HIVE;
|
||||
} else if (rawUrl.startsWith("jdbc:phoenix:")) {
|
||||
return PHOENIX;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateSequenceStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGShowStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerCommitStatement;
|
||||
@@ -2388,7 +2387,7 @@ public class WallVisitorUtils {
|
||||
|| x instanceof SQLCreateIndexStatement //
|
||||
|| x instanceof SQLCreateViewStatement //
|
||||
|| x instanceof SQLCreateTriggerStatement //
|
||||
|| x instanceof OracleCreateSequenceStatement //
|
||||
|| x instanceof SQLCreateSequenceStatement //
|
||||
) {
|
||||
allow = config.isCreateTableAllow();
|
||||
denyMessage = "create table not allow";
|
||||
|
||||
Reference in New Issue
Block a user