Skip to content

Commit

Permalink
Remove the old NodePropertyDescriptor
Browse files Browse the repository at this point in the history
Also the `NodeMultiPropertyDescriptor`
  • Loading branch information
ragadeeshu committed Mar 17, 2017
1 parent 22ae1ee commit 9f72f77
Show file tree
Hide file tree
Showing 63 changed files with 212 additions and 450 deletions.
Expand Up @@ -23,7 +23,6 @@

import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.store.RecordAccessStub;
import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.impl.store.SchemaStorage;
Expand Down
Expand Up @@ -30,7 +30,6 @@ import org.neo4j.kernel.api.constraints.UniquenessConstraint
import org.neo4j.kernel.api.exceptions.KernelException
import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.{ConstraintBoundary, ConstraintDescriptor}
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
Expand All @@ -46,7 +45,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
val labelId = tc.statement.readOperations().labelGetForName(labelName)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

getOnlineIndex(tc.statement.readOperations().indexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId)))
getOnlineIndex(tc.statement.readOperations().indexGetForLabelAndPropertyKey(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
}

def hasIndexRule(labelName: String): Boolean = {
Expand All @@ -63,7 +62,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

// here we do not need to use getOnlineIndex method because uniqueness constraint creation is synchronous
Some(tc.statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId)))
Some(tc.statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
}

private def evalOrNone[T](f: => Option[T]): Option[T] =
Expand Down
Expand Up @@ -49,7 +49,6 @@ import org.neo4j.kernel.api.constraints.{NodePropertyExistenceConstraint, Relati
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.schema_new.IndexQuery
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.{ConstraintBoundary, ConstraintDescriptorFactory}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
Expand Down Expand Up @@ -458,7 +457,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
} catch {
case _: AlreadyIndexedException =>

val indexDescriptor = tc.statement.readOperations().indexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId))
val indexDescriptor = tc.statement.readOperations().indexGetForLabelAndPropertyKey( SchemaDescriptorFactory.forLabel(labelId, propertyKeyId))

if (tc.statement.readOperations().indexGetState(indexDescriptor) == InternalIndexState.FAILED)
throw new FailedIndexException(indexDescriptor.userDescription(tokenNameLookup))
Expand Down
Expand Up @@ -36,7 +36,6 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType
import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.{ConstraintBoundary, ConstraintDescriptor}
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
Expand All @@ -53,7 +52,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter
val labelId = tc.statement.readOperations().labelGetForName(labelName)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

getOnlineIndex(tc.statement.readOperations().indexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId)))
getOnlineIndex(tc.statement.readOperations().indexGetForLabelAndPropertyKey(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
}

def hasIndexRule(labelName: String): Boolean = {
Expand All @@ -70,7 +69,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

// here we do not need to use getOnlineIndex method because uniqueness constraint creation is synchronous
Some(tc.statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId)))
Some(tc.statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
}

private def evalOrNone[T](f: => Option[T]): Option[T] =
Expand Down
Expand Up @@ -54,7 +54,6 @@ import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, Alre
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema_new.IndexQuery
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.{ConstraintBoundary, ConstraintDescriptorFactory}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
Expand Down Expand Up @@ -463,7 +462,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
IdempotentResult(txContext.statement.schemaWriteOperations().indexCreate( SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
} catch {
case _: AlreadyIndexedException =>
val indexDescriptor = txContext.statement.readOperations().indexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId))
val indexDescriptor = txContext.statement.readOperations().indexGetForLabelAndPropertyKey(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId))
if(txContext.statement.readOperations().indexGetState(indexDescriptor) == InternalIndexState.FAILED)
throw new FailedIndexException(indexDescriptor.userDescription(tokenNameLookup))
IdempotentResult(indexDescriptor, wasCreated = false)
Expand Down
Expand Up @@ -53,7 +53,8 @@ import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, Alre
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.CallableUserAggregationFunction.Aggregator
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.IndexQuery
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema_new.{IndexQuery, SchemaDescriptorFactory}
import org.neo4j.kernel.impl.core.NodeManager
Expand Down Expand Up @@ -470,7 +471,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
IdempotentResult(transactionalContext.statement.schemaWriteOperations().indexCreate( descriptor ))
} catch {
case _: AlreadyIndexedException =>
val indexDescriptor = transactionalContext.statement.readOperations().indexGetForLabelAndPropertyKey(new NodePropertyDescriptor( descriptor.label, descriptor.property))
val indexDescriptor = transactionalContext.statement.readOperations().indexGetForLabelAndPropertyKey (SchemaDescriptorFactory.forLabel(descriptor.getLabelId, descriptor.getPropertyId));
if(transactionalContext.statement.readOperations().indexGetState(indexDescriptor) == InternalIndexState.FAILED)
throw new FailedIndexException(indexDescriptor.userDescription(tokenNameLookup))
IdempotentResult(indexDescriptor, wasCreated = false)
Expand Down
Expand Up @@ -29,9 +29,6 @@
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.cursor.Cursor;
import org.neo4j.graphdb.Direction;
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.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.ProcedureException;
Expand All @@ -47,8 +44,8 @@
import org.neo4j.kernel.api.proc.ProcedureSignature;
import org.neo4j.kernel.api.proc.QualifiedName;
import org.neo4j.kernel.api.proc.UserFunctionSignature;
import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.schema_new.IndexQuery;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
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.NewIndexDescriptor;
Expand Down Expand Up @@ -228,7 +225,7 @@ <EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVi
//===========================================

/** Returns the index rule for the given labelId and propertyKey. */
NewIndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor )
NewIndexDescriptor indexGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor )
throws SchemaRuleNotFoundException;

/** Get all indexes for a label. */
Expand All @@ -238,7 +235,7 @@ NewIndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descri
Iterator<NewIndexDescriptor> indexesGetAll();

/** Returns the constraint index for the given labelId and propertyKey. */
NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor )
NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor )
throws SchemaRuleNotFoundException, DuplicateSchemaRuleException;

/** Get all constraint indexes for a label. */
Expand Down
Expand Up @@ -20,17 +20,16 @@
package org.neo4j.kernel.api.constraints;

import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;

/**
* Base class describing property constraint on nodes.
*/
public abstract class NodePropertyConstraint implements PropertyConstraint
{
protected final NodePropertyDescriptor descriptor;
protected final LabelSchemaDescriptor descriptor;

public NodePropertyConstraint( NodePropertyDescriptor descriptor )
public NodePropertyConstraint( LabelSchemaDescriptor descriptor )
{
this.descriptor = descriptor;
}
Expand All @@ -40,21 +39,16 @@ public final int label()
return descriptor.getLabelId();
}

public NodePropertyDescriptor descriptor()
public LabelSchemaDescriptor descriptor()
{
return descriptor;
}

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];
descriptor.getPropertyId() == other.getPropertyIds()[0];
// this is safe because we are replacing this class before introducing composite constraints
}

Expand Down
Expand Up @@ -19,16 +19,16 @@
*/
package org.neo4j.kernel.api.constraints;

import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;

/**
* Description of constraint enforcing nodes to contain a certain property.
*/
public class NodePropertyExistenceConstraint extends NodePropertyConstraint
{
public NodePropertyExistenceConstraint( NodePropertyDescriptor descriptor )
public NodePropertyExistenceConstraint( LabelSchemaDescriptor descriptor )
{
super( descriptor );
}
Expand All @@ -52,13 +52,13 @@ public String userDescription( TokenNameLookup tokenNameLookup )
String boundIdentifier = labelName.toLowerCase();
return String.format( "CONSTRAINT ON ( %s:%s ) ASSERT exists(%s.%s)",
boundIdentifier, labelName, boundIdentifier,
descriptor.propertyNameText( tokenNameLookup ) );
tokenNameLookup.labelGetName( descriptor.getLabelId() ) );
}

@Override
public String toString()
{
return String.format( "CONSTRAINT ON ( n:label[%s] ) ASSERT exists(n.property[%s])",
descriptor.getLabelId(), descriptor.propertyIdText() );
return String.format( "CONSTRAINT ON ( n:label[%d] ) ASSERT exists(n.property[%d])",
descriptor.getLabelId(), descriptor.getPropertyId() );
}
}
Expand Up @@ -19,9 +19,9 @@
*/
package org.neo4j.kernel.api.constraints;

import org.neo4j.kernel.api.schema.EntityPropertyDescriptor;
import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.schema_new.SchemaDescriptor;

/**
* Interface describing a property constraint.
Expand Down Expand Up @@ -49,7 +49,7 @@ void visitAddedRelationshipPropertyExistenceConstraint( RelationshipPropertyExis

void removed( ChangeVisitor visitor );

EntityPropertyDescriptor descriptor();
SchemaDescriptor descriptor();

String userDescription( TokenNameLookup tokenNameLookup );

Expand Down
Expand Up @@ -20,7 +20,10 @@
package org.neo4j.kernel.api.constraints;

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.SchemaBoundary;
import org.neo4j.kernel.api.schema_new.SchemaDescriptor;

/**
* Base class describing property constraint on relationships.
Expand All @@ -35,9 +38,9 @@ public RelationshipPropertyConstraint( RelationshipPropertyDescriptor descriptor
}

@Override
public final RelationshipPropertyDescriptor descriptor()
public final SchemaDescriptor descriptor()
{
return descriptor;
return SchemaBoundary.map( descriptor );
}

public boolean matches( RelationshipPropertyDescriptor descriptor )
Expand All @@ -49,7 +52,7 @@ public boolean matches( RelationTypeSchemaDescriptor other )
{
return other != null &&
descriptor.getRelationshipTypeId() == other.getRelTypeId() &&
descriptor.getPropertyKeyId() == other.getPropertyIds()[0];
descriptor.getPropertyId() == other.getPropertyIds()[0];
// this is safe because we are replacing this class before introducing composite constraints
}

Expand Down
Expand Up @@ -58,6 +58,6 @@ public String userDescription( TokenNameLookup tokenNameLookup )
public String toString()
{
return String.format( "CONSTRAINT ON ()-[ n:relationshipType[%s] ]-() ASSERT exists(n.property[%s])",
descriptor.getRelationshipTypeId(), descriptor.propertyIdText() );
descriptor.getRelationshipTypeId(), descriptor.getPropertyId() );
}
}
Expand Up @@ -19,9 +19,8 @@
*/
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_new.SchemaBoundary;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory;

Expand All @@ -30,14 +29,14 @@
*/
public class UniquenessConstraint extends NodePropertyConstraint
{
public UniquenessConstraint( NodePropertyDescriptor descriptor )
public UniquenessConstraint( LabelSchemaDescriptor descriptor )
{
super( descriptor );
}

public NewIndexDescriptor indexDescriptor()
{
return NewIndexDescriptorFactory.forSchema( SchemaBoundary.map( descriptor ) );
return NewIndexDescriptorFactory.forSchema( descriptor );
}

@Override
Expand All @@ -57,14 +56,15 @@ public String userDescription( TokenNameLookup tokenNameLookup )
{
String labelName = labelName( tokenNameLookup );
String boundIdentifier = labelName.toLowerCase();
return String.format( "CONSTRAINT ON ( %s:%s ) ASSERT %s.%s IS UNIQUE",
boundIdentifier, labelName, boundIdentifier, descriptor.propertyNameText( tokenNameLookup ) );
return String
.format( "CONSTRAINT ON ( %s:%s ) ASSERT %s.%s IS UNIQUE", boundIdentifier, labelName, boundIdentifier,
tokenNameLookup.labelGetName( descriptor.getLabelId() ) );
}

@Override
public String toString()
{
return String.format( "CONSTRAINT ON ( n:label[%s] ) ASSERT n.property[%s] IS UNIQUE",
descriptor.getLabelId(), descriptor.propertyIdText() );
return String.format( "CONSTRAINT ON ( n:label[%d] ) ASSERT n.property[%d] IS UNIQUE",
descriptor.getLabelId(), descriptor.getPropertyId() );
}
}
Expand Up @@ -19,25 +19,25 @@
*/
package org.neo4j.kernel.api.exceptions.index;

import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;

public class IndexPopulationFailedKernelException extends KernelException
{
private static final String FORMAT_MESSAGE = "Failed to populate index for %s [labelId: %d, propertyKeyId %s]";

public IndexPopulationFailedKernelException( NodePropertyDescriptor descriptor, String indexUserDescription,
public IndexPopulationFailedKernelException( LabelSchemaDescriptor descriptor, String indexUserDescription,
Throwable cause )
{
super( Status.Schema.IndexCreationFailed, cause, FORMAT_MESSAGE, indexUserDescription,
descriptor.getLabelId(), descriptor.propertyIdText() );
descriptor.getLabelId(), descriptor.getPropertyId() );
}

public IndexPopulationFailedKernelException( NodePropertyDescriptor descriptor, String indexUserDescription,
public IndexPopulationFailedKernelException( LabelSchemaDescriptor descriptor, String indexUserDescription,
String message )
{
super( Status.Schema.IndexCreationFailed, FORMAT_MESSAGE + ", due to " + message,
indexUserDescription, descriptor.getLabelId(), descriptor.propertyIdText() );
indexUserDescription, descriptor.getLabelId(), descriptor.getPropertyId() );
}
}

0 comments on commit 9f72f77

Please sign in to comment.