Skip to content

Commit

Permalink
Cleanup of schema processors and computers
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Jun 15, 2018
1 parent 854aeac commit e0759eb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 76 deletions.
Expand Up @@ -26,8 +26,8 @@
import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.store.RecordAccess;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaProcessor;
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
Expand Down Expand Up @@ -250,24 +250,18 @@ static class CheckSchema implements SchemaProcessor
public void processSpecific( LabelSchemaDescriptor schema )
{
engine.comparativeCheck( records.label( schema.getLabelId() ), VALID_LABEL );
for ( int propertyId : schema.getPropertyIds() )
{
engine.comparativeCheck( records.propertyKey( propertyId ), VALID_PROPERTY_KEY );
}
checkProperties( schema.getPropertyIds() );
}

@Override
public void processSpecific( RelationTypeSchemaDescriptor schema )
{
engine.comparativeCheck( records.relationshipType( schema.getRelTypeId() ), VALID_RELATIONSHIP_TYPE );
for ( int propertyId : schema.getPropertyIds() )
{
engine.comparativeCheck( records.propertyKey( propertyId ), VALID_PROPERTY_KEY );
}
checkProperties( schema.getPropertyIds() );
}

@Override
public void processSpecific( MultiTokenSchemaDescriptor schema )
public void processSpecific( SchemaDescriptor schema )
{
switch ( schema.entityType() )
{
Expand All @@ -287,7 +281,12 @@ public void processSpecific( MultiTokenSchemaDescriptor schema )
throw new IllegalArgumentException( "Schema with given entity type is not supported: " + schema.entityType() );
}

for ( int propertyId : schema.getPropertyIds() )
checkProperties( schema.getPropertyIds() );
}

private void checkProperties( int[] propertyIds )
{
for ( int propertyId : propertyIds )
{
engine.comparativeCheck( records.propertyKey( propertyId ), VALID_PROPERTY_KEY );
}
Expand Down
Expand Up @@ -32,8 +32,8 @@
import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.report.ConsistencyReporter;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaProcessor;
import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.StoreAccess;
Expand Down Expand Up @@ -84,9 +84,9 @@ public void processSpecific( RelationTypeSchemaDescriptor schema )
}

@Override
public void processSpecific( MultiTokenSchemaDescriptor multiTokenSchemaDescriptor )
public void processSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiTokenSchemaDescriptor cannot support constraints" );
throw new IllegalStateException( "General SchemaDescriptors cannot support constraints" );
}
};

Expand Down
Expand Up @@ -39,5 +39,5 @@ public interface SchemaComputer<R>
*/
R computeSpecific( LabelSchemaDescriptor schema );
R computeSpecific( RelationTypeSchemaDescriptor schema );
R computeSpecific( MultiTokenSchemaDescriptor schema );
R computeSpecific( SchemaDescriptor schema );
}
Expand Up @@ -32,5 +32,5 @@ public interface SchemaProcessor
*/
void processSpecific( LabelSchemaDescriptor schema );
void processSpecific( RelationTypeSchemaDescriptor schema );
void processSpecific( MultiTokenSchemaDescriptor multiTokenSchemaDescriptor );
void processSpecific( SchemaDescriptor schema );
}
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.kernel.api.schema.constaints;

import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaComputer;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
Expand Down Expand Up @@ -96,10 +95,13 @@ public ConstraintDescriptor computeSpecific( RelationTypeSchemaDescriptor schema
}

@Override
public ConstraintDescriptor computeSpecific( MultiTokenSchemaDescriptor schema )
public ConstraintDescriptor computeSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiToken schema rules cannot support constraints" );
}
throw new UnsupportedOperationException(
format( "Cannot create existence constraint for schema '%s' of type %s",
schema.userDescription( SchemaUtil.idTokenNameLookup ),
schema.getClass().getSimpleName()
) ); }
};

private static SchemaComputer<UniquenessConstraintDescriptor> convertToUniquenessConstraint =
Expand All @@ -122,10 +124,13 @@ public UniquenessConstraintDescriptor computeSpecific( RelationTypeSchemaDescrip
}

@Override
public UniquenessConstraintDescriptor computeSpecific( MultiTokenSchemaDescriptor schema )
public UniquenessConstraintDescriptor computeSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiToken schema rules cannot support constraints" );
}
throw new UnsupportedOperationException(
format( "Cannot create uniqueness constraint for schema '%s' of type %s",
schema.userDescription( SchemaUtil.idTokenNameLookup ),
schema.getClass().getSimpleName()
) ); }
};

private static SchemaComputer<NodeKeyConstraintDescriptor> convertToNodeKeyConstraint =
Expand All @@ -148,9 +153,12 @@ public NodeKeyConstraintDescriptor computeSpecific( RelationTypeSchemaDescriptor
}

@Override
public NodeKeyConstraintDescriptor computeSpecific( MultiTokenSchemaDescriptor schema )
public NodeKeyConstraintDescriptor computeSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiToken schema rules cannot support constraints" );
}
throw new UnsupportedOperationException(
format( "Cannot create node key constraint for schema '%s' of type %s",
schema.userDescription( SchemaUtil.idTokenNameLookup ),
schema.getClass().getSimpleName()
) ); }
};
}
Expand Up @@ -23,7 +23,6 @@
import java.util.Optional;

import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaComputer;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
Expand Down Expand Up @@ -64,7 +63,7 @@ public class SchemaRuleSerialization
// Schema type
private static final byte SIMPLE_LABEL = 91;
private static final byte SIMPLE_REL_TYPE = 92;
private static final byte MULTI_TOKEN_TYPE = 93;
private static final byte GENERIC_MULTI_TOKEN_TYPE = 93;

private static final long NO_OWNING_CONSTRAINT_YET = -1;
private static final int LEGACY_LABEL_OR_REL_TYPE_ID = -1;
Expand Down Expand Up @@ -277,17 +276,6 @@ private static StoreIndexDescriptor readIndexRule( long id, ByteBuffer source )

}

private static MultiTokenSchemaDescriptor readMultiTokenSchema( ByteBuffer source ) throws MalformedSchemaRuleException
{
SchemaDescriptor schemaDescriptor = readMultitokenSchema( source );
if ( !(schemaDescriptor instanceof MultiTokenSchemaDescriptor) )
{
throw new MalformedSchemaRuleException(
"Non schema StoreIndexDescriptors must have MultiTokenSchemaDescriptor, got " + schemaDescriptor.getClass().getSimpleName() );
}
return (MultiTokenSchemaDescriptor) schemaDescriptor;
}

private static IndexProvider.Descriptor readIndexProviderDescriptor( ByteBuffer source )
{
String providerKey = getDecodedStringFrom( source );
Expand Down Expand Up @@ -354,15 +342,15 @@ private static SchemaDescriptor readSchema( ByteBuffer source ) throws Malformed
int relTypeId = source.getInt();
propertyIds = readTokenIdList( source );
return SchemaDescriptorFactory.forRelType( relTypeId, propertyIds );
case MULTI_TOKEN_TYPE:
case GENERIC_MULTI_TOKEN_TYPE:
return readMultiTokenSchema( source );
default:
throw new MalformedSchemaRuleException( format( "Got unknown schema descriptor type '%d'.",
schemaDescriptorType ) );
}
}

private static SchemaDescriptor readMultitokenSchema( ByteBuffer source ) throws MalformedSchemaRuleException
private static SchemaDescriptor readMultiTokenSchema( ByteBuffer source ) throws MalformedSchemaRuleException
{
byte schemaDescriptorType = source.get();
EntityType type;
Expand Down Expand Up @@ -409,33 +397,21 @@ public void processSpecific( LabelSchemaDescriptor schema )
{
target.put( SIMPLE_LABEL );
target.putInt( schema.getLabelId() );

int[] propertyIds = schema.getPropertyIds();
target.putShort( (short)propertyIds.length );
for ( int propertyId : propertyIds )
{
target.putInt( propertyId );
}
putIds( schema.getPropertyIds() );
}

@Override
public void processSpecific( RelationTypeSchemaDescriptor schema )
{
target.put( SIMPLE_REL_TYPE );
target.putInt( schema.getRelTypeId() );

int[] propertyIds = schema.getPropertyIds();
target.putShort( (short)propertyIds.length );
for ( int propertyId : propertyIds )
{
target.putInt( propertyId );
}
putIds( schema.getPropertyIds() );
}

@Override
public void processSpecific( MultiTokenSchemaDescriptor schema )
public void processSpecific( SchemaDescriptor schema )
{
target.put( MULTI_TOKEN_TYPE );
target.put( GENERIC_MULTI_TOKEN_TYPE );
if ( schema.entityType() == EntityType.NODE )
{
target.put( SIMPLE_LABEL );
Expand All @@ -445,18 +421,16 @@ public void processSpecific( MultiTokenSchemaDescriptor schema )
target.put( SIMPLE_REL_TYPE );
}

int[] entityTokenIds = schema.getEntityTokenIds();
target.putShort( (short) entityTokenIds.length );
for ( int entityTokenId : entityTokenIds )
{
target.putInt( entityTokenId );
}
putIds( schema.getEntityTokenIds() );
putIds( schema.getPropertyIds() );
}

int[] propertyIds = schema.getPropertyIds();
target.putShort( (short)propertyIds.length );
for ( int propertyId : propertyIds )
private void putIds( int[] ids )
{
target.putShort( (short) ids.length );
for ( int entityTokenId : ids )
{
target.putInt( propertyId );
target.putInt( entityTokenId );
}
}
}
Expand Down Expand Up @@ -484,7 +458,7 @@ public Integer computeSpecific( RelationTypeSchemaDescriptor schema )
}

@Override
public Integer computeSpecific( MultiTokenSchemaDescriptor schema )
public Integer computeSpecific( SchemaDescriptor schema )
{
return 1 // schema descriptor type
+ 1 // entity token type
Expand Down
Expand Up @@ -20,9 +20,9 @@
package org.neo4j.storageengine.api.schema;

import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaComputer;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier;
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
Expand Down Expand Up @@ -173,9 +173,9 @@ public Kind computeSpecific( RelationTypeSchemaDescriptor schema )
}

@Override
public Kind computeSpecific( MultiTokenSchemaDescriptor schema )
public Kind computeSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiToken schema rules cannot support constraints" );
throw new IllegalStateException( "General schema rules cannot support constraints" );
}
};
}
Expand Down
Expand Up @@ -54,9 +54,9 @@ public void processSpecific( org.neo4j.internal.kernel.api.schema.RelationTypeSc
}

@Override
public void processSpecific( org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor multiTokenSchemaDescriptor )
public void processSpecific( org.neo4j.internal.kernel.api.schema.SchemaDescriptor schemaDescriptor )
{
callHistory.add( "MultiTokenSchemaDescriptor" );
callHistory.add( "SchemaDescriptor" );
}
};

Expand Down
Expand Up @@ -45,8 +45,8 @@
import org.neo4j.internal.kernel.api.RelationshipScanCursor;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.MultiTokenSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaProcessor;
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
import org.neo4j.kernel.api.exceptions.schema.NodePropertyExistenceException;
Expand Down Expand Up @@ -145,9 +145,9 @@ public void processSpecific( RelationTypeSchemaDescriptor schema )
}

@Override
public void processSpecific( MultiTokenSchemaDescriptor multiTokenSchemaDescriptor )
public void processSpecific( SchemaDescriptor schema )
{
throw new IllegalStateException( "MultiTokenSchemaDescriptor cannot support constraints" );
throw new UnsupportedOperationException( "General SchemaDescriptor cannot support constraints" );
}
} );
}
Expand Down

0 comments on commit e0759eb

Please sign in to comment.