private int get( Value value, int defaultValue ) { if( value.equals( Values.NULL ) ) { return defaultValue; } else { return value.asInt(); } }
private static int counterValue( Value countersValue, String name ) { Value value = countersValue.get( name ); return value.isNull() ? 0 : value.asInt(); }
public static final String formatToString(Value value) { if(value instanceof StringValue) return value.asString(); else if(value instanceof IntegerValue) return String.valueOf(value.asInt()); else if(value instanceof FloatValue) return String.valueOf(value.asFloat()); else if(value instanceof BooleanValue) return String.valueOf(value.asBoolean()); throw new NotSupportConvertException(); }
@Override public void onDataPoint(DataPoint dataPoint) { for (Field field : dataPoint.getDataType().getFields()) { Value val = dataPoint.getValue(field); Log.i(TAG, "Detected DataPoint field: " + field.getName()); Log.i(TAG, "Detected DataPoint value: " + val); final int value = val.asInt(); if (field.getName().compareToIgnoreCase("steps") == 0) { runOnUiThread(new Runnable() { @Override public void run() { tv.setText("Value" + value) } }); } } }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { if(!shouldProcess(sqlMethod)) return next.deSerialize(src , sqlMethod); Class<?> returnType = DeSerializers.getReturnType(sqlMethod); final AtomicInteger pageNum = new AtomicInteger(0); final AtomicInteger pageSize = new AtomicInteger(0); if(DeSerializers.isBaseType(returnType)) { return src.listAsync(record -> { pageNum.set(record.get(1).asInt()); pageSize.set(record.get(2).asInt()); return DeSerializers.formatValue(returnType , record.get(0)); }).thenApplyAsync(records -> wrapPageReturn(pageNum , pageSize , records)); } else { return src.listAsync(record -> { pageNum.set(record.get(1).asInt()); pageSize.set(record.get(2).asInt()); return DeSerializers.formatJavaBean(returnType , sqlMethod , record.get(0)); }).thenApplyAsync(records -> wrapPageReturn(pageNum , pageSize , records)); } }
public static final Object formatValue(Class<?> clazz, Value value) { if(value.isNull()) return null; if(clazz.isAssignableFrom(Integer.class)) return (Integer)value.asInt(); if(clazz.isAssignableFrom(Short.class)) return Short.valueOf(value.asString()); if(clazz.isAssignableFrom(Character.class)) return (Character)value.asString().charAt(0); if(clazz.isAssignableFrom(Float.class)) return (Float)value.asFloat(); if(clazz.isAssignableFrom(Double.class)) return (Double)value.asDouble(); if(clazz.isAssignableFrom(Long.class)) return (Long)value.asLong(); if(clazz.isAssignableFrom(Number.class)) return value.asNumber(); if(clazz.isAssignableFrom(Boolean.class)) return (Boolean)value.asBoolean(); if(clazz.isAssignableFrom(byte[].class)) return value.asByteArray(); if(clazz.isAssignableFrom(LocalDate.class)) return value.asLocalDate(); if(clazz.isAssignableFrom(LocalTime.class)) return value.asLocalTime(); if(clazz.isAssignableFrom(LocalDateTime.class)) return value.asLocalDateTime(); if(clazz.isAssignableFrom(OffsetTime.class)) return value.asOffsetTime(); if(clazz.isAssignableFrom(IsoDuration.class)) return value.asIsoDuration(); if(clazz.isAssignableFrom(ZonedDateTime.class)) return value.asZonedDateTime(); if(clazz.isAssignableFrom(Date.class)) return LocalDateTimeOperation.toDate().convert(value.asLocalDateTime()); if(clazz.isAssignableFrom(String.class)) return formatToString(value); if(clazz.isAssignableFrom(Enum.class)) return MethodOperation.invoked(null , MethodOperation.getMethod(clazz , "valueOf" , String.class), value.asString()); throw new NotSupportConvertException(); }
private int getTotalCelLocationNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.CELLULAR_LOCATION + ") RETURN count(n) AS count") .peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" + NodeTypes.CELLULAR_LOCATION + ") RETURN count(n) AS count") // .peek().get("count").asInt(); }
private int getTotalNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n) RETURN count(n) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n) RETURN count(n) AS count").peek().get("count").asInt(); }
private int getTotalOntologyRelationships() { Session session = this.driver.session(); int count = session.run("MATCH (n)-[r:" + RelTypes.ONTOLOGY + "|" + RelTypes.CELLOC_ONTOLOGY + "]->(m:" + NodeTypes.ONTOLOGY + ") RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n)-[r:" + RelTypes.ONTOLOGY + "|" + RelTypes.CELLOC_ONTOLOGY // + "]->(m:" + NodeTypes.ONTOLOGY + ") RETURN count(r) AS count").peek().get("count").asInt(); }
private int getTotalRelationships() { Session session = this.driver.session(); int count = session.run("MATCH ()-[r]-() RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH ()-[r]-() RETURN count(r) AS count").peek().get("count").asInt(); }
private int getTotalXrefRelationships() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.PHYSICAL_ENTITY + ")-[r:" + RelTypes.XREF + "]->(m:" + NodeTypes.XREF + ") RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" // + NodeTypes.PHYSICAL_ENTITY + ")-[r:" + RelTypes.XREF + "]->(m:" // + NodeTypes.XREF + ") RETURN count(r) AS count").peek().get("count").asInt(); }
private int getTotalXrefNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.XREF + ") RETURN count(n) AS count") .peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" + NodeTypes.XREF + ") RETURN count(n) AS count") // .peek().get("count").asInt(); }
private int getTotalOntologyNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.ONTOLOGY + ") RETURN count(n) AS count") .peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" + NodeTypes.ONTOLOGY + ") RETURN count(n) AS count") // .peek().get("count").asInt(); }
private int getTotalCelLocationRelationships() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.PHYSICAL_ENTITY + ")-[r:" + RelTypes.CELLULAR_LOCATION + "]->(m:" + NodeTypes.CELLULAR_LOCATION + ") RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" + NodeTypes.PHYSICAL_ENTITY // + ")-[r:" + RelTypes.CELLULAR_LOCATION + "]->(m:" + NodeTypes.CELLULAR_LOCATION // + ") RETURN count(r) AS count").peek().get("count").asInt(); }
@Test public void single() { List<Map<String, Object>> results = singletonList(getRow(1)); StatementResult statementResult = new GremlinServerStatementResult(serverInfo, statement, results.iterator(), converter); assertThat(statementResult.single().get(KEY1).asInt()).isEqualTo(1); }
@Test public void create() { List<Map<String, Object>> results = asList( getRow(1), getRow(2), getRow(3) ); StatementResult statementResult = new GremlinServerStatementResult(serverInfo, statement, results.iterator(), converter); assertThat(statementResult.keys()).containsExactly(KEY1, KEY2); assertThat(statementResult.peek().get(KEY1).asInt()).isEqualTo(1); assertThat(statementResult.hasNext()).isTrue(); assertThat(statementResult.next().get(KEY1).asInt()).isEqualTo(1); assertThat(statementResult.hasNext()).isTrue(); assertThat(statementResult.next().get(KEY1).asInt()).isEqualTo(2); assertThat(statementResult.hasNext()).isTrue(); //see org.neo4j.driver.internal.InternalStatementResult#list() assertThat(statementResult.list()).hasSize(1); assertThat(statementResult.hasNext()).isFalse(); assertThat(statementResult.summary().server()).isEqualTo(serverInfo); }
@Override public Notification apply( Value value ) { String code = value.get( "code" ).asString(); String title = value.get( "title" ).asString(); String description = value.get( "description" ).asString(); String severity = value.containsKey( "severity" ) ? value.get( "severity" ).asString() : "N/A"; Value posValue = value.get( "position" ); InputPosition position = null; if( posValue != NULL ) { position = new InternalInputPosition( posValue.get( "offset" ).asInt(), posValue.get( "line" ).asInt(), posValue.get( "column" ).asInt() ); } return new InternalNotification( code, title, description, severity, position ); } };
@Test public void simple() { Driver adam = GremlinDatabase.driver("//localhost:" + server.getPort()); try (Session session = adam.session()) { StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count"); int count = result.single().get("count").asInt(); assertThat(count).isEqualTo(4); } }
@Test public void translating() { Config config = Config.build() .withTranslation(TranslatorFlavor.gremlinServer()) .toConfig(); Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config); try (Session session = driver.session()) { StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count"); int count = result.single().get("count").asInt(); assertThat(count).isEqualTo(4); } }
@Test public void multipleRows() { Cluster cluster = Cluster.build() .addContactPoints("localhost") .port(server.getPort()) .create(); Driver driver = GremlinDatabase.driver(cluster); try (Session session = driver.session()) { StatementResult result = session.run("MATCH (p:person) RETURN p.name, p.age"); List<String> rows = result.list(r -> r.get("p.name").asString() + r.get("p.age").asInt()); assertThat(rows).containsExactly("marko29", "vadas27", "josh32", "peter35"); } }