/// <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); } }
private IndexDefinition IndexAliensBySpecimen() { using (Transaction tx = _db.beginTx()) { IndexDefinition definition = _db.schema().indexFor(_alien).on(SPECIMEN).create(); tx.Success(); return(definition); } }
/// <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)); } }
private void CreateConstraint(GraphDatabaseService database) { using (Transaction transaction = database.BeginTx()) { Schema schema = database.Schema(); Schema.constraintFor(_constraintIndexLabel).assertPropertyIsUnique(UNIQUE_PROPERTY_NAME).create(); transaction.Success(); } }
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); } }
private Node CreateEmptyNode(GraphDatabaseService db) { using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(); tx.Success(); return(node); } }
private static long NumberOfNodesHavingLabel(GraphDatabaseService db, Label label) { using (Transaction tx = Db.beginTx()) { long count = count(Db.findNodes(label)); tx.Success(); return(count); } }
//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)); } }
//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); } }
//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() { GraphDatabaseAPI api = DbRule.GraphDatabaseAPI; _graph = api; DependencyResolver dependencyResolver = api.DependencyResolver; this._bridge = dependencyResolver.ResolveDependency(typeof(ThreadToStatementContextBridge)); this._tx = _graph.beginTx(); }
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(); } }
//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(); }
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(); } }
//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 org.neo4j.test.OtherThreadExecutor.WorkerCommand<Void, org.neo4j.graphdb.Lock> acquireWriteLock(final org.neo4j.graphdb.Node resource) private OtherThreadExecutor.WorkerCommand <Void, Lock> AcquireWriteLock(Node resource) { return(state => { using (Transaction tx = _db.beginTx()) { return tx.acquireWriteLock(resource); } }); }
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(); } }
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(); } }
private void CreateData() { Label label = Label.label("toRetry"); using (Transaction transaction = _database.beginTx()) { Node node = _database.createNode(label); node.SetProperty("c", "d"); transaction.Success(); } }
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); } }
//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(); } }
//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(); }
private static void ExecuteDummyTxs(GraphDatabaseService db, int count) { for (int i = 0; i < count; i++) { using (Transaction tx = Db.beginTx()) { Db.createNode(); tx.Success(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeLabelChangesInTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeLabelChangesInTransaction() { long nodeId; int toRetain, toDelete, toAdd, toRegret; const string toRetainName = "ToRetain"; const string toDeleteName = "ToDelete"; const string toAddName = "ToAdd"; const string toRegretName = "ToRegret"; using (Transaction tx = beginTransaction()) { nodeId = tx.DataWrite().nodeCreate(); toRetain = tx.Token().labelGetOrCreateForName(toRetainName); toDelete = tx.Token().labelGetOrCreateForName(toDeleteName); tx.DataWrite().nodeAddLabel(nodeId, toRetain); tx.DataWrite().nodeAddLabel(nodeId, toDelete); tx.Success(); } using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx()) { assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toDeleteName))); } using (Transaction tx = beginTransaction()) { toAdd = tx.Token().labelGetOrCreateForName(toAddName); tx.DataWrite().nodeAddLabel(nodeId, toAdd); tx.DataWrite().nodeRemoveLabel(nodeId, toDelete); toRegret = tx.Token().labelGetOrCreateForName(toRegretName); tx.DataWrite().nodeAddLabel(nodeId, toRegret); tx.DataWrite().nodeRemoveLabel(nodeId, toRegret); using (NodeCursor node = tx.Cursors().allocateNodeCursor()) { tx.DataRead().singleNode(nodeId, node); assertTrue("should access node", node.Next()); AssertLabels(node.Labels(), toRetain, toAdd); assertTrue(node.HasLabel(toAdd)); assertTrue(node.HasLabel(toRetain)); assertFalse(node.HasLabel(toDelete)); assertFalse(node.HasLabel(toRegret)); assertFalse("should only find one node", node.Next()); } tx.Success(); } using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx()) { assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toAddName))); } }
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(); } }
private static long CreateNode(GraphDatabaseService db) { long node1; using (Transaction tx = Db.beginTx()) { node1 = Db.createNode().Id; tx.Success(); } return(node1); }
public virtual void FinishTx(bool success) { if (_tx != null) { if (success) { _tx.success(); } _tx.close(); _tx = null; } }
//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"); } }
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); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testSetDoubleArrayProperty() public virtual void TestSetDoubleArrayProperty() { using (Transaction ignore = _db.beginTx()) { Node node = _db.createNode(); for (int i = 0; i < 100; i++) { node.SetProperty("foo", new double[] { 0, 0, i, i }); assertArrayEquals(new double[] { 0, 0, i, i }, ( double[] )node.GetProperty("foo"), 0.1D); } } }
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); } } }