From d9b57fc799ff5ac6538b5a5094240c267527dfdf Mon Sep 17 00:00:00 2001 From: fickludd Date: Wed, 1 Feb 2017 14:53:25 +0100 Subject: [PATCH] Pushed IndexDescriptor boundary on StoreReadLayer. 4 methods left. --- .../constraints/NodePropertyConstraint.java | 13 ++++- .../RelationshipPropertyConstraint.java | 9 +++ .../kernel/api/schema_new/SchemaBoundary.java | 46 ++++++++++++++++ .../constaints/ConstraintBoundary.java | 3 +- .../api/schema_new/index/IndexBoundary.java | 25 +++++++-- .../api/StateHandlingStatementOperations.java | 32 ++++++----- .../kernel/impl/api/store/SchemaCache.java | 24 ++++---- .../kernel/impl/api/store/StorageLayer.java | 55 +++++++------------ .../storageengine/api/StoreReadLayer.java | 46 +++++++--------- .../state/IndexQueryTransactionStateTest.java | 13 +++-- .../api/state/LabelTransactionStateTest.java | 5 +- .../api/state/SchemaTransactionStateTest.java | 28 ++++++---- .../StateHandlingStatementOperationsTest.java | 27 ++++----- .../impl/api/store/SchemaCacheTest.java | 33 ++++++----- .../api/store/StorageLayerSchemaTest.java | 9 ++- .../store/StorageLayerSchemaWithPECTest.java | 11 ++-- 16 files changed, 231 insertions(+), 148 deletions(-) create mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaBoundary.java diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/NodePropertyConstraint.java b/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/NodePropertyConstraint.java index da6d30b8cc748..7fdc1ac22b0f1 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/NodePropertyConstraint.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/NodePropertyConstraint.java @@ -19,10 +19,9 @@ */ package org.neo4j.kernel.api.constraints; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.TokenNameLookup; -import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; /** * Base class describing property constraint on nodes. @@ -51,6 +50,14 @@ public boolean matches( NodePropertyDescriptor descriptor ) return this.descriptor.equals( descriptor ); } + public boolean matches( LabelSchemaDescriptor other ) + { + return other != null && + descriptor.getLabelId() == other.getLabelId() && + descriptor.getPropertyKeyId() == other.getPropertyIds()[0]; + // this is safe because we are replacing this class before introducing composite constraints + } + @Override public boolean equals( Object o ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/RelationshipPropertyConstraint.java b/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/RelationshipPropertyConstraint.java index 96c1c01f2015f..1c7797dd5e6be 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/RelationshipPropertyConstraint.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/constraints/RelationshipPropertyConstraint.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.api.constraints; import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; /** * Base class describing property constraint on relationships. @@ -44,6 +45,14 @@ public boolean matches( RelationshipPropertyDescriptor descriptor ) return this.descriptor.equals( descriptor ); } + public boolean matches( RelationTypeSchemaDescriptor other ) + { + return other != null && + descriptor.getRelationshipTypeId() == other.getRelTypeId() && + descriptor.getPropertyKeyId() == other.getPropertyIds()[0]; + // this is safe because we are replacing this class before introducing composite constraints + } + @Override public boolean equals( Object o ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaBoundary.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaBoundary.java new file mode 100644 index 0000000000000..39747f0df3aa3 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaBoundary.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2002-2017 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.api.schema_new; + +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; + +/** + * This class represents the boundary of where new schema descriptors are converted to old descriptors. This class + * should disappear once the old schema descriptors are no longer used. + */ +public class SchemaBoundary +{ + private SchemaBoundary() + { + } + + public static LabelSchemaDescriptor map( NodePropertyDescriptor descriptor ) + { + return descriptor.isComposite() ? + SchemaDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyIds() ) : + SchemaDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() ); + } + + public static RelationTypeSchemaDescriptor map( RelationshipPropertyDescriptor descriptor ) + { + return SchemaDescriptorFactory.forRelType( descriptor.getRelationshipTypeId(), descriptor.getPropertyKeyId() ); + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/constaints/ConstraintBoundary.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/constaints/ConstraintBoundary.java index e9d6830f00312..3abe19009b9b1 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/constaints/ConstraintBoundary.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/constaints/ConstraintBoundary.java @@ -32,7 +32,8 @@ import org.neo4j.kernel.api.schema_new.SchemaComputer; /** - * This class represents the boundary of where new constraint descriptors are converted to old constraints + * This class represents the boundary of where new constraint descriptors are converted to old constraints. This class + * should disappear once the old constraints are no longer used. */ public class ConstraintBoundary { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/IndexBoundary.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/IndexBoundary.java index 4ea60c417c81e..50acb97beeea1 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/IndexBoundary.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/IndexBoundary.java @@ -19,23 +19,38 @@ */ package org.neo4j.kernel.api.schema_new.index; +import java.util.Iterator; + +import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema.IndexDescriptorFactory; /** - * This class represents the boundary of where new index descriptors are converted to old index descriptors + * This class represents the boundary of where new index descriptors are converted to old index descriptors. Take me + * away when possible... */ public class IndexBoundary { public static IndexDescriptor map( NewIndexDescriptor descriptor ) { - LabelSchemaDescriptor labelSchema = (LabelSchemaDescriptor) descriptor.schema(); - return org.neo4j.kernel.api.schema.IndexDescriptorFactory.of( - labelSchema.getLabelId(), labelSchema.getPropertyIds()[0] ); + if ( descriptor == null ) + { + return null; + } + return IndexDescriptorFactory.of( descriptor.schema().getLabelId(), descriptor.schema().getPropertyIds()[0] ); } public static NewIndexDescriptor map( IndexDescriptor descriptor ) { + if ( descriptor == null ) + { + return null; + } return NewIndexDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() ); } + + public static Iterator map( Iterator iterator ) + { + return Iterators.map( IndexBoundary::map, iterator ); + } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java index d3047a8249852..e32f5232c4651 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java @@ -67,6 +67,8 @@ import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; import org.neo4j.kernel.api.txstate.TransactionCountingStateVisitor; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.impl.api.operations.CountsOperations; @@ -406,7 +408,8 @@ public UniquenessConstraint uniquePropertyConstraintCreate( KernelStatement stat } else // *CREATE* { // create from scratch - for ( Iterator it = storeLayer.constraintsGetForLabelAndPropertyKey( descriptor ); + for ( Iterator it = storeLayer.constraintsGetForLabelAndPropertyKey( + SchemaBoundary.map( descriptor) ); it.hasNext(); ) { if ( it.next().equals( constraint ) ) @@ -451,7 +454,7 @@ public Iterator constraintsGetForLabelAndPropertyKey( Ke NodePropertyDescriptor descriptor ) { Iterator constraints = - storeLayer.constraintsGetForLabelAndPropertyKey(descriptor ); + storeLayer.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor ) ); if ( state.hasTxStateWithChanges() ) { return state.txState().constraintsChangesForLabelAndProperty( descriptor ).apply( constraints ); @@ -475,7 +478,7 @@ public Iterator constraintsGetForRelationshipTyp KernelStatement state, RelationshipPropertyDescriptor descriptor ) { Iterator constraints = - storeLayer.constraintsGetForRelationshipTypeAndPropertyKey( descriptor ); + storeLayer.constraintsGetForRelationshipTypeAndPropertyKey( SchemaBoundary.map( descriptor ) ); if ( state.hasTxStateWithChanges() ) { return state.txState() @@ -524,7 +527,8 @@ public void constraintDrop( KernelStatement state, RelationshipPropertyConstrain @Override public IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ) { - IndexDescriptor indexDescriptor = storeLayer.indexGetForLabelAndPropertyKey( descriptor ); + IndexDescriptor indexDescriptor = IndexBoundary.map( + storeLayer.indexGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor ) ) ); Iterator rules = iterator( indexDescriptor ); if ( state.hasTxStateWithChanges() ) @@ -610,10 +614,10 @@ public Iterator indexesGetForLabel( KernelStatement state, int if ( state.hasTxStateWithChanges() ) { return state.txState().indexDiffSetsByLabel( labelId ) - .apply( storeLayer.indexesGetForLabel( labelId ) ); + .apply( IndexBoundary.map( storeLayer.indexesGetForLabel( labelId ) ) ); } - return storeLayer.indexesGetForLabel( labelId ); + return IndexBoundary.map( storeLayer.indexesGetForLabel( labelId ) ); } @Override @@ -621,10 +625,10 @@ public Iterator indexesGetAll( KernelStatement state ) { if ( state.hasTxStateWithChanges() ) { - return state.txState().indexChanges().apply( storeLayer.indexesGetAll() ); + return state.txState().indexChanges().apply( IndexBoundary.map( storeLayer.indexesGetAll() ) ); } - return storeLayer.indexesGetAll(); + return IndexBoundary.map( storeLayer.indexesGetAll() ); } @Override @@ -633,10 +637,10 @@ public Iterator uniqueIndexesGetForLabel( KernelStatement state if ( state.hasTxStateWithChanges() ) { return state.txState().constraintIndexDiffSetsByLabel( labelId ) - .apply( storeLayer.uniquenessIndexesGetForLabel( labelId ) ); + .apply( IndexBoundary.map( storeLayer.uniquenessIndexesGetForLabel( labelId ) ) ); } - return storeLayer.uniquenessIndexesGetForLabel( labelId ); + return IndexBoundary.map( storeLayer.uniquenessIndexesGetForLabel( labelId ) ); } @Override @@ -645,10 +649,10 @@ public Iterator uniqueIndexesGetAll( KernelStatement state ) if ( state.hasTxStateWithChanges() ) { return state.txState().constraintIndexChanges() - .apply( storeLayer.uniquenessIndexesGetAll() ); + .apply( IndexBoundary.map( storeLayer.uniquenessIndexesGetAll() ) ); } - return storeLayer.uniquenessIndexesGetAll(); + return IndexBoundary.map( storeLayer.uniquenessIndexesGetAll() ); } @Override @@ -1168,14 +1172,14 @@ public DoubleLongRegister indexSample( KernelStatement statement, IndexDescripto public Long indexGetOwningUniquenessConstraintId( KernelStatement state, IndexDescriptor index ) throws SchemaRuleNotFoundException { - return storeLayer.indexGetOwningUniquenessConstraintId( index ); + return storeLayer.indexGetOwningUniquenessConstraintId( IndexBoundary.map( index ) ); } @Override public long indexGetCommittedId( KernelStatement state, IndexDescriptor index, Predicate filter ) throws SchemaRuleNotFoundException { - return storeLayer.indexGetCommittedId( index, filter ); + return storeLayer.indexGetCommittedId( IndexBoundary.map( index ), filter ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java index f7b8eeef28ee4..a38a7ecc24342 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/SchemaCache.java @@ -25,19 +25,16 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.constraints.NodePropertyConstraint; import org.neo4j.kernel.api.constraints.PropertyConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint; -import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.IndexDescriptorFactory; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; -import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema_new.SchemaDescriptor; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; -import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.constraints.ConstraintSemantics; import org.neo4j.kernel.impl.store.record.ConstraintRule; import org.neo4j.kernel.impl.store.record.IndexRule; @@ -59,7 +56,7 @@ public class SchemaCache private final Collection nodeConstraints = new HashSet<>(); private final Collection relationshipConstraints = new HashSet<>(); - private final Set indexDescriptors = new HashSet<>(); + private final Map indexDescriptors = new HashMap<>(); private final ConstraintSemantics constraintSemantics; public SchemaCache( ConstraintSemantics constraintSemantics, Iterable initialRules ) @@ -126,7 +123,7 @@ public Iterator constraintsForLabel( final int label ) nodeConstraints.iterator() ); } - public Iterator constraintsForLabelAndProperty( NodePropertyDescriptor descriptor ) + public Iterator constraintsForLabelAndProperty( LabelSchemaDescriptor descriptor ) { return Iterators.filter( constraint -> constraint.matches( descriptor ), @@ -141,7 +138,7 @@ public Iterator constraintsForRelationshipType( } public Iterator constraintsForRelationshipTypeAndProperty( - RelationshipPropertyDescriptor descriptor ) + RelationTypeSchemaDescriptor descriptor ) { return Iterators.filter( constraint -> constraint.matches( descriptor ), @@ -168,7 +165,7 @@ else if ( rule instanceof IndexRule ) { IndexRule indexRule = (IndexRule) rule; indexRuleById.put( indexRule.getId(), indexRule ); - indexDescriptors.add( IndexBoundary.map( indexRule.getIndexDescriptor() ) ); + indexDescriptors.put( indexRule.getSchemaDescriptor(), indexRule.getIndexDescriptor() ); } } @@ -208,13 +205,12 @@ else if ( constraint instanceof RelationshipPropertyConstraint ) else if ( indexRuleById.containsKey( id ) ) { IndexRule rule = indexRuleById.remove( id ); - indexDescriptors.remove( IndexBoundary.map( rule.getIndexDescriptor() ) ); + indexDescriptors.remove( rule.getSchemaDescriptor() ); } } - public IndexDescriptor indexDescriptor( NodePropertyDescriptor descriptor ) + public NewIndexDescriptor indexDescriptor( LabelSchemaDescriptor descriptor ) { - IndexDescriptor key = IndexDescriptorFactory.of( descriptor ); - return indexDescriptors.contains( key ) ? key : null; + return indexDescriptors.get( descriptor ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java index 442e73334fb5c..676fb5e414ffc 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java @@ -44,10 +44,10 @@ import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.properties.PropertyKeyIdIterator; import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; -import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.DegreeVisitor; import org.neo4j.kernel.impl.api.RelationshipVisitor; import org.neo4j.kernel.impl.api.index.IndexingService; @@ -83,7 +83,6 @@ import org.neo4j.storageengine.api.schema.SchemaRule; import static org.neo4j.helpers.collection.Iterables.filter; -import static org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory.forLabel; import static org.neo4j.kernel.api.schema_new.SchemaDescriptorPredicates.hasLabel; import static org.neo4j.kernel.impl.api.store.DegreeCounter.countByFirstPrevPointer; import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP; @@ -185,26 +184,26 @@ public PrimitiveLongIterator nodesGetForLabel( StorageStatement statement, int l } @Override - public IndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + public NewIndexDescriptor indexGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor ) { return schemaCache.indexDescriptor( descriptor ); } @Override - public Iterator indexesGetForLabel( int labelId ) + public Iterator indexesGetForLabel( int labelId ) { return toIndexDescriptors( filter( rule -> hasLabel( rule, labelId ) && !rule.canSupportUniqueConstraint(), schemaCache.indexRules() ) ); } @Override - public Iterator indexesGetAll() + public Iterator indexesGetAll() { return toIndexDescriptors( filter( rule -> !rule.canSupportUniqueConstraint(), schemaCache.indexRules() ) ); } @Override - public Iterator uniquenessIndexesGetForLabel( int labelId ) + public Iterator uniquenessIndexesGetForLabel( int labelId ) { Predicate indexRulePredicate = rule -> hasLabel( rule, labelId ) && rule.canSupportUniqueConstraint(); @@ -212,58 +211,46 @@ public Iterator uniquenessIndexesGetForLabel( int labelId ) } @Override - public Iterator uniquenessIndexesGetAll() + public Iterator uniquenessIndexesGetAll() { return toIndexDescriptors( filter( IndexRule::canSupportUniqueConstraint, schemaCache.indexRules() ) ); } @Override - public Long indexGetOwningUniquenessConstraintId( IndexDescriptor index ) throws SchemaRuleNotFoundException + public Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException { IndexRule rule = indexRule( index, Predicates.alwaysTrue() ); if ( rule != null ) { return rule.getOwningConstraint(); } - - IndexRule indexRule = - schemaStorage.indexGetForSchema( forLabel( index.getLabelId(), index.getPropertyKeyId() ) ); - return indexRule == null ? null : indexRule.getOwningConstraint(); + return null; } @Override - public long indexGetCommittedId( IndexDescriptor index, Predicate filter ) + public long indexGetCommittedId( NewIndexDescriptor index, Predicate filter ) throws SchemaRuleNotFoundException { IndexRule rule = indexRule( index, filter ); - if ( rule != null ) + if ( rule == null ) { - return rule.getId(); + throw new SchemaRuleNotFoundException( SchemaRule.Kind.INDEX_RULE, index.schema() ); } - - LabelSchemaDescriptor schemaDescriptor = forLabel( index.getLabelId(), index.getPropertyKeyId() ); - IndexRule indexRule = schemaStorage.indexGetForSchema( schemaDescriptor ); - if ( indexRule == null ) - { - throw new SchemaRuleNotFoundException( SchemaRule.Kind.INDEX_RULE, schemaDescriptor ); - } - return indexRule.getId(); + return rule.getId(); } - @Override - public IndexRule indexRule( IndexDescriptor index, Predicate filter ) +// @Override + private IndexRule indexRule( NewIndexDescriptor index, Predicate filter ) { - LabelSchemaDescriptor schemaDescription = forLabel( index.getLabelId(), index.getPropertyKeyId() ); - for ( IndexRule rule : schemaCache.indexRules() ) { - if ( filter.test( rule ) && rule.getSchemaDescriptor().equals( schemaDescription ) ) + if ( filter.test( rule ) && rule.getSchemaDescriptor().equals( index.schema() ) ) { return rule; } } - return schemaStorage.indexGetForSchema( forLabel( index.getLabelId(), index.getPropertyKeyId() ), filter ); + return schemaStorage.indexGetForSchema( index.schema(), filter ); } @Override @@ -299,7 +286,7 @@ public String indexGetFailure( IndexDescriptor descriptor ) throws IndexNotFound } @Override - public Iterator constraintsGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + public Iterator constraintsGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor ) { return schemaCache.constraintsForLabelAndProperty( descriptor ); } @@ -312,7 +299,7 @@ public Iterator constraintsGetForLabel( int labelId ) @Override public Iterator constraintsGetForRelationshipTypeAndPropertyKey( - RelationshipPropertyDescriptor descriptor ) + RelationTypeSchemaDescriptor descriptor ) { return schemaCache.constraintsForRelationshipTypeAndProperty( descriptor ); } @@ -622,8 +609,8 @@ private Direction directionOf( long nodeId, long relationshipId, long startNode, " with startNode:" + startNode + " and endNode:" + endNode ); } - private static Iterator toIndexDescriptors( Iterable rules ) + private static Iterator toIndexDescriptors( Iterable rules ) { - return Iterators.map( TO_INDEX_RULE, rules.iterator() ); + return Iterators.map( IndexRule::getIndexDescriptor, rules.iterator() ); } } diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java index 58b62ebce6fe2..87bdc660ff283 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java @@ -36,8 +36,9 @@ import org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; -import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.DegreeVisitor; import org.neo4j.kernel.impl.api.RelationshipVisitor; import org.neo4j.kernel.impl.api.store.RelationshipIterator; @@ -57,51 +58,42 @@ public interface StoreReadLayer /** * @param labelId label to list indexes for. - * @return {@link IndexDescriptor} associated with the given {@code labelId}. + * @return {@link NewIndexDescriptor} associated with the given {@code labelId}. */ - Iterator indexesGetForLabel( int labelId ); + Iterator indexesGetForLabel( int labelId ); /** - * @return all {@link IndexDescriptor} in storage. + * @return all {@link NewIndexDescriptor} in storage. */ - Iterator indexesGetAll(); + Iterator indexesGetAll(); /** * @param labelId label to list indexes related to uniqueness constraints for. - * @return {@link IndexDescriptor} related to uniqueness constraints associated with the given {@code labelId}. + * @return {@link NewIndexDescriptor} related to uniqueness constraints associated with the given {@code labelId}. */ - Iterator uniquenessIndexesGetForLabel( int labelId ); + Iterator uniquenessIndexesGetForLabel( int labelId ); /** - * @return all {@link IndexDescriptor} related to uniqueness constraints. + * @return all {@link NewIndexDescriptor} related to uniqueness constraints. */ - Iterator uniquenessIndexesGetAll(); + Iterator uniquenessIndexesGetAll(); /** - * @param index {@link IndexDescriptor} to get related uniqueness constraint for. + * @param index {@link NewIndexDescriptor} to get related uniqueness constraint for. * @return schema rule id of uniqueness constraint that owns the given {@code index}, or {@code null} * if the given index isn't related to a uniqueness constraint. * @throws SchemaRuleNotFoundException if there's no such index matching the given {@code index} in storage. */ - Long indexGetOwningUniquenessConstraintId( IndexDescriptor index ) + Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException; /** - * @param index {@link IndexDescriptor} to get schema rule id for. + * @param index {@link NewIndexDescriptor} to get schema rule id for. * @param filter for type of index to match. * @return schema rule id for matching index. * @throws SchemaRuleNotFoundException if no such index exists in storage. */ - long indexGetCommittedId( IndexDescriptor index, Predicate filter ) - throws SchemaRuleNotFoundException; - - /** - * @param index {@link IndexDescriptor} to get index schema rule for. - * @param filter for type of index to match. - * @return index schema rule for matching index. - * @throws SchemaRuleNotFoundException if no such index exists in storage. - */ - IndexRule indexRule( IndexDescriptor index, Predicate filter ) + long indexGetCommittedId( NewIndexDescriptor index, Predicate filter ) throws SchemaRuleNotFoundException; /** @@ -124,7 +116,7 @@ IndexRule indexRule( IndexDescriptor index, Predicate filter ) * @param descriptor describing the label and property key (or keys) defining the requested constraint. * @return node property constraints associated with the label and one or more property keys token ids. */ - Iterator constraintsGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ); + Iterator constraintsGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor ); /** * @param labelId label token id. @@ -137,7 +129,7 @@ IndexRule indexRule( IndexDescriptor index, Predicate filter ) * @return relationship property constraints associated with the relationship description. */ Iterator constraintsGetForRelationshipTypeAndPropertyKey( - RelationshipPropertyDescriptor descriptor ); + RelationTypeSchemaDescriptor descriptor ); /** * @param typeId relationship type token id . @@ -156,9 +148,9 @@ Iterator constraintsGetForRelationshipTypeAndPro * Looks for a stored index by given {@code descriptor} * * @param descriptor a description of the node . - * @return {@link IndexDescriptor} for matching index, or {@code null} if not found. TODO should throw exception. + * @return {@link NewIndexDescriptor} for matching index, or {@code null} if not found. TODO should throw exception. */ - IndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ); + NewIndexDescriptor indexGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor ); /** * Returns state of a stored index. diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java index fe93a8bd02f50..6af44731a09b8 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java @@ -35,6 +35,9 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations; @@ -71,6 +74,7 @@ public class IndexQueryTransactionStateTest String value = "My Value"; NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId, propertyKeyId ); IndexDescriptor indexDescriptor = IndexDescriptorFactory.of( descriptor ); + List indexes = Collections.singletonList( IndexBoundary.map( indexDescriptor ) ); private StoreReadLayer store; private StoreStatement statement; @@ -93,7 +97,8 @@ public void before() throws Exception .emptyList() ) ); when( store.indexesGetAll() ).then( answerAsIteratorFrom( Collections.emptyList() ) ); when( store.constraintsGetForLabel( labelId ) ).thenReturn( Collections.emptyIterator() ); - when( store.indexGetForLabelAndPropertyKey( descriptor ) ).thenReturn( indexDescriptor ); + when( store.indexGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor ) ) ).thenReturn( + IndexBoundary.map( indexDescriptor ) ); statement = mock( StoreStatement.class ); when( state.getStoreStatement() ).thenReturn( statement ); @@ -190,7 +195,6 @@ public void shouldIncludeCreatedNodesWithCorrectLabelAndProperty() throws Except when( statement.acquireSingleNodeCursor( nodeId ) ).thenReturn( asNodeCursor( nodeId, asPropertyCursor( stringProperty( propertyKeyId, value ) ) ) ); - List indexes = Collections.singletonList( indexDescriptor ); when( store.indexesGetForLabel( labelId ) ).thenReturn( indexes.iterator() ); txContext.nodeAddLabel( state, nodeId, labelId ); @@ -213,7 +217,7 @@ public void shouldIncludeUniqueCreatedNodeWithCorrectLabelAndProperty() throws E when( statement.acquireSingleNodeCursor( nodeId ) ) .thenReturn( asNodeCursor( nodeId, asPropertyCursor( stringProperty( propertyKeyId, value ) ) ) ); - List indexes = Collections.singletonList( indexDescriptor ); + when( store.indexesGetForLabel( labelId ) ).thenReturn( indexes.iterator() ); txContext.nodeAddLabel( state, nodeId, labelId ); @@ -234,7 +238,7 @@ public void shouldIncludeExistingNodesWithCorrectPropertyAfterAddingLabel() thro when( statement.acquireSingleNodeCursor( nodeId ) ) .thenReturn( asNodeCursor( nodeId, asPropertyCursor( stringProperty( propertyKeyId, value ) ) ) ); - List indexes = Collections.singletonList( indexDescriptor ); + when( store.indexesGetForLabel( labelId ) ).thenReturn( indexes.iterator() ); txContext.nodeAddLabel( state, nodeId, labelId ); @@ -257,7 +261,6 @@ public void shouldIncludeExistingUniqueNodeWithCorrectPropertyAfterAddingLabel() asNodeCursor( nodeId, asPropertyCursor( stringProperty( propertyKeyId, value ) ) ) ); - List indexes = Collections.singletonList( indexDescriptor ); when( store.indexesGetForLabel( labelId ) ).thenReturn( indexes.iterator() ); txContext.nodeAddLabel( state, nodeId, labelId ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/LabelTransactionStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/LabelTransactionStateTest.java index 6a068391dbf97..e0e953594bd67 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/LabelTransactionStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/LabelTransactionStateTest.java @@ -36,6 +36,8 @@ import org.neo4j.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.api.StateHandlingStatementOperations; @@ -167,8 +169,7 @@ public void addedLabelsShouldBeReflectedWhenGettingNodesForLabel() throws Except labels( 2, 1, 3 ) ); // WHEN - List indexes = Collections.singletonList( - IndexDescriptorFactory.of( 2, 2 ) ); + List indexes = Collections.singletonList( NewIndexDescriptorFactory.forLabel( 2, 2 ) ); when( store.indexesGetForLabel( 2 ) ).thenReturn( indexes.iterator() ); txContext.nodeAddLabel( state, 2, 2 ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java index 0fdfb5358c508..3f7297f536a39 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java @@ -36,6 +36,10 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.index.InternalIndexState; +import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.api.StateHandlingStatementOperations; @@ -70,9 +74,9 @@ private static IndexDescriptor indexGetForLabelAndPropertyKey( StateHandlingStat return txContext.indexGetForLabelAndPropertyKey( state, new NodePropertyDescriptor( labelId, propertyKey ) ); } - private static IndexDescriptor indexGetForLabelAndPropertyKey( StoreReadLayer store, int labelId, int propertyKey ) + private static NewIndexDescriptor indexGetForLabelAndPropertyKey( StoreReadLayer store, int labelId, int propertyKey ) { - return store.indexGetForLabelAndPropertyKey( new NodePropertyDescriptor( labelId, propertyKey ) ); + return store.indexGetForLabelAndPropertyKey( SchemaDescriptorFactory.forLabel( labelId, propertyKey ) ); } @Test @@ -164,10 +168,10 @@ public void shouldReturnNonExistentRuleAddedInTransactionFromLookup() throws Exc { // GIVEN // -- the store already have an index on the label and a different property - IndexDescriptor existingRule1 = IndexDescriptorFactory.of( labelId1, key1 ); + NewIndexDescriptor existingRule1 = NewIndexDescriptorFactory.forLabel( labelId1, key1 ); when( indexGetForLabelAndPropertyKey( store, labelId1, key1 ) ).thenReturn( existingRule1 ); // -- the store already have an index on a different label with the same property - IndexDescriptor existingRule2 = IndexDescriptorFactory.of( labelId2, key2 ); + NewIndexDescriptor existingRule2 = NewIndexDescriptorFactory.forLabel( labelId2, key2 ); when( indexGetForLabelAndPropertyKey( store, labelId2, key2 ) ).thenReturn( existingRule2 ); // -- a non-existent rule has been added in the transaction indexCreate( txContext, state, labelId1, key2 ); @@ -184,11 +188,11 @@ public void shouldNotReturnRulesAddedInTransactionWithDifferentLabelOrPropertyFr { // GIVEN // -- the store already have an index on the label and a different property - IndexDescriptor existingRule1 = IndexDescriptorFactory.of( labelId1, key1 ); - when( indexGetForLabelAndPropertyKey( store,labelId1, key1) ).thenReturn( existingRule1 ); + NewIndexDescriptor existingIndex1 = NewIndexDescriptorFactory.forLabel( labelId1, key1 ); + when( indexGetForLabelAndPropertyKey( store,labelId1, key1) ).thenReturn( existingIndex1 ); // -- the store already have an index on a different label with the same property - IndexDescriptor existingRule2 = IndexDescriptorFactory.of( labelId2, key2 ); - when( indexGetForLabelAndPropertyKey( store, labelId2, key2 ) ).thenReturn( existingRule2 ); + NewIndexDescriptor existingIndex2 = NewIndexDescriptorFactory.forLabel( labelId2, key2 ); + when( indexGetForLabelAndPropertyKey( store, labelId2, key2 ) ).thenReturn( existingIndex2 ); // -- a non-existent rule has been added in the transaction indexCreate( txContext, state, labelId1, key2 ); @@ -197,8 +201,8 @@ public void shouldNotReturnRulesAddedInTransactionWithDifferentLabelOrPropertyFr IndexDescriptor lookupRule2 = indexGetForLabelAndPropertyKey( txContext, state, labelId2, key2 ); // THEN - assertEquals( existingRule1, lookupRule1 ); - assertEquals( existingRule2, lookupRule2 ); + assertEquals( existingIndex1, IndexBoundary.map( lookupRule1 ) ); + assertEquals( existingIndex2, IndexBoundary.map( lookupRule2 ) ); } @Test @@ -206,10 +210,10 @@ public void shouldNotReturnExistentRuleDroppedInTransaction() throws Exception { // GIVEN // -- a rule that exists in the store - IndexDescriptor rule = IndexDescriptorFactory.of( labelId1, key1 ); + NewIndexDescriptor rule = NewIndexDescriptorFactory.forLabel( labelId1, key1 ); when( store.indexesGetForLabel( labelId1 ) ).thenReturn( option( rule ).iterator() ); // -- that same rule dropped in the transaction - txContext.indexDrop( state, rule ); + txContext.indexDrop( state, IndexBoundary.map( rule ) ); // WHEN assertNull( indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java index 2afa31ee0b119..200d4b6b6b208 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java @@ -22,7 +22,6 @@ import org.junit.Test; import java.util.Collections; -import java.util.Iterator; import java.util.Set; import org.neo4j.collection.primitive.PrimitiveLongCollections; @@ -30,13 +29,15 @@ import org.neo4j.cursor.Cursor; import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Iterators; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.constraints.NodePropertyConstraint; import org.neo4j.kernel.api.constraints.PropertyConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.api.StateHandlingStatementOperations; @@ -59,6 +60,7 @@ import static org.mockito.Mockito.when; import static org.neo4j.helpers.collection.Iterators.asIterable; import static org.neo4j.helpers.collection.Iterators.asSet; +import static org.neo4j.helpers.collection.Iterators.iterator; import static org.neo4j.kernel.api.properties.Property.intProperty; import static org.neo4j.kernel.impl.api.StatementOperationsTestHelper.mockedState; import static org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor; @@ -86,8 +88,7 @@ public void shouldNeverDelegateWrites() throws Exception when( state.txState() ).thenReturn( new TxState() ); StoreStatement storeStatement = mock( StoreStatement.class ); when( state.getStoreStatement() ).thenReturn( storeStatement ); - Iterator indexesIterator = Collections.singletonList( IndexDescriptorFactory.of( 0, 0 ) ).iterator(); - when( inner.indexesGetForLabel( 0 ) ).thenReturn( indexesIterator ); + when( inner.indexesGetForLabel( 0 ) ).thenReturn( iterator( NewIndexDescriptorFactory.forLabel( 0, 0 ) ) ); when( storeStatement.acquireSingleNodeCursor( anyLong() ) ). thenReturn( asNodeCursor( 0 ) ); @@ -114,8 +115,8 @@ public void shouldNotAddConstraintAlreadyExistsInTheStore() throws Exception when( txState.nodesWithLabelChanged( anyInt() ) ).thenReturn( new DiffSets() ); when( txState.hasChanges() ).thenReturn( true ); KernelStatement state = mockedState( txState ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor1 ) ) - .thenAnswer( invocation -> Iterators.iterator( constraint ) ); + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor1 ) ) ) + .thenAnswer( invocation -> iterator( constraint ) ); StateHandlingStatementOperations context = newTxStateOps( inner ); // when @@ -132,7 +133,7 @@ public void shouldGetConstraintsByLabelAndProperty() throws Exception PropertyConstraint constraint = new UniquenessConstraint( descriptor1 ); TransactionState txState = new TxState(); KernelStatement state = mockedState( txState ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor1 ) ) + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor1 ) ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); StateHandlingStatementOperations context = newTxStateOps( inner ); context.uniquePropertyConstraintCreate( state, descriptor1 ); @@ -154,14 +155,14 @@ public void shouldGetConstraintsByLabel() throws Exception TransactionState txState = new TxState(); KernelStatement state = mockedState( txState ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor1 ) ) + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor1 ) ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor2 ) ) + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor2 ) ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); when( inner.constraintsGetForLabel( 10 ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); when( inner.constraintsGetForLabel( 11 ) ) - .thenAnswer( invocation -> Iterators.iterator( constraint1 ) ); + .thenAnswer( invocation -> iterator( constraint1 ) ); StateHandlingStatementOperations context = newTxStateOps( inner ); context.uniquePropertyConstraintCreate( state, descriptor1 ); context.uniquePropertyConstraintCreate( state, descriptor2 ); @@ -182,12 +183,12 @@ public void shouldGetAllConstraints() throws Exception TransactionState txState = new TxState(); KernelStatement state = mockedState( txState ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor1 ) ) + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor1 ) ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); - when( inner.constraintsGetForLabelAndPropertyKey( descriptor2 ) ) + when( inner.constraintsGetForLabelAndPropertyKey( SchemaBoundary.map( descriptor2 ) ) ) .thenAnswer( invocation -> Iterators.emptyIterator() ); when( inner.constraintsGetAll() ) - .thenAnswer( invocation -> Iterators.iterator( constraint2 ) ); + .thenAnswer( invocation -> iterator( constraint2 ) ); StateHandlingStatementOperations context = newTxStateOps( inner ); context.uniquePropertyConstraintCreate( state, descriptor1 ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/SchemaCacheTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/SchemaCacheTest.java index 6bbd5a0d13bd5..6ebc1a790e9cb 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/SchemaCacheTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/SchemaCacheTest.java @@ -28,17 +28,19 @@ import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Iterators; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; -import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; import org.neo4j.kernel.api.constraints.NodePropertyConstraint; import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.PropertyConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; -import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; import org.neo4j.kernel.api.schema_new.constaints.ConstraintBoundary; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics; import org.neo4j.kernel.impl.store.record.ConstraintRule; @@ -47,6 +49,8 @@ import static java.util.Arrays.asList; import static java.util.Collections.singleton; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.neo4j.helpers.collection.Iterators.asSet; @@ -112,11 +116,11 @@ public void should_list_constraints() assertEquals( asSet( new UniquenessConstraint( new NodePropertyDescriptor( 1, 2 ) ) ), - asSet( cache.constraintsForLabelAndProperty( new NodePropertyDescriptor( 1, 2 ) ) ) ); + asSet( cache.constraintsForLabelAndProperty( SchemaDescriptorFactory.forLabel( 1, 2 ) ) ) ); assertEquals( asSet(), - asSet( cache.constraintsForLabelAndProperty( new NodePropertyDescriptor( 1, 3 ) ) ) ); + asSet( cache.constraintsForLabelAndProperty( SchemaDescriptorFactory.forLabel( 1, 3 ) ) ) ); assertEquals( asSet( new RelationshipPropertyExistenceConstraint( new RelationshipPropertyDescriptor( 5, 6 ) ) ), @@ -124,7 +128,8 @@ public void should_list_constraints() assertEquals( asSet( new RelationshipPropertyExistenceConstraint( new RelationshipPropertyDescriptor( 5, 6 ) ) ), - asSet( cache.constraintsForRelationshipTypeAndProperty( new RelationshipPropertyDescriptor( 5, 6 ) ) ) ); + asSet( cache.constraintsForRelationshipTypeAndProperty( SchemaDescriptorFactory.forRelType( 5, 6 ) ) + ) ); } @Test @@ -150,7 +155,7 @@ public void should_remove_constraints() assertEquals( asSet(), - asSet( cache.constraintsForLabelAndProperty( new NodePropertyDescriptor( 1, 2 ) ) ) ); + asSet( cache.constraintsForLabelAndProperty( SchemaDescriptorFactory.forLabel( 1, 2 ) ) ) ); } @Test @@ -181,11 +186,11 @@ public void shouldResolveIndexDescriptor() throws Exception cache.addSchemaRule( newIndexRule( 3L, 2, 2 ) ); // When - IndexDescriptor descriptor = cache.indexDescriptor( new NodePropertyDescriptor( 1, 3 ) ); + LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( 1, 3 ); + NewIndexDescriptor descriptor = cache.indexDescriptor( schema ); // Then - assertEquals( 1, descriptor.getLabelId() ); - assertEquals( 3, descriptor.getPropertyKeyId() ); + assertThat( descriptor.schema(), equalTo( schema ) ); } @Test @@ -195,7 +200,7 @@ public void shouldReturnNullWhenNoIndexExists() SchemaCache schemaCache = newSchemaCache(); // When - IndexDescriptor indexDescriptor = schemaCache.indexDescriptor( new NodePropertyDescriptor( 1, 1 ) ); + NewIndexDescriptor indexDescriptor = schemaCache.indexDescriptor( SchemaDescriptorFactory.forLabel( 1, 1 ) ); // Then assertNull( indexDescriptor ); @@ -232,7 +237,8 @@ public void shouldListConstraintsForLabelAndProperty() SchemaCache cache = newSchemaCache( rule1, rule2, rule3 ); // When - Set listed = asSet( cache.constraintsForLabelAndProperty( new NodePropertyDescriptor( 1, 2 ) ) ); + Set listed = asSet( cache.constraintsForLabelAndProperty( + SchemaDescriptorFactory.forLabel( 1, 2 ) ) ); // Then assertEquals( singleton( ConstraintBoundary.mapNode( rule3.getConstraintDescriptor() ) ), listed ); @@ -269,7 +275,8 @@ public void shouldListConstraintsForRelationshipTypeAndProperty() SchemaCache cache = newSchemaCache( rule1, rule2, rule3 ); // When - Set listed = asSet( cache.constraintsForRelationshipTypeAndProperty( new RelationshipPropertyDescriptor( 2, 1 ) ) ); + Set listed = asSet( cache.constraintsForRelationshipTypeAndProperty( + SchemaDescriptorFactory.forRelType( 2, 1 ) ) ); // Then assertEquals( singleton( ConstraintBoundary.mapRelationship( rule2.getConstraintDescriptor() ) ), listed ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaTest.java index 70dceb9f1a684..c4375c926d3f9 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaTest.java @@ -29,6 +29,8 @@ import org.neo4j.kernel.api.constraints.NodePropertyConstraint; import org.neo4j.kernel.api.constraints.PropertyConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; import static org.junit.Assert.assertEquals; import static org.neo4j.helpers.collection.Iterators.asSet; @@ -82,7 +84,7 @@ public void shouldListAllConstraintsForLabelAndProperty() // When Set constraints = asSet( - disk.constraintsGetForLabelAndPropertyKey( descriptorFrom( label1, propertyKey ) ) ); + disk.constraintsGetForLabelAndPropertyKey( newDescriptorFrom( label1, propertyKey ) ) ); // Then Set expectedConstraints = asSet( @@ -104,4 +106,9 @@ private NodePropertyDescriptor descriptorFrom( Label label, String propertyKey ) { return new NodePropertyDescriptor( labelId( label ), propertyKeyId( propertyKey ) ); } + + private LabelSchemaDescriptor newDescriptorFrom( Label label, String propertyKey ) + { + return SchemaDescriptorFactory.forLabel( labelId( label ), propertyKeyId( propertyKey ) ); + } } diff --git a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaWithPECTest.java b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaWithPECTest.java index 6cbd6b6c0a196..94d55daac225f 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaWithPECTest.java +++ b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerSchemaWithPECTest.java @@ -34,6 +34,8 @@ import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; import org.neo4j.test.TestEnterpriseGraphDatabaseFactory; import static org.junit.Assert.assertEquals; @@ -118,7 +120,8 @@ public void shouldListAllConstraintsForLabelAndProperty() // When NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId( label1 ), propertyKeyId( propertyKey ) ); - Set constraints = asSet( disk.constraintsGetForLabelAndPropertyKey( descriptor ) ); + Set constraints = asSet( disk.constraintsGetForLabelAndPropertyKey( + SchemaBoundary.map( descriptor ) ) ); // Then Set expectedConstraints = asSet( @@ -141,7 +144,7 @@ public void shouldListAllConstraintsForRelationshipType() Set constraints = asSet( disk.constraintsGetForRelationshipType( relTypeId ) ); // Then - Set expectedConstraints = Iterators.asSet( + Set expectedConstraints = Iterators.asSet( new RelationshipPropertyExistenceConstraint( new RelationshipPropertyDescriptor( relTypeId, propertyKeyId( propertyKey ) ) ), new RelationshipPropertyExistenceConstraint( @@ -165,10 +168,10 @@ public void shouldListAllConstraintsForRelationshipTypeAndProperty() int propKeyId = propertyKeyId( propertyKey ); Set constraints = asSet( disk.constraintsGetForRelationshipTypeAndPropertyKey( - new RelationshipPropertyDescriptor( relTypeId, propKeyId ) ) ); + SchemaDescriptorFactory.forRelType( relTypeId, propKeyId ) ) ); // Then - Set expectedConstraints = Iterators.asSet( + Set expectedConstraints = Iterators.asSet( new RelationshipPropertyExistenceConstraint( new RelationshipPropertyDescriptor( relTypeId, propKeyId ) ) );