Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update IndexTxStateUpdater on property changes
- Loading branch information
1 parent
e9241cf
commit 6166f41
Showing
4 changed files
with
223 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeSchemaMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.neo4j.kernel.impl.newapi; | ||
|
||
|
||
import java.util.Iterator; | ||
|
||
import org.neo4j.collection.primitive.Primitive; | ||
import org.neo4j.collection.primitive.PrimitiveIntSet; | ||
import org.neo4j.function.ThrowingBiConsumer; | ||
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; | ||
import org.neo4j.kernel.api.schema.LabelSchemaSupplier; | ||
|
||
/** | ||
* This class holds functionality to match LabelSchemaDescriptors to nodes | ||
*/ | ||
class NodeSchemaMatcher | ||
{ | ||
private final Read read; | ||
|
||
NodeSchemaMatcher( Read read ) | ||
{ | ||
this.read = read; | ||
} | ||
|
||
/** | ||
* Iterate over some schema suppliers, and invoke a callback for every supplier that matches the node. To match the | ||
* node N the supplier must supply a LabelSchemaDescriptor D, such that N has the label of D, and values for all | ||
* the properties of D. | ||
* | ||
* To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the node if some | ||
* descriptor has a valid label. | ||
* | ||
* @param <SUPPLIER> the type to match. Must implement LabelSchemaDescriptor.Supplier | ||
* @param <EXCEPTION> The type of exception that can be thrown when taking the action | ||
* @param schemaSuppliers The suppliers to match | ||
* @param node The node cursor | ||
* @param property The property cursor | ||
* @param specialPropertyId This property id will always count as a match for the descriptor, regardless of | ||
* whether the node has this property or not | ||
* @param callback The action to take on match | ||
* @throws EXCEPTION This exception is propagated from the action | ||
*/ | ||
<SUPPLIER extends LabelSchemaSupplier,EXCEPTION extends Exception> void onMatchingSchema( | ||
Iterator<SUPPLIER> schemaSuppliers, | ||
org.neo4j.internal.kernel.api.NodeCursor node, | ||
org.neo4j.internal.kernel.api.PropertyCursor property, | ||
int specialPropertyId, | ||
ThrowingBiConsumer<SUPPLIER,PrimitiveIntSet,EXCEPTION> callback | ||
) throws EXCEPTION | ||
{ | ||
PrimitiveIntSet nodePropertyIds = null; | ||
while ( schemaSuppliers.hasNext() ) | ||
{ | ||
SUPPLIER schemaSupplier = schemaSuppliers.next(); | ||
LabelSchemaDescriptor schema = schemaSupplier.schema(); | ||
if ( node.labels().contains( schema.getLabelId() ) ) | ||
{ | ||
if ( nodePropertyIds == null ) | ||
{ | ||
nodePropertyIds = Primitive.intSet(); | ||
node.properties( property ); | ||
while (property.next()) | ||
{ | ||
nodePropertyIds.add( property.propertyKey() ); | ||
} | ||
} | ||
|
||
if ( nodeHasSchemaProperties( nodePropertyIds, schema.getPropertyIds(), specialPropertyId ) ) | ||
{ | ||
callback.accept( schemaSupplier, nodePropertyIds ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static boolean nodeHasSchemaProperties( | ||
PrimitiveIntSet nodeProperties, int[] indexPropertyIds, int changedPropertyId ) | ||
{ | ||
for ( int indexPropertyId : indexPropertyIds ) | ||
{ | ||
if ( indexPropertyId != changedPropertyId && !nodeProperties.contains( indexPropertyId ) ) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters