Esempio n. 1
0
        /// <summary>
        /// Serialize the provided ConstraintRule onto the target buffer </summary>
        /// <param name="constraintRule"> the ConstraintRule to serialize </param>
        /// <exception cref="IllegalStateException"> if the ConstraintRule is of type unique, but the owned index has not been set </exception>
        public static sbyte[] Serialize(ConstraintRule constraintRule)
        {
            ByteBuffer target = ByteBuffer.allocate(LengthOf(constraintRule));

            target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID);
            target.put(CONSTRAINT_RULE);

            ConstraintDescriptor constraintDescriptor = constraintRule.ConstraintDescriptor;

            switch (constraintDescriptor.Type())
            {
            case EXISTS:
                target.put(EXISTS_CONSTRAINT);
                break;

            case UNIQUE:
                target.put(UNIQUE_CONSTRAINT);
                target.putLong(constraintRule.OwnedIndex);
                break;

            case UNIQUE_EXISTS:
                target.put(UNIQUE_EXISTS_CONSTRAINT);
                target.putLong(constraintRule.OwnedIndex);
                break;

            default:
                throw new System.NotSupportedException(format("Got unknown index descriptor type '%s'.", constraintDescriptor.Type()));
            }

            constraintDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target));
            UTF8.putEncodedStringInto(constraintRule.Name, target);
            return(target.array());
        }
Esempio n. 2
0
        public override ConstraintDescriptor ReadConstraint(ConstraintRule rule)
        {
            ConstraintDescriptor desc = rule.ConstraintDescriptor;

            switch (desc.Type())
            {
            case EXISTS:
                return(ReadNonStandardConstraint(rule, ERROR_MESSAGE_EXISTS));

            case UNIQUE_EXISTS:
                return(ReadNonStandardConstraint(rule, ERROR_MESSAGE_NODE_KEY));

            default:
                return(desc);
            }
        }