mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
enhance mapping
This commit is contained in:
@@ -32,11 +32,11 @@ public class MappingEngine {
|
||||
public MappingEngine(){
|
||||
this(new MySqlMappingProvider());
|
||||
}
|
||||
|
||||
|
||||
public MappingEngine(MappingProvider provider){
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
|
||||
public Entity getFirstEntity() {
|
||||
for (Map.Entry<String, Entity> entry : entities.entrySet()) {
|
||||
return entry.getValue();
|
||||
@@ -76,11 +76,11 @@ public class MappingEngine {
|
||||
public MappingVisitor createMappingVisitor() {
|
||||
return provider.createMappingVisitor(this);
|
||||
}
|
||||
|
||||
|
||||
public MappingVisitor createMappingVisitor(List<Object> parameters) {
|
||||
return createMappingVisitor(new MappingContext(parameters));
|
||||
}
|
||||
|
||||
|
||||
public MappingVisitor createMappingVisitor(MappingContext context) {
|
||||
return provider.createMappingVisitor(this, context);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class MappingEngine {
|
||||
public SQLSelectQueryBlock explainToSelectSQLObject(String sql) {
|
||||
return provider.explainToSelectSQLObject(this, sql);
|
||||
}
|
||||
|
||||
|
||||
public String explainToSelectSQL(String sql) {
|
||||
return explainToSelectSQL(sql, Collections.emptyList());
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class MappingEngine {
|
||||
public String explainToSelectSQL(String sql, List<Object> parameters) {
|
||||
return explainToSelectSQL(sql, new MappingContext(parameters));
|
||||
}
|
||||
|
||||
|
||||
public String explainToSelectSQL(String sql, MappingContext context) {
|
||||
SQLSelectQueryBlock query = explainToSelectSQLObject(sql);
|
||||
|
||||
@@ -111,9 +111,9 @@ public class MappingEngine {
|
||||
|
||||
return toSQL(query);
|
||||
}
|
||||
|
||||
|
||||
public void afterResole(MappingVisitor visitor) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public SQLDeleteStatement explainToDeleteSQLObject(String sql) {
|
||||
@@ -122,7 +122,7 @@ public class MappingEngine {
|
||||
|
||||
public String explainToDeleteSQL(String sql) {
|
||||
SQLDeleteStatement stmt = explainToDeleteSQLObject(sql);
|
||||
|
||||
|
||||
MappingVisitor visitor = this.createMappingVisitor(Collections.emptyList());
|
||||
stmt.accept(visitor);
|
||||
visitor.afterResolve();
|
||||
@@ -130,12 +130,12 @@ public class MappingEngine {
|
||||
|
||||
return toSQL(stmt);
|
||||
}
|
||||
|
||||
public String resolveTableName(Entity entity, List<Object> parameters) {
|
||||
|
||||
public String resolveTableName(Entity entity, MappingContext context) {
|
||||
return entity.getTableName();
|
||||
}
|
||||
|
||||
public String resovleColumnName(Entity entity, Property property, List<Object> parameters) {
|
||||
|
||||
public String resovleColumnName(Entity entity, Property property, MappingContext context) {
|
||||
return property.getDbColumnName();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ public class MSSQLServerMappingVisitor extends SQLServerASTVisitorAdapter implem
|
||||
|
||||
@Override
|
||||
public String resolveTableName(Entity entity) {
|
||||
return engine.resolveTableName(entity, context.getParameters());
|
||||
return engine.resolveTableName(entity, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resovleColumnName(Entity entity, Property property) {
|
||||
return engine.resovleColumnName(entity, property, context.getParameters());
|
||||
return engine.resovleColumnName(entity, property, context);
|
||||
}
|
||||
|
||||
public Entity getEntity(String name) {
|
||||
|
||||
@@ -208,7 +208,10 @@ public class MappingVisitorUtils {
|
||||
Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
|
||||
Object value = x.getRight().getAttribute(MAPPING_VALUE);
|
||||
|
||||
visitor.getPropertyValues().add(new PropertyValue(entity, property, value));
|
||||
PropertyValue propertyValue = new PropertyValue(entity, property, value);
|
||||
propertyValue.putAttribute("mapping.expr", x.getRight());
|
||||
|
||||
visitor.getPropertyValues().add(propertyValue);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +224,10 @@ public class MappingVisitorUtils {
|
||||
Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
|
||||
Object value = x.getRight().getAttribute(MAPPING_VALUE);
|
||||
|
||||
visitor.getPropertyValues().add(new PropertyValue(entity, property, value));
|
||||
PropertyValue propertyValue = new PropertyValue(entity, property, value);
|
||||
propertyValue.putAttribute("mapping.expr", x.getRight());
|
||||
|
||||
visitor.getPropertyValues().add(propertyValue);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public class MySqlMappingVisitor extends MySqlASTVisitorAdapter implements Mappi
|
||||
|
||||
@Override
|
||||
public String resolveTableName(Entity entity) {
|
||||
return engine.resolveTableName(entity, context.getParameters());
|
||||
return engine.resolveTableName(entity, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resovleColumnName(Entity entity, Property property) {
|
||||
return engine.resovleColumnName(entity, property, context.getParameters());
|
||||
return engine.resovleColumnName(entity, property, context);
|
||||
}
|
||||
|
||||
public Entity getEntity(String name) {
|
||||
|
||||
@@ -71,12 +71,12 @@ public class OracleMappingVisitor extends OracleASTVisitorAdapter implements Map
|
||||
|
||||
@Override
|
||||
public String resolveTableName(Entity entity) {
|
||||
return engine.resolveTableName(entity, context.getParameters());
|
||||
return engine.resolveTableName(entity, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resovleColumnName(Entity entity, Property property) {
|
||||
return engine.resovleColumnName(entity, property, context.getParameters());
|
||||
return engine.resovleColumnName(entity, property, context);
|
||||
}
|
||||
|
||||
public Entity getEntity(String name) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.alibaba.druid.mapping.spi;
|
||||
|
||||
import com.alibaba.druid.mapping.Entity;
|
||||
import com.alibaba.druid.mapping.MappingObject;
|
||||
import com.alibaba.druid.mapping.Property;
|
||||
|
||||
public class PropertyValue {
|
||||
public class PropertyValue extends MappingObject {
|
||||
|
||||
private Property property;
|
||||
private Entity entity;
|
||||
|
||||
Reference in New Issue
Block a user