예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long createLabeledNode(int labelId) throws Exception
        private long CreateLabeledNode(int labelId)
        {
            KernelTransaction ktx = ktx();

            long nodeId = ktx.DataWrite().nodeCreate();

            ktx.DataWrite().nodeAddLabel(nodeId, labelId);
            return(nodeId);
        }
예제 #2
0
파일: KernelIT.cs 프로젝트: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mixingBeansApiWithKernelAPI() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MixingBeansApiWithKernelAPI()
        {
            // 1: Start your transactions through the Beans API
            Transaction transaction = Db.beginTx();

            // 2: Get a hold of a KernelAPI transaction this way:
            KernelTransaction ktx = StatementContextSupplier.getKernelTransactionBoundToThisThread(true);

            // 3: Now you can interact through both the statement context and the kernel API to manipulate the
            //    same transaction.
            Node node = Db.createNode();

            int labelId = ktx.TokenWrite().labelGetOrCreateForName("labello");

            ktx.DataWrite().nodeAddLabel(node.Id, labelId);

            // 4: Commit through the beans API
            transaction.Success();
            transaction.Close();
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createRel(long startId, int relTypeId, long endId) throws Exception
        private void CreateRel(long startId, int relTypeId, long endId)
        {
            KernelTransaction ktx = ktx();

            ktx.DataWrite().relationshipCreate(startId, relTypeId, endId);
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }