コード例 #1
0
  public void createIndex(MIndexTable index) throws SQLException {
    log.info(index.toString());

    final String[] indexColNames = index.getColumnNames();
    if (indexColNames.length <= 0) {
      throw new AdempiereException("No Index columns specified");
    }
    // Arrays.sort(indexColNames);

    DBIndex dbIndex = getDBIndex(index.getTableName(), index.getName(), index.get_TrxName());
    // DB Index not found => Create new
    if (dbIndex == null) {
      executeDDL(index.getDDL(), index.get_TrxName());
    }
    // DB Index found but modified => Drop and recreate
    else if ((index.isUnique() != dbIndex.isUnique)
        || !equalsIgnoreCase(index.getWhereClause(), dbIndex.filterCondition)
        || !equalsIgnoreCase(dbIndex.columnNames, indexColNames)) {
      executeDDL(
          "DROP INDEX IF EXISTS " + dbIndex.name,
          index
              .get_TrxName()); // metas-ts:adding "IF EXISTS" - solves some SQL migration script
                               // errors
      executeDDL(index.getDDL(), index.get_TrxName());
    }
  }
コード例 #2
0
 public static Map<String, List<MIndexTable>> getAllByTable(Properties ctx, boolean requery) {
   if (requery || s_indexesByTable == null) {
     final List<MIndexTable> listAll =
         new Query(ctx, Table_Name, null, null).setOnlyActiveRecords(true).list();
     s_indexesByTable = new HashMap<String, List<MIndexTable>>();
     for (final MIndexTable idxTable : listAll) {
       final String tableName = idxTable.getTableName();
       List<MIndexTable> list = s_indexesByTable.get(tableName);
       if (list == null) {
         list = new ArrayList<MIndexTable>();
       }
       list.add(idxTable);
       s_indexesByTable.put(tableName, list);
       s_cacheName.put(idxTable.getName(), idxTable);
     }
   }
   return s_indexesByTable;
 }