本文整理汇总了Java中org.neo4j.driver.v1.Record类的典型用法代码示例。如果您正苦于以下问题:Java Record类的具体用法?Java Record怎么用?Java Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Record类属于org.neo4j.driver.v1包,在下文中一共展示了Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@GET
@Produces({"text/plain"})
public String get() {
Session session = driver.session();
try {
session.run("CREATE (a:Person {name:'Arthur', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
示例2: shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin() throws Exception
{
Driver driver = GraphDatabase.driver( server.boltURI(), AuthTokens.basic( "moraeus", "suearom" ) );
Session session = driver.session();
session.run( "CREATE (a:Person {name:'Kalle Moraeus', title:'Riksspelman'})" );
StatementResult result =
session.run( "MATCH (a:Person) WHERE a.name = 'Kalle Moraeus' RETURN a.name AS name, a.title AS title" );
assertTrue( result.hasNext() );
while ( result.hasNext() )
{
Record record = result.next();
assertThat( record.get( "name" ).asString(), equalTo( "Kalle Moraeus" ) );
assertThat( record.get( "title" ).asString(), equalTo( "Riksspelman" ) );
System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
}
session.close();
driver.close();
}
示例3: run
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
public static SubGraph run(String query, SubGraph searchResult1, SubGraph linkedSearchResult1, ApiLocatorContext context){
SubGraph r = new SubGraph();
r.getNodes().addAll(searchResult1.getNodes());
r.cost = searchResult1.cost;
List<LuceneSearchResult> luceneSearchResults=context.getLuceneSearcher().query(query);
luceneSearchResults.sort((LuceneSearchResult a, LuceneSearchResult b)->{
Double aDist=new Double(dist(a.nodeSet,searchResult1.getNodes(),context));
Double bDist=new Double(dist(b.nodeSet,searchResult1.getNodes(),context));
return aDist.compareTo(bDist);
});
for (int i=0;i<3&&i<luceneSearchResults.size();i++) {
r.getNodes().add(luceneSearchResults.get(i).id);
for (long node:linkedSearchResult1.getNodes()){
Session session=context.connection.session();
StatementResult rs=session.run("match (a)-[r]-(b) where id(a)="+node+" and id(b)="+luceneSearchResults.get(i).id+" return id(r)");
while (rs.hasNext()){
Record item=rs.next();
r.getEdges().add(item.get("id(r)").asLong());
}
session.close();
}
}
return r;
}
示例4: run
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
public String run(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
final StatementResult result = dbServices.execute(GET_LAST_COMMIT_HASH);
JSONObject response = new JSONObject();
while (result.hasNext()) {
Record next = result.next();
Object commitHash = next.get("commitHash");
response.put("commitHash", commitHash);
}
return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "ERROR";
}
示例5: shouldCreateComplexArray1
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldCreateComplexArray1(){
String key = "shouldCreateComplexArray1";
String json = "{\"id\": \"1\", "
+ "\"type\": \"artist\","
+ "\"name\": \"Genesis\","
+ "\"albums\": ["
+ " {"
+ " \"type\": \"album\","
+ " \"id\": \"10\","
+ " \"producer\": \"Jonathan King\","
+ " \"title\": \"From Genesis to Revelation\""
+ " }"
+ "]"
+ "}";
session.run(CALL_UPSERT, Values.parameters( "key", key, "json", json ));
StatementResult result = session.run("MATCH (art {type: 'artist'}) - [r] -> (alb {type: 'album'}) RETURN art.name, alb.title,r");
Record single = result.single();
Assert.assertEquals("Wrong node","Genesis", single.get("art.name").asString());
Assert.assertEquals("Wrong inner node","From Genesis to Revelation", single.get("alb.title").asString());
Assert.assertEquals("Wrong inner node","shouldCreateComplexArray1", single.get("r").asRelationship().type());
}
示例6: shouldCreateRelation
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldCreateRelation() {
String key = "shouldCreateRelation";
String json = "{\"id\": \"1\", "
+ "\"type\": \"artist\","
+ "\"name\": \"Genesis\","
+ "\"origin\": {"
+ " \"type\": \"origin\","
+ " \"id\": \"1483\","
+ " \"sovereign-state\": \"UK\","
+ " \"country\": \"England\","
+ " \"region\": \"South East\""
+ " }"
+ "}";
session.run(CALL_UPSERT, Values.parameters( "key", key, "json", json ));
StatementResult result = session.run("MATCH (a {id: '1', type: 'artist'}) - [r] -> (o) RETURN a.name, o.country,r");
Record single = result.single();
Assert.assertEquals("Wrong node","Genesis", single.get("a.name").asString());
Assert.assertEquals("Wrong inner node","England", single.get("o.country").asString());
Assert.assertEquals("Wrong inner node","shouldCreateRelation", single.get("r").asRelationship().type());
}
示例7: shouldCreateComplexArray1
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldCreateComplexArray1(){
String key = "shouldCreateComplexArray1";
String json = "{\"id\": 1, "
+ "\"type\": \"artist\","
+ "\"name\": \"Genesis\","
+ "\"albums\": ["
+ " {"
+ " \"type\": \"album\","
+ " \"id\": 1,"
+ " \"producer\": \"Jonathan King\","
+ " \"title\": \"From Genesis to Revelation\""
+ " }"
+ "]"
+ "}";
session.run(CALL_UPSERT, Values.parameters( "key", key, "json", json ));
StatementResult result = session.run("MATCH (art {type: 'artist'}) - [r] -> (alb {type: 'album'}) RETURN art.name, alb.title,r");
Record single = result.single();
Assert.assertEquals("Wrong node","Genesis", single.get("art.name").asString());
Assert.assertEquals("Wrong inner node","From Genesis to Revelation", single.get("alb.title").asString());
Assert.assertEquals("Wrong inner node","HAS_ALBUM", single.get("r").asRelationship().type());
}
示例8: shouldCreateRelation
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldCreateRelation() {
String key = "shouldCreateRelation";
String json = "{\"id\": 1, "
+ "\"type\": \"artist\","
+ "\"name\": \"Genesis\","
+ "\"origin\": {"
+ " \"type\": \"origin\","
+ " \"id\": 1483,"
+ " \"sovereign-state\": \"UK\","
+ " \"country\": \"England\","
+ " \"region\": \"South East\""
+ " }"
+ "}";
session.run(CALL_UPSERT, Values.parameters( "key", key, "json", json ));
StatementResult result = session.run("MATCH (a {id: 1, type: 'artist'}) - [r] -> (o) RETURN a.name, o.country,r");
Record single = result.single();
Assert.assertEquals("Wrong node","Genesis", single.get("a.name").asString());
Assert.assertEquals("Wrong inner node","England", single.get("o.country").asString());
Assert.assertEquals("Wrong inner node","HAS_ORIGIN", single.get("r").asRelationship().type());
}
示例9: loadVertex
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
private Vertex loadVertex(Record record) {
// node
Node node = record.get(0).asNode();
// vertex id
Object vertexId = vertexIdProvider.get(node);
// check vertex has been deleted
if (!deletedVertices.contains(vertexId)) {
// check this vertex has been already loaded into this session
Vertex vertex = vertices.get(vertexId);
if (vertex == null) {
// check node belongs to partition
if (partition.containsVertex(StreamSupport.stream(node.labels().spliterator(), false).collect(Collectors.toSet()))) {
// create and register vertex
return registerVertex(new Neo4JVertex(graph, this, vertexIdProvider, edgeIdProvider, node));
}
// skip vertex (not in partition)
return null;
}
// return vertex
return vertex;
}
// skip vertex (deleted)
return null;
}
示例10: shouldRunCypherQuery
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void shouldRunCypherQuery() throws CommandException {
Session sessionMock = mock(Session.class);
StatementResult versionMock = mock(StatementResult.class);
StatementResult resultMock = mock(StatementResult.class);
Record recordMock = mock(Record.class);
Value valueMock = mock(Value.class);
Driver driverMock = stubVersionInAnOpenSession(versionMock, sessionMock, "neo4j-version");
when(resultMock.list()).thenReturn(asList(recordMock));
when(valueMock.toString()).thenReturn("999");
when(recordMock.get(0)).thenReturn(valueMock);
when(sessionMock.run(any(Statement.class))).thenReturn(resultMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
boltStateHandler.connect();
BoltResult boltResult = boltStateHandler.runCypher("RETURN 999",
new HashMap<>()).get();
verify(sessionMock).run(any(Statement.class));
assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
示例11: setParamShouldAddParamWithSpecialCharactersAndValue
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void setParamShouldAddParamWithSpecialCharactersAndValue() throws CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = mock(BoltResult.class);
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(boltResult.getRecords()).thenReturn(asList(recordMock));
when(recordMock.get("bo`b")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getAll().isEmpty());
Optional result = offlineTestShell.set("`bo``b`", "99");
assertEquals("99", result.get());
assertEquals("99", offlineTestShell.getAll().get("bo`b"));
}
示例12: setParamShouldAddParam
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Test
public void setParamShouldAddParam() throws CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = mock(BoltResult.class);
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(boltResult.getRecords()).thenReturn(asList(recordMock));
when(recordMock.get("bob")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getAll().isEmpty());
Optional result = offlineTestShell.set("`bob`", "99");
assertEquals("99", result.get());
assertEquals("99", offlineTestShell.getAll().get("bob"));
}
示例13: getLabels
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
public Map<String, String> getLabels(boolean refresh) {
if (labels == null || refresh) {
Map<String, String> old = labels == null ?
new LinkedHashMap<String, String>() : new LinkedHashMap<>(labels);
labels = new LinkedHashMap<>();
StatementResult result = this.neo4jConnectionManager.execute("CALL db.labels()");
Set<String> colors = new HashSet<>();
while (result.hasNext()) {
Record record = result.next();
String label = record.get("label").asString();
String color = old.get(label);
while (color == null || colors.contains(color)) {
color = Neo4jConversionUtils.getRandomLabelColor();
}
colors.add(color);
labels.put(label, color);
}
}
return labels;
}
示例14: executeOperation
import org.neo4j.driver.v1.Record; //导入依赖的package包/类
@Override
public void executeOperation(OperationType operation, CypherDriverConnectionStore<QueryStore> state,
ResultReporter resultReporter) throws DbException {
Session session = state.getSession();
OperationResult tuple = null;
int resultCount = 0;
final String queryString = getQueryString(state, operation);
state.logQuery(operation.getClass().getSimpleName(), queryString);
final StatementResult result = session.run(queryString);
if (result.hasNext()) {
final Record record = result.next();
resultCount++;
tuple = convertSingleResult(record);
if (state.isPrintResults()) {
System.out.println(tuple.toString());
}
}
session.close();
resultReporter.report(resultCount, tuple, operation);
}
示例15: getPropertiesObject
import org.neo4j.driver.v1.Record; //导入依赖的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);
}