private boolean purgeOverlappingContexts( Dependency egd, Repair repair, Set<AttributeRef> affectedAttributesSoFar) { // Needed also for FDs due to the presence of cellgroups that can span different eq. classes, // but only if some earlier dependencies has generated a cell group for this attribute if (affectedAttributesSoFar.isEmpty()) { return true; } if (logger.isDebugEnabled()) logger.debug("Checking independence of violation contexts for egd " + egd); boolean consistent = true; Map<AttributeRef, Set<CellRef>> changedCellMap = new HashMap<AttributeRef, Set<CellRef>>(); for (Iterator<ChangeDescription> it = repair.getChangeDescriptions().iterator(); it.hasNext(); ) { ChangeDescription changeDescription = it.next(); Set<AttributeRef> changedAttributes = ChaseUtility.extractAffectedAttributes(changeDescription); if (LunaticUtility.hasEmptyIntersection(affectedAttributesSoFar, changedAttributes)) { continue; } if (ChaseUtility.occurrencesOverlap(changeDescription, changedCellMap) || ChaseUtility.witnessOverlaps(changeDescription, changedCellMap)) { if (logger.isDebugEnabled()) logger.debug("Violation context has overlaps: " + changeDescription); it.remove(); consistent = false; } else { ChaseUtility.addChangedCellsToMap( changeDescription.getCellGroup().getOccurrences(), changedCellMap); } } return consistent; }
private NewChaseSteps applyRepairs( DeltaChaseStep currentNode, List<Repair> repairs, Dependency egd, Scenario scenario) { if (logger.isDebugEnabled()) logger.debug("---Applying repairs..."); NewChaseSteps newChaseSteps = new NewChaseSteps(egd); for (int i = 0; i < repairs.size(); i++) { Repair repair = repairs.get(i); boolean consistentRepair = purgeOverlappingContexts(egd, repair, currentNode.getAffectedAttributesInAncestors()); try { CellGroupUtility.checkCellGroupConsistency(repair); } catch (ChaseException ex) { // TODO++ IExportSolution solutionExporter = OperatorFactory.getInstance().getSolutionExporter(scenario); solutionExporter.export(currentNode, "error", scenario); throw ex; } String egdId = egd.getId(); String localId = ChaseUtility.generateChaseStepIdForEGDs(egdId, i, repair); DeltaChaseStep newStep = new DeltaChaseStep(scenario, currentNode, localId, egd, repair, repair.getChaseModes()); for (ChangeDescription changeSet : repair.getChangeDescriptions()) { this.cellChanger.changeCells( changeSet.getCellGroup(), newStep.getDeltaDB(), newStep.getId(), scenario); } if (consistentRepair) { if (logger.isDebugEnabled()) logger.debug("EGD " + egd.getId() + " is satisfied in this step..."); newStep.addSatisfiedEGD(egd); } newStep.setAffectedAttributesInNode(ChaseUtility.extractAffectedAttributes(repair)); newStep.setAffectedAttributesInAncestors( ChaseUtility.findChangedAttributesInAncestors(newStep)); if (logger.isDebugEnabled()) logger.debug("Generated step " + newStep.getId() + " for repair: " + repair); newChaseSteps.addChaseStep(newStep); } this.cellChanger.flush(currentNode.getDeltaDB()); if (repairs.isEmpty()) { newChaseSteps.setNoRepairsNeeded(true); } return newChaseSteps; }