Skip to content

Commit

Permalink
Fixed inheritance issues with AbstractSchemaRule and couple minor cle…
Browse files Browse the repository at this point in the history
…anups
  • Loading branch information
lutovich committed Jul 17, 2015
1 parent e64a352 commit fe7c513
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 164 deletions.
Expand Up @@ -31,7 +31,7 @@
public interface ConstraintDefinition public interface ConstraintDefinition
{ {
/** /**
* This accessor method returns a label which this constraint is associated with iff this constraint has type * This accessor method returns a label which this constraint is associated with if this constraint has type
* {@link ConstraintType#UNIQUENESS} or {@link ConstraintType#MANDATORY_NODE_PROPERTY}. * {@link ConstraintType#UNIQUENESS} or {@link ConstraintType#MANDATORY_NODE_PROPERTY}.
* Type of the constraint can be examined by calling {@link #getConstraintType()} or * Type of the constraint can be examined by calling {@link #getConstraintType()} or
* {@link #isConstraintType(ConstraintType)} methods. * {@link #isConstraintType(ConstraintType)} methods.
Expand All @@ -42,7 +42,7 @@ public interface ConstraintDefinition
Label getLabel(); Label getLabel();


/** /**
* This accessor method returns a relationship type which this constraint is associated with iff this constraint * This accessor method returns a relationship type which this constraint is associated with if this constraint
* has type {@link ConstraintType#UNIQUENESS} or {@link ConstraintType#MANDATORY_NODE_PROPERTY}. * has type {@link ConstraintType#UNIQUENESS} or {@link ConstraintType#MANDATORY_NODE_PROPERTY}.
* Type of the constraint can be examined by calling {@link #getConstraintType()} or * Type of the constraint can be examined by calling {@link #getConstraintType()} or
* {@link #isConstraintType(ConstraintType)} methods. * {@link #isConstraintType(ConstraintType)} methods.
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.function.Predicate; import org.neo4j.function.Predicate;
import org.neo4j.function.Predicates;
import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.Direction;
import org.neo4j.helpers.collection.FilteringIterator; import org.neo4j.helpers.collection.FilteringIterator;
import org.neo4j.kernel.api.constraints.MandatoryNodePropertyConstraint; import org.neo4j.kernel.api.constraints.MandatoryNodePropertyConstraint;
Expand Down Expand Up @@ -66,6 +67,9 @@


public class ConstraintEnforcingEntityOperations implements EntityOperations, SchemaWriteOperations public class ConstraintEnforcingEntityOperations implements EntityOperations, SchemaWriteOperations
{ {
private static final Predicate<NodePropertyConstraint> UNIQUENESS_CONSTRAINT =
Predicates.instanceOf( UniquenessConstraint.class );

private final EntityWriteOperations entityWriteOperations; private final EntityWriteOperations entityWriteOperations;
private final EntityReadOperations entityReadOperations; private final EntityReadOperations entityReadOperations;
private final SchemaWriteOperations schemaWriteOperations; private final SchemaWriteOperations schemaWriteOperations;
Expand Down Expand Up @@ -162,14 +166,7 @@ private void assertIndexOnline( KernelStatement state, IndexDescriptor indexDesc


private Iterator<NodePropertyConstraint> uniquePropertyConstraints( Iterator<NodePropertyConstraint> constraints ) private Iterator<NodePropertyConstraint> uniquePropertyConstraints( Iterator<NodePropertyConstraint> constraints )
{ {
return new FilteringIterator<>( constraints, new Predicate<NodePropertyConstraint>() return new FilteringIterator<>( constraints, UNIQUENESS_CONSTRAINT );
{
@Override
public boolean test( NodePropertyConstraint constraint )
{
return constraint instanceof UniquenessConstraint;
}
} );
} }


// Simply delegate the rest of the invocations // Simply delegate the rest of the invocations
Expand Down
Expand Up @@ -25,6 +25,7 @@


import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.function.Predicate; import org.neo4j.function.Predicate;
import org.neo4j.function.Predicates;
import org.neo4j.helpers.collection.FilteringIterator; import org.neo4j.helpers.collection.FilteringIterator;
import org.neo4j.kernel.api.constraints.MandatoryNodePropertyConstraint; import org.neo4j.kernel.api.constraints.MandatoryNodePropertyConstraint;
import org.neo4j.kernel.api.constraints.MandatoryRelationshipPropertyConstraint; import org.neo4j.kernel.api.constraints.MandatoryRelationshipPropertyConstraint;
Expand All @@ -45,6 +46,12 @@


public class MandatoryPropertyEnforcer extends TxStateVisitor.Adapter public class MandatoryPropertyEnforcer extends TxStateVisitor.Adapter
{ {
private static final Predicate<NodePropertyConstraint> MANDATORY_NODE_PROPERTY_CONSTRAINT =
Predicates.instanceOf( MandatoryNodePropertyConstraint.class );

private static final Predicate<RelationshipPropertyConstraint> MANDATORY_RELATIONSHIP_PROPERTY_CONSTRAINT =
Predicates.instanceOf( MandatoryRelationshipPropertyConstraint.class );

private final EntityReadOperations readOperations; private final EntityReadOperations readOperations;
private final StoreReadLayer storeLayer; private final StoreReadLayer storeLayer;
private final StoreStatement storeStatement; private final StoreStatement storeStatement;
Expand Down Expand Up @@ -176,26 +183,12 @@ private PrimitiveIntIterator labelsOf( long nodeId )
private Iterator<NodePropertyConstraint> mandatoryNodePropertyConstraints( int label ) private Iterator<NodePropertyConstraint> mandatoryNodePropertyConstraints( int label )
{ {
return new FilteringIterator<>( storeLayer.constraintsGetForLabel( label ), return new FilteringIterator<>( storeLayer.constraintsGetForLabel( label ),
new Predicate<NodePropertyConstraint>() MANDATORY_NODE_PROPERTY_CONSTRAINT );
{
@Override
public boolean test( NodePropertyConstraint constraint )
{
return constraint instanceof MandatoryNodePropertyConstraint;
}
} );
} }


private Iterator<RelationshipPropertyConstraint> mandatoryRelPropertyConstraints( int type ) private Iterator<RelationshipPropertyConstraint> mandatoryRelPropertyConstraints( int type )
{ {
return new FilteringIterator<>( storeLayer.constraintsGetForRelationshipType( type ), return new FilteringIterator<>( storeLayer.constraintsGetForRelationshipType( type ),
new Predicate<RelationshipPropertyConstraint>() MANDATORY_RELATIONSHIP_PROPERTY_CONSTRAINT );
{
@Override
public boolean test( RelationshipPropertyConstraint constraint )
{
return constraint instanceof MandatoryRelationshipPropertyConstraint;
}
} );
} }
} }
Expand Up @@ -29,12 +29,14 @@ public class MandatoryNodePropertyConstraintRule extends NodePropertyConstraintR
{ {
private final int propertyKeyId; private final int propertyKeyId;


public static MandatoryNodePropertyConstraintRule mandatoryNodePropertyConstraintRule( long id, int labelId, int propertyKeyId ) public static MandatoryNodePropertyConstraintRule mandatoryNodePropertyConstraintRule( long id, int labelId,
int propertyKeyId )
{ {
return new MandatoryNodePropertyConstraintRule( id, labelId, propertyKeyId ); return new MandatoryNodePropertyConstraintRule( id, labelId, propertyKeyId );
} }


public static MandatoryNodePropertyConstraintRule readMandatoryNodePropertyConstraintRule( long id, int labelId, ByteBuffer buffer ) public static MandatoryNodePropertyConstraintRule readMandatoryNodePropertyConstraintRule( long id, int labelId,
ByteBuffer buffer )
{ {
return new MandatoryNodePropertyConstraintRule( id, labelId, readPropertyKey( buffer ) ); return new MandatoryNodePropertyConstraintRule( id, labelId, readPropertyKey( buffer ) );
} }
Expand All @@ -46,34 +48,25 @@ private MandatoryNodePropertyConstraintRule( long id, int labelId, int propertyK
} }


@Override @Override
public int hashCode() public String toString()
{
return super.hashCode() | propertyKeyId;
}

@Override
public boolean equals( Object obj )
{ {
return super.equals( obj ) && propertyKeyId == ((MandatoryNodePropertyConstraintRule) obj).propertyKeyId; return "MandatoryNodePropertyConstraintRule[id=" + id + ", label=" + label + ", kind=" + kind +
} ", propertyKeyId=" + propertyKeyId + "]";

@Override
protected String innerToString()
{
return ", propertyKey=" + propertyKeyId;
} }


@Override @Override
public int length() public int length()
{ {
return super.length() + return 4 /* label id */ +
4; /* propertyKeyId */ 1 /* kind id */ +
4; /* property key id */
} }


@Override @Override
public void serialize( ByteBuffer target ) public void serialize( ByteBuffer target )
{ {
super.serialize( target ); target.putInt( label );
target.put( kind.id() );
target.putInt( propertyKeyId ); target.putInt( propertyKeyId );
} }


Expand All @@ -98,4 +91,29 @@ public boolean containsPropertyKeyId( int propertyKeyId )
{ {
return propertyKeyId == this.propertyKeyId; return propertyKeyId == this.propertyKeyId;
} }

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
if ( !super.equals( o ) )
{
return false;
}
return propertyKeyId == ((MandatoryNodePropertyConstraintRule) o).propertyKeyId;

}

@Override
public int hashCode()
{
return 31 * super.hashCode() + propertyKeyId;
}
} }
Expand Up @@ -28,12 +28,14 @@ public class MandatoryRelationshipPropertyConstraintRule extends RelationshipPro
{ {
private final int propertyKeyId; private final int propertyKeyId;


public static MandatoryRelationshipPropertyConstraintRule mandatoryRelPropertyConstraintRule( long id, int relTypeId, int propertyKeyId ) public static MandatoryRelationshipPropertyConstraintRule mandatoryRelPropertyConstraintRule( long id,
int relTypeId, int propertyKeyId )
{ {
return new MandatoryRelationshipPropertyConstraintRule( id, relTypeId, propertyKeyId ); return new MandatoryRelationshipPropertyConstraintRule( id, relTypeId, propertyKeyId );
} }


public static MandatoryRelationshipPropertyConstraintRule readMandatoryRelPropertyConstraintRule( long id, int relTypeId, ByteBuffer buffer ) public static MandatoryRelationshipPropertyConstraintRule readMandatoryRelPropertyConstraintRule( long id,
int relTypeId, ByteBuffer buffer )
{ {
return new MandatoryRelationshipPropertyConstraintRule( id, relTypeId, readPropertyKey( buffer ) ); return new MandatoryRelationshipPropertyConstraintRule( id, relTypeId, readPropertyKey( buffer ) );
} }
Expand All @@ -45,34 +47,25 @@ private MandatoryRelationshipPropertyConstraintRule( long id, int relTypeId, int
} }


@Override @Override
public int hashCode() public String toString()
{
return super.hashCode() | propertyKeyId;
}

@Override
public boolean equals( Object obj )
{
return super.equals( obj ) && propertyKeyId == ((MandatoryRelationshipPropertyConstraintRule) obj).propertyKeyId;
}

@Override
protected String innerToString()
{ {
return ", propertyKey=" + propertyKeyId; return "MandatoryRelationshipPropertyConstraint" + id + ", relationshipType=" + relationshipType +
", kind=" + kind + ", propertyKeyId=" + propertyKeyId + "]";
} }


@Override @Override
public int length() public int length()
{ {
return super.length() + return 4 /* relationship type id */ +
4; /* propertyKeyId */ 1 /* kind id */ +
4; /* property key id */
} }


@Override @Override
public void serialize( ByteBuffer target ) public void serialize( ByteBuffer target )
{ {
super.serialize( target ); target.putInt( relationshipType );
target.put( kind.id() );
target.putInt( propertyKeyId ); target.putInt( propertyKeyId );
} }


Expand All @@ -97,4 +90,28 @@ public boolean containsPropertyKeyId( int propertyKeyId )
{ {
return propertyKeyId == this.propertyKeyId; return propertyKeyId == this.propertyKeyId;
} }

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
if ( !super.equals( o ) )
{
return false;
}
return propertyKeyId == ((MandatoryRelationshipPropertyConstraintRule) o).propertyKeyId;
}

@Override
public int hashCode()
{
return 31 * super.hashCode() + propertyKeyId;
}
} }
Expand Up @@ -23,15 +23,18 @@


public abstract class NodePropertyConstraintRule extends PropertyConstraintRule public abstract class NodePropertyConstraintRule extends PropertyConstraintRule
{ {
protected final int label;

public NodePropertyConstraintRule( long id, int label, Kind kind ) public NodePropertyConstraintRule( long id, int label, Kind kind )
{ {
super( id, label, NOT_INITIALIZED, kind ); super( id, kind );
this.label = label;
} }


@Override @Override
public final int getLabel() public final int getLabel()
{ {
return getLabelOrRelationshipType(); return label;
} }


@Override @Override
Expand All @@ -42,4 +45,29 @@ public final int getRelationshipType()


@Override @Override
public abstract NodePropertyConstraint toConstraint(); public abstract NodePropertyConstraint toConstraint();

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
if ( !super.equals( o ) )
{
return false;
}
return label == ((NodePropertyConstraintRule) o).label;

}

@Override
public int hashCode()
{
return 31 * super.hashCode() + label;
}
} }
Expand Up @@ -25,9 +25,9 @@


public abstract class PropertyConstraintRule extends AbstractSchemaRule public abstract class PropertyConstraintRule extends AbstractSchemaRule
{ {
PropertyConstraintRule( long id, int label, int relationshipType, Kind kind ) PropertyConstraintRule( long id, Kind kind )
{ {
super( id, label, relationshipType, kind ); super( id, kind );
} }


public abstract PropertyConstraint toConstraint(); public abstract PropertyConstraint toConstraint();
Expand Down
Expand Up @@ -23,9 +23,12 @@


public abstract class RelationshipPropertyConstraintRule extends PropertyConstraintRule public abstract class RelationshipPropertyConstraintRule extends PropertyConstraintRule
{ {
protected final int relationshipType;

public RelationshipPropertyConstraintRule( long id, int relationshipType, Kind kind ) public RelationshipPropertyConstraintRule( long id, int relationshipType, Kind kind )
{ {
super( id, NOT_INITIALIZED, relationshipType, kind ); super( id, kind );
this.relationshipType = relationshipType;
} }


@Override @Override
Expand All @@ -37,9 +40,33 @@ public final int getLabel()
@Override @Override
public final int getRelationshipType() public final int getRelationshipType()
{ {
return getLabelOrRelationshipType(); return relationshipType;
} }


@Override @Override
public abstract RelationshipPropertyConstraint toConstraint(); public abstract RelationshipPropertyConstraint toConstraint();

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
if ( !super.equals( o ) )
{
return false;
}
return relationshipType == ((RelationshipPropertyConstraintRule) o).relationshipType;
}

@Override
public int hashCode()
{
return 31 * super.hashCode() + relationshipType;
}
} }

0 comments on commit fe7c513

Please sign in to comment.