diff --git a/propelgraph-neo4j/src/main/java/org/propelgraph/neo4j/Neo4jLocatableGraphFactory.java b/propelgraph-neo4j/src/main/java/org/propelgraph/neo4j/Neo4jLocatableGraphFactory.java index 566d61a..0b884a4 100644 --- a/propelgraph-neo4j/src/main/java/org/propelgraph/neo4j/Neo4jLocatableGraphFactory.java +++ b/propelgraph-neo4j/src/main/java/org/propelgraph/neo4j/Neo4jLocatableGraphFactory.java @@ -15,50 +15,54 @@ import org.propelgraph.LocatableGraphFactoryFactoryImpl; import org.propelgraph.LocatableGraphFactory; import org.propelgraph.DeleteableGraphFactory; +import org.propelgraph.UnsupportedFActionException; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph; + public class Neo4jLocatableGraphFactory implements LocatableGraphFactory, DeleteableGraphFactory { - static final String PREFIX = LocatableGraphFactory.SCHEME_PGGRAPH+":"+Neo4jLocatableGraphFactory.class.getName()+"/?"; + static final String PREFIX = LocatableGraphFactory.SCHEME_PGGRAPH+":"+Neo4jLocatableGraphFactory.class.getName()+"/?"; + + @Override + public void delete(String urlPath) { + if (!urlPath.startsWith(PREFIX)) throw new RuntimeException("unsupported urlPath: "+urlPath); + int idx0 = PREFIX.length(); + String graphname = LocatableGraphFactoryFactoryImpl.parseForURLParameter("&graphname=", urlPath); + String hostname = null; // hostname = byLocatableGraphFactoryFactoryImpl.parseForURLParameter("&hostname=", urlPath); + try { + Runtime.getRuntime().exec("rm -Rf neo4jstores/"+graphname+"/"); + } catch (Exception exc) { + throw new RuntimeException(exc); + } + } - @Override - public void delete(String urlPath) { - if (!urlPath.startsWith(PREFIX)) throw new RuntimeException("unsupported urlPath: "+urlPath); - int idx0 = PREFIX.length(); - String graphname = LocatableGraphFactoryFactoryImpl.parseForURLParameter("&graphname=", urlPath); - String hostname = null; // hostname = byLocatableGraphFactoryFactoryImpl.parseForURLParameter("&hostname=", urlPath); - try { - Runtime.getRuntime().exec("rm -Rf neo4jstores/"+graphname+"/"); - } catch (Exception exc) { - throw new RuntimeException(exc); - } - } - @Override - public Graph create(String urlPath) { - if (!urlPath.startsWith(PREFIX)) throw new RuntimeException("unsupported urlPath: "+urlPath); - int idx0 = PREFIX.length(); - String graphname = LocatableGraphFactoryFactoryImpl.parseForURLParameter("&graphname=", urlPath); - String hostname = null; // hostname = byLocatableGraphFactoryFactoryImpl.parseForURLParameter("&hostname=", urlPath); - try { - File fiDirGraph = new File("neo4jstores/"+graphname); - boolean boolAlreadyExists = fiDirGraph.exists(); - Neo4jGraph g = new Neo4jGraph(fiDirGraph.getAbsolutePath()); - if (!boolAlreadyExists) { - g.createKeyIndex("_id", Vertex.class); - //g.createKeyIndex(idPropForPeople, Vertex.class); + @Override + public Graph open(String urlPath, String faction, String fmode) throws UnsupportedFActionException { + if (!urlPath.startsWith(PREFIX)) throw new RuntimeException("unsupported urlPath: "+urlPath); + int idx0 = PREFIX.length(); + String graphname = LocatableGraphFactoryFactoryImpl.parseForURLParameter("&graphname=", urlPath); + String hostname = null; // hostname = byLocatableGraphFactoryFactoryImpl.parseForURLParameter("&hostname=", urlPath); + if (!faction.equals(org.propelgraph.LocatableGraphFactory.FACTION_CREATE_OPEN)) throw new UnsupportedFActionException(); + try { + File fiDirGraph = new File("neo4jstores/"+graphname); + boolean boolAlreadyExists = fiDirGraph.exists(); + Neo4jGraph g = new Neo4jGraph(fiDirGraph.getAbsolutePath()); + if (!boolAlreadyExists) { + g.createKeyIndex("_id", Vertex.class); + //g.createKeyIndex(idPropForPeople, Vertex.class); + } + return g; + } catch (Exception exc) { + throw new RuntimeException(exc); } - return g; - } catch (Exception exc) { - throw new RuntimeException(exc); - } - } + } - @Override - public String getGraphURL(Graph graph) { - // we don't know how to determine the graph file being used if all we have is the Graph object - throw new RuntimeException("don't currently support this method"); - } + @Override + public String getGraphURL(Graph graph) { + // we don't know how to determine the graph file being used if all we have is the Graph object + throw new RuntimeException("don't currently support this method"); + } }