mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved support hints.
This commit is contained in:
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SQLCharacterDataType extends SQLDataTypeImpl {
|
||||
|
||||
private String charSetName;
|
||||
@@ -26,6 +29,8 @@ public class SQLCharacterDataType extends SQLDataTypeImpl {
|
||||
private String charType;
|
||||
private boolean hasBinary;
|
||||
|
||||
public List<SQLCommentHint> hints;
|
||||
|
||||
public final static String CHAR_TYPE_BYTE = "BYTE";
|
||||
public final static String CHAR_TYPE_CHAR = "CHAR";
|
||||
|
||||
@@ -65,6 +70,14 @@ public class SQLCharacterDataType extends SQLDataTypeImpl {
|
||||
this.charType = charType;
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
|
||||
@@ -15,18 +15,33 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SQLConstraintImpl extends SQLObjectImpl implements SQLConstraint {
|
||||
|
||||
private SQLName name;
|
||||
private Boolean enable;
|
||||
|
||||
public List<SQLCommentHint> hints;
|
||||
|
||||
public SQLConstraintImpl(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SQLNotNullConstraint extends SQLConstraintImpl implements SQLColumnConstraint {
|
||||
|
||||
|
||||
|
||||
public SQLNotNullConstraint(){
|
||||
|
||||
}
|
||||
|
||||
@@ -405,6 +405,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(charType.getCollate());
|
||||
}
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = ((SQLCharacterDataType) x).hints;
|
||||
if (hints != null) {
|
||||
print(' ');
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -434,6 +442,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(x.getCollate());
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = ((SQLCharacterDataType) x).hints;
|
||||
if (hints != null) {
|
||||
print(' ');
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1758,7 +1758,14 @@ public class SQLExprParser extends SQLParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return parseCharTypeRest(charType);
|
||||
charType = (SQLCharacterDataType) parseCharTypeRest(charType);
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
List<SQLCommentHint> hints = this.parseHints();
|
||||
charType.setHints(hints);
|
||||
}
|
||||
|
||||
return charType;
|
||||
}
|
||||
|
||||
if ("character".equalsIgnoreCase(typeName) && "varying".equalsIgnoreCase(lexer.stringVal())) {
|
||||
@@ -1867,7 +1874,12 @@ public class SQLExprParser extends SQLParser {
|
||||
if (lexer.token() == Token.NOT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NULL);
|
||||
column.addConstraint(new SQLNotNullConstraint());
|
||||
SQLNotNullConstraint notNull = new SQLNotNullConstraint();
|
||||
if (lexer.token() == Token.HINT) {
|
||||
List<SQLCommentHint> hints = this.parseHints();
|
||||
notNull.setHints(hints);
|
||||
}
|
||||
column.addConstraint(notNull);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
|
||||
@@ -537,6 +537,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
public boolean visit(SQLCharacterDataType x) {
|
||||
visit((SQLDataType) x);
|
||||
|
||||
List<SQLCommentHint> hints = ((SQLCharacterDataType) x).hints;
|
||||
if (hints != null) {
|
||||
print(' ');
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1678,6 +1687,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
print(' ');
|
||||
}
|
||||
print0(ucase ? "NOT NULL" : "not null");
|
||||
|
||||
List<SQLCommentHint> hints = x.hints;
|
||||
|
||||
if (hints != null) {
|
||||
print(' ');
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user