Search in sources :

Example 1 with EntityIndex

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;
}
Also used : ArrayList(java.util.ArrayList) EntityIndex(org.nutz.dao.entity.EntityIndex) MappingField(org.nutz.dao.entity.MappingField) Sql(org.nutz.dao.sql.Sql)

Aggregations

ArrayList (java.util.ArrayList)1 EntityIndex (org.nutz.dao.entity.EntityIndex)1 MappingField (org.nutz.dao.entity.MappingField)1 Sql (org.nutz.dao.sql.Sql)1