use of org.nutz.dao.entity.EntityField in project nutz by nutzam.
the class AbstractJdbcExpert method createIndexSql.
public Sql createIndexSql(Entity<?> en, EntityIndex index) {
StringBuilder sb = new StringBuilder();
if (index.isUnique())
sb.append("Create UNIQUE Index ");
else
sb.append("Create Index ");
sb.append(index.getName(en));
sb.append(" ON ").append(en.getTableName()).append("(");
for (EntityField field : index.getFields()) {
if (field instanceof MappingField) {
MappingField mf = (MappingField) field;
sb.append(mf.getColumnNameInSql()).append(',');
} else {
throw Lang.makeThrow(DaoException.class, "%s %s is NOT a mapping field, can't use as index field!!", en.getClass(), field.getName());
}
}
sb.setCharAt(sb.length() - 1, ')');
return Sqls.create(sb.toString());
}
use of org.nutz.dao.entity.EntityField in project nutz by nutzam.
the class AnnotationEntityMaker method _evalEntityIndexes.
private void _evalEntityIndexes(NutEntity<?> en, TableIndexes indexes) {
for (Index idx : indexes.value()) {
NutEntityIndex index = new NutEntityIndex();
index.setUnique(idx.unique());
index.setName(idx.name());
for (String indexName : idx.fields()) {
EntityField ef = en.getField(indexName);
if (null == ef) {
throw Lang.makeThrow("Fail to find field '%s' in '%s' by @Index(%s:%s)", indexName, en.getType().getName(), index.getName(en), Lang.concat(idx.fields()));
}
index.addField(ef);
}
en.addIndex(index);
}
for (Field field : en.getMirror().getFields()) {
Index idx = field.getAnnotation(Index.class);
if (idx == null)
continue;
NutEntityIndex index = new NutEntityIndex();
index.setUnique(idx.unique());
index.setName(idx.name());
index.addField(en.getField(field.getName()));
en.addIndex(index);
}
}
Aggregations