/** * Get the constraint rule that matches the given ConstraintDescriptor * @param descriptor the ConstraintDescriptor to match * @return the matching ConstrainRule * @throws SchemaRuleNotFoundException if no ConstraintRule matches the given descriptor * @throws DuplicateSchemaRuleException if two or more ConstraintRules match the given descriptor */ public ConstraintRule constraintsGetSingle( final ConstraintDescriptor descriptor ) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException { Iterator<ConstraintRule> rules = loadAllSchemaRules( descriptor::isSame, ConstraintRule.class, false ); if ( !rules.hasNext() ) { throw new SchemaRuleNotFoundException( SchemaRule.Kind.map( descriptor ), descriptor.schema() ); } ConstraintRule rule = rules.next(); if ( rules.hasNext() ) { throw new DuplicateSchemaRuleException( SchemaRule.Kind.map( descriptor ), descriptor.schema() ); } return rule; }
private static SchemaRule newRule( Kind kind, long id, int labelId, ByteBuffer buffer ) { switch ( kind ) { case INDEX_RULE: return readIndexRule( id, false, labelId, buffer ); case CONSTRAINT_INDEX_RULE: return readIndexRule( id, true, labelId, buffer ); case UNIQUENESS_CONSTRAINT: return readUniquenessConstraintRule( id, labelId, buffer ); case NODE_PROPERTY_EXISTENCE_CONSTRAINT: return readNodePropertyExistenceConstraintRule( id, labelId, buffer ); case RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT: return readRelPropertyExistenceConstraintRule( id, labelId, buffer ); default: throw new IllegalArgumentException( kind.name() ); } }
/** * @param messageTemplate Template for String.format. Must match two strings representing the schema kind and the * descriptor */ protected SchemaRuleException( Status status, String messageTemplate, SchemaRule.Kind kind, SchemaDescriptor descriptor ) { super( status, format( messageTemplate, kind.userString().toLowerCase(), descriptor.userDescription( SchemaUtil.idTokenNameLookup ) ) ); this.descriptor = descriptor; this.messageTemplate = messageTemplate; this.kind = kind; }
/** * Get the constraint rule that matches the given ConstraintDescriptor * @param descriptor the ConstraintDescriptor to match * @return the matching ConstrainRule * @throws SchemaRuleNotFoundException if no ConstraintRule matches the given descriptor * @throws DuplicateSchemaRuleException if two or more ConstraintRules match the given descriptor */ public ConstraintRule constraintsGetSingle( final ConstraintDescriptor descriptor ) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException { Iterator<ConstraintRule> rules = loadAllSchemaRules( descriptor::isSame, ConstraintRule.class, false ); if ( !rules.hasNext() ) { throw new SchemaRuleNotFoundException( SchemaRule.Kind.map( descriptor ), descriptor.schema() ); } ConstraintRule rule = rules.next(); if ( rules.hasNext() ) { throw new DuplicateSchemaRuleException( SchemaRule.Kind.map( descriptor ), descriptor.schema() ); } return rule; }
static SchemaRule deserialize( long id, int labelId, byte kindByte, ByteBuffer buffer ) throws MalformedSchemaRuleException { Kind kind = Kind.forId( kindByte ); try { SchemaRule rule = newRule( kind, id, labelId, buffer ); if ( null == rule ) { throw new MalformedSchemaRuleException( null, "Deserialized null schema rule for id %d with kind %s", id, kind.name() ); } return rule; } catch ( Exception e ) { throw new MalformedSchemaRuleException( e, "Could not deserialize schema rule for id %d with kind %s", id, kind.name() ); } }
private static SchemaRule newRule( Kind kind, long id, int labelId, ByteBuffer buffer ) { switch ( kind ) { case INDEX_RULE: return readIndexRule( id, false, labelId, buffer ); case CONSTRAINT_INDEX_RULE: return readIndexRule( id, true, labelId, buffer ); case UNIQUENESS_CONSTRAINT: return readUniquenessConstraintRule( id, labelId, buffer ); case NODE_PROPERTY_EXISTENCE_CONSTRAINT: return readNodePropertyExistenceConstraintRule( id, labelId, buffer ); case RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT: return readRelPropertyExistenceConstraintRule( id, labelId, buffer ); default: throw new IllegalArgumentException( kind.name() ); } }
public byte id() { return (byte) (ordinal() + 1); }
static boolean isLegacySchemaRule( byte schemaRuleType ) { return schemaRuleType >= 1 && schemaRuleType <= SchemaRule.Kind.values().length; }
/** * @param messageTemplate Template for String.format. Must match two strings representing the schema kind and the * descriptor */ protected SchemaRuleException( Status status, String messageTemplate, SchemaRule.Kind kind, SchemaDescriptor descriptor ) { super( status, format( messageTemplate, kind.userString().toLowerCase(), descriptor.userDescription( SchemaUtil.idTokenNameLookup ) ) ); this.descriptor = descriptor; this.messageTemplate = messageTemplate; this.kind = kind; }
public static Kind forId( byte id ) throws MalformedSchemaRuleException { if ( id >= 1 && id <= ALL.length ) { return values()[id - 1]; } throw new MalformedSchemaRuleException( null, "Unknown kind id %d", id ); }
@Override public String getUserMessage( TokenNameLookup tokenNameLookup ) { return format( messageTemplate, kind.userString().toLowerCase(), descriptor.userDescription( tokenNameLookup ) ); } }
static SchemaRule deserialize( long id, int labelId, byte kindByte, ByteBuffer buffer ) throws MalformedSchemaRuleException { Kind kind = Kind.forId( kindByte ); try { SchemaRule rule = newRule( kind, id, labelId, buffer ); if ( null == rule ) { throw new MalformedSchemaRuleException( null, "Deserialized null schema rule for id %d with kind %s", id, kind.name() ); } return rule; } catch ( Exception e ) { throw new MalformedSchemaRuleException( e, "Could not deserialize schema rule for id %d with kind %s", id, kind.name() ); } }
static boolean isLegacySchemaRule( byte schemaRuleType ) { return schemaRuleType >= 1 && schemaRuleType <= SchemaRule.Kind.values().length; }
public byte id() { return (byte) (ordinal() + 1); }
@Override public String getUserMessage( TokenNameLookup tokenNameLookup ) { return format( messageTemplate, kind.userString().toLowerCase(), descriptor.userDescription( tokenNameLookup ) ); } }
public static Kind forId( byte id ) throws MalformedSchemaRuleException { if ( id >= 1 && id <= ALL.length ) { return values()[id - 1]; } throw new MalformedSchemaRuleException( null, "Unknown kind id %d", id ); }