I was thinking something like this.... along with a couple other
instances for the variations.
The intent is a single API to connect to various implementations, so
if a customer wants to connect a piece of BluePrint based software to
a particular database, this can be done in a configuration file and
doesn't require the programmer to write in a specific implementation.
In fact, it would be really cool if we could come to an agreement on a
configuration file. So I could just point to it openConfig() and
BluePrint would know what implementation to create.
package com.tinkerpop.blueprints.pgm;
import com.tinkerpop.blueprints.pgm.impls.dex.DexGraph;
import com.tinkerpop.blueprints.pgm.impls.neo4j.GraphDatabaseService;
import com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jGraph;
import com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph;
import com.tinkerpop.blueprints.pgm.impls.rexster.RexsterGraph;
import
com.tinkerpop.blueprints.pgm.impls.sail.impls.MemoryStoreSailGraph;
import
com.tinkerpop.blueprints.pgm.impls.sail.impls.NativeStoreSailGraph;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.pgm.oupls.sail.GraphSail;
import com.orientechnologies.orient.core.db.graph.OGraphDatabase;
/**
* Generic Connection API for creating a BluePrint Graph
*
*/
public class GraphConnect {
public static Graph openGraph(final String databasetype, String path)
{
if (databasetype.equalsIgnoreCase("Rexster") ||
databasetype.equalsIgnoreCase("RexsterGraph")) {
return new RexsterGraph(path);
} else if (databasetype.equalsIgnoreCase("OrientDB") ||
databasetype.equalsIgnoreCase("OrientGraph")) {
if (!path.startsWith("local:") || !path.startsWith("memory:") || !
path.startsWith("remote:")) {
path = "local:" + path; //default to local
}
return new OrientGraph(path);
} else if (databasetype.equalsIgnoreCase("Neo4j") ||
databasetype.equalsIgnoreCase("Neo4jGraph")) {
return new Neo4jGraph(path);
} else if (databasetype.equalsIgnoreCase("Dex") ||
databasetype.equalsIgnoreCase("DexGraph")) {
return new DexGraph(path);
} else if (databasetype.equalsIgnoreCase("InfiniteGraph")) {
return new IGGraph(path);
} else if (databasetype.equalsIgnoreCase("TinkerGraph") ||
databasetype.equalsIgnoreCase("TinkerPop")) {
if (path == null || path.length() == 0) {
return new TinkerGraph();
}
return new TinkerGraph(path);
} else if (databasetype.equalsIgnoreCase("Sail")) {
if (path == null || path.length() == 0) {
return new MemoryStoreSailGraph();
}
return new NativeStoreSailGraph(path);
}
return null;
}
public static Graph openGraph(final OGraphDatabase iDatabase) {
return new OrientGraph(iDatabase);
}
public static Graph openGraph(final GraphDatabaseService rawGraph) {
return new Neo4jGraph(rawGraph);
}
public static Graph openGraph(final GraphDatabaseService rawGraph,
boolean fresh) {
return new Neo4jGraph(rawGraph, fresh);
}
public static Graph openGraph() {
return new TinkerGraph();