• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Relationship类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.neo4j.driver.v1.types.Relationship的典型用法代码示例。如果您正苦于以下问题:Java Relationship类的具体用法?Java Relationship怎么用?Java Relationship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Relationship类属于org.neo4j.driver.v1.types包,在下文中一共展示了Relationship类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: pathAsString

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Nonnull
default String pathAsString(@Nonnull Path path) {
    List<String> list = new ArrayList<>(path.length());
    Node lastTraversed = path.start();
    if (lastTraversed != null) {
        list.add(nodeAsString(lastTraversed));

        for (Path.Segment segment : path) {
            Relationship relationship = segment.relationship();
            if (relationship.startNodeId() == lastTraversed.id()) {
                list.add("-" + relationshipAsString(relationship) + "->");
            } else {
                list.add("<-" + relationshipAsString(relationship) + "-");
            }
            list.add(nodeAsString(segment.end()));
            lastTraversed = segment.end();
        }
    }

    return list.stream().collect(Collectors.joining());
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:22,代码来源:OutputFormatter.java


示例2: getPropertiesObject

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
	Record rec = this.records.get(rowIndex);
	List<Pair<String, Value>> flds = rec.fields();
	for (Pair<String, Value> pair : flds) {
		if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
			Node nd = pair.value().asNode();
			if (nd.id() == id)
				return nd;
		} else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
			Relationship rel = pair.value().asRelationship();
			if (rel.id() == id)
				return rel;
		}
	}
	
	// element with id may not have been loaded
	return this.reloaded.getEntity(id, typ);
}
 
开发者ID:Wolfgang-Schuetzelhofer,项目名称:jcypher,代码行数:19,代码来源:BoltContentHandler.java


示例3: getPathInfo

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Override
public PathInfo getPathInfo(String colKey) {
	PathInfo pathInfo = null;
	Value val;
	try {
		val = this.record.get(colKey);
	} catch (NoSuchRecordException e) {
		throw new RuntimeException("no result column: " + colKey);
	}
	String typName = val.type().name();
	if ("PATH".equals(typName)) {
		Path p = val.asPath();
		long startId = p.start().id();
		long endId = p.end().id();
		List<Long> relIds = new ArrayList<Long>();
		Iterator<Relationship> it = p.relationships().iterator();
		while(it.hasNext()) {
			Relationship rel = it.next();
			relIds.add(Long.valueOf(rel.id()));
		}
		pathInfo = new PathInfo(startId, endId, relIds, p);
	}
	return pathInfo;
}
 
开发者ID:Wolfgang-Schuetzelhofer,项目名称:jcypher,代码行数:25,代码来源:BoltContentHandler.java


示例4: shouldGetCurrentPathByGivenEntity

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void shouldGetCurrentPathByGivenEntity() {
    // This is in a try-block, to make sure we close the driver after the test
    try (Driver driver = GraphDatabase
            .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
        // Given
        session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'})");
        session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:593910000000}]->(s)");
        Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode();
        Node state = session.run("MATCH (s:State) RETURN s").single().get("s").asNode();

        // When
        StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.current.path(e) YIELD path RETURN path");

        Path current = result.single().get("path").asPath();
        Iterator<Relationship> relsIterator = current.relationships().iterator();
        Map<String, Object> rels = new HashMap<>();
        while (relsIterator.hasNext()) {
            Relationship support = relsIterator.next();
            rels.put(support.type(), support);
        }

        // Then
        assertThat(current.contains(entity), equalTo(true));
        assertThat(rels.containsKey(Utility.CURRENT_TYPE), equalTo(true));
        assertThat(current.contains(state), equalTo(true));
    }
}
 
开发者ID:h-omer,项目名称:neo4j-versioner-core,代码行数:29,代码来源:GetTest.java


示例5: shouldGetAllStateNodesByGivenEntity

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void shouldGetAllStateNodesByGivenEntity() {
    // This is in a try-block, to make sure we close the driver after the test
    try (Driver driver = GraphDatabase
            .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
        // Given
        session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'})");
        session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:593910000000}]->(s)");
        session.run("MATCH (e)-[hs:HAS_STATE]->(s) CREATE (e)-[:HAS_STATE {startDate: 593900000000, endDate: hs.startDate}]->(:State{key:'oldState'})");
        session.run("MATCH (s1:State {key:'oldState'}), (s2:State {key:'initialValue'}) CREATE (s1)<-[:PREVIOUS {date: 593900000000}]-(s2) ");
        Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode();
        Node stateNew = session.run("MATCH (s:State {key:'initialValue'}) RETURN s").single().get("s").asNode();
        Node stateOld = session.run("MATCH (s:State {key:'oldState'}) RETURN s").single().get("s").asNode();

        // When
        StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.all(e) YIELD path RETURN path");

        Path current = result.single().get("path").asPath();
        Iterator<Relationship> relsIterator = current.relationships().iterator();
        Map<String, Object> rels = new HashMap<>();
        while (relsIterator.hasNext()) {
            Relationship support = relsIterator.next();
            rels.put(support.type(), support);
        }

        // Then
        assertThat(current.contains(entity), equalTo(true));
        assertThat(current.contains(stateNew), equalTo(true));
        assertThat(rels.containsKey(Utility.PREVIOUS_TYPE), equalTo(true));
        assertThat(current.contains(stateOld), equalTo(true));
    }
}
 
开发者ID:h-omer,项目名称:neo4j-versioner-core,代码行数:33,代码来源:GetTest.java


示例6: shouldGetAllStateNodesByGivenEntityWithOnlyOneCurrentState

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void shouldGetAllStateNodesByGivenEntityWithOnlyOneCurrentState() {
    // This is in a try-block, to make sure we close the driver after the test
    try (Driver driver = GraphDatabase
            .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
        // Given
        session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'})");
        session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:593910000000}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:593910000000}]->(s)");
        Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode();
        Node stateNew = session.run("MATCH (s:State {key:'initialValue'}) RETURN s").single().get("s").asNode();

        // When
        StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.all(e) YIELD path RETURN path");

        Path current = result.single().get("path").asPath();
        Iterator<Relationship> relsIterator = current.relationships().iterator();
        Map<String, Object> rels = new HashMap<>();
        while (relsIterator.hasNext()) {
            Relationship support = relsIterator.next();
            rels.put(support.type(), support);
        }

        // Then
        assertThat(current.contains(entity), equalTo(true));
        assertThat(current.contains(stateNew), equalTo(true));
    }
}
 
开发者ID:h-omer,项目名称:neo4j-versioner-core,代码行数:28,代码来源:GetTest.java


示例7: Neo4JEdge

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
Neo4JEdge(Neo4JGraph graph, Neo4JSession session, Neo4JElementIdProvider<?> edgeIdProvider, Neo4JVertex out, Relationship relationship, Neo4JVertex in) {
    Objects.requireNonNull(graph, "graph cannot be null");
    Objects.requireNonNull(session, "session cannot be null");
    Objects.requireNonNull(edgeIdProvider, "edgeIdProvider cannot be null");
    Objects.requireNonNull(out, "out cannot be null");
    Objects.requireNonNull(relationship, "relationship cannot be null");
    Objects.requireNonNull(in, "in cannot be null");
    // store fields
    this.graph = graph;
    this.session = session;
    this.edgeIdProvider = edgeIdProvider;
    // from relationship
    this.id = edgeIdProvider.get(relationship);
    this.label = relationship.type();
    // id field name (if any)
    String idFieldName = edgeIdProvider.fieldName();
    // copy properties from relationship, remove idFieldName from map
    StreamSupport.stream(relationship.keys().spliterator(), false).filter(key -> !key.equals(idFieldName)).forEach(key -> {
        // value
        Value value = relationship.get(key);
        // add property value
        properties.put(key, new Neo4JEdgeProperty<>(this, key, value.asObject()));
    });
    // vertices
    this.out = out;
    this.in = in;
    // initialize original properties
    originalProperties = new HashMap<>(properties);
    // this is a persisted edge
    newEdge = false;
}
 
开发者ID:SteelBridgeLabs,项目名称:neo4j-gremlin-bolt,代码行数:32,代码来源:Neo4JEdge.java


示例8: prettyPrintRelationships

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void prettyPrintRelationships() throws Exception {
    // given
    BoltResult result = mock(BoltResult.class);

    Record record = mock(Record.class);
    Value value = mock(Value.class);

    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", "prop1_value");
    propertiesAsMap.put("prop2", "prop2_value");

    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());

    when(value.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));

    when(record.keys()).thenReturn(asList("rel"));
    when(record.get(eq("rel"))).thenReturn(value);
    when(record.values()).thenReturn(asList(value));
    when(record.asMap(anyObject())).thenReturn(Collections.singletonMap("rel",value));
    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = verbosePrinter.format(result);

    // then
    assertThat(actual, containsString("| [:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}] |"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:33,代码来源:TableOutputFormatTest.java


示例9: prettyPrintRelationships

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void prettyPrintRelationships() throws Exception {
    // given
    BoltResult result = mock(BoltResult.class);

    Record record = mock(Record.class);
    Value value = mock(Value.class);

    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", "prop1_value");
    propertiesAsMap.put("prop2", "prop2_value");

    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());

    when(value.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));

    when(record.keys()).thenReturn(asList("rel"));
    when(record.values()).thenReturn(asList(value));

    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = plainPrinter.format(result);

    // then
    assertThat(actual, is("rel\n[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:32,代码来源:PrettyPrinterTest.java


示例10: renderGraph

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
private InterpreterResult renderGraph(Set<Node> nodes,
    Set<Relationship> relationships) {
  logger.info("Executing renderGraph method");
  List<org.apache.zeppelin.tabledata.Node> nodesList = new ArrayList<>();
  List<org.apache.zeppelin.tabledata.Relationship> relsList = new ArrayList<>();
  for (Relationship rel : relationships) {
    relsList.add(Neo4jConversionUtils.toZeppelinRelationship(rel));
  }
  Map<String, String> labels = getLabels(true);
  for (Node node : nodes) {
    nodesList.add(Neo4jConversionUtils.toZeppelinNode(node, labels));
  }
  return new GraphResult(Code.SUCCESS,
      new GraphResult.Graph(nodesList, relsList, labels, getTypes(true), true));
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:16,代码来源:Neo4jCypherInterpreter.java


示例11: getRelationType

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Override
public String getRelationType(long relationId, int rowIndex) {
	if (rowIndex >= 0) {
		Relationship rel = (Relationship) getPropertiesObject(relationId, rowIndex, ElemType.RELATION);
		return rel.type();
	}
	return null;
}
 
开发者ID:Wolfgang-Schuetzelhofer,项目名称:jcypher,代码行数:9,代码来源:BoltContentHandler.java


示例12: convert

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Override
public Object convert(Object value) {
    if (value instanceof Node) {
        return sessionCache.getNode((Node) value);
    } else if (value instanceof Relationship) {
        return sessionCache.getRelationship((Relationship) value);
    }
    throw new XOException("Unsupported value type " + value);
}
 
开发者ID:buschmais,项目名称:extended-objects,代码行数:10,代码来源:RemoteEntityConverter.java


示例13: findRelationById

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Override
public RemoteRelationship findRelationById(RelationTypeMetadata<RelationshipMetadata<RemoteRelationshipType>> metadata, Long id) {
    String statement = String.format("MATCH (start)-[r:%s]->(end) WHERE id(r)={id} RETURN start,r,end",
            metadata.getDatastoreMetadata().getDiscriminator().getName());
    Record record = statementExecutor.getSingleResult(statement, parameters("id", id));
    Node start = record.get("start").asNode();
    Relationship relationship = record.get("r").asRelationship();
    Node end = record.get("end").asNode();
    return datastoreSessionCache.getRelationship(start, relationship, end);
}
 
开发者ID:buschmais,项目名称:extended-objects,代码行数:11,代码来源:RemoteDatastoreRelationManager.java


示例14: getRelationships

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
private StateTracker<RemoteRelationship, Set<RemoteRelationship>> getRelationships(RemoteNode source, RemoteRelationshipType type,
        RemoteDirection remoteDirection) {
    StateTracker<RemoteRelationship, Set<RemoteRelationship>> trackedRelationships = source.getState().getRelationships(remoteDirection, type);
    if (trackedRelationships == null) {
        String sourceIdentifier;
        switch (remoteDirection) {
        case OUTGOING:
            sourceIdentifier = "start";
            break;
        case INCOMING:
            sourceIdentifier = "end";
            break;
        default:
            throw new XOException("Direction not supported: " + remoteDirection);
        }
        String statement = String.format("MATCH (start)-[r:%s]->(end) WHERE id(%s)={id} RETURN start,r,end", type.getName(), sourceIdentifier);
        StatementResult statementResult = statementExecutor.execute(statement, parameters("id", source.getId()));
        Set<RemoteRelationship> loaded = new LinkedHashSet<>();
        try {
            while (statementResult.hasNext()) {
                Record record = statementResult.next();
                Node start = record.get("start").asNode();
                Relationship relationship = record.get("r").asRelationship();
                Node end = record.get("end").asNode();
                RemoteRelationship remoteRelationship = datastoreSessionCache.getRelationship(start, relationship, end);
                loaded.add(remoteRelationship);
            }
        } finally {
            statementResult.consume();
        }
        trackedRelationships = new StateTracker<>(loaded);
        source.getState().setRelationships(remoteDirection, type, trackedRelationships);
    }
    return trackedRelationships;
}
 
开发者ID:buschmais,项目名称:extended-objects,代码行数:36,代码来源:RemoteDatastoreRelationManager.java


示例15: getRelationship

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
private RemoteRelationship getRelationship(Relationship relationship, RemoteNode startNode, RemoteNode endNode, RemoteRelationshipType type) {
    RemoteRelationship remoteRelationship = getRelationship(relationship.id(), startNode, type, endNode);
    if (!remoteRelationship.getState().isLoaded()) {
        remoteRelationship.getState().load(relationship.asMap());
    }
    return remoteRelationship;
}
 
开发者ID:buschmais,项目名称:extended-objects,代码行数:8,代码来源:RemoteDatastoreSessionCache.java


示例16: loadEdge

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
private Edge loadEdge(Record record) {
    // relationship
    Relationship relationship = record.get(1).asRelationship();
    // edge id
    Object edgeId = edgeIdProvider.get(relationship);
    // check edge has been deleted
    if (!deletedEdges.contains(edgeId)) {
        // check we have record in memory
        Neo4JEdge edge = edges.get(edgeId);
        if (edge == null) {
            // nodes
            Node firstNode = record.get(0).asNode();
            Node secondNode = record.get(2).asNode();
            // node ids
            Object firstNodeId = vertexIdProvider.get(firstNode);
            Object secondNodeId = vertexIdProvider.get(secondNode);
            // check edge has been deleted (one of the vertices was deleted) or the vertices are not in the read partition
            if (deletedVertices.contains(firstNodeId) || deletedVertices.contains(secondNodeId) || !partition.containsVertex(StreamSupport.stream(firstNode.labels().spliterator(), false).collect(Collectors.toSet())) || !partition.containsVertex(StreamSupport.stream(secondNode.labels().spliterator(), false).collect(Collectors.toSet())))
                return null;
            // check we have first vertex in memory
            Neo4JVertex firstVertex = vertices.get(firstNodeId);
            if (firstVertex == null) {
                // create vertex
                firstVertex = new Neo4JVertex(graph, this, vertexIdProvider, edgeIdProvider, firstNode);
                // register it
                registerVertex(firstVertex);
            }
            // check we have second vertex in memory
            Neo4JVertex secondVertex = vertices.get(secondNodeId);
            if (secondVertex == null) {
                // create vertex
                secondVertex = new Neo4JVertex(graph, this, vertexIdProvider, edgeIdProvider, secondNode);
                // register it
                registerVertex(secondVertex);
            }
            // find out start and end of the relationship (edge could come in either direction)
            Neo4JVertex out = relationship.startNodeId() == firstNode.id() ? firstVertex : secondVertex;
            Neo4JVertex in = relationship.endNodeId() == firstNode.id() ? firstVertex : secondVertex;
            // create edge
            edge = new Neo4JEdge(graph, this, edgeIdProvider, out, relationship, in);
            // register with adjacent vertices
            out.addOutEdge(edge);
            in.addInEdge(edge);
            // register edge
            return registerEdge(edge);
        }
        // return edge
        return edge;
    }
    // skip edge
    return null;
}
 
开发者ID:SteelBridgeLabs,项目名称:neo4j-gremlin-bolt,代码行数:53,代码来源:Neo4JSession.java


示例17: prettyPrintPath

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void prettyPrintPath() throws Exception {
    // given
    BoltResult result = mock(BoltResult.class);
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Path path = mock(Path.class);


    Node n1 = mock(Node.class);
    when(n1.id()).thenReturn(1L);
    when(n1.labels()).thenReturn(asList("L1"));
    when(n1.asMap(anyObject())).thenReturn(Collections.emptyMap());

    Relationship r1 = mock(Relationship.class);
    when(r1.startNodeId()).thenReturn(2L);
    when(r1.type()).thenReturn("R1");
    when(r1.asMap(anyObject())).thenReturn(Collections.emptyMap());

    Node n2 = mock(Node.class);
    when(n2.id()).thenReturn(2L);
    when(n2.labels()).thenReturn(asList("L2"));
    when(n2.asMap(anyObject())).thenReturn(Collections.emptyMap());

    Relationship r2 = mock(Relationship.class);
    when(r2.startNodeId()).thenReturn(2L);
    when(r2.type()).thenReturn("R2");
    when(r2.asMap(anyObject())).thenReturn(Collections.emptyMap());

    Node n3 = mock(Node.class);
    when(n3.id()).thenReturn(3L);
    when(n3.labels()).thenReturn(asList("L3"));
    when(n3.asMap(anyObject())).thenReturn(Collections.emptyMap());

    Path.Segment s1 = mock(Path.Segment.class);
    when(s1.relationship()).thenReturn(r1);
    when(s1.start()).thenReturn(n1);
    when(s1.end()).thenReturn(n2);

    Path.Segment s2 = mock(Path.Segment.class);
    when(s2.relationship()).thenReturn(r2);
    when(s2.start()).thenReturn(n2);
    when(s2.end()).thenReturn(n3);
   
    when(path.start()).thenReturn(n1);
    when(path.iterator()).thenAnswer((i) -> Arrays.asList(s1,s2).iterator());

    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
    when(value.asPath()).thenReturn(path);

    when(record.keys()).thenReturn(asList("path"));
    when(record.get(eq("path"))).thenReturn(value);
    when(record.values()).thenReturn(asList(value));
    when(record.asMap(anyObject())).thenReturn(Collections.singletonMap("path",value));
    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = verbosePrinter.format(result);

    // then
    assertThat(actual, containsString("| (:L1)<-[:R1]-(:L2)-[:R2]->(:L3) |"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:64,代码来源:TableOutputFormatTest.java


示例18: printRelationshipsAndNodesWithEscapingForSpecialCharacters

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() throws Exception {
    BoltResult result = mock(BoltResult.class);

    Record record = mock(Record.class);
    Value relVal = mock(Value.class);
    Value nodeVal = mock(Value.class);

    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> relProp = new HashMap<>();
    relProp.put("prop1", "\"prop1, value\"");
    relProp.put("prop2", "prop2_value");

    Node node = mock(Node.class);
    HashMap<String, Object> nodeProp = new HashMap<>();
    nodeProp.put("prop1", "\"prop1:value\"");
    nodeProp.put("1prop2", "\"\"");
    nodeProp.put("ä", "not-escaped");


    when(relVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
    when(nodeVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());

    when(relVal.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP,TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(relProp));


    when(nodeVal.asNode()).thenReturn(node);
    when(node.labels()).thenReturn(asList("label `1", "label2"));
    when(node.asMap(anyObject())).thenReturn(unmodifiableMap(nodeProp));


    Map<String,Value> recordMap = new LinkedHashMap<>();
    recordMap.put("rel",relVal);
    recordMap.put("node",nodeVal);
    when(record.keys()).thenReturn(asList("rel", "node"));
    when(record.get(eq("rel"))).thenReturn(relVal);
    when(record.get(eq("node"))).thenReturn(nodeVal);

    when(record.<Value>asMap(anyObject())).thenReturn(recordMap);

    when(record.values()).thenReturn(asList(relVal, nodeVal));

    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = verbosePrinter.format(result);

    // then
    assertThat(actual, containsString("| [:`RELATIONSHIP,TYPE` {prop2: prop2_value, prop1: \"prop1, value\"}] |"));
    assertThat(actual, containsString("| (:`label ``1`:label2 {prop1: \"prop1:value\", `1prop2`: \"\", ä: not-escaped})"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:55,代码来源:TableOutputFormatTest.java


示例19: printRelationshipsAndNodesWithEscapingForSpecialCharacters

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() throws Exception {
    BoltResult result = mock(BoltResult.class);

    Record record = mock(Record.class);
    Value relVal = mock(Value.class);
    Value nodeVal = mock(Value.class);

    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> relProp = new HashMap<>();
    relProp.put("prop1", "\"prop1, value\"");
    relProp.put("prop2", "prop2_value");

    Node node = mock(Node.class);
    HashMap<String, Object> nodeProp = new HashMap<>();
    nodeProp.put("prop1", "\"prop1:value\"");
    nodeProp.put("1prop2", "\"\"");
    nodeProp.put("ä", "not-escaped");


    when(relVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
    when(nodeVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());

    when(relVal.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP,TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(relProp));


    when(nodeVal.asNode()).thenReturn(node);
    when(node.labels()).thenReturn(asList("label `1", "label2"));
    when(node.asMap(anyObject())).thenReturn(unmodifiableMap(nodeProp));


    when(record.keys()).thenReturn(asList("rel", "node"));
    when(record.values()).thenReturn(asList(relVal, nodeVal));

    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = plainPrinter.format(result);

    // then
    assertThat(actual, is("rel, node\n[:`RELATIONSHIP,TYPE` {prop2: prop2_value, prop1: \"prop1, value\"}], " +
            "(:`label ``1`:label2 {prop1: \"prop1:value\", `1prop2`: \"\", ä: not-escaped})"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:47,代码来源:PrettyPrinterTest.java


示例20: prettyPrintPaths

import org.neo4j.driver.v1.types.Relationship; //导入依赖的package包/类
@Test
public void prettyPrintPaths() throws Exception {
    // given
    BoltResult result = mock(BoltResult.class);

    Record record = mock(Record.class);
    Value value = mock(Value.class);

    Node start = mock(Node.class);
    HashMap<String, Object> startProperties = new HashMap<>();
    startProperties.put("prop1", "prop1_value");
    when(start.labels()).thenReturn(asList("start"));
    when(start.id()).thenReturn(1l);

    Node middle = mock(Node.class);
    when(middle.labels()).thenReturn(asList("middle"));
    when(middle.id()).thenReturn(2l);

    Node end = mock(Node.class);
    HashMap<String, Object> endProperties = new HashMap<>();
    endProperties.put("prop2", "prop2_value");
    when(end.labels()).thenReturn(asList("end"));
    when(end.id()).thenReturn(3l);

    Path path = mock(Path.class);
    when(path.start()).thenReturn(start);

    Relationship relationship = mock(Relationship.class);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.startNodeId()).thenReturn(1l).thenReturn(3l);


    Path.Segment segment1 = mock(Path.Segment.class);
    when(segment1.start()).thenReturn(start);
    when(segment1.end()).thenReturn(middle);
    when(segment1.relationship()).thenReturn(relationship);

    Path.Segment segment2 = mock(Path.Segment.class);
    when(segment2.start()).thenReturn(middle);
    when(segment2.end()).thenReturn(end);
    when(segment2.relationship()).thenReturn(relationship);

    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
    when(value.asPath()).thenReturn(path);
    when(path.iterator()).thenReturn(asList(segment1, segment2).iterator());
    when(start.asMap(anyObject())).thenReturn(unmodifiableMap(startProperties));
    when(end.asMap(anyObject())).thenReturn(unmodifiableMap(endProperties));

    when(record.keys()).thenReturn(asList("path"));
    when(record.values()).thenReturn(asList(value));

    when(result.getRecords()).thenReturn(asList(record));
    when(result.getSummary()).thenReturn(mock(ResultSummary.class));

    // when
    String actual = plainPrinter.format(result);

    // then
    assertThat(actual, is("path\n" +
            "(:start {prop1: prop1_value})-[:RELATIONSHIP_TYPE]->" +
            "(:middle)<-[:RELATIONSHIP_TYPE]-(:end {prop2: prop2_value})"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:63,代码来源:PrettyPrinterTest.java



注:本文中的org.neo4j.driver.v1.types.Relationship类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataRenderer类代码示例发布时间:2022-05-23
下一篇:
Java ByteBufferInputStream类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap