add testcase & remove unused code

This commit is contained in:
wenshao
2013-06-17 23:34:35 +08:00
parent b199d3043f
commit 72c9665577
75 changed files with 2415 additions and 1077 deletions
@@ -57,18 +57,28 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
return this.arguments;
}
public void output(StringBuffer buf) {
buf.append(this.name);
if (this.arguments.size() > 0) {
buf.append("(");
int i = 0;
for (int size = this.arguments.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
((SQLExpr) this.arguments.get(i)).output(buf);
}
buf.append(")");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLDataTypeImpl other = (SQLDataTypeImpl) obj;
if (arguments == null) {
if (other.arguments != null) return false;
} else if (!arguments.equals(other.arguments)) return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
return true;
}
}
@@ -42,16 +42,24 @@ public class SQLOrderBy extends SQLObjectImpl {
visitor.endVisit(this);
}
public void output(StringBuffer buf) {
buf.append("ORDER ");
buf.append("BY ");
int i = 0;
for (int size = this.items.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
this.items.get(i).output(buf);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((items == null) ? 0 : items.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLOrderBy other = (SQLOrderBy) obj;
if (items == null) {
if (other.items != null) return false;
} else if (!items.equals(other.items)) return false;
return true;
}
}
@@ -24,9 +24,9 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
private static final long serialVersionUID = 1L;
private SQLExpr left;
private SQLExpr right;
private SQLBinaryOperator operator;
private SQLExpr left;
private SQLExpr right;
private SQLBinaryOperator operator;
public SQLBinaryOpExpr(){
@@ -76,14 +76,6 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
this.operator = operator;
}
public void output(StringBuffer buf) {
this.left.output(buf);
buf.append(" ");
buf.append(this.operator.name);
buf.append(" ");
this.right.output(buf);
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.left);
@@ -50,14 +50,6 @@ public class SQLCastExpr extends SQLExprImpl {
this.dataType = dataType;
}
public void output(StringBuffer buf) {
buf.append("CAST(");
this.expr.output(buf);
buf.append(" AS ");
this.dataType.output(buf);
buf.append(")");
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.expr);
@@ -1,56 +0,0 @@
/*
* Copyright 1999-2011 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.ast.expr;
public class SQLDateLiteralValue {
private int years;
private int months;
private int days;
public int getYears() {
return years;
}
public void setYears(int years) {
this.years = years;
}
public int getMonths() {
return months;
}
public void setMonths(int months) {
this.months = months;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public void output(StringBuffer buf) {
buf.append(years);
buf.append("-");
buf.append(months);
buf.append("-");
buf.append(days);
}
}
@@ -54,4 +54,25 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
public void output(StringBuffer buf) {
this.expr.output(buf);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLExprTableSource other = (SQLExprTableSource) obj;
if (expr == null) {
if (other.expr != null) return false;
} else if (!expr.equals(other.expr)) return false;
return true;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright 1999-2011 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.ast.statement;
public class SQLIndexDefinition {
}
@@ -29,15 +29,15 @@ public class SQLSelectItem extends SQLObjectImpl {
public SQLSelectItem(){
}
public SQLSelectItem(SQLExpr expr) {
public SQLSelectItem(SQLExpr expr){
this(expr, null);
}
public SQLSelectItem(SQLExpr expr, String alias){
this.expr = expr;
this.alias = alias;
if (expr != null) {
expr.setParent(this);
}
@@ -76,4 +76,29 @@ public class SQLSelectItem extends SQLObjectImpl {
}
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((alias == null) ? 0 : alias.hashCode());
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLSelectItem other = (SQLSelectItem) obj;
if (alias == null) {
if (other.alias != null) return false;
} else if (!alias.equals(other.alias)) return false;
if (expr == null) {
if (other.expr != null) return false;
} else if (!expr.equals(other.expr)) return false;
return true;
}
}
@@ -63,4 +63,31 @@ public class SQLSelectOrderByItem extends SQLObjectImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((collate == null) ? 0 : collate.hashCode());
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLSelectOrderByItem other = (SQLSelectOrderByItem) obj;
if (collate == null) {
if (other.collate != null) return false;
} else if (!collate.equals(other.collate)) return false;
if (expr == null) {
if (other.expr != null) return false;
} else if (!expr.equals(other.expr)) return false;
if (type != other.type) return false;
return true;
}
}
@@ -1,32 +0,0 @@
/*
* Copyright 1999-2011 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.ast.statement;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@SuppressWarnings("serial")
public class SQLTableConstaintImpl extends SQLConstaintImpl implements SQLTableConstaint {
public SQLTableConstaintImpl(){
}
@Override
protected void accept0(SQLASTVisitor visitor) {
}
}
@@ -46,13 +46,6 @@ public class MySqlExtractExpr extends SQLExprImpl implements MySqlExpr {
this.unit = unit;
}
@Override
public void output(StringBuffer buf) {
value.output(buf);
buf.append(' ');
buf.append(unit.name());
}
protected void accept0(SQLASTVisitor visitor) {
MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor;
mysqlVisitor.visit(this);
@@ -1,31 +0,0 @@
/*
* Copyright 1999-2011 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.mysql.ast.expr;
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
public class MySqlHexadecimalExpr extends MySqlExprImpl implements SQLLiteralExpr {
private static final long serialVersionUID = 1L;
@Override
public void accept0(MySqlASTVisitor visitor) {
}
}
@@ -248,19 +248,7 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
return;
}
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.limit);
acceptChild(visitor, this.procedureName);
acceptChild(visitor, this.procedureArgumentList);
acceptChild(visitor, this.into);
}
visitor.endVisit(this);
super.accept0(visitor);
}
@Override
@@ -46,15 +46,6 @@ public class OracleExtractExpr extends SQLExprImpl implements OracleExpr {
this.from = from;
}
public void output(StringBuffer buf) {
buf.append("EXTRACT(");
buf.append(this.unit.name());
buf.append(" FROM ");
this.from.output(buf);
buf.append(")");
}
@Override
protected void accept0(SQLASTVisitor visitor) {
this.accept0((OracleASTVisitor) visitor);
}
@@ -19,8 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
@@ -66,14 +64,7 @@ public class OracleSelectQueryBlock extends SQLSelectQueryBlock {
return;
}
if (visitor.visit(this)) {
acceptChild(visitor, this.selectList);
acceptChild(visitor, this.into);
acceptChild(visitor, this.from);
acceptChild(visitor, this.where);
acceptChild(visitor, this.groupBy);
}
visitor.endVisit(this);
super.accept0(visitor);
}
protected void accept0(OracleASTVisitor visitor) {
@@ -89,46 +80,4 @@ public class OracleSelectQueryBlock extends SQLSelectQueryBlock {
}
visitor.endVisit(this);
}
public void output(StringBuffer buf) {
buf.append("SELECT ");
if (SQLSetQuantifier.ALL == this.distionOption) {
buf.append("ALL ");
} else if (SQLSetQuantifier.DISTINCT == this.distionOption) {
buf.append("DISTINCT ");
} else if (SQLSetQuantifier.UNIQUE == this.distionOption) {
buf.append("UNIQUE ");
}
int i = 0;
for (int size = this.selectList.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
((SQLSelectItem) this.selectList.get(i)).output(buf);
}
buf.append(" FROM ");
if (this.from != null) {
buf.append("DUAL");
} else {
this.from.output(buf);
}
if (this.where != null) {
buf.append(" WHERE ");
this.where.output(buf);
}
if (this.hierachicalQueryClause != null) {
buf.append(" ");
this.hierachicalQueryClause.output(buf);
}
if (this.groupBy != null) {
buf.append(" ");
this.groupBy.output(buf);
}
}
}
@@ -366,6 +366,12 @@ public class OracleExprParser extends SQLExprParser {
sqlExpr = new OracleBinaryDoubleExpr(Double.parseDouble(lexer.numberString()));
lexer.nextToken();
break;
case LPAREN:
lexer.nextToken();
sqlExpr = expr();
accept(Token.RPAREN);
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Plus, sqlExpr);
break;
default:
throw new ParserException("TODO");
}
@@ -412,6 +418,12 @@ public class OracleExprParser extends SQLExprParser {
sqlExpr = expr();
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
break;
case LPAREN:
lexer.nextToken();
sqlExpr = expr();
accept(Token.RPAREN);
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
break;
default:
throw new ParserException("TODO " + lexer.token());
}
@@ -1,74 +0,0 @@
/*
* Copyright 1999-2011 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.parser;
public final class OracleTokenType {
public static final int LineComment = 0;
public static final int Identifier = 1;
public static final int Variable = 2;
public static final int Keyword = 3;
public static final int Operator = 4;
public static final int Punctuation = 5;
public static final int Char = 6;
public static final int NChar = 7;
public static final int Int = 8;
public static final int Float = 9;
public static final int Double = 10;
public static final int Decimal = 11;
public static final int EOF = 12;
public static final int Unknown = 13;
public static final int MultiLineComment = 14;
public static final int Long = 15;
public static final int HINT = 16;
public static final String typename(int tokType) {
switch (tokType) {
case 0:
return "Comment";
case 1:
return "Identifier";
case 2:
return "Variable";
case 3:
return "Keyword";
case 4:
return "Operator";
case 5:
return "Punctuation";
case 6:
return "Char";
case 7:
return "NChar";
case 8:
return "Int";
case 9:
return "Float";
case 10:
return "Double";
case 11:
return "Decimal";
case 12:
return "EOF";
case 16:
return "Hints";
case 13:
case 14:
case 15:
}
return "Unknown";
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 1999-2011 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.transact.ast;
public class TransactSQLSelect {
}
@@ -335,13 +335,20 @@ public class SQLExprParser extends SQLParser {
lexer.nextToken();
break;
case IDENTIFIER: // 当负号后面为字段的情况
sqlExpr = new SQLIdentifierExpr('-' + lexer.stringVal());
sqlExpr = new SQLIdentifierExpr(lexer.stringVal());
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
lexer.nextToken();
break;
case QUES:
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, new SQLVariantRefExpr("?"));
lexer.nextToken();
break;
case LPAREN:
lexer.nextToken();
sqlExpr = expr();
accept(Token.RPAREN);
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
break;
default:
throw new ParserException("TODO : " + lexer.token());
}
@@ -357,6 +364,12 @@ public class SQLExprParser extends SQLParser {
sqlExpr = new SQLNumberExpr(lexer.decimalValue());
lexer.nextToken();
break;
case LPAREN:
lexer.nextToken();
sqlExpr = expr();
accept(Token.RPAREN);
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Plus, sqlExpr);
break;
default:
throw new ParserException("TODO");
}
@@ -20,20 +20,7 @@ import com.alibaba.druid.DruidRuntimeException;
/**
* @author wenshao<szujobs@hotmail.com>
*/
@SuppressWarnings("serial")
@Deprecated
public class SQLParseException extends DruidRuntimeException {
private static final long serialVersionUID = 1L;
public SQLParseException(){
super();
}
public SQLParseException(String message){
super(message);
}
public SQLParseException(String message, Throwable cause){
super(message, cause);
}
}