public override StandardExpander Add(RelationshipType type, Direction direction) { Exclusion excluded = Exclusion[type.Name()]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String, Exclusion> newExclusion; IDictionary <string, Exclusion> newExclusion; if ((excluded == null ? DefaultExclusion : excluded).includes(direction)) { return(this); } else { excluded = Exclusion.include(direction); if (excluded == DefaultExclusion) { if (Exclusion.Count == 1) { return(new AllExpander(DefaultExclusion.direction)); } else { newExclusion = new Dictionary <string, Exclusion>(Exclusion); newExclusion.Remove(type.Name()); } } else { newExclusion = new Dictionary <string, Exclusion>(Exclusion); newExclusion[type.Name()] = excluded; } } return(new ExcludingExpander(DefaultExclusion, newExclusion)); }
public override StandardExpander Remove(RelationshipType type) { Exclusion excluded = Exclusion[type.Name()]; if (excluded == Exclusion.All) { return(this); } IDictionary <string, Exclusion> newExclusion = new Dictionary <string, Exclusion>(Exclusion); newExclusion[type.Name()] = Exclusion.All; return(new ExcludingExpander(DefaultExclusion, newExclusion)); }
public override StandardExpander Remove(RelationshipType type) { IDictionary <string, Exclusion> exclude = new Dictionary <string, Exclusion>(); exclude[type.Name()] = Exclusion.All; return(new ExcludingExpander(Exclusion.include(Direction), exclude)); }
public virtual int getDegree(RelationshipType type, Direction direction) { KernelTransaction transaction = SafeAcquireTransaction(); int typeId = transaction.TokenRead().relationshipType(type.Name()); if (typeId == NO_TOKEN) { // This type doesn't even exist. Return 0 return(0); } using (Statement ignore = transaction.AcquireStatement()) { NodeCursor nodes = transaction.AmbientNodeCursor(); SingleNode(transaction, nodes); switch (direction.innerEnumValue) { case Direction.InnerEnum.OUTGOING: return(Nodes.countOutgoing(nodes, transaction.Cursors(), typeId)); case Direction.InnerEnum.INCOMING: return(Nodes.countIncoming(nodes, transaction.Cursors(), typeId)); case Direction.InnerEnum.BOTH: return(Nodes.countAll(nodes, transaction.Cursors(), typeId)); default: throw new System.InvalidOperationException("Unknown direction " + direction); } } }
protected internal virtual int RelationshipTypeId(RelationshipType type) { using (Transaction tx = Db.beginTx()) { int id = Ktx().tokenRead().relationshipType(type.Name()); tx.Success(); return(id); } }
public override StandardExpander Remove(RelationshipType type) { ICollection <Pair <RelationshipType, Direction> > newTypes = new List <Pair <RelationshipType, Direction> >(); foreach (Pair <RelationshipType, Direction> pair in _orderedTypes) { if (!type.Name().Equals(pair.First().name())) { newTypes.Add(pair); } } return(new OrderedByTypeExpander(newTypes)); }
public virtual IEnumerable <ConstraintDefinition> getConstraints(RelationshipType type) { KernelTransaction transaction = SafeAcquireTransaction(_transactionSupplier); using (Statement ignore = transaction.AcquireStatement()) { TokenRead tokenRead = transaction.TokenRead(); SchemaRead schemaRead = transaction.SchemaRead(); int typeId = tokenRead.RelationshipType(type.Name()); if (typeId == [email protected]_Fields.NO_TOKEN) { return(emptyList()); } return(AsConstraintDefinitions(schemaRead.ConstraintsGetForRelationshipType(typeId), tokenRead)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 30_000) public void shouldListAllRelationshipTypesInUseEvenWhenExclusiveRelationshipTypeLocksAreTaken() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldListAllRelationshipTypesInUseEvenWhenExclusiveRelationshipTypeLocksAreTaken() { // Given GraphDatabaseService db = DbRule.GraphDatabaseAPI; RelationshipType relType = RelationshipType.withName("REL"); Node node = CreateNode(db, Labels.MyLabel); using (Transaction tx = Db.beginTx()) { node.CreateRelationshipTo(node, relType).setProperty("prop", "val"); tx.Success(); } BinaryLatch indexCreateStarted = new BinaryLatch(); BinaryLatch indexCreateAllowToFinish = new BinaryLatch(); Thread indexCreator = new Thread(() => { using (Transaction tx = Db.beginTx()) { Db.execute("CALL db.index.fulltext.createRelationshipIndex('myIndex', ['REL'], ['prop'] )").close(); indexCreateStarted.Release(); indexCreateAllowToFinish.Await(); tx.Success(); } }); indexCreator.Start(); // When indexCreateStarted.Await(); IList <RelationshipType> relTypes; using (Transaction ignored = Db.beginTx()) { relTypes = new IList <RelationshipType> { Db.AllRelationshipTypesInUse }; } indexCreateAllowToFinish.Release(); indexCreator.Join(); // Then assertEquals(1, relTypes.Count); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: assertThat(map(RelationshipType::name, relTypes), hasItems(relType.Name())); }
public virtual int getDegree(RelationshipType type) { KernelTransaction transaction = SafeAcquireTransaction(); int typeId = transaction.TokenRead().relationshipType(type.Name()); if (typeId == NO_TOKEN) { // This type doesn't even exist. Return 0 return(0); } using (Statement ignore = transaction.AcquireStatement()) { NodeCursor nodes = transaction.AmbientNodeCursor(); SingleNode(transaction, nodes); return(Nodes.countAll(nodes, transaction.Cursors(), typeId)); } }
/// <summary> /// Returns an <seealso cref="Evaluator"/> which compares the type of the last relationship /// in a <seealso cref="Path"/> to a given set of relationship types (one or more).If the type of /// the last relationship in a path is of one of the given types then /// {@code evaluationIfMatch} will be returned, otherwise /// {@code evaluationIfNoMatch} will be returned. /// </summary> /// <param name="evaluationIfMatch"> the <seealso cref="Evaluation"/> to return if the type of the /// last relationship in the path matches any of the given types. </param> /// <param name="evaluationIfNoMatch"> the <seealso cref="Evaluation"/> to return if the type of the /// last relationship in the path doesn't match any of the given types. </param> /// <param name="type"> the (first) type (of possibly many) to match the last relationship /// in paths with. </param> /// <param name="orAnyOfTheseTypes"> additional types to match the last relationship in /// paths with. </param> /// @param <STATE> the type of the state object. </param> /// <returns> an <seealso cref="Evaluator"/> which compares the type of the last relationship /// in a <seealso cref="Path"/> to a given set of relationship types. </returns> //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public static <STATE> PathEvaluator<STATE> lastRelationshipTypeIs(final Evaluation evaluationIfMatch, final Evaluation evaluationIfNoMatch, final org.neo4j.graphdb.RelationshipType type, org.neo4j.graphdb.RelationshipType... orAnyOfTheseTypes) public static PathEvaluator <STATE> LastRelationshipTypeIs <STATE>(Evaluation evaluationIfMatch, Evaluation evaluationIfNoMatch, RelationshipType type, params RelationshipType[] orAnyOfTheseTypes) { if (orAnyOfTheseTypes.Length == 0) { return(new PathEvaluator_AdapterAnonymousInnerClass6(evaluationIfMatch, evaluationIfNoMatch, type)); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Set<String> expectedTypes = new java.util.HashSet<>(); ISet <string> expectedTypes = new HashSet <string>(); expectedTypes.Add(type.Name()); foreach (RelationshipType otherType in orAnyOfTheseTypes) { expectedTypes.Add(otherType.Name()); } return(new PathEvaluator_AdapterAnonymousInnerClass7(evaluationIfMatch, evaluationIfNoMatch, expectedTypes)); }
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); } } }
public override bool IsType(RelationshipType type) { _spi.assertInUnterminatedTransaction(); return(_spi.getRelationshipTypeById(TypeId()).name().Equals(type.Name())); }
public override ConstraintDefinition CreatePropertyExistenceConstraint(RelationshipType type, string propertyKey) { KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier); using (Statement ignore = transaction.AcquireStatement()) { try { TokenWrite tokenWrite = transaction.TokenWrite(); int typeId = tokenWrite.RelationshipTypeGetOrCreateForName(type.Name()); int[] propertyKeyId = getOrCreatePropertyKeyIds(tokenWrite, propertyKey); transaction.SchemaWrite().relationshipPropertyExistenceConstraintCreate(SchemaDescriptorFactory.forRelType(typeId, propertyKeyId)); return(new RelationshipPropertyExistenceConstraintDefinition(this, type, propertyKey)); } catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is RepeatedSchemaComponentException) { throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e); } catch (IllegalTokenNameException e) { throw new System.ArgumentException(e); } catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException) { throw new ConstraintViolationException(e.Message, e); } } }
private void RightSide(KernelTransaction ktx, DbStructureVisitor visitor, Label label, int labelId, RelationshipType relType, int relTypeId) { string userDescription = format("MATCH ()-[%s]->(%s) RETURN count(*)", Colon(relType.Name()), Colon(label.Name())); long amount = ktx.DataRead().countsForRelationship(ANY_LABEL, relTypeId, labelId); visitor.VisitRelCount(ANY_LABEL, relTypeId, labelId, userDescription, amount); }
public virtual GraphResult BuildSchemaGraph() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String,VirtualNodeHack> nodes = new java.util.HashMap<>(); IDictionary <string, VirtualNodeHack> nodes = new Dictionary <string, VirtualNodeHack>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String,java.util.Set<VirtualRelationshipHack>> relationships = new java.util.HashMap<>(); IDictionary <string, ISet <VirtualRelationshipHack> > relationships = new Dictionary <string, ISet <VirtualRelationshipHack> >(); using (Statement statement = _kernelTransaction.acquireStatement()) { Read dataRead = _kernelTransaction.dataRead(); TokenRead tokenRead = _kernelTransaction.tokenRead(); TokenNameLookup tokenNameLookup = new SilentTokenNameLookup(tokenRead); SchemaRead schemaRead = _kernelTransaction.schemaRead(); using (Transaction transaction = _graphDatabaseAPI.beginTx()) { // add all labelsInDatabase using (ResourceIterator <Label> labelsInDatabase = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator()) { while (labelsInDatabase.MoveNext()) { Label label = labelsInDatabase.Current; int labelId = tokenRead.NodeLabel(label.Name()); IDictionary <string, object> properties = new Dictionary <string, object>(); IEnumerator <IndexReference> indexReferences = schemaRead.IndexesGetForLabel(labelId); List <string> indexes = new List <string>(); while (indexReferences.MoveNext()) { IndexReference index = indexReferences.Current; if (!index.Unique) { string[] propertyNames = PropertyNameUtils.getPropertyKeys(tokenNameLookup, index.Properties()); indexes.Add(string.join(",", propertyNames)); } } properties["indexes"] = indexes; IEnumerator <ConstraintDescriptor> nodePropertyConstraintIterator = schemaRead.ConstraintsGetForLabel(labelId); List <string> constraints = new List <string>(); while (nodePropertyConstraintIterator.MoveNext()) { ConstraintDescriptor constraint = nodePropertyConstraintIterator.Current; constraints.Add(constraint.PrettyPrint(tokenNameLookup)); } properties["constraints"] = constraints; GetOrCreateLabel(label.Name(), properties, nodes); } } //add all relationships using (ResourceIterator <RelationshipType> relationshipTypeIterator = _graphDatabaseAPI.AllRelationshipTypesInUse.GetEnumerator()) { while (relationshipTypeIterator.MoveNext()) { RelationshipType relationshipType = relationshipTypeIterator.Current; string relationshipTypeGetName = relationshipType.Name(); int relId = tokenRead.RelationshipType(relationshipTypeGetName); using (ResourceIterator <Label> labelsInUse = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator()) { IList <VirtualNodeHack> startNodes = new LinkedList <VirtualNodeHack>(); IList <VirtualNodeHack> endNodes = new LinkedList <VirtualNodeHack>(); while (labelsInUse.MoveNext()) { Label labelToken = labelsInUse.Current; string labelName = labelToken.Name(); IDictionary <string, object> properties = new Dictionary <string, object>(); VirtualNodeHack node = GetOrCreateLabel(labelName, properties, nodes); int labelId = tokenRead.NodeLabel(labelName); if (dataRead.CountsForRelationship(labelId, relId, [email protected]_Fields.ANY_LABEL) > 0) { startNodes.Add(node); } if (dataRead.CountsForRelationship([email protected]_Fields.ANY_LABEL, relId, labelId) > 0) { endNodes.Add(node); } } foreach (VirtualNodeHack startNode in startNodes) { foreach (VirtualNodeHack endNode in endNodes) { AddRelationship(startNode, endNode, relationshipTypeGetName, relationships); } } } } } transaction.Success(); return(GetGraphResult(nodes, relationships)); } } }
public static ValueRepresentation RelationshipType(RelationshipType type) { return(new ValueRepresentation(RepresentationType.RelationshipType, type.Name())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void awaitIndexesOnlineMustWorkOnFulltextIndexes() public virtual void AwaitIndexesOnlineMustWorkOnFulltextIndexes() { string prop1 = "prop1"; string prop2 = "prop2"; string prop3 = "prop3"; string val1 = "foo foo"; string val2 = "bar bar"; string val3 = "baz baz"; Label label1 = Label.label("FirstLabel"); Label label2 = Label.label("SecondLabel"); Label label3 = Label.label("ThirdLabel"); RelationshipType relType1 = RelationshipType.withName("FirstRelType"); RelationshipType relType2 = RelationshipType.withName("SecondRelType"); RelationshipType relType3 = RelationshipType.withName("ThirdRelType"); LongHashSet nodes1 = new LongHashSet(); LongHashSet nodes2 = new LongHashSet(); LongHashSet nodes3 = new LongHashSet(); LongHashSet rels1 = new LongHashSet(); LongHashSet rels2 = new LongHashSet(); LongHashSet rels3 = new LongHashSet(); using (Transaction tx = Db.beginTx()) { for (int i = 0; i < 100; i++) { Node node1 = Db.createNode(label1); node1.SetProperty(prop1, val1); nodes1.add(node1.Id); Relationship rel1 = node1.CreateRelationshipTo(node1, relType1); rel1.SetProperty(prop1, val1); rels1.add(rel1.Id); Node node2 = Db.createNode(label2); node2.SetProperty(prop2, val2); nodes2.add(node2.Id); Relationship rel2 = node1.CreateRelationshipTo(node2, relType2); rel2.SetProperty(prop2, val2); rels2.add(rel2.Id); Node node3 = Db.createNode(label3); node3.SetProperty(prop3, val3); nodes3.add(node3.Id); Relationship rel3 = node1.CreateRelationshipTo(node3, relType3); rel3.SetProperty(prop3, val3); rels3.add(rel3.Id); } tx.Success(); } // Test that multi-token node indexes can be waited for. using (Transaction tx = Db.beginTx()) { Db.execute(format(NODE_CREATE, "nodeIndex", array(label1.Name(), label2.Name(), label3.Name()), array(prop1, prop2, prop3))).close(); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS); tx.Success(); } using (Transaction tx = Db.beginTx()) { assertQueryFindsIds(Db, true, "nodeIndex", "foo", nodes1); assertQueryFindsIds(Db, true, "nodeIndex", "bar", nodes2); assertQueryFindsIds(Db, true, "nodeIndex", "baz", nodes3); tx.Success(); } // Test that multi-token relationship indexes can be waited for. using (Transaction tx = Db.beginTx()) { Db.execute(format(RELATIONSHIP_CREATE, "relIndex", array(relType1.Name(), relType2.Name(), relType3.Name()), array(prop1, prop2, prop3))).close(); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS); tx.Success(); } using (Transaction tx = Db.beginTx()) { assertQueryFindsIds(Db, false, "relIndex", "foo", rels1); assertQueryFindsIds(Db, false, "relIndex", "bar", rels2); assertQueryFindsIds(Db, false, "relIndex", "baz", rels3); tx.Success(); } }
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); } }