public void accept(Visitor visitor) { super.accept(visitor); if (labelDiffSets != null) { visitor.visitLabelChanges(getId(), labelDiffSets.getAdded(), labelDiffSets.getRemoved()); } if (relationshipsAdded != null || relationshipsRemoved != null) { visitor.visitRelationshipChanges(getId(), relationshipsAdded, relationshipsRemoved); } }
public void clearIndexDiffs(long nodeId) { if (indexDiffs != null) { for (DiffSets<Long> diff : indexDiffs) { if (diff.getAdded().contains(nodeId)) { diff.remove(nodeId); } else if (diff.getRemoved().contains(nodeId)) { diff.add(nodeId); } } } }
private PrimitiveLongIterator filterIndexStateChanges( KernelStatement state, IndexDescriptor index, Object value, PrimitiveLongIterator nodeIds) { if (state.hasTxStateWithChanges()) { DiffSets<Long> labelPropertyChanges = state.txState().indexUpdates(index, value); DiffSets<Long> nodes = state.txState().addedAndRemovedNodes(); // Apply to actual index lookup return nodes.augmentWithRemovals(labelPropertyChanges.augment(nodeIds)); } return nodeIds; }
private Iterator<UniquenessConstraint> applyConstraintsDiff( KernelStatement state, Iterator<UniquenessConstraint> constraints) { if (state.hasTxStateWithChanges()) { DiffSets<UniquenessConstraint> diff = state.txState().constraintsChanges(); if (diff != null) { return diff.apply(constraints); } } return constraints; }
private boolean checkIndexState(IndexDescriptor indexRule, DiffSets<IndexDescriptor> diffSet) throws IndexNotFoundKernelException { if (diffSet.isAdded(indexRule)) { return true; } if (diffSet.isRemoved(indexRule)) { throw new IndexNotFoundKernelException( String.format( "Index for label id %d on property id %d has been " + "dropped in this transaction.", indexRule.getLabelId(), indexRule.getPropertyKeyId())); } return false; }
private Iterator<UniquenessConstraint> applyConstraintsDiff( KernelStatement state, Iterator<UniquenessConstraint> constraints, int labelId, int propertyKeyId) { if (state.hasTxStateWithChanges()) { DiffSets<UniquenessConstraint> diff = state.txState().constraintsChangesForLabelAndProperty(labelId, propertyKeyId); if (diff != null) { return diff.apply(constraints); } } return constraints; }
@Override public IndexDescriptor indexesGetForLabelAndPropertyKey( KernelStatement state, int labelId, int propertyKey) { Iterable<IndexDescriptor> committedRules; try { committedRules = option(storeLayer.indexesGetForLabelAndPropertyKey(labelId, propertyKey)); } catch (SchemaRuleNotFoundException e) { committedRules = emptyList(); } DiffSets<IndexDescriptor> ruleDiffSet = state.txState().indexDiffSetsByLabel(labelId); boolean hasTxStateWithChanges = state.hasTxStateWithChanges(); Iterator<IndexDescriptor> rules = hasTxStateWithChanges ? filterByPropertyKeyId(ruleDiffSet.apply(committedRules.iterator()), propertyKey) : committedRules.iterator(); return singleOrNull(rules); }
@Override public void clear() { super.clear(); if (relationshipsAdded != null) { relationshipsAdded.clear(); } if (relationshipsRemoved != null) { relationshipsRemoved.clear(); } if (labelDiffSets != null) { labelDiffSets.clear(); } if (indexDiffs != null) { indexDiffs.clear(); } }
@Test public void shouldNotAddConstraintAlreadyExistsInTheStore() throws Exception { // given UniquenessConstraint constraint = new UniquenessConstraint(10, 66); TxState txState = mock(TxState.class); when(txState.nodesWithLabelChanged(anyInt())).thenReturn(DiffSets.<Long>emptyDiffSets()); KernelStatement state = mockedState(txState); when(inner.constraintsGetForLabelAndPropertyKey(10, 66)) .thenAnswer(asAnswer(asList(constraint))); StateHandlingStatementOperations context = newTxStateOps(inner); // when context.uniquenessConstraintCreate(state, 10, 66); // then verify(txState).constraintIndexDoUnRemove(any(IndexDescriptor.class)); }