use of org.nutz.dao.entity.annotation.Table in project nutz by nutzam.
the class ExtDaoInvocationHandler method dataDict.
/** 根据Pojo生成数据字典,zdoc格式 */
public static StringBuilder dataDict(Dao dao, String... packages) {
StringBuilder sb = new StringBuilder();
List<Class<?>> ks = new ArrayList<Class<?>>();
for (String packageName : packages) {
ks.addAll(Scans.me().scanPackage(packageName));
}
Iterator<Class<?>> it = ks.iterator();
while (it.hasNext()) {
Class<?> klass = it.next();
if (klass.getAnnotation(Table.class) == null)
it.remove();
}
// log.infof("Found %d table class", ks.size());
JdbcExpert exp = dao.getJdbcExpert();
Entity<?> entity = null;
String line = "-------------------------------------------------------------------\n";
sb.append("#title:数据字典\n");
sb.append("#author:wendal\n");
sb.append("#index:0,1\n").append(line);
for (Class<?> klass : ks) {
sb.append(line);
entity = dao.getEntity(klass);
sb.append("表名 ").append(entity.getTableName()).append("\n\n");
if (!Strings.isBlank(entity.getTableComment()))
sb.append("表注释: ").append(entity.getTableComment());
sb.append("\t").append("Java类名 ").append(klass.getName()).append("\n\n");
sb.append("\t||序号||列名||数据类型||主键||非空||默认值||java属性名||java类型||注释||\n");
int index = 1;
for (MappingField field : entity.getMappingFields()) {
String dataType = exp.evalFieldType(field);
sb.append("\t||").append(index++).append("||").append(field.getColumnName()).append("||").append(dataType).append("||").append(field.isPk()).append("||").append(field.isNotNull()).append("||").append(field.getDefaultValue(null) == null ? " " : field.getDefaultValue(null)).append("||").append(field.getName()).append("||").append(field.getTypeClass().getName()).append("||").append(field.getColumnComment() == null ? " " : field.getColumnComment()).append("||\n");
}
}
return sb;
}
Aggregations