Esempio n. 1
0
 private void DropIndex(IndexDefinition index, DoubleLatch populationCompletionLatch)
 {
     using (Transaction tx = _db.beginTx())
     {
         index.Drop();
         populationCompletionLatch.Finish();
         tx.Success();
     }
 }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCheckUniquenessWhenAddingLabel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCheckUniquenessWhenAddingLabel()
        {
            // GIVEN
            long nodeConflicting, nodeNotConflicting;

            AddConstraints("FOO", "prop");
            using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx())
            {
                Node conflict = graphDb.createNode();
                conflict.SetProperty("prop", 1337);
                nodeConflicting = conflict.Id;

                Node ok = graphDb.createNode();
                ok.SetProperty("prop", 42);
                nodeNotConflicting = ok.Id;

                //Existing node
                Node existing = graphDb.createNode();
                existing.AddLabel(Label.label("FOO"));
                existing.SetProperty("prop", 1337);
                tx.Success();
            }

            int label;

            using (Transaction tx = beginTransaction())
            {
                label = tx.tokenWrite().labelGetOrCreateForName("FOO");

                //This is ok, since it will satisfy constraint
                assertTrue(tx.dataWrite().nodeAddLabel(nodeNotConflicting, label));

                try
                {
                    tx.dataWrite().nodeAddLabel(nodeConflicting, label);
                    fail();
                }
                catch (ConstraintValidationException)
                {
                    //ignore
                }
                tx.Success();
            }

            //Verify
            using (Transaction tx = beginTransaction(), NodeCursor nodeCursor = tx.cursors().allocateNodeCursor())
            {
                //Node without conflict
                tx.dataRead().singleNode(nodeNotConflicting, nodeCursor);
                assertTrue(nodeCursor.Next());
                assertTrue(nodeCursor.Labels().contains(label));
                //Node with conflict
                tx.dataRead().singleNode(nodeConflicting, nodeCursor);
                assertTrue(nodeCursor.Next());
                assertFalse(nodeCursor.Labels().contains(label));
            }
        }
Esempio n. 3
0
 private static IndexDefinition CreateIndex(GraphDatabaseService db)
 {
     using (Transaction tx = Db.beginTx())
     {
         IndexDefinition index = Db.schema().indexFor(LABEL_ONE).on(KEY).create();
         tx.Success();
         return(index);
     }
 }
Esempio n. 4
0
 private static long NumberOfNodesHavingLabel(GraphDatabaseService db, Label label)
 {
     using (Transaction tx = Db.beginTx())
     {
         long count = count(Db.findNodes(label));
         tx.Success();
         return(count);
     }
 }
Esempio n. 5
0
 private Index <Node> CreateNodeIndex(GraphDatabaseAPI db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Index <Node> index = Db.index().forNodes("test", stringMap(PROVIDER, IDENTIFIER));
         tx.Success();
         return(index);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Transactional version of <seealso cref="countsForNode(Label)"/> </summary>
 private long NumberOfNodesWith(Label label)
 {
     using (Transaction tx = Db.GraphDatabaseAPI.beginTx())
     {
         long nodeCount = CountsForNode(label);
         tx.Success();
         return(nodeCount);
     }
 }
Esempio n. 7
0
 private IndexDefinition IndexAliensBySpecimen()
 {
     using (Transaction tx = _db.beginTx())
     {
         IndexDefinition definition = _db.schema().indexFor(_alien).on(SPECIMEN).create();
         tx.Success();
         return(definition);
     }
 }
Esempio n. 8
0
 private void CreateConstraint(GraphDatabaseService database)
 {
     using (Transaction transaction = database.BeginTx())
     {
         Schema schema = database.Schema();
         Schema.constraintFor(_constraintIndexLabel).assertPropertyIsUnique(UNIQUE_PROPERTY_NAME).create();
         transaction.Success();
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Transactional version of <seealso cref="countsForRelationship(Label, RelationshipType, Label)"/>
 /// </summary>
 private MatchingRelationships NumberOfRelationshipsMatching(Label lhs, RelationshipType type, Label rhs)
 {
     using (Transaction tx = Db.GraphDatabaseAPI.beginTx())
     {
         long nodeCount = CountsForRelationship(lhs, type, rhs);
         tx.Success();
         return(new MatchingRelationships(string.Format("({0})-{1}->({2})", lhs == null ? "" : ":" + lhs.Name(), type == null ? "" : "[:" + type.Name() + "]", rhs == null ? "" : ":" + rhs.Name()), nodeCount));
     }
 }
Esempio n. 10
0
 private IndexDefinition CreateIndex()
 {
     using (Transaction tx = _db.beginTx())
     {
         IndexDefinition index = _db.schema().indexFor(_myLabel).on("number_of_bananas_owned").create();
         tx.Success();
         return(index);
     }
 }
Esempio n. 11
0
 private Node CreateEmptyNode(GraphDatabaseService db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.createNode();
         tx.Success();
         return(node);
     }
 }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAsLittleAsPossibleRecoveryScenario() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestAsLittleAsPossibleRecoveryScenario()
        {
            using (Transaction tx = Db.beginTx())
            {
                Db.index().forNodes("my-index").add(Db.createNode(), "key", "value");
                tx.Success();
            }

            ForceRecover();
        }
Esempio n. 13
0
 private void CheckNodeOnSlave(long nodeId, HighlyAvailableGraphDatabase slave2)
 {
     using (Transaction tx = slave2.BeginTx())
     {
         string value = slave2.GetNodeById(nodeId).getProperty("Hello").ToString();
         Logger.Logger.info("Hello=" + value);
         assertEquals("World", value);
         tx.Success();
     }
 }
Esempio n. 14
0
 private static void CreateRelationshipExplicitIndexWithSingleRelationship(GraphDatabaseService db, string indexName)
 {
     using (Transaction tx = Db.beginTx())
     {
         Relationship         relationship           = Db.createNode().createRelationshipTo(Db.createNode(), _type);
         Index <Relationship> relationshipIndexIndex = Db.index().forRelationships(indexName);
         relationshipIndexIndex.Add(relationship, "key", DateTimeHelper.CurrentUnixTimeMillis());
         tx.Success();
     }
 }
Esempio n. 15
0
 private static void CreateNodeExplicitIndexWithSingleNode(GraphDatabaseService db, string indexName)
 {
     using (Transaction tx = Db.beginTx())
     {
         Node         node      = Db.createNode();
         Index <Node> nodeIndex = Db.index().forNodes(indexName);
         nodeIndex.Add(node, "key", DateTimeHelper.CurrentUnixTimeMillis());
         tx.Success();
     }
 }
Esempio n. 16
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 getOrCreateSchemaState(String key, final String maybeSetThisState)
        private string GetOrCreateSchemaState(string key, string maybeSetThisState)
        {
            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction ktx   = StatementContextSupplier.getKernelTransactionBoundToThisThread(true);
                string            state = ktx.SchemaRead().schemaStateGetOrCreate(key, s => maybeSetThisState);
                tx.Success();
                return(state);
            }
        }
Esempio n. 17
0
        private void CreateData()
        {
            Label label = Label.label("toRetry");

            using (Transaction transaction = _database.beginTx())
            {
                Node node = _database.createNode(label);
                node.SetProperty("c", "d");
                transaction.Success();
            }
        }
Esempio n. 18
0
 public override long?apply(GraphDatabaseService graphDb)
 {
     using (Transaction tx = graphDb.BeginTx())
     {
         _rel.delete();
         long whatThisThreadSees = outerInstance.countsForRelationship(null, null, null);
         _barrier.reached();
         tx.Success();
         return(whatThisThreadSees);
     }
 }
Esempio n. 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getNonExistentGraphPropertyWithDefaultValue()
        public virtual void getNonExistentGraphPropertyWithDefaultValue()
        {
            GraphDatabaseAPI  db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase();
            PropertyContainer graphProperties = Properties(db);
            Transaction       tx = Db.beginTx();

            assertEquals("default", graphProperties.GetProperty("test", "default"));
            tx.Success();
            tx.Close();
            Db.shutdown();
        }
Esempio n. 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx())
            {
                foreach (ConstraintDefinition definition in graphDb.schema().Constraints)
                {
                    definition.Drop();
                }
                tx.Success();
            }
        }
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Index().forNodes("foo").add(graphDb.CreateNode(), "bar", "this is it");
                Relationship edge = graphDb.CreateNode().createRelationshipTo(graphDb.CreateNode(), withName("LALA"));
                graphDb.Index().forRelationships("rels").add(edge, "alpha", "betting on the wrong string");

                tx.Success();
            }
        }
Esempio n. 22
0
 private static void CreateSomeLabeledNodes(GraphDatabaseService db, params Label[][] labelArrays)
 {
     using (Transaction tx = Db.beginTx())
     {
         foreach (Label[] labels in labelArrays)
         {
             Db.createNode(labels);
         }
         tx.Success();
     }
 }
 protected internal override void generateInitialData(GraphDatabaseService graphDb)
 {
     // TODO: create bigger sample graph here
     using (Org.Neo4j.Graphdb.Transaction tx = graphDb.BeginTx())
     {
         Node node1 = set(graphDb.CreateNode(label("Foo")));
         Node node2 = set(graphDb.CreateNode(label("Foo")), property("key", "value"));
         node1.CreateRelationshipTo(node2, RelationshipType.withName("C"));
         tx.Success();
     }
 }
Esempio n. 24
0
        private static long CreateNode(GraphDatabaseService db)
        {
            long node1;

            using (Transaction tx = Db.beginTx())
            {
                node1 = Db.createNode().Id;
                tx.Success();
            }
            return(node1);
        }
Esempio n. 25
0
 private static void ExecuteDummyTxs(GraphDatabaseService db, int count)
 {
     for (int i = 0; i < count; i++)
     {
         using (Transaction tx = Db.beginTx())
         {
             Db.createNode();
             tx.Success();
         }
     }
 }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindRemovedProperties() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotFindRemovedProperties()
        {
            IndexReference index;

            using (KernelTransactionImplementation tx = KernelTransaction)
            {
                SchemaDescriptor descriptor = FulltextAdapter.schemaFor(NODE, new string[] { Label.name() }, Settings, "prop", "prop2");
                index = tx.SchemaWrite().indexCreate(descriptor, FulltextIndexProviderFactory.Descriptor.name(), NODE_INDEX_NAME);
                tx.Success();
            }
            Await(index);
            long firstID;
            long secondID;
            long thirdID;

            using (Transaction tx = Db.beginTx())
            {
                firstID  = CreateNodeIndexableByPropertyValue(Label, "Hello. Hello again.");
                secondID = CreateNodeIndexableByPropertyValue(Label, "A zebroid (also zedonk, zorse, zebra mule, zonkey, and zebmule) is the offspring of any " + "cross between a zebra and any other equine: essentially, a zebra hybrid.");
                thirdID  = CreateNodeIndexableByPropertyValue(Label, "Hello. Hello again.");

                SetNodeProp(firstID, "zebra");
                SetNodeProp(secondID, "Hello. Hello again.");

                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Node node  = Db.getNodeById(firstID);
                Node node2 = Db.getNodeById(secondID);
                Node node3 = Db.getNodeById(thirdID);

                node.SetProperty("prop", "tomtar");
                node.SetProperty("prop2", "tomtar");

                node2.SetProperty("prop", "tomtar");
                node2.SetProperty("prop2", "Hello");

                node3.RemoveProperty("prop");

                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction ktx = KernelTransaction(tx);
                AssertQueryFindsIds(ktx, NODE_INDEX_NAME, "hello", secondID);
                AssertQueryFindsNothing(ktx, NODE_INDEX_NAME, "zebra");
                AssertQueryFindsNothing(ktx, NODE_INDEX_NAME, "zedonk");
                AssertQueryFindsNothing(ktx, NODE_INDEX_NAME, "cross");
            }
        }
Esempio n. 27
0
 public override long?apply(GraphDatabaseService graphDb)
 {
     using (Transaction tx = graphDb.BeginTx())
     {
         graphDb.CreateNode();
         graphDb.CreateNode();
         _barrier.reached();
         long whatThisThreadSees = outerInstance.countsForNode();
         tx.Success();
         return(whatThisThreadSees);
     }
 }
Esempio n. 28
0
 public override Response SetAllNodeProperties(long nodeId, string body)
 {
     using (Transaction transaction = _graph.beginTx())
     {
         Response response = _restfulGraphDatabase.setAllNodeProperties(nodeId, body);
         if (response.Status < 300)
         {
             transaction.Success();
         }
         return(response);
     }
 }
Esempio n. 29
0
 public override Response DeleteNode(long nodeId)
 {
     using (Transaction transaction = _graph.beginTx())
     {
         Response response = _restfulGraphDatabase.deleteNode(nodeId);
         if (response.Status < 300)
         {
             transaction.Success();
         }
         return(response);
     }
 }
Esempio n. 30
0
 private T FindSingle <T>(GraphDatabaseService db, Index <T> index, string key, string value, System.Func <IndexHits <T>, T> getter) where T : Org.Neo4j.Graphdb.PropertyContainer
 {
     using (Transaction tx = Db.beginTx())
     {
         using (IndexHits <T> hits = index.get(key, value))
         {
             T entity = getter(hits);
             tx.Success();
             return(entity);
         }
     }
 }