/// <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());
        }
        /// <summary>
        /// Compute the byte size needed to serialize the provided ConstraintRule using serialize. </summary>
        /// <param name="constraintRule"> the ConstraintRule </param>
        /// <returns> the byte size of ConstraintRule </returns>
        internal static int LengthOf(ConstraintRule constraintRule)
        {
            int length = 4;            // legacy label or relType id

            length += 1;               // schema rule type

            length += 1;               // constraint type
            ConstraintDescriptor constraintDescriptor = constraintRule.ConstraintDescriptor;

            if (constraintDescriptor.EnforcesUniqueness())
            {
                length += 8;                         // owned index id
            }

            length += constraintDescriptor.Schema().computeWith(schemaSizeComputer);
            length += UTF8.computeRequiredByteBufferSize(constraintRule.Name);
            return(length);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseRelationshipPropertyExistsRule(String serialized, String name) throws Exception
        private void AssertParseRelationshipPropertyExistsRule(string serialized, string name)
        {
            // GIVEN
            long ruleId      = 51;
            int  propertyKey = 6119;
            int  relTypeId   = 8512;
            ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(relTypeId, propertyKey);

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            ConstraintRule deserialized = AssertConstraintRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized.ConstraintDescriptor, equalTo(constraint));
            assertThat(deserialized.Schema(), equalTo(constraint.Schema()));
            assertException(deserialized.getOwnedIndex, typeof(System.InvalidOperationException));
            assertThat(deserialized.Name, @is(name));
        }
Example #4
0
        private static string ConstructUserMessage(OperationContext context, TokenNameLookup tokenNameLookup, ConstraintDescriptor constraint)
        {
            switch (context)
            {
            case SchemaKernelException.OperationContext.INDEX_CREATION:
                return(MessageWithLabelAndPropertyName(tokenNameLookup, _indexContextFormat, constraint.Schema()));

            case SchemaKernelException.OperationContext.CONSTRAINT_CREATION:
                return(ALREADY_CONSTRAINED_MESSAGE_PREFIX + constraint.PrettyPrint(tokenNameLookup));

            default:
                return(format(NO_CONTEXT_FORMAT, constraint));
            }
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.impl.store.record.ConstraintRule createExistenceConstraint(long ruleId, org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException
        public override ConstraintRule CreateExistenceConstraint(long ruleId, ConstraintDescriptor descriptor)
        {
            throw PropertyExistenceConstraintsNotAllowed(descriptor.Schema());
        }