Reputation: 235
I'm working on neo4j in java and I have one question. When I create a node, how can I verify that the database is empty?
Here's my code to create a node:
br = new BufferedReader(new FileReader(csvFile));
while (br.ready()==true) {
transaction = graphDb.beginTx();
int cont = 0;//limitador de tuplas por query
while ((line = br.readLine()) != null && cont < 10000) {
String[] dado = line.split(cvsSplitBy);
// inserir comando para criar o nós com a data
Node no = graphDb.createNode();
no.setProperty("data", dado[0]);
no.setProperty("temperatura", dado[1]);
no.setProperty("latitude", dado[2]);
no.setProperty("longitude", dado[3]);
no.setProperty("variação", dado[4]);
System.out.println(cont);
cont++;
}
transaction.success();
transaction.close();
}
Upvotes: 2
Views: 1315
Reputation: 67019
UPDATED ANSWER
Here is an efficient Cypher query that returns a boolean isEmpty
result.
OPTIONAL MATCH (n)
RETURN n IS NULL AS isEmpty
LIMIT 1;
Upvotes: 2
Reputation: 323
match (n)
return 1
limit 1
I hope Neo4J would bother less processing this query, knowing it doesnt has to bother counting or bother filtering as suggested in previous answers
Upvotes: 1
Reputation: 18022
Execute a cypher query from java.
Use this query:
MATCH (n) RETURN count(n);
If the answer is zero, the database is empty. If it's anything else, it's not.
Upvotes: 4