Пример #1
0
        public override void SetProperty(string key, object value)
        {
            KernelTransaction transaction = _spi.kernelTransaction();
            int propertyKeyId;

            try
            {
                propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(format("Invalid property key '%s'.", key), e);
            }

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    transaction.DataWrite().relationshipSetProperty(_id, propertyKeyId, Values.of(value, false));
                }
            }
            catch (System.ArgumentException e)
            {
                // Trying to set an illegal value is a critical error - fail this transaction
                _spi.failTransaction();
                throw e;
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException(e);
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (AutoIndexingKernelException e)
            {
                throw new System.InvalidOperationException("Auto indexing encountered a failure while setting property: " + e.Message, e);
            }
        }
Пример #2
0
 public virtual Lock SharedLock(KernelTransaction ktx, PropertyContainer container)
 {
     using (Statement ignore = ktx.AcquireStatement())
     {
         if (container is Node)
         {
             long id = (( Node )container).Id;
             ktx.Locks().acquireSharedNodeLock(id);
             return(new CoreAPILock(() => ktx.Locks().releaseSharedNodeLock(id)));
         }
         else if (container is Relationship)
         {
             long id = (( Relationship )container).Id;
             ktx.Locks().acquireSharedRelationshipLock(id);
             return(new CoreAPILock(() => ktx.Locks().releaseSharedRelationshipLock(id)));
         }
         else
         {
             throw new System.NotSupportedException("Only relationships and nodes can be locked.");
         }
     }
 }
Пример #3
0
            public override void DropNodePropertyExistenceConstraint(Label label, string[] properties)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenRead tokenRead      = transaction.TokenRead();
                        int       labelId        = tokenRead.NodeLabel(label.Name());
                        int[]     propertyKeyIds = ResolveAndValidatePropertyKeys(tokenRead, properties);
                        transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForLabel(labelId, propertyKeyIds));
                    }
                    catch (DropConstraintFailureException e)
                    {
                        throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Пример #4
0
        public override RelationshipIndex GetOrCreateRelationshipIndex(string indexName, IDictionary <string, string> customConfiguration)
        {
            KernelTransaction ktx = _transactionBridge.get();

            try
            {
                using (Statement ignore = ktx.AcquireStatement())
                {
                    if (!ktx.IndexRead().relationshipExplicitIndexExists(indexName, customConfiguration))
                    {
                        // There's a sub-o-meta thing here where we create index config,
                        // and the index will itself share the same IndexConfigStore as us and pick up and use
                        // that. We should pass along config somehow with calls.
                        ktx.IndexWrite().relationshipExplicitIndexCreateLazily(indexName, customConfiguration);
                    }
                    return(new RelationshipExplicitIndexProxy(indexName, _gds, _transactionBridge));
                }
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #5
0
        public override void Add(T entity, string key, object value)
        {
            KernelTransaction ktx = TxBridge.get();

            try
            {
                using (Statement ignore = ktx.AcquireStatement())
                {
                    InternalAdd(entity, key, value, ktx);
                }
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException(format("%s %d not found", Type, Type.id(entity)), e);
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
            catch (ExplicitIndexNotFoundKernelException)
            {
                throw new NotFoundException(Type + " index '" + NameConflict + "' doesn't exist");
            }
        }
Пример #6
0
            public override void DropRelationshipPropertyExistenceConstraint(RelationshipType type, string propertyKey)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenRead tokenRead = transaction.TokenRead();

                        int typeId        = tokenRead.RelationshipType(type.Name());
                        int propertyKeyId = tokenRead.PropertyKey(propertyKey);
                        transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForRelType(typeId, propertyKeyId));
                    }
                    catch (DropConstraintFailureException e)
                    {
                        throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Пример #7
0
            public override ConstraintDefinition CreateNodeKeyConstraint(IndexDefinition indexDefinition)
            {
                if (indexDefinition.MultiTokenIndex)
                {
                    throw new ConstraintViolationException("A node key constraint does not support multi-token index definitions. " + "That is, only a single label is supported, but the following labels were provided: " + labelNameList(indexDefinition.Labels, "", "."));
                }
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite tokenWrite     = transaction.TokenWrite();
                        int        labelId        = tokenWrite.LabelGetOrCreateForName(single(indexDefinition.Labels).name());
                        int[]      propertyKeyIds = getOrCreatePropertyKeyIds(tokenWrite, indexDefinition);
                        transaction.SchemaWrite().nodeKeyConstraintCreate(forLabel(labelId, propertyKeyIds));
                        return(new NodeKeyConstraintDefinition(this, indexDefinition));
                    }
                    catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is AlreadyIndexedException || e is RepeatedSchemaComponentException)
                    {
                        throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (TooManyLabelsException e)
                    {
                        throw new System.InvalidOperationException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
Пример #8
0
        public override void RemoveLabel(Label label)
        {
            KernelTransaction transaction = _spi.kernelTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    int labelId = transaction.TokenRead().nodeLabel(label.Name());
                    if (labelId != [email protected]_Fields.NO_TOKEN)
                    {
                        transaction.DataWrite().nodeRemoveLabel(Id, labelId);
                    }
                }
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException("No node with id " + Id + " found.", e);
            }
            catch (KernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #9
0
        public override Relationship CreateRelationshipTo(Node otherNode, RelationshipType type)
        {
            if (otherNode == null)
            {
                throw new System.ArgumentException("Other node is null.");
            }
            // TODO: This is the checks we would like to do, but we have tests that expect to mix nodes...
            //if ( !(otherNode instanceof NodeProxy) || (((NodeProxy) otherNode).actions != actions) )
            //{
            //    throw new IllegalArgumentException( "Nodes do not belong to same graph database." );
            //}

            KernelTransaction transaction = SafeAcquireTransaction();

            try
            {
                using (Statement ignore = transaction.AcquireStatement())
                {
                    int  relationshipTypeId = transaction.TokenWrite().relationshipTypeGetOrCreateForName(type.Name());
                    long relationshipId     = transaction.DataWrite().relationshipCreate(_nodeId, relationshipTypeId, otherNode.Id);
                    return(_spi.newRelationshipProxy(relationshipId, _nodeId, relationshipTypeId, otherNode.Id));
                }
            }
            catch (IllegalTokenNameException e)
            {
                throw new System.ArgumentException(e);
            }
            catch (EntityNotFoundException e)
            {
                throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
            }
            catch (InvalidTransactionTypeKernelException e)
            {
                throw new ConstraintViolationException(e.Message, e);
            }
        }
Пример #10
0
 public IndexProcedures(KernelTransaction tx, IndexingService indexingService)
 {
     this._ktx             = tx;
     _statement            = tx.AcquireStatement();
     this._indexingService = indexingService;
 }
Пример #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void checkIndexCounts(Store store, org.neo4j.kernel.internal.GraphDatabaseAPI db) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private static void CheckIndexCounts(Store store, GraphDatabaseAPI db)
        {
            InwardKernel kernel = Db.DependencyResolver.resolveDependency(typeof(InwardKernel));

            using (KernelTransaction tx = kernel.BeginTransaction(@implicit, AnonymousContext.read()), Statement ignore = tx.AcquireStatement())
            {
                SchemaRead schemaRead = tx.SchemaRead();
                IEnumerator <IndexReference> indexes  = IndexReference.sortByType(GetAllIndexes(schemaRead));
                Register_DoubleLongRegister  register = Registers.newDoubleLongRegister();
                for (int i = 0; indexes.MoveNext(); i++)
                {
                    IndexReference reference = indexes.Current;

                    // wait index to be online since sometimes we need to rebuild the indexes on migration
                    AwaitOnline(schemaRead, reference);

                    AssertDoubleLongEquals(store.IndexCounts[i][0], store.IndexCounts[i][1], schemaRead.IndexUpdatesAndSize(reference, register));
                    AssertDoubleLongEquals(store.IndexCounts[i][2], store.IndexCounts[i][3], schemaRead.IndexSample(reference, register));
                    double selectivity = schemaRead.IndexUniqueValuesSelectivity(reference);
                    assertEquals(store.IndexSelectivity[i], selectivity, 0.0000001d);
                }
            }
        }