Skip to content

Commit

Permalink
Removed IndexEntryUpdate.value()
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and ragadeeshu committed Feb 15, 2017
1 parent e39e6e9 commit e03d6ad
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 86 deletions.
Expand Up @@ -78,19 +78,6 @@ public Object[] values()
return values;
}

public Object value()
{
if ( values.length == 1 )
{
return values[0];
}
else
{
throw new IllegalStateException(
"Expected single value index update but found " + values.length + " values" );
}
}

@Override
public boolean equals( Object o )
{
Expand Down Expand Up @@ -124,31 +111,21 @@ public String toString()
.userDescription( SchemaUtil.noopTokenNameLookup ), Arrays.toString(values) );
}

public static IndexEntryUpdate add( long nodeId, NewIndexDescriptor descriptor, Object value )
public static IndexEntryUpdate add( long nodeId, NewIndexDescriptor descriptor, Object... values )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.ADDED, new Object[]{value} );
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.ADDED, values );
}

public static IndexEntryUpdate remove( long nodeId, NewIndexDescriptor descriptor, Object value )
public static IndexEntryUpdate remove( long nodeId, NewIndexDescriptor descriptor, Object... values )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.REMOVED, new Object[]{value} );
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.REMOVED, values );
}

public static IndexEntryUpdate change( long nodeId, NewIndexDescriptor descriptor, Object before, Object after )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.CHANGED, new Object[]{before}, new Object[]{after} );
}

public static IndexEntryUpdate add( long nodeId, NewIndexDescriptor descriptor, Object[] values )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.ADDED, values );
}

public static IndexEntryUpdate remove( long nodeId, NewIndexDescriptor descriptor, Object[] values )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.REMOVED, values );
}

public static IndexEntryUpdate change( long nodeId, NewIndexDescriptor descriptor, Object[] before, Object[] after )
{
return new IndexEntryUpdate( nodeId, descriptor, UpdateMode.CHANGED, before, after );
Expand All @@ -162,5 +139,4 @@ public Object[] beforeValues()
}
return before;
}

}
Expand Up @@ -271,7 +271,7 @@ public void markAsFailed( String failure )
@Override
public void includeSample( IndexEntryUpdate update )
{
addValueToSample( update.getEntityId(), update.value() );
addValueToSample( update.getEntityId(), update.values()[0] );
}

@Override
Expand Down
Expand Up @@ -492,7 +492,7 @@ public void add( Collection<IndexEntryUpdate> updates )
{
job.update( IndexEntryUpdate.change( nodeToChange, index, previousValue, newValue ) );
}
added.add( Pair.of( update.getEntityId(), update.value() ) );
added.add( Pair.of( update.getEntityId(), update.values()[0] ) );
}
}

Expand All @@ -508,7 +508,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntryCon
{
case ADDED:
case CHANGED:
added.add( Pair.of( update.getEntityId(), update.value() ) );
added.add( Pair.of( update.getEntityId(), update.values()[0] ) );
break;
default:
throw new IllegalArgumentException( update.updateMode().name() );
Expand Down Expand Up @@ -564,7 +564,7 @@ public void add( Collection<IndexEntryUpdate> updates )
{
job.update( IndexEntryUpdate.remove( nodeToDelete, index, valueToDelete ) );
}
added.put( update.getEntityId(), update.value() );
added.put( update.getEntityId(), update.values()[0] );
}
}

Expand All @@ -580,10 +580,10 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntryCon
{
case ADDED:
case CHANGED:
added.put( update.getEntityId(), update.value() );
added.put( update.getEntityId(), update.values()[0] );
break;
case REMOVED:
removed.put( update.getEntityId(), update.value() ); // on remove, value is the before value
removed.put( update.getEntityId(), update.values()[0] ); // on remove, value is the before value
break;
default:
throw new IllegalArgumentException( update.updateMode().name() );
Expand Down
Expand Up @@ -64,7 +64,7 @@ public boolean visited( long nodeId ) throws RuntimeException
this( new HashBasedIndex() );
}

InMemoryIndex( InMemoryIndexImplementation indexData )
private InMemoryIndex( InMemoryIndexImplementation indexData )
{
this.indexData = indexData;
}
Expand Down Expand Up @@ -92,17 +92,6 @@ final IndexAccessor getOnlineAccessor()
return new OnlineAccessor();
}

protected final PrimitiveLongIterator indexSeek( Object propertyValue )
{
return indexData.seek( propertyValue );
}

protected boolean add( long nodeId, Object propertyValue, boolean applyIdempotently )
throws IndexEntryConflictException, IOException
{
return indexData.add( nodeId, propertyValue, applyIdempotently );
}

protected boolean add( long nodeId, Object[] propertyValues, boolean applyIdempotently )
throws IndexEntryConflictException, IOException
{
Expand All @@ -117,11 +106,6 @@ protected boolean add( long nodeId, Object[] propertyValues, boolean applyIdempo
}
}

protected void remove( long nodeId, Object propertyValue )
{
indexData.remove( nodeId, propertyValue );
}

protected void remove( long nodeId, Object[] propertyValues )
{
assert propertyValues.length > 0;
Expand Down
Expand Up @@ -28,8 +28,8 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure;
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.impl.api.index.UpdateMode;

/**
Expand All @@ -47,28 +47,28 @@ public LuceneIndexPopulatingUpdater( LuceneIndexWriter writer )
}

@Override
public void process( NodePropertyUpdate update ) throws IOException, IndexEntryConflictException
public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException
{
long nodeId = update.getNodeId();
long nodeId = update.getEntityId();

switch ( update.getUpdateMode() )
switch ( update.updateMode() )
{
case ADDED:
added( update );
writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ),
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.getValueAfter() ) );
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.values()[0] ) );
break;
case CHANGED:
changed( update );
writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ),
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.getValueAfter() ) );
LuceneDocumentStructure.documentRepresentingProperty( nodeId, update.values()[0] ) );
break;
case REMOVED:
removed( update );
writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) );
break;
default:
throw new IllegalStateException( "Unknown update mode " + update.getUpdateMode() );
throw new IllegalStateException( "Unknown update mode " + update.values()[0] );
}
}

Expand All @@ -79,23 +79,23 @@ public final void remove( PrimitiveLongSet nodeIds )
}

/**
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#ADDED} is processed.
* Method is invoked when {@link IndexEntryUpdate} with {@link UpdateMode#ADDED} is processed.
*
* @param update the update being processed.
*/
protected abstract void added( NodePropertyUpdate update );
protected abstract void added( IndexEntryUpdate update );

/**
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#CHANGED} is processed.
* Method is invoked when {@link IndexEntryUpdate} with {@link UpdateMode#CHANGED} is processed.
*
* @param update the update being processed.
*/
protected abstract void changed( NodePropertyUpdate update );
protected abstract void changed( IndexEntryUpdate update );

/**
* Method is invoked when {@link NodePropertyUpdate} with {@link UpdateMode#REMOVED} is processed.
* Method is invoked when {@link IndexEntryUpdate} with {@link UpdateMode#REMOVED} is processed.
*
* @param update the update being processed.
*/
protected abstract void removed( NodePropertyUpdate update );
protected abstract void removed( IndexEntryUpdate update );
}
Expand Up @@ -29,8 +29,8 @@
import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure;
import org.neo4j.kernel.api.impl.schema.SchemaIndex;
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.NodePropertyUpdate;

/**
* An {@link IndexPopulator} used to create, populate and mark as online a Lucene schema index.
Expand Down Expand Up @@ -60,7 +60,7 @@ public void drop() throws IOException
}

@Override
public void add( Collection<NodePropertyUpdate> updates ) throws IndexEntryConflictException, IOException
public void add( Collection<IndexEntryUpdate> updates ) throws IndexEntryConflictException, IOException
{
// Lucene documents stored in a ThreadLocal and reused so we can't create an eager collection of documents here
// That is why we create a lazy Iterator and then Iterable
Expand Down Expand Up @@ -91,8 +91,8 @@ public void markAsFailed( String failure ) throws IOException
luceneIndex.markAsFailed( failure );
}

private static Document updateAsDocument( NodePropertyUpdate update )
private static Document updateAsDocument( IndexEntryUpdate update )
{
return LuceneDocumentStructure.documentRepresentingProperty( update.getNodeId(), update.getValueAfter() );
return LuceneDocumentStructure.documentRepresentingProperty( update.getEntityId(), update.values()[0] );
}
}
Expand Up @@ -21,7 +21,7 @@

import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure;
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler;

/**
Expand All @@ -38,26 +38,26 @@ public NonUniqueLuceneIndexPopulatingUpdater( LuceneIndexWriter writer, NonUniqu
}

@Override
protected void added( NodePropertyUpdate update )
protected void added( IndexEntryUpdate update )
{
String encodedValue = LuceneDocumentStructure.encodedStringValue( update.getValueAfter() );
String encodedValue = LuceneDocumentStructure.encodedStringValue( update.values()[0] );
sampler.include( encodedValue );
}

@Override
protected void changed( NodePropertyUpdate update )
protected void changed( IndexEntryUpdate update )
{
String encodedValueBefore = LuceneDocumentStructure.encodedStringValue( update.getValueBefore() );
String encodedValueBefore = LuceneDocumentStructure.encodedStringValue( update.beforeValues()[0] );
sampler.exclude( encodedValueBefore );

String encodedValueAfter = LuceneDocumentStructure.encodedStringValue( update.getValueAfter() );
String encodedValueAfter = LuceneDocumentStructure.encodedStringValue( update.values()[0] );
sampler.include( encodedValueAfter );
}

@Override
protected void removed( NodePropertyUpdate update )
protected void removed( IndexEntryUpdate update )
{
String removedValue = LuceneDocumentStructure.encodedStringValue( update.getValueBefore() );
String removedValue = LuceneDocumentStructure.encodedStringValue( update.values()[0] );
sampler.exclude( removedValue );
}

Expand Down
Expand Up @@ -24,8 +24,8 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure;
import org.neo4j.kernel.api.impl.schema.SchemaIndex;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
Expand Down Expand Up @@ -70,12 +70,12 @@ public IndexUpdater newPopulatingUpdater( PropertyAccessor propertyAccessor ) th
}

@Override
public void includeSample( NodePropertyUpdate update )
public void includeSample( IndexEntryUpdate update )
{
if ( updateSampling )
{
checkSampler();
sampler.include( LuceneDocumentStructure.encodedStringValue( update.getValueAfter() ) );
sampler.include( LuceneDocumentStructure.encodedStringValue( update.values()[0] ) );
}
}

Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.impl.schema.SchemaIndex;
import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.impl.api.index.sampling.UniqueIndexSampler;

Expand Down Expand Up @@ -55,20 +55,20 @@ public UniqueLuceneIndexPopulatingUpdater( LuceneIndexWriter writer, int propert
}

@Override
protected void added( NodePropertyUpdate update )
protected void added( IndexEntryUpdate update )
{
sampler.increment( 1 );
updatedPropertyValues.add( update.getValueAfter() );
updatedPropertyValues.add( update.values()[0] );
}

@Override
protected void changed( NodePropertyUpdate update )
protected void changed( IndexEntryUpdate update )
{
updatedPropertyValues.add( update.getValueAfter() );
updatedPropertyValues.add( update.values()[0] );
}

@Override
protected void removed( NodePropertyUpdate update )
protected void removed( IndexEntryUpdate update )
{
sampler.increment( -1 );
}
Expand Down
Expand Up @@ -479,7 +479,7 @@ public long next()
case ADDED:
node.addLabel(
Label.label( labelsIdNameMap.get( descriptor.schema().getLabelId() ) ) );
node.setProperty( NAME_PROPERTY, indexUpdate.value() );
node.setProperty( NAME_PROPERTY, indexUpdate.values()[0] );
break;
case REMOVED:
node.addLabel(
Expand Down

0 comments on commit e03d6ad

Please sign in to comment.