/// <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());
        }
Example #2
0
 internal ConstraintRule(long id, ConstraintDescriptor descriptor, long?ownedIndex, string name)
 {
     this._id         = id;
     this._descriptor = descriptor;
     this._ownedIndex = ownedIndex;
     this._name       = SchemaRule.nameOrDefault(name, "constraint_" + id);
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void dropConstraint(org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void DropConstraint(ConstraintDescriptor descriptor)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                transaction.SchemaWrite().constraintDrop(descriptor);
                transaction.Success();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor createConstraint() throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private ConstraintDescriptor CreateConstraint()
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                ConstraintDescriptor descriptor = transaction.SchemaWrite().uniquePropertyConstraintCreate(SchemaDescriptorFactory.forLabel(1, 1));
                transaction.Success();
                return(descriptor);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInvalidateSchemaStateOnDropConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldInvalidateSchemaStateOnDropConstraint()
        {
            // given
            ConstraintDescriptor descriptor = CreateConstraint();

            CommitToSchemaState("test", "before");

            DropConstraint(descriptor);

            // when
            string after = CommitToSchemaState("test", "after");

            // then
            assertEquals("after", after);
        }
Example #6
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);
            }
        }
        /// <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);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void visitsUniqueConstraintsAndIndices() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void VisitsUniqueConstraintsAndIndices()
        {
            DbStructureVisitor visitor = mock(typeof(DbStructureVisitor));
            int labelId = CreateLabel("Person");
            int pkId    = CreatePropertyKey("name");

            CommitAndReOpen();

            ConstraintDescriptor constraint = CreateUniqueConstraint(labelId, pkId);
            IndexDescriptor      descriptor = TestIndexDescriptorFactory.uniqueForLabel(labelId, pkId);

            // WHEN
            Accept(visitor);

            // THEN
            verify(visitor).visitIndex(descriptor, ":Person(name)", 1.0d, 0L);
            verify(visitor).visitUniqueConstraint(( UniquenessConstraintDescriptor )constraint, "CONSTRAINT ON ( person:Person ) ASSERT person.name IS " + "UNIQUE");
        }
//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));
        }
 public NoSuchConstraintException(ConstraintDescriptor constraint) : base(org.neo4j.kernel.api.exceptions.Status_Schema.ConstraintNotFound, format(MESSAGE, constraint))
 {
     this._constraint = constraint;
 }
Example #11
0
 public override ConstraintRule CreateExistenceConstraint(long ruleId, ConstraintDescriptor descriptor)
 {
     return(ConstraintRule.constraintRule(ruleId, descriptor));
 }
Example #12
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());
        }
Example #13
0
 public abstract bool ConstraintExists(Org.Neo4j.@internal.Kernel.Api.schema.constraints.ConstraintDescriptor descriptor);
Example #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public abstract 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 abstract ConstraintRule CreateExistenceConstraint(long ruleId, ConstraintDescriptor descriptor);
Example #15
0
//JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type:
        public static ConstraintRule ConstraintRuleConflict(long id, ConstraintDescriptor descriptor, string name)
        {
            return(new ConstraintRule(id, descriptor, null, name));
        }
Example #16
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 #17
0
 public AlreadyConstrainedException(ConstraintDescriptor constraint, OperationContext context, TokenNameLookup tokenNameLookup) : base(org.neo4j.kernel.api.exceptions.Status_Schema.ConstraintAlreadyExists, ConstructUserMessage(context, tokenNameLookup, constraint))
 {
     this._constraint = constraint;
     this._context    = context;
 }
Example #18
0
 internal ConstraintRule(long id, ConstraintDescriptor descriptor, long?ownedIndex) : this(id, descriptor, ownedIndex, null)
 {
 }