format code

This commit is contained in:
温少
2012-05-09 09:32:05 +08:00
@@ -26,8 +26,10 @@ import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
public class MappingVisitorUtils {
private static final String MAPPING_PROPERTY = "mapping.property";
private static final String MAPPING_ENTITY = "mapping.entity";
private static final String MAPPING_VAR_INDEX = "mapping.varIndex";
private static final String MAPPING_VALUE = "mapping.value";
private static final String MAPPING_PROPERTY = "mapping.property";
private static final String MAPPING_ENTITY = "mapping.entity";
public static boolean visit(MappingVisitor visitor, SQLExprTableSource x) {
SQLExpr expr = x.getExpr();
@@ -43,7 +45,7 @@ public class MappingVisitorUtils {
}
if (entity == null) {
throw new DruidMappingException("entity not foudn : " + entityName);
throw new DruidMappingException("entity not found : " + entityName);
}
if (x.getParent() instanceof SQLSelectQueryBlock) {
@@ -77,7 +79,7 @@ public class MappingVisitorUtils {
public static boolean fillSelectList(MappingVisitor visitor, SQLSelectQueryBlock x) {
Entity entity = (Entity) x.getAttribute(MAPPING_ENTITY);
if (entity == null && x.getFrom() != null) {
entity = (Entity) x.getFrom().getAttribute(MAPPING_ENTITY);
}
@@ -87,24 +89,24 @@ public class MappingVisitorUtils {
}
x.getSelectList().clear();
for (Property property : entity.getProperties().values()) {
String columnName = visitor.resovleColumnName(entity, property);
String alias = null;
if (visitor.getContext().isGenerateAlias()) {
alias = '"' + property.getName() + '"';
}
SQLExpr expr = new SQLIdentifierExpr(columnName);
expr.putAttribute(MAPPING_ENTITY, entity);
expr.putAttribute(MAPPING_PROPERTY, property);
SQLSelectItem selelctItem = new SQLSelectItem(expr, alias);
x.getSelectList().add(selelctItem);
}
return true;
}
@@ -146,9 +148,10 @@ public class MappingVisitorUtils {
if (visitor.getContext().isExplainAllColumnToList()) {
visitor.getUnresolveList().add(x);
}
return true;
}
public static boolean visit(MappingVisitor visitor, SQLIdentifierExpr x) {
String propertyName = x.getName();
@@ -195,7 +198,7 @@ public class MappingVisitorUtils {
public static boolean visit(MappingVisitor visitor, SQLBinaryOpExpr x) {
x.getLeft().setParent(x);
x.getRight().setParent(x);
if (x.getOperator() == SQLBinaryOperator.Equality) {
if (x.getLeft() instanceof SQLIdentifierExpr && isSimpleValue(visitor, x.getRight())) {
visit(visitor, (SQLIdentifierExpr) x.getLeft());
@@ -203,7 +206,7 @@ public class MappingVisitorUtils {
Entity entity = (Entity) x.getLeft().getAttribute(MAPPING_ENTITY);
Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
Object value = x.getRight().getAttribute("mapping.value");
Object value = x.getRight().getAttribute(MAPPING_VALUE);
visitor.getPropertyValues().add(new PropertyValue(entity, property, value));
@@ -216,7 +219,7 @@ public class MappingVisitorUtils {
Entity entity = (Entity) x.getLeft().getAttribute(MAPPING_ENTITY);
Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
Object value = x.getRight().getAttribute("mapping.value");
Object value = x.getRight().getAttribute(MAPPING_VALUE);
visitor.getPropertyValues().add(new PropertyValue(entity, property, value));
@@ -229,26 +232,26 @@ public class MappingVisitorUtils {
private static boolean isSimpleValue(MappingVisitor visitor, SQLExpr expr) {
if (expr instanceof SQLNumericLiteralExpr) {
expr.putAttribute("mapping.value", ((SQLNumericLiteralExpr) expr).getNumber());
expr.putAttribute(MAPPING_VALUE, ((SQLNumericLiteralExpr) expr).getNumber());
return true;
}
if (expr instanceof SQLCharExpr) {
expr.putAttribute("mapping.value", ((SQLCharExpr) expr).getText());
expr.putAttribute(MAPPING_VALUE, ((SQLCharExpr) expr).getText());
return true;
}
if (expr instanceof SQLVariantRefExpr) {
Map<String, Object> attributes = expr.getAttributes();
Integer varIndex = (Integer) attributes.get("mapping.varIndex");
Integer varIndex = (Integer) attributes.get(MAPPING_VAR_INDEX);
if (varIndex == null) {
varIndex = visitor.getAndIncrementVariantIndex();
expr.putAttribute("mapping.varIndex", varIndex);
expr.putAttribute(MAPPING_VAR_INDEX, varIndex);
}
if (visitor.getParameters().size() > varIndex) {
Object parameter = visitor.getParameters().get(varIndex);
expr.putAttribute("mapping.value", parameter);
expr.putAttribute(MAPPING_VALUE, parameter);
}
return true;
@@ -277,17 +280,17 @@ public class MappingVisitorUtils {
}
public static boolean resolve(MappingVisitor visitor, SQLAllColumnExpr x) {
if (! (x.getParent() instanceof SQLSelectItem)) {
if (!(x.getParent() instanceof SQLSelectItem)) {
return true;
}
SQLSelectItem selectItem = (SQLSelectItem) x.getParent();
if (! (selectItem.getParent() instanceof SQLSelectQueryBlock)) {
if (!(selectItem.getParent() instanceof SQLSelectQueryBlock)) {
return true;
}
SQLSelectQueryBlock select = (SQLSelectQueryBlock) selectItem.getParent();
if (select.getSelectList().size() == 1) {
if (select.getSelectList().get(0).getExpr() instanceof SQLAllColumnExpr) {
boolean result = fillSelectList(visitor, select);
@@ -296,9 +299,10 @@ public class MappingVisitorUtils {
}
}
}
return false;
}
public static boolean resolve(MappingVisitor visitor, SQLIdentifierExpr x) {
String propertyName = x.getName();
@@ -359,10 +363,10 @@ public class MappingVisitorUtils {
public static boolean visit(MappingVisitor visitor, SQLVariantRefExpr x) {
Map<String, Object> attributes = x.getAttributes();
Integer varIndex = (Integer) attributes.get("mapping.varIndex");
Integer varIndex = (Integer) attributes.get(MAPPING_VAR_INDEX);
if (varIndex == null) {
varIndex = visitor.getAndIncrementVariantIndex();
x.putAttribute("mapping.varIndex", varIndex);
x.putAttribute(MAPPING_VAR_INDEX, varIndex);
}
return false;
}
@@ -372,7 +376,7 @@ public class MappingVisitorUtils {
SQLAllColumnExpr expr = new SQLAllColumnExpr();
SQLSelectItem selectItem = new SQLSelectItem(expr);
x.getSelectList().add(selectItem);
expr.setParent(selectItem);
}