private Object toNode(Object value, boolean virtual, Map<Long, Object> nodesCache) { Value internalValue = ((InternalEntity) value).asValue(); Node node = internalValue.asNode(); if (virtual) { List<Label> labels = new ArrayList<>(); node.labels().forEach(l -> labels.add(Label.label(l))); VirtualNode virtualNode = new VirtualNode(node.id(), labels.toArray(new Label[0]), node.asMap(), db); nodesCache.put(node.id(), virtualNode); return virtualNode; } else return Util.map("entityType", internalValue.type().name(), "labels", node.labels(), "id", node.id(), "properties", node.asMap()); }
private Object toRelationship(Object value, boolean virtual, Map<Long, Object> nodesCache) { Value internalValue = ((InternalEntity) value).asValue(); Relationship relationship = internalValue.asRelationship(); if (virtual) { VirtualNode start = (VirtualNode) nodesCache.getOrDefault(relationship.startNodeId(), new VirtualNode(relationship.startNodeId(), db)); VirtualNode end = (VirtualNode) nodesCache.getOrDefault(relationship.endNodeId(), new VirtualNode(relationship.endNodeId(), db)); VirtualRelationship virtualRelationship = new VirtualRelationship(relationship.id(), start, end, RelationshipType.withName(relationship.type()), relationship.asMap()); return virtualRelationship; } else return Util.map("entityType", internalValue.type().name(), "type", relationship.type(), "id", relationship.id(), "start", relationship.startNodeId(), "end", relationship.endNodeId(), "properties", relationship.asMap()); }
private boolean isProjection(Value value) { return !( InternalTypeSystem.TYPE_SYSTEM.NODE().equals( value.type() ) ); }
/** * Create a new statement. * @param text the statement text * @param parameters the statement parameters */ public Statement( String text, Value parameters ) { this.text = validateQuery( text ); if( parameters == null ) { this.parameters = Values.EmptyMap; } else if ( parameters instanceof MapValue ) { this.parameters = parameters; } else { throw new IllegalArgumentException( "The parameters should be provided as Map type. Unsupported parameters type: " + parameters.type().name() ); } }
@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; }
@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; }
static Object convert(Value value) { switch (value.type().name()) { case "PATH": return value.asList(BoltCypherExecutor::convert); case "NODE": case "RELATIONSHIP": return value.asMap(); } return value.asObject(); }
private void checkMapForPrettyPrint(Map<String, String> map, String expectedResult) { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.MAP()); when(value.asMap((Function<Value, String>) anyObject())).thenReturn(map); when(record.keys()).thenReturn(asList("map")); 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(expectedResult)); }
Value val = (Value) value; Object ret = null; Type typ = val.type(); InternalTypeSystem ts = InternalTypeSystem.TYPE_SYSTEM; if (typ == ts.NUMBER())
Value val = (Value) value; Object ret = null; Type typ = val.type(); InternalTypeSystem ts = InternalTypeSystem.TYPE_SYSTEM; if (typ == ts.NUMBER())
@Test public void prettyPrintList() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record1 = mock(Record.class); Record record2 = mock(Record.class); Value value1 = mock(Value.class); Value value2 = mock(Value.class); when(value1.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST()); when(value2.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST()); when(value1.asList(Matchers.any(Function.class))).thenReturn(asList("val1_1", "val1_2")); when(value2.asList(Matchers.any(Function.class))).thenReturn(asList("val2_1")); when(record1.keys()).thenReturn(asList("col1", "col2")); when(record1.values()).thenReturn(asList(value1, value2)); when(record2.values()).thenReturn(asList(value2)); when(result.getRecords()).thenReturn(asList(record1, record2)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is("col1, col2\n[val1_1, val1_2], [val2_1]\n[val2_1]")); }
@Test public void prettyPrintNode() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); Node node = mock(Node.class); HashMap<String, Object> propertiesAsMap = new HashMap<>(); propertiesAsMap.put("prop1", "prop1_value"); propertiesAsMap.put("prop2", "prop2_value"); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE()); when(value.asNode()).thenReturn(node); when(node.labels()).thenReturn(asList("label1", "label2")); when(node.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap)); when(record.keys()).thenReturn(asList("col1", "col2")); 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("col1, col2\n" + "(:label1:label2 {prop2: prop2_value, prop1: prop1_value})")); }
@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}]")); }
public static ElementInfo fromRecordValue(Value val) { if (val instanceof ListValue) return ElementInfo.fromRecordValue(((ListValue)val).get(0)); ElementInfo ret = null; if (val != null) { String typName = val.type().name(); // NODE, RELATIONSHIP, NULL if ("NODE".equals(typName)) { ret = new ElementInfo(); ret.isNull = false; ret.id = val.asNode().id(); ret.type = ElemType.NODE; } else if ("RELATIONSHIP".equals(typName)) { ret = new ElementInfo(); ret.isNull = false; ret.id = val.asRelationship().id(); ret.type = ElemType.RELATION; } else if ("NULL".equals(typName)) ret = ElementInfo.nullElement(); } return ret; }
public static RelationInfo fromRecordValue(Value val) { if (val instanceof ListValue) return RelationInfo.fromRecordValue(((ListValue)val).get(0)); RelationInfo ret = null; if (val != null) { String typName = val.type().name(); // must be: RELATIONSHIP if ("RELATIONSHIP".equals(typName)) { ret = new RelationInfo(); ret.startNodeId = val.asRelationship().startNodeId(); ret.endNodeId = val.asRelationship().endNodeId(); } } return ret; }
public static RelationInfo fromRecordValue(Value val) { if (val instanceof ListValue) return RelationInfo.fromRecordValue(((ListValue)val).get(0)); RelationInfo ret = null; if (val != null) { String typName = val.type().name(); // must be: RELATIONSHIP if ("RELATIONSHIP".equals(typName)) { ret = new RelationInfo(); ret.startNodeId = val.asRelationship().startNodeId(); ret.endNodeId = val.asRelationship().endNodeId(); } } return ret; }
public static ElementInfo fromRecordValue(Value val) { if (val instanceof ListValue) return ElementInfo.fromRecordValue(((ListValue)val).get(0)); ElementInfo ret = null; if (val != null) { String typName = val.type().name(); // NODE, RELATIONSHIP, NULL if ("NODE".equals(typName)) { ret = new ElementInfo(); ret.isNull = false; ret.id = val.asNode().id(); ret.type = ElemType.NODE; } else if ("RELATIONSHIP".equals(typName)) { ret = new ElementInfo(); ret.isNull = false; ret.id = val.asRelationship().id(); ret.type = ElemType.RELATION; } else if ("NULL".equals(typName)) ret = ElementInfo.nullElement(); } return ret; }
when(segment1.relationship()).thenReturn(relationship); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH()); when(value.asPath()).thenReturn(path); when(path.iterator()).thenReturn(asList(segment1).iterator());
@Nonnull default String formatValue(@Nonnull final Value value) { TypeRepresentation type = (TypeRepresentation) value.type(); switch (type.constructor()) { case LIST: