mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge branch 'master' of https://github.com/AlibabaTech/druid
This commit is contained in:
@@ -27,16 +27,15 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected String methodName;
|
||||
protected int option;
|
||||
protected Option option;
|
||||
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
|
||||
|
||||
public SQLAggregateExpr(String methodName){
|
||||
|
||||
this.methodName = methodName;
|
||||
this.option = 1;
|
||||
}
|
||||
|
||||
public SQLAggregateExpr(String methodName, int option){
|
||||
public SQLAggregateExpr(String methodName, Option option){
|
||||
this.methodName = methodName;
|
||||
this.option = option;
|
||||
}
|
||||
@@ -49,11 +48,11 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public int getOption() {
|
||||
public Option getOption() {
|
||||
return this.option;
|
||||
}
|
||||
|
||||
public void setOption(int option) {
|
||||
public void setOption(Option option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
|
||||
int result = 1;
|
||||
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
|
||||
result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
|
||||
result = prime * result + option;
|
||||
result = prime * result + ((option == null) ? 0 : option.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -121,4 +120,8 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static enum Option {
|
||||
DISTINCT, ALL, UNIQUE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MySqlLexer extends Lexer {
|
||||
public void scanVariable() {
|
||||
final char first = ch;
|
||||
|
||||
if (ch != '@' && ch != ':' && ch != '#') {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -104,6 +104,31 @@ public class MySqlLexer extends Lexer {
|
||||
|
||||
stringVal = symbolTable.addSymbol(buf, np, sp, hash);
|
||||
token = Token.VARIANT;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
++bp;
|
||||
++sp;
|
||||
char ch;
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
if (ch == '}') {
|
||||
sp++;
|
||||
ch = buf[++bp];
|
||||
break;
|
||||
} else if (ch == EOI) {
|
||||
throw new SQLParseException("illegal identifier");
|
||||
}
|
||||
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
stringVal = symbolTable.addSymbol(buf, np, sp, hash);
|
||||
token = Token.VARIANT;
|
||||
} else {
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
@@ -494,7 +494,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.isGlobal()) {
|
||||
print("@@global.");
|
||||
} else {
|
||||
if ((!x.getName().startsWith("@")) && (!x.getName().equals("?"))) {
|
||||
String varName = x.getName();
|
||||
if ((!varName.startsWith("@")) && (!varName.equals("?")) && (!varName.startsWith("#")) && (!varName.startsWith("$"))) {
|
||||
print("@@");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -24,17 +24,16 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OracleAggregateExpr extends SQLAggregateExpr implements Serializable, OracleExpr {
|
||||
|
||||
private boolean unique = false;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private OracleAnalytic over;
|
||||
private boolean ignoreNulls = false;
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
return Option.UNIQUE.equals(this.getOption());
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
this.setOption(Option.UNIQUE);
|
||||
}
|
||||
|
||||
public boolean isIgnoreNulls() {
|
||||
@@ -49,7 +48,7 @@ public class OracleAggregateExpr extends SQLAggregateExpr implements Serializabl
|
||||
super(methodName);
|
||||
}
|
||||
|
||||
public OracleAggregateExpr(String methodName, int option){
|
||||
public OracleAggregateExpr(String methodName, Option option){
|
||||
super(methodName, option);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
@@ -524,25 +525,22 @@ public class OracleExprParser extends SQLExprParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected OracleAggregateExpr parseAggregateExpr(String method_name) {
|
||||
boolean unique = false;
|
||||
|
||||
if (lexer.token() == Token.UNIQUE) {
|
||||
lexer.nextToken();
|
||||
unique = true;
|
||||
}
|
||||
protected OracleAggregateExpr parseAggregateExpr(String methodName) {
|
||||
methodName = methodName.toUpperCase();
|
||||
|
||||
OracleAggregateExpr aggregateExpr;
|
||||
if (lexer.token() == (Token.ALL)) {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 1);
|
||||
if (lexer.token() == Token.UNIQUE) {
|
||||
aggregateExpr = new OracleAggregateExpr(methodName, SQLAggregateExpr.Option.UNIQUE);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == (Token.ALL)) {
|
||||
aggregateExpr = new OracleAggregateExpr(methodName, SQLAggregateExpr.Option.ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == (Token.DISTINCT)) {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 0);
|
||||
aggregateExpr = new OracleAggregateExpr(methodName, SQLAggregateExpr.Option.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new OracleAggregateExpr(methodName);
|
||||
}
|
||||
aggregateExpr.setUnique(unique);
|
||||
exprList(aggregateExpr.getArguments());
|
||||
|
||||
if (lexer.stringVal().equalsIgnoreCase("IGNORE")) {
|
||||
|
||||
@@ -87,7 +87,7 @@ public class OracleLexer extends Lexer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch != ':' && ch != '#') {
|
||||
if (ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -98,12 +98,19 @@ public class OracleLexer extends Lexer {
|
||||
char ch;
|
||||
|
||||
boolean quoteFlag = false;
|
||||
boolean mybatisFlag = false;
|
||||
if (buf[bp + 1] == '"') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
quoteFlag = true;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
mybatisFlag = true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
ch = buf[++bp];
|
||||
|
||||
@@ -116,6 +123,7 @@ public class OracleLexer extends Lexer {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quoteFlag) {
|
||||
if (ch != '"') {
|
||||
throw new SQLParseException("syntax error");
|
||||
@@ -123,6 +131,13 @@ public class OracleLexer extends Lexer {
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
} else if (mybatisFlag) {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
@@ -211,9 +211,12 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
public boolean visit(OracleAggregateExpr expr) {
|
||||
print(expr.getMethodName());
|
||||
print("(");
|
||||
if (expr.isUnique()) {
|
||||
print("UNIQUE ");
|
||||
|
||||
if (expr.getOption() != null) {
|
||||
print(expr.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
printAndAccept(expr.getArguments(), ", ");
|
||||
print(")");
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class PGAggregateExpr extends SQLAggregateExpr implements PGSQLObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PGAggregateExpr(String methodName, int option) {
|
||||
public PGAggregateExpr(String methodName, Option option) {
|
||||
super(methodName, option);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,18 @@ public class PGExprParser extends SQLExprParser{
|
||||
super(lexer);
|
||||
}
|
||||
|
||||
protected SQLAggregateExpr parseAggregateExpr(String method_name) throws ParserException {
|
||||
protected SQLAggregateExpr parseAggregateExpr(String methodName) throws ParserException {
|
||||
methodName = methodName.toUpperCase();
|
||||
|
||||
PGAggregateExpr aggregateExpr;
|
||||
if (lexer.token() == Token.ALL) {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new PGAggregateExpr(methodName, SQLAggregateExpr.Option.ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DISTINCT) {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 0);
|
||||
aggregateExpr = new PGAggregateExpr(methodName, SQLAggregateExpr.Option.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new PGAggregateExpr(methodName);
|
||||
}
|
||||
|
||||
exprList(aggregateExpr.getArguments());
|
||||
|
||||
@@ -433,12 +433,21 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
@Override
|
||||
public boolean visit(PGAggregateExpr x) {
|
||||
print(x.getMethodName());
|
||||
|
||||
print("(");
|
||||
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
printAndAccept(x.getArguments(), ", ");
|
||||
print(")");
|
||||
|
||||
if (x.getOver() != null) {
|
||||
x.getOver().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,9 +205,13 @@ public class Lexer {
|
||||
if (isWhitespace(ch)) {
|
||||
scanChar();
|
||||
continue;
|
||||
}// QS_TODO skip comment
|
||||
}
|
||||
|
||||
if (ch == '$' && buf[bp + 1] == '{') {
|
||||
scanVariable();
|
||||
return;
|
||||
}
|
||||
|
||||
// QS_TODO id may start from digit
|
||||
if (isFirstIdentifierChar(ch)) {
|
||||
if (ch == 'N') {
|
||||
if (buf[bp + 1] == '\'') {
|
||||
@@ -571,7 +575,7 @@ public class Lexer {
|
||||
public void scanVariable() {
|
||||
final char first = ch;
|
||||
|
||||
if (ch != '@' && ch != ':' && ch != '#') {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new SQLParseException("illegal variable");
|
||||
}
|
||||
|
||||
@@ -581,11 +585,17 @@ public class Lexer {
|
||||
sp = 1;
|
||||
char ch;
|
||||
|
||||
boolean mybatisFlag = false;
|
||||
if (buf[bp + 1] == '@') {
|
||||
ch = buf[++bp];
|
||||
hash = 31 * hash + ch;
|
||||
|
||||
sp++;
|
||||
} else if (buf[bp + 1] == '{') {
|
||||
hash = 31 * hash + '"';
|
||||
bp++;
|
||||
sp++;
|
||||
mybatisFlag = true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -600,6 +610,15 @@ public class Lexer {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mybatisFlag) {
|
||||
if (ch != '}') {
|
||||
throw new SQLParseException("syntax error");
|
||||
}
|
||||
hash = 31 * hash + '"';
|
||||
++bp;
|
||||
sp++;
|
||||
}
|
||||
|
||||
this.ch = buf[bp];
|
||||
|
||||
|
||||
@@ -675,16 +675,18 @@ public class SQLExprParser extends SQLParser {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected SQLAggregateExpr parseAggregateExpr(String method_name) throws ParserException {
|
||||
protected SQLAggregateExpr parseAggregateExpr(String methodName) throws ParserException {
|
||||
methodName = methodName.toUpperCase();
|
||||
|
||||
SQLAggregateExpr aggregateExpr;
|
||||
if (lexer.token() == Token.ALL) {
|
||||
aggregateExpr = new SQLAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateExpr.Option.ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DISTINCT) {
|
||||
aggregateExpr = new SQLAggregateExpr(method_name, 0);
|
||||
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateExpr.Option.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
aggregateExpr = new SQLAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new SQLAggregateExpr(methodName);
|
||||
}
|
||||
|
||||
exprList(aggregateExpr.getArguments());
|
||||
|
||||
@@ -426,6 +426,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLAggregateExpr x) {
|
||||
print(x.getMethodName());
|
||||
print("(");
|
||||
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
printAndAccept(x.getArguments(), ", ");
|
||||
print(")");
|
||||
return false;
|
||||
|
||||
@@ -17,10 +17,10 @@ package com.alibaba.druid.stat;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
public class JdbcStatManagerFactoryBean implements FactoryBean {
|
||||
public class JdbcStatManagerFactoryBean implements FactoryBean<JdbcStatManager> {
|
||||
|
||||
@Override
|
||||
public Object getObject() throws Exception {
|
||||
public JdbcStatManager getObject() throws Exception {
|
||||
return JdbcStatManager.getInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import javax.management.MBeanServer;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
public class MBeanServerFactoryBean implements FactoryBean {
|
||||
public class MBeanServerFactoryBean implements FactoryBean<MBeanServer> {
|
||||
|
||||
public MBeanServer getObject() throws Exception {
|
||||
return ManagementFactory.getPlatformMBeanServer();
|
||||
|
||||
Reference in New Issue
Block a user