use of indi.mybatis.flying.annotations.FieldMapperAnnotation in project mybatis.flying by limeng32.
the class SqlBuilder method buildConditionMapper.
private static void buildConditionMapper(ConditionMapper conditionMapper, ConditionMapperAnnotation conditionMapperAnnotation, Class<?> pojoClass, Field field) {
conditionMapper.setFieldName(field.getName());
conditionMapper.setDbFieldName(conditionMapperAnnotation.dbFieldName());
conditionMapper.setConditionType(conditionMapperAnnotation.conditionType());
conditionMapper.setSubTarget(conditionMapperAnnotation.subTarget());
conditionMapper.setTypeHandlerPath(conditionMapperAnnotation.customTypeHandler());
for (Field pojoField : pojoClass.getDeclaredFields()) {
for (Annotation oan : pojoField.getDeclaredAnnotations()) {
boolean b1 = oan instanceof FieldMapperAnnotation && ((FieldMapperAnnotation) oan).dbFieldName().equalsIgnoreCase(conditionMapperAnnotation.dbFieldName());
boolean b2 = oan instanceof Column && (FieldMapper.getColumnName((Column) oan, pojoField)).equalsIgnoreCase(conditionMapperAnnotation.dbFieldName());
boolean b3 = (conditionMapper.getSubTarget() != null) && (!Void.class.equals(conditionMapper.getSubTarget()));
if (b1 || b2 || b3) {
FieldMapper fieldMapper = new FieldMapper();
if (b3) {
if (!tableMapperCache.containsKey(conditionMapper.getSubTarget())) {
buildTableMapper(conditionMapper.getSubTarget());
}
TableMapper tableMapper = tableMapperCache.get(conditionMapper.getSubTarget());
Map<String, FieldMapper> fieldMapperCache = tableMapper.getFieldMapperCache();
for (Map.Entry<String, FieldMapper> e : fieldMapperCache.entrySet()) {
if (conditionMapper.getDbFieldName().equalsIgnoreCase(e.getValue().getDbFieldName())) {
fieldMapper = e.getValue();
break;
}
}
} else {
fieldMapper = new FieldMapper();
fieldMapper.buildMapper(pojoField);
}
conditionMapper.setFieldType(fieldMapper.getFieldType());
conditionMapper.setJdbcType(fieldMapper.getJdbcType());
conditionMapper.setCryptKeyColumn(fieldMapper.getCryptKeyColumn());
conditionMapper.setCryptKeyAddition(fieldMapper.getCryptKeyAddition());
conditionMapper.setDbFieldNameForJoin(fieldMapper.getDbFieldNameForJoin());
if (!"".equals(fieldMapper.getDbAssociationUniqueKey())) {
conditionMapper.setDbAssociationUniqueKey(fieldMapper.getDbAssociationUniqueKey());
conditionMapper.setForeignKey(true);
}
if (conditionMapper.isForeignKey() && (!ConditionType.NULL_OR_NOT.equals(conditionMapper.getConditionType())) && !fieldMapper.isDelegate()) {
if (!tableMapperCache.containsKey(pojoField.getType())) {
buildTableMapper(pojoField.getType());
}
TableMapper tm = tableMapperCache.get(pojoField.getType());
String foreignFieldName = getFieldMapperByDbFieldName(tm.getFieldMapperCache(), fieldMapper.getDbAssociationUniqueKey()).getFieldName();
conditionMapper.setForeignFieldName(foreignFieldName);
}
}
}
}
}
use of indi.mybatis.flying.annotations.FieldMapperAnnotation in project mybatis.flying by limeng32.
the class FieldMapper method buildMapper.
public boolean buildMapper(Field field) {
Annotation[] fieldAnnotations = field.getDeclaredAnnotations();
if (fieldAnnotations.length == 0) {
return false;
}
boolean b = false;
for (Annotation an1 : fieldAnnotations) {
if (an1 instanceof Id) {
setId((Id) an1);
}
if ((an1 instanceof FieldMapperAnnotation) || (an1 instanceof Column)) {
b = true;
setField(field);
if (an1 instanceof FieldMapperAnnotation) {
setFieldMapperAnnotation((FieldMapperAnnotation) an1);
} else if (an1 instanceof Column) {
setColumn((Column) an1);
}
}
}
if (b) {
buildMapper();
}
return b;
}
Aggregations