public static boolean isAnyIndexedValueChanged(Properties ctx, GridTab tab, boolean newRecord) { for (final MIndexTable index : MIndexTable.getByTable(ctx, tab.getTableName())) { if (index.isIndexedValuesChanged(tab, newRecord)) { return true; } } return false; }
public static List<I_AD_Index_Table> getAffectedIndexes( Properties ctx, GridTab tab, boolean newRecord) { final List<I_AD_Index_Table> list = new ArrayList<I_AD_Index_Table>(); for (final MIndexTable index : MIndexTable.getByTable(ctx, tab.getTableName())) { if (index.isMatched(tab, newRecord)) { list.add(index); } } return list; }
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; }
public void createBeforeChangeFunction(MIndexTable index) throws SQLException { final String ddlFunction = index.getBeforeChangeCodeFunctionDDL(); if (Check.isEmpty(ddlFunction, true)) return; executeDDL(ddlFunction, index.get_TrxName()); // final String ddlTrigger = index.getBeforeChangeCodeTriggerDDL(); if (Check.isEmpty(ddlTrigger, true)) return; if (existsFunction(index.getDBFunctionName())) executeDDL( "DROP TRIGGER IF EXISTS " + index.getDBTriggerName() + " ON " + index.getTableName(), index.get_TrxName()); executeDDL(ddlTrigger, index.get_TrxName()); }
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()); } }