예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference getOrCreateUniquenessConstraintIndex(org.neo4j.internal.kernel.api.SchemaRead schemaRead, org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.schema.SchemaDescriptor schema, String provider) throws org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private IndexReference GetOrCreateUniquenessConstraintIndex(SchemaRead schemaRead, TokenRead tokenRead, SchemaDescriptor schema, string provider)
        {
            IndexReference descriptor = schemaRead.Index(schema);

            if (descriptor != IndexReference.NO_INDEX)
            {
                if (descriptor.Unique)
                {
                    // OK so we found a matching constraint index. We check whether or not it has an owner
                    // because this may have been a left-over constraint index from a previously failed
                    // constraint creation, due to crash or similar, hence the missing owner.
                    if (schemaRead.IndexGetOwningUniquenessConstraintId(descriptor) == null)
                    {
                        return(descriptor);
                    }
                    throw new AlreadyConstrainedException(ConstraintDescriptorFactory.uniqueForSchema(schema), SchemaKernelException.OperationContext.CONSTRAINT_CREATION, new SilentTokenNameLookup(tokenRead));
                }
                // There's already an index for this schema descriptor, which isn't of the type we're after.
                throw new AlreadyIndexedException(schema, CONSTRAINT_CREATION);
            }
            IndexDescriptor indexDescriptor = CreateConstraintIndex(schema, provider);
            IndexProxy      indexProxy      = _indexingService.getIndexProxy(indexDescriptor.Schema());

            return(indexProxy.Descriptor);
        }