/// <summary>
        /// Serialize the provided IndexRule onto the target buffer
        /// </summary>
        /// <param name="indexDescriptor"> the StoreIndexDescriptor to serialize </param>
        /// <exception cref="IllegalStateException"> if the StoreIndexDescriptor is of type unique, but the owning constrain has not been set </exception>
        public static sbyte[] Serialize(StoreIndexDescriptor indexDescriptor)
        {
            ByteBuffer target = ByteBuffer.allocate(LengthOf(indexDescriptor));

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

            IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor();

            UTF8.putEncodedStringInto(providerDescriptor.Key, target);
            UTF8.putEncodedStringInto(providerDescriptor.Version, target);

            switch (indexDescriptor.Type())
            {
            case GENERAL:
                target.put(GENERAL_INDEX);
                break;

            case UNIQUE:
                target.put(UNIQUE_INDEX);

                // The owning constraint can be null. See IndexRule.getOwningConstraint()
                long?owningConstraint = indexDescriptor.OwningConstraint;
                target.putLong(owningConstraint == null ? NO_OWNING_CONSTRAINT_YET : owningConstraint);
                break;

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

            indexDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target));
            UTF8.putEncodedStringInto(indexDescriptor.Name, target);
            return(target.array());
        }
        // HELPERS

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertSerializeAndDeserializeIndexRule(org.neo4j.storageengine.api.schema.StoreIndexDescriptor indexRule) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private void AssertSerializeAndDeserializeIndexRule(StoreIndexDescriptor indexRule)
        {
            StoreIndexDescriptor deserialized = AssertIndexRule(SerialiseAndDeserialise(indexRule));

            assertThat(deserialized.Id, equalTo(indexRule.Id));
            assertThat(deserialized, equalTo(indexRule));
            assertThat(deserialized.Schema(), equalTo(indexRule.Schema()));
            assertThat(deserialized.ProviderDescriptor(), equalTo(indexRule.ProviderDescriptor()));
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateGeneralIndex()
        public virtual void ShouldCreateGeneralIndex()
        {
            // GIVEN
            IndexDescriptor      descriptor = ForLabel(LABEL_ID, PROPERTY_ID_1);
            StoreIndexDescriptor indexRule  = descriptor.WithId(RULE_ID);

            // THEN
            assertThat(indexRule.Id, equalTo(RULE_ID));
            assertFalse(indexRule.CanSupportUniqueConstraint());
            assertThat(indexRule.Schema(), equalTo(descriptor.Schema()));
            assertThat(indexRule, equalTo(descriptor));
            assertThat(indexRule.ProviderDescriptor(), equalTo(ProviderDescriptor));
            assertException(indexRule.getOwningConstraint, typeof(System.InvalidOperationException));
            assertException(() => indexRule.WithOwningConstraint(RULE_ID_2), typeof(System.InvalidOperationException));
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateUniqueIndex()
        public virtual void ShouldCreateUniqueIndex()
        {
            // GIVEN
            IndexDescriptor      descriptor = UniqueForLabel(LABEL_ID, PROPERTY_ID_1);
            StoreIndexDescriptor indexRule  = descriptor.WithId(RULE_ID);

            // THEN
            assertThat(indexRule.Id, equalTo(RULE_ID));
            assertTrue(indexRule.CanSupportUniqueConstraint());
            assertThat(indexRule.Schema(), equalTo(descriptor.Schema()));
            assertThat(indexRule, equalTo(descriptor));
            assertThat(indexRule.ProviderDescriptor(), equalTo(ProviderDescriptor));
            assertThat(indexRule.OwningConstraint, equalTo(null));

            StoreIndexDescriptor withConstraint = indexRule.WithOwningConstraint(RULE_ID_2);

            assertThat(withConstraint.OwningConstraint, equalTo(RULE_ID_2));
            assertThat(indexRule.OwningConstraint, equalTo(null));                   // this is unchanged
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseIndexRule(String serialized, String name) throws Exception
        private void AssertParseIndexRule(string serialized, string name)
        {
            // GIVEN
            long                    ruleId        = 24;
            IndexDescriptor         index         = ForLabel(512, 4);
            IndexProviderDescriptor indexProvider = new IndexProviderDescriptor("index-provider", "25.0");

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            StoreIndexDescriptor deserialized = AssertIndexRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized, equalTo(index));
            assertThat(deserialized.Schema(), equalTo(index.Schema()));
            assertThat(deserialized.ProviderDescriptor(), equalTo(indexProvider));
            assertThat(deserialized.Name, @is(name));
            assertException(deserialized.getOwningConstraint, typeof(System.InvalidOperationException));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseUniqueIndexRule(String serialized, String name) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private void AssertParseUniqueIndexRule(string serialized, string name)
        {
            // GIVEN
            long                    ruleId        = 33;
            long                    constraintId  = 11;
            IndexDescriptor         index         = TestIndexDescriptorFactory.uniqueForLabel(61, 988);
            IndexProviderDescriptor indexProvider = new IndexProviderDescriptor("index-provider", "25.0");

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            StoreIndexDescriptor deserialized = AssertIndexRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized, equalTo(index));
            assertThat(deserialized.Schema(), equalTo(index.Schema()));
            assertThat(deserialized.ProviderDescriptor(), equalTo(indexProvider));
            assertThat(deserialized.OwningConstraint, equalTo(constraintId));
            assertThat(deserialized.Name, @is(name));
        }
        /// <summary>
        /// Compute the byte size needed to serialize the provided IndexRule using serialize. </summary>
        /// <param name="indexDescriptor"> the StoreIndexDescriptor </param>
        /// <returns> the byte size of StoreIndexDescriptor </returns>
        internal static int LengthOf(StoreIndexDescriptor indexDescriptor)
        {
            int length = 4;            // legacy label or relType id

            length += 1;               // schema rule type

            IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor();

            length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Key);
            length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Version);

            length += 1;               // index type
            if (indexDescriptor.Type() == IndexDescriptor.Type.UNIQUE)
            {
                length += 8;                         // owning constraint id
            }

            length += indexDescriptor.Schema().computeWith(schemaSizeComputer);
            length += UTF8.computeRequiredByteBufferSize(indexDescriptor.Name);
            return(length);
        }
Exemple #8
0
        internal IndexCheck(StoreIndexDescriptor indexRule)
        {
            this._indexRule = indexRule;
            SchemaDescriptor schema = indexRule.Schema();

            int[]  entityTokenIntIds  = Schema.EntityTokenIds;
            long[] entityTokenLongIds = new long[entityTokenIntIds.Length];
            for (int i = 0; i < entityTokenIntIds.Length; i++)
            {
                entityTokenLongIds[i] = entityTokenIntIds[i];
            }
            [email protected]_PropertySchemaType propertySchemaType = Schema.propertySchemaType();
            _entityType = Schema.entityType();
            if (_entityType == EntityType.NODE)
            {
                _nodeChecker = new NodeInUseWithCorrectLabelsCheck <IndexEntry, Org.Neo4j.Consistency.report.ConsistencyReport_IndexConsistencyReport>(entityTokenLongIds, propertySchemaType, false);
            }
            if (_entityType == EntityType.RELATIONSHIP)
            {
                _relationshipChecker = new RelationshipInUseWithCorrectRelationshipTypeCheck <IndexEntry, Org.Neo4j.Consistency.report.ConsistencyReport_IndexConsistencyReport>(entityTokenLongIds);
            }
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private String indexUserDescription(final org.neo4j.storageengine.api.schema.StoreIndexDescriptor descriptor)
        private string IndexUserDescription(StoreIndexDescriptor descriptor)
        {
            return(format("%s [provider: %s]", descriptor.Schema().userDescription(_tokenNameLookup), descriptor.ProviderDescriptor().ToString()));
        }