I'm attempting to delete around 60,000 nodes from a database of around 1.2 million nodes. The nodes to delete are all nodes of type1, type2 and type3. (There are around 60K type1 nodes, and less than 200 for the other types.) I'm using the following Groovy code, using the dexjava.jar library:
/** Ad hoc class to delete all data for certain node types. */
public class AdHocDelete {
public static void main(args) {
assert new File(args[0]).exists() && new File(args[1]).exists();
def types = [ "type1", "type2", "type3" ];
def dex, db, sess, graph;
try {
println "Load dex properties from $args[1]";
DexProperties.load(args[1]);
DexConfig cfg = new DexConfig();
dex = new Dex(cfg);
println "Opening dex db at $args[0]...";
db = dex.open(args[0], false);
println "Dex db opened.";
sess = db.newSession();
graph = sess.getGraph();
types.each { type ->
int typeId = graph.findType(type);
if(typeId != Type.InvalidType) {
def objs = graph.select(typeId);
println "Deleting $type nodes...";
graph.drop(objs);
objs.close();
println "Deleted all $type nodes.";
}
else {
println "$type is an invalid type.";
}
}
}
catch(ex) {
println "Something went wrong.";
ex.printStackTrace();
}
finally {
sess.close();
db.close();
dex.close();
}
println "Done."
}
}