@Override public void process( IndexEntryUpdate<?> update ) throws IndexEntryConflictException { IndexUpdater to = select( ((PointValue)update.values()[0]).getCoordinateReferenceSystem() ); switch ( update.updateMode() ) { case ADDED: case REMOVED: to.process( update ); break; case CHANGED: IndexUpdater from = select( ((PointValue) update.beforeValues()[0]).getCoordinateReferenceSystem() ); // There are two cases: // - both before/after go into the same updater --> pass update into that updater if ( from == to ) { from.process( update ); } // - before go into one and after into the other --> REMOVED from one and ADDED into the other else { from.process( IndexEntryUpdate.remove( update.getEntityId(), update.indexKey(), update.beforeValues() ) ); to.process( IndexEntryUpdate.add( update.getEntityId(), update.indexKey(), update.values() ) ); } break; default: throw new IllegalArgumentException( "Unknown update mode" ); } }
void add( IndexEntryUpdate<?> update ) { if ( update.getEntityId() == 2 ) { job.update( IndexEntryUpdate.change( nodeToChange, index, previousValue, newValue ) ); } added.add( Pair.of( update.getEntityId(), update.values()[0].asObjectCopy() ) ); }
private static Document updateAsDocument( IndexEntryUpdate<?> update ) { return LuceneDocumentStructure.documentRepresentingProperties( update.getEntityId(), update.values() ); } }
@Override public void process( IndexEntryUpdate<?> update ) throws IndexEntryConflictException { actual.process( update ); if ( update.updateMode() != REMOVED ) { touchedTuples.add( ValueTuple.of( update.values() ) ); } }
@Override public void process( IndexEntryUpdate<?> update ) { switch ( update.updateMode() ) { case ADDED: case CHANGED: added.add( Pair.of( update.getEntityId(), update.values()[0].asObjectCopy() ) ); break; default: throw new IllegalArgumentException( update.updateMode().name() ); } }
updates[i] = remove( toRemove.getEntityId(), indexDescriptor, toRemove.values() ); updates[i] = change( toChange.getEntityId(), indexDescriptor, toChange.values(), updateContainingValue.values() );
long nodeId = 0; List<IndexEntryUpdate<IndexDescriptor>> updates = new ArrayList<>(); updates.add( add( nodeId++, descriptor, tuple( 10, 11 ) ) ); updates.add( change( nodeId++, descriptor, tuple( "abc", "def" ), tuple( "ghi", "klm" ) ) ); updates.add( remove( nodeId++, descriptor, tuple( 1001L, 1002L ) ) ); updates.add( change( nodeId++, descriptor, tuple( (byte) 2, (byte) 3 ), tuple( (byte) 4, (byte) 5 ) ) ); updates.add( add( nodeId++, descriptor, tuple( 5, "5" ) ) ); try ( DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater( actual, () -> reader, descriptor ) ) if ( update.updateMode() == UpdateMode.ADDED || update.updateMode() == UpdateMode.CHANGED ) Value[] tuple = update.values(); IndexQuery[] query = new IndexQuery[tuple.length]; for ( int i = 0; i < tuple.length; i++ )
@Override public void process( IndexEntryUpdate<?> update ) { assert update.indexKey().schema().equals( descriptor.schema() ); try { switch ( update.updateMode() ) { case ADDED: long nodeId = update.getEntityId(); luceneIndex.getIndexWriter().updateDocument( LuceneFulltextDocumentStructure.newTermForChangeOrRemove( nodeId ), LuceneFulltextDocumentStructure.documentRepresentingProperties( nodeId, descriptor.propertyNames(), update.values() ) ); case CHANGED: long nodeId1 = update.getEntityId(); luceneIndex.getIndexWriter().updateDocument( LuceneFulltextDocumentStructure.newTermForChangeOrRemove( nodeId1 ), LuceneFulltextDocumentStructure.documentRepresentingProperties( nodeId1, descriptor.propertyNames(), update.values() ) ); break; case REMOVED: luceneIndex.getIndexWriter().deleteDocuments( LuceneFulltextDocumentStructure.newTermForChangeOrRemove( update.getEntityId() ) ); break; default: throw new UnsupportedOperationException(); } } catch ( IOException e ) { throw new UncheckedIOException( e ); } }
switch ( update.updateMode() ) addition = valueCreatorUtil.add( update.getEntityId(), update.values()[0] ); break; case CHANGED: addition = valueCreatorUtil.add( update.getEntityId(), update.values()[0] ); removal = valueCreatorUtil.add( update.getEntityId(), update.beforeValues()[0] ); break; case REMOVED: removal = valueCreatorUtil.add( update.getEntityId(), update.values()[0] ); break; default: throw new IllegalArgumentException( update.updateMode().name() );
void add( IndexEntryUpdate<?> update ) { if ( update.getEntityId() == 2 ) { job.update( IndexEntryUpdate.remove( nodeToDelete, index, valueToDelete ) ); } added.put( update.getEntityId(), update.values()[0].asObjectCopy() ); }
@SuppressWarnings( "ConstantConditions" ) private <INDEX_KEY extends SchemaDescriptorSupplier> Iterable<IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials( Iterable<INDEX_KEY> potentiallyRelevant ) { List<IndexEntryUpdate<INDEX_KEY>> indexUpdates = new ArrayList<>(); for ( INDEX_KEY indexKey : potentiallyRelevant ) { SchemaDescriptor schema = indexKey.schema(); boolean relevantBefore = relevantBefore( schema ); boolean relevantAfter = relevantAfter( schema ); int[] propertyIds = schema.getPropertyIds(); if ( relevantBefore && !relevantAfter ) { indexUpdates.add( IndexEntryUpdate.remove( entityId, indexKey, valuesBefore( propertyIds ) ) ); } else if ( !relevantBefore && relevantAfter ) { indexUpdates.add( IndexEntryUpdate.add( entityId, indexKey, valuesAfter( propertyIds ) ) ); } else if ( relevantBefore && relevantAfter ) { if ( valuesChanged( propertyIds, schema.propertySchemaType() ) ) { indexUpdates.add( IndexEntryUpdate.change( entityId, indexKey, valuesBefore( propertyIds ), valuesAfter( propertyIds ) ) ); } } } return indexUpdates; }
private static <KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> void processChange( KEY treeKey, VALUE treeValue, IndexEntryUpdate<?> update, Writer<KEY,VALUE> writer, ConflictDetectingValueMerger<KEY,VALUE> conflictDetectingValueMerger ) throws IndexEntryConflictException { // Remove old entry initializeKeyFromUpdate( treeKey, update.getEntityId(), update.beforeValues() ); writer.remove( treeKey ); // Insert new entry initializeKeyFromUpdate( treeKey, update.getEntityId(), update.values() ); treeValue.from( update.values() ); conflictDetectingValueMerger.controlConflictDetection( treeKey ); writer.merge( treeKey, treeValue, conflictDetectingValueMerger ); conflictDetectingValueMerger.checkConflict( update.values() ); }
private static IndexEntryUpdate<SchemaDescriptor> add( long nodeId, SchemaDescriptor schema, Value value1, Value value2 ) { return IndexEntryUpdate.add( nodeId, schema, value1, value2 ); } }
@Override protected void changed( IndexEntryUpdate<?> update ) { updatedValueTuples.add( update.values() ); }
@Test public void changedShouldRetainValues() { Value singleAfter = Values.of( "Hello" ); IndexEntryUpdate<?> singleChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue, singleAfter ); Value[] multiAfter = {Values.of( "Hello" ), Values.of( "Hi" )}; IndexEntryUpdate<?> multiChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4, 5 ), multiValue, multiAfter ); assertThat( new Object[]{singleValue}, equalTo( singleChange.beforeValues() ) ); assertThat( new Object[]{singleAfter}, equalTo( singleChange.values() ) ); assertThat( multiValue, equalTo( multiChange.beforeValues() ) ); assertThat( multiAfter, equalTo( multiChange.values() ) ); } }
@Test public void addShouldRetainValues() { IndexEntryUpdate<?> single = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); IndexEntryUpdate<?> multi = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4, 5 ), multiValue ); assertThat( single, not( equalTo( multi ) ) ); assertThat( single.values(), equalTo( new Object[]{singleValue} ) ); assertThat( multi.values(), equalTo( multiValue ) ); }
@Test public void removeShouldRetainValues() { IndexEntryUpdate<?> single = IndexEntryUpdate.remove( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); IndexEntryUpdate<?> multi = IndexEntryUpdate .remove( 0, SchemaDescriptorFactory.forLabel( 3, 4, 5 ), multiValue ); assertThat( single, not( equalTo( multi ) ) ); assertThat( single.values(), equalTo( new Object[]{singleValue} ) ); assertThat( multi.values(), equalTo( multiValue ) ); }
@Override protected void changed( IndexEntryUpdate<?> update ) { String encodedValueBefore = LuceneDocumentStructure.encodedStringValuesForSampling( update.beforeValues() ); sampler.exclude( encodedValueBefore ); String encodedValueAfter = LuceneDocumentStructure.encodedStringValuesForSampling( update.values() ); sampler.include( encodedValueAfter ); }
private void updateUniqueSample( IndexEntryUpdate<?> update ) { switch ( update.updateMode() ) { case ADDED: uniqueSampler.increment( 1 ); break; case REMOVED: uniqueSampler.increment( -1 ); break; case CHANGED: break; default: throw new IllegalArgumentException( "Unsupported update mode type:" + update.updateMode() ); } }