private static ConstraintRule readConstraintRule( long id, ByteBuffer source ) throws MalformedSchemaRuleException { SchemaDescriptor schema; byte constraintRuleType = source.get(); String name; switch ( constraintRuleType ) { case EXISTS_CONSTRAINT: schema = readSchema( source ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, ConstraintDescriptorFactory.existsForSchema( schema ), name ); case UNIQUE_CONSTRAINT: long ownedUniqueIndex = source.getLong(); schema = readSchema( source ); UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForSchema( schema ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, descriptor, ownedUniqueIndex, name ); case UNIQUE_EXISTS_CONSTRAINT: long ownedNodeKeyIndex = source.getLong(); schema = readSchema( source ); NodeKeyConstraintDescriptor nodeKeyConstraintDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema( schema ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, nodeKeyConstraintDescriptor, ownedNodeKeyIndex, name ); default: throw new MalformedSchemaRuleException( format( "Got unknown constraint rule type '%d'.", constraintRuleType ) ); } }
private static StoreIndexDescriptor readIndexRule( long id, ByteBuffer source ) throws MalformedSchemaRuleException { IndexProviderDescriptor indexProvider = readIndexProviderDescriptor( source ); byte indexRuleType = source.get(); Optional<String> name; switch ( indexRuleType ) { case GENERAL_INDEX: { SchemaDescriptor schema = readSchema( source ); name = readRuleName( source ); return IndexDescriptorFactory.forSchema( schema, name, indexProvider ).withId( id ); } case UNIQUE_INDEX: { long owningConstraint = source.getLong(); SchemaDescriptor schema = readSchema( source ); name = readRuleName( source ); IndexDescriptor descriptor = IndexDescriptorFactory.uniqueForSchema( schema, name, indexProvider ); return owningConstraint == NO_OWNING_CONSTRAINT_YET ? descriptor.withId( id ) : descriptor.withIds( id, owningConstraint ); } default: throw new MalformedSchemaRuleException( format( "Got unknown index rule type '%d'.", indexRuleType ) ); } }
private static ConstraintRule readConstraintRule( long id, ByteBuffer source ) throws MalformedSchemaRuleException { SchemaDescriptor schema; byte constraintRuleType = source.get(); String name; switch ( constraintRuleType ) { case EXISTS_CONSTRAINT: schema = readSchema( source ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, ConstraintDescriptorFactory.existsForSchema( schema ), name ); case UNIQUE_CONSTRAINT: long ownedUniqueIndex = source.getLong(); schema = readSchema( source ); UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForSchema( schema ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, descriptor, ownedUniqueIndex, name ); case UNIQUE_EXISTS_CONSTRAINT: long ownedNodeKeyIndex = source.getLong(); schema = readSchema( source ); NodeKeyConstraintDescriptor nodeKeyConstraintDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema( schema ); name = readRuleName( source ).orElse( null ); return ConstraintRule.constraintRule( id, nodeKeyConstraintDescriptor, ownedNodeKeyIndex, name ); default: throw new MalformedSchemaRuleException( format( "Got unknown constraint rule type '%d'.", constraintRuleType ) ); } }
private static StoreIndexDescriptor readIndexRule( long id, ByteBuffer source ) throws MalformedSchemaRuleException { IndexProviderDescriptor indexProvider = readIndexProviderDescriptor( source ); byte indexRuleType = source.get(); Optional<String> name; switch ( indexRuleType ) { case GENERAL_INDEX: { SchemaDescriptor schema = readSchema( source ); name = readRuleName( source ); return IndexDescriptorFactory.forSchema( schema, name, indexProvider ).withId( id ); } case UNIQUE_INDEX: { long owningConstraint = source.getLong(); SchemaDescriptor schema = readSchema( source ); name = readRuleName( source ); IndexDescriptor descriptor = IndexDescriptorFactory.uniqueForSchema( schema, name, indexProvider ); return owningConstraint == NO_OWNING_CONSTRAINT_YET ? descriptor.withId( id ) : descriptor.withIds( id, owningConstraint ); } default: throw new MalformedSchemaRuleException( format( "Got unknown index rule type '%d'.", indexRuleType ) ); } }