本文整理汇总了Java中com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr类的典型用法代码示例。如果您正苦于以下问题:Java SQLIdentifierExpr类的具体用法?Java SQLIdentifierExpr怎么用?Java SQLIdentifierExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLIdentifierExpr类属于com.alibaba.druid.sql.ast.expr包,在下文中一共展示了SQLIdentifierExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: statementParse
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {
MySqlCreateTableStatement createStmt = (MySqlCreateTableStatement)stmt;
if(createStmt.getQuery() != null) {
String msg = "create table from other table not supported :" + stmt;
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
}
String tableName = StringUtil.removeBackquote(createStmt.getTableSource().toString().toUpperCase());
if(schema.getTables().containsKey(tableName)) {
TableConfig tableConfig = schema.getTables().get(tableName);
AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
if(algorithm instanceof SlotFunction){
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("int"));
column.setName(new SQLIdentifierExpr("_slot"));
column.setComment(new SQLCharExpr("自动迁移算法slot,禁止修改"));
((SQLCreateTableStatement)stmt).getTableElementList().add(column);
String sql = createStmt.toString();
rrs.setStatement(sql);
ctx.setSql(sql);
}
}
ctx.addTable(tableName);
}
示例2: changeCreateTable
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private static String changeCreateTable(SchemaConfig schema,String tableName,String sql) {
if (schema.getTables().containsKey(tableName)) {
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement insertStatement = parser.parseStatement();
if (insertStatement instanceof MySqlCreateTableStatement) {
TableConfig tableConfig = schema.getTables().get(tableName);
AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
if (algorithm instanceof SlotFunction) {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("int"));
column.setName(new SQLIdentifierExpr("_slot"));
column.setComment(new SQLCharExpr("自动迁移算法slot,禁止修改"));
((SQLCreateTableStatement) insertStatement).getTableElementList().add(column);
return insertStatement.toString();
}
}
}
return sql;
}
示例3: isUNI
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
/**
* only for show columns
*/
public boolean isUNI(String columnName) {
for (SQLTableElement element : this.tableElementList) {
if (element instanceof MySqlUnique) {
MySqlUnique unique = (MySqlUnique) element;
if (unique.getColumns().size() == 0) {
continue;
}
SQLExpr column = unique.getColumns().get(0).getExpr();
if (column instanceof SQLIdentifierExpr
&& SQLUtils.nameEquals(columnName, ((SQLIdentifierExpr) column).getName())) {
return unique.columns.size() == 1;
} else if (column instanceof SQLMethodInvokeExpr
&& SQLUtils.nameEquals(((SQLMethodInvokeExpr) column).getMethodName(), columnName)) {
return true;
}
}
}
return false;
}
示例4: setSchema
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
public void setSchema(String schema) {
if (expr instanceof SQLIdentifierExpr) {
if (schema == null) {
return;
}
String ident = ((SQLIdentifierExpr) expr).getName();
this.setExpr(new SQLPropertyExpr(schema, ident));
} else if (expr instanceof SQLPropertyExpr) {
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
if (schema == null) {
setExpr(new SQLIdentifierExpr(propertyExpr.getName()));
} else {
propertyExpr.setOwner(schema);
}
}
}
示例5: visit
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
@Override
public boolean visit(SQLCreateUserStatement x) {
print0(ucase ? "CREATE USER " : "create user ");
x.getUser().accept(this);
print0(ucase ? " WITH PASSWORD = " : " with password = ");
SQLExpr passoword = x.getPassword();
if (passoword instanceof SQLIdentifierExpr) {
print('\'');
passoword.accept(this);
print('\'');
} else {
passoword.accept(this);
}
return false;
}
示例6: genIndexName
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
public static String genIndexName(SQLName srcIndexName, List<SQLExpr> columnExprs, Set<String> indexNames) {
String indexName;
if (srcIndexName != null) {
indexName = StringUtil.removeBackQuote(srcIndexName.getSimpleName());
} else {
SQLExpr firstColumn = columnExprs.get(0);
String columnName = firstColumn.toString();
if (firstColumn instanceof SQLIdentifierExpr) {
columnName = StringUtil.removeBackQuote(((SQLIdentifierExpr) firstColumn).getName());
} else if (firstColumn instanceof SQLMethodInvokeExpr) {
columnName = StringUtil.removeBackQuote(((SQLMethodInvokeExpr) firstColumn).getMethodName());
}
indexName = columnName;
int indexNum = 1;
while (indexNames.contains(indexName)) {
indexNum++;
indexName = columnName + "_" + indexNum;
}
}
indexNames.add(indexName);
return indexName;
}
示例7: getChangeIndex
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private int getChangeIndex(boolean isFirst, SQLExpr afterColumn, List<StructureMeta.ColumnMeta> columnMetas) {
int changeIndex = -1;
if (isFirst) {
changeIndex = 0;
} else if (afterColumn != null) {
String afterColName = StringUtil.removeBackQuote(((SQLIdentifierExpr) afterColumn).getName());
for (int i = 0; i < columnMetas.size(); i++) {
String colName = columnMetas.get(i).getName();
if (afterColName.equalsIgnoreCase(colName)) {
changeIndex = i + 1;
break;
}
}
} else {
changeIndex = columnMetas.size();
}
return changeIndex;
}
示例8: visit
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
/**
* 将表名替换成占位符.
*
* <p>
* 1. 如果二元表达式使用别名, 如: {@code FROM order o WHERE o.column_name = 't' },
* 则Column中的tableName为o.
* </p>
*
* <p>
* 2. 如果二元表达式使用表名, 如: {@code FROM order WHERE order.column_name = 't' },
* 则Column中的tableName为order.
* </p>
*
* @param x
* SQL属性表达式
* @return true表示继续遍历AST, false表示终止遍历AST
*/
@Override
// TODO SELECT [别名.xxx]的情况,目前都是替换成token,解析之后应该替换回去
public final boolean visit(final SQLPropertyExpr x) {
if (!(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem)) {
return super.visit(x);
}
if (!(x.getOwner() instanceof SQLIdentifierExpr)) {
return super.visit(x);
}
String tableOrAliasName = ((SQLIdentifierExpr) x.getOwner()).getLowerName();
if (isBinaryOperateWithAlias(x, tableOrAliasName)) {
return super.visit(x);
}
printToken(tableOrAliasName);
print(".");
print(x.getName());
return false;
}
示例9: visit
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
/**
* 将表名替换成占位符.
*
* <p>
* 1. 如果二元表达式使用别名, 如: {@code FROM order o WHERE o.column_name = 't' },
* 则Column中的tableName为o.
* </p>
*
* <p>
* 2. 如果二元表达式使用表名, 如: {@code FROM order WHERE order.column_name = 't' },
* 则Column中的tableName为order.
* </p>
*
* @param x
* SQL属性表达式
* @return true表示继续遍历AST, false表示终止遍历AST
*/
@Override
public final boolean visit(final SQLPropertyExpr x) {
if (!(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem)) {
return super.visit(x);
}
if (!(x.getOwner() instanceof SQLIdentifierExpr)) {
return super.visit(x);
}
String tableOrAliasName = ((SQLIdentifierExpr) x.getOwner()).getLowerName();
if (isBinaryOperateWithAlias(x, tableOrAliasName)) {
return super.visit(x);
}
printToken(tableOrAliasName);
print(".");
print(x.getName());
return false;
}
示例10: parseOneIdx
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private Map parseOneIdx(String idx)
{
Map map = new HashMap();
OracleStatementParser parser = new OracleStatementParser(idx);
OracleCreateIndexStatement statement = parser.parseCreateIndex(true);
SQLExprTableSource tableSource = (SQLExprTableSource) statement.getTable();
String tableName = ((SQLPropertyExpr) tableSource.getExpr()).getSimleName().toLowerCase();
String idxType = statement.getType();
List<SQLSelectOrderByItem> items = statement.getItems();
List fields = new ArrayList();
for (SQLSelectOrderByItem item : items)
{
SQLIdentifierExpr expr = (SQLIdentifierExpr) item.getExpr();
fields.add(expr.getSimleName().toLowerCase());
}
if ("unique".equalsIgnoreCase(idxType))
map.put(tableName, fields);
return map;
}
示例11: reverseAppendTo
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private void reverseAppendTo(SQLSelectOrderByItem order, SQLServerOutputVisitor visitor, String tmpTableAlias, List<SQLSelectItem> items) {
SQLExpr expression=order.getExpr();
if(expression instanceof SQLPropertyExpr){
SQLPropertyExpr c=(SQLPropertyExpr)expression;
if(items!=null){
fixWithSelects(c,items);
}
if(c.getOwner()!=null){
c.setOwner(new SQLIdentifierExpr(tmpTableAlias));
}
}
expression.accept(visitor);
if(order.getType()==SQLOrderingSpecification.ASC || order.getType()==null){
try {
visitor.getAppender().append(" DESC");
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例12: parseValue
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private Object parseValue(SQLExpr expr) throws SqlParseException {
if (expr instanceof SQLNumericLiteralExpr) {
Number number = ((SQLNumericLiteralExpr) expr).getNumber();
if(number instanceof BigDecimal){
return number.doubleValue();
}
if(number instanceof BigInteger){
return number.longValue();
}
return ((SQLNumericLiteralExpr) expr).getNumber();
} else if (expr instanceof SQLCharExpr) {
return ((SQLCharExpr) expr).getText();
} else if (expr instanceof SQLMethodInvokeExpr) {
return expr;
} else if (expr instanceof SQLNullExpr) {
return null;
} else if (expr instanceof SQLIdentifierExpr) {
return expr;
} else if (expr instanceof SQLPropertyExpr) {
return expr;
} else {
throw new SqlParseException(
String.format("Failed to parse SqlExpression of type %s. expression value: %s", expr.getClass(), expr)
);
}
}
示例13: getSqlName
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private String getSqlName(SQLExpr sqlName) {
if (sqlName == null) {
return null;
}
if (sqlName instanceof SQLPropertyExpr) {
SQLIdentifierExpr owner = (SQLIdentifierExpr) ((SQLPropertyExpr) sqlName).getOwner();
return DruidDdlParser.unescapeName(owner.getName()) + "."
+ DruidDdlParser.unescapeName(((SQLPropertyExpr) sqlName).getName());
} else if (sqlName instanceof SQLIdentifierExpr) {
return DruidDdlParser.unescapeName(((SQLIdentifierExpr) sqlName).getName());
} else if (sqlName instanceof SQLCharExpr) {
return ((SQLCharExpr) sqlName).getText();
} else {
return sqlName.toString();
}
}
示例14: processName
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
private static void processName(DdlResult ddlResult, String schema, SQLExpr sqlName, boolean isOri) {
if (sqlName == null) {
return;
}
String table = null;
if (sqlName instanceof SQLPropertyExpr) {
SQLIdentifierExpr owner = (SQLIdentifierExpr) ((SQLPropertyExpr) sqlName).getOwner();
schema = unescapeName(owner.getName());
table = unescapeName(((SQLPropertyExpr) sqlName).getName());
} else if (sqlName instanceof SQLIdentifierExpr) {
table = unescapeName(((SQLIdentifierExpr) sqlName).getName());
}
if (isOri) {
ddlResult.setOriSchemaName(schema);
ddlResult.setOriTableName(table);
} else {
ddlResult.setSchemaName(schema);
ddlResult.setTableName(table);
}
}
示例15: addColumnIfCreate
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; //导入依赖的package包/类
static String addColumnIfCreate(String sql, SQLStatement statement) {
if (isCreate(statement) && sql.trim().toUpperCase().startsWith("CREATE TABLE ") && !hasGlobalColumn(statement)) {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("bigint"));
column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_MYCAT_COLUMN));
column.setComment(new SQLCharExpr("全局表保存修改时间戳的字段名"));
((SQLCreateTableStatement)statement).getTableElementList().add(column);
}
return statement.toString();
}