return (Entity<T>) re;
}
@SuppressWarnings({"rawtypes", "unchecked"})
public <T extends Map<String, ?>> Entity<T> makeEntity(String tableName, T map) {
final NutEntity<T> en = new NutEntity(map.getClass());
en.setTableName(tableName);
en.setViewName(tableName);
for (Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
// 是实体补充描述吗?
if (key.startsWith("#")) {
en.getMetas().put(key.substring(1), entry.getValue().toString());
continue;
}
// 以 "." 开头的字段,不是实体字段
else if (key.startsWith(".")) {
continue;
}
// 是实体字段
Object value = entry.getValue();
Mirror<?> mirror = Mirror.me(value);
NutMappingField ef = new NutMappingField(en);
if (key.startsWith("+")) {
ef.setAsAutoIncreasement();
key = key.substring(1);
}
if (key.startsWith("!")) {
ef.setAsNotNull();
key = key.substring(1);
}
if (key.startsWith("*")) {
key = key.substring(1);
if (mirror != null && mirror.isIntLike())
ef.setAsId();
else
ef.setAsName();
}
ef.setName(key);
ef.setType(null == value ? Object.class : value.getClass());
ef.setColumnName(key);
// 猜测一下数据库类型
Jdbcs.guessEntityFieldColumnType(ef);
ef.setAdaptor(support.expert.getAdaptor(ef));
if(mirror != null)
ef.setType(mirror.getType());
ef.setInjecting(new InjectToMap(key));
ef.setEjecting(new EjectFromMap(key));
en.addMappingField(ef);
}
en.checkCompositeFields(null);
// 最后在数据库中验证一下实体各个字段
support.run(new ConnCallback() {
public void invoke(Connection conn) throws Exception {
support.expert.setupEntityField(conn, en);