use of org.nutz.dao.entity.EntityIndex in project nutz by nutzam.
the class ExtDaoInvocationHandler method createIndexs.
private static UpdateIndexSql createIndexs(Dao dao, Entity<?> en, Set<String> indexsHis, Object t) {
UpdateIndexSql uis = new UpdateIndexSql();
List<Sql> sqls = new ArrayList<Sql>();
List<String> delIndexs = new ArrayList<String>();
List<EntityIndex> indexs = en.getIndexes();
for (EntityIndex index : indexs) {
sqls.add(dao.getJdbcExpert().createIndexSql(en, index));
}
if (!Lang.isEmpty(sqls)) {
uis.setSqlsAdd(sqls.toArray(new Sql[0]));
}
Iterator<String> iterator = indexsHis.iterator();
List<Sql> delSqls = new ArrayList<Sql>();
while (iterator.hasNext()) {
String index = iterator.next();
if (delIndexs.contains(index) || Lang.equals("PRIMARY", index)) {
continue;
}
MappingField mf = en.getColumn(index);
if (mf != null) {
if (mf.isName())
continue;
}
delSqls.add(Sqls.createf("ALTER TABLE %s DROP INDEX %s", getTableName(dao, en, t), index));
}
if (!Lang.isEmpty(delSqls)) {
uis.setSqlsDel(Lang.collection2array(delSqls));
}
return uis;
}
Aggregations