cn.sylinx.hbatis.plugin.model.ModelFabric Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbatis-core Show documentation
Show all versions of hbatis-core Show documentation
hbatis is a simple orm framework
package cn.sylinx.hbatis.plugin.model;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import cn.sylinx.hbatis.db.mapper.anno.AttributeColumnMapping;
import cn.sylinx.hbatis.db.mapper.anno.ColumnDesc;
import cn.sylinx.hbatis.db.mapper.anno.PrimaryKey;
import cn.sylinx.hbatis.db.mapper.anno.Table;
import cn.sylinx.hbatis.kit.StrKit;
/**
* model结构
*
* @author han
*
*/
public class ModelFabric {
private Table table;
private PrimaryKey primaryKey;
private AttributeColumnMapping mapping;
private Map fieldMap;
private List fields;
private Map fieldDesc;
private Class> clz;
private Map attrMapping;
public Map getAttrMapping() {
return attrMapping;
}
public Map getJdbcMapping() {
Map jdbcMapping = new HashMap();
if (attrMapping == null) {
return jdbcMapping;
}
Set> entrys = attrMapping.entrySet();
for (Entry entry : entrys) {
jdbcMapping.put(entry.getValue(), entry.getKey());
}
return jdbcMapping;
}
public void setAttrMapping(Map attrMapping) {
this.attrMapping = attrMapping;
}
public List getFields() {
return fields;
}
public void setFields(List fields) {
this.fields = fields;
}
public Table getTable() {
return table;
}
public String getTableName() {
if (table == null) {
if (clz == null) {
return null;
}
// 默认使用模型作为表名(驼峰转下划线)
return StrKit.enCodeUnderlined(clz.getSimpleName());
}
return table.value();
}
public void setTable(Table table) {
this.table = table;
}
public PrimaryKey getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(PrimaryKey primaryKey) {
this.primaryKey = primaryKey;
}
public AttributeColumnMapping getMapping() {
return mapping;
}
public void setMapping(AttributeColumnMapping mapping) {
this.mapping = mapping;
}
public Map getFieldMap() {
return fieldMap;
}
public void setFieldMap(Map fieldMap) {
this.fieldMap = fieldMap;
}
public Class> getClz() {
return clz;
}
public void setClz(Class> clz) {
this.clz = clz;
}
public void clear() {
table = null;
primaryKey = null;
mapping = null;
if (fieldMap != null) {
fieldMap.clear();
fieldMap = null;
}
if (fields != null) {
fields.clear();
fields = null;
}
if (attrMapping != null) {
attrMapping.clear();
attrMapping = null;
}
clz = null;
}
public Map getFieldDesc() {
return fieldDesc;
}
public void setFieldDesc(Map fieldDesc) {
this.fieldDesc = fieldDesc;
}
public boolean isMappingEmpty() {
if (attrMapping == null || attrMapping.isEmpty()) {
return true;
}
return false;
}
}