Skip to content

Commit

Permalink
implemented delete; ignore _local checkpoint docs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiledpanda committed Oct 28, 2013
1 parent 700b761 commit a5a911c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.genealogysystems</groupId>
<artifactId>neo4j-couchbase</artifactId>
<version>0.1</version>
<version>0.2</version>
<dependencies>
<dependency>
<groupId>com.couchbase</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Neo4jCAPIBehavior implements CAPIBehavior {
static String cypherCreateCovers = "Match (col:Collection), (cov:Coverage) WHERE col.id={colid} AND cov.id={covid} CREATE UNIQUE (col)-[rel:COVERS {id:{id}, from:{from}, to:{to}, tag:{tag}}]->(cov) return rel";
static String cypherDeleteCovers = "Match (col:Collection)-[rel:COVERS]->(cov:Coverage) WHERE col.id={colid} AND cov.id={covid} AND NOT(rel.id IN {ids}) DELETE rel";
static String cypherDeleteCoverages = "MATCH (col:Collection)-[rel:COVERS]->(cover:Coverage) WHERE col.id={colid} AND NOT(cover.id IN {ids}) DELETE rel,cover";
static String cypherDeleteCollection = "Match (col:Collection)-[rel:COVERS]->(cov:Coverage) WHERE col.id={colid} DELETE col,ret,cov;";

public Neo4jCAPIBehavior(int maxConcurrentRequests, Logger logger) {
this.activeRequests = new Semaphore(maxConcurrentRequests);
Expand Down Expand Up @@ -159,13 +160,31 @@ public List<Object> bulkDocs(String database, List<Map<String, Object>> docs) th
itemResponse.put("rev", revisions.get(rev));
result.add(itemResponse);

//ignore checkpoint requests
if(id.startsWith("_local/")) {
continue;
}

boolean deleted = meta.containsKey("deleted") ? (Boolean)meta.get("deleted") : false;

if(deleted) {
List<Object> calls = new ArrayList<Object>();
List<Object> deleteCalls = neoCreateDelete(meta, json, calls.size());
if(deleteCalls == null) {
continue;
}
calls.addAll(deleteCalls);
try {
String body = mapper.writeValueAsString(calls);
//System.out.println(body);
String ret = executePost("http://localhost:7474/db/data/batch", body);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}

} else {
//create calls for batch
System.out.println(""+id);
//System.out.println(""+id);

List<Object> calls = new ArrayList<Object>();
List<Object> newCalls;
Expand Down Expand Up @@ -210,7 +229,18 @@ public List<Object> bulkDocs(String database, List<Map<String, Object>> docs) th
return result;
}

private List<Object> neoCreateDelete(Map<String, Object> meta, Map<String, Object> json, int offset) {
List<Object> calls = new ArrayList<Object>();

String collectionId = (String)meta.get("id");

Map<String, Object> params = new HashMap<String, Object>();
params.put("colid",collectionId);

calls.add(createCypherQuery(cypherDeleteCollection, params, offset));

return calls;
}

private void neoCallIndex(List<Object> json) {

Expand Down

0 comments on commit a5a911c

Please sign in to comment.