Blueprints - generic connection API

68 views
Skip to first unread message

jeffg

unread,
Feb 10, 2012, 9:38:28 AM2/10/12
to gremli...@googlegroups.com
It would be nice if we could add a generic connection API to blueprints. If I create a visualization tool with no knowledge of the underlining DB, just that it be BP compliant, I'd like to give a simple config for the user.

For example, Neo4j & OrientDB

Graph graph = new Neo4jGraph("/tmp/neo4j");

Graph graph = new OrientGraph("local:/tmp/orient");

1. File path - they use different methods of path, so I can't just have the user "Enter the path to the DB".
2. I have different creation methods - I can't just have the user "Enter the DB Name".

Wouldn't something like this be worthwhile?

graphname = "Neo4j"; //User supplied in config
graphpath = "/tmp/neo4j"; //User supplied in config

Graph graph = new Graph(graphname, graphpath);

The Graph Method could do the work selecting the creation method and adding "local:" for OrientDB or whatever. My thought is that I shouldn't have to code for a particular DB. We should have a generic connection API. :)

Luca Garulli

unread,
Feb 10, 2012, 10:37:30 AM2/10/12
to gremli...@googlegroups.com
Hi,
for OrientDB that is the URL of database and the first part is the storage type. In fact you could use a in-memory (example: memory:demo) a database located in a remote machine (remote:localhost/demo). Local means embedded database.

Lvc@

jeffg

unread,
Feb 10, 2012, 11:09:30 AM2/10/12
to gremli...@googlegroups.com
Yes, I understand the logic of the connection for OrientDB and Neo4j. I don't have problem with connecting to either. I'm just saying there is no generic way to connect to either based on a user supplied configuration. We need a standardized connection API.

Marko Rodriguez

unread,
Feb 10, 2012, 12:54:53 PM2/10/12
to gremli...@googlegroups.com
Huh -- I didn't know the "memory:" prefix existed. Thats great to know.

Thanks Luca,
Marko.

project2501

unread,
Feb 13, 2012, 4:58:17 PM2/13/12
to Gremlin-users
I use the bulbflow python API to rexster and it achieves this since
rexster handles the graph implementation on the backend.

e.g.

g = Graph('http://localhost:8182/graphs/demo')
g.vertices.create({'name':'me'})
...
...

By changing the graph URL reference, I use different backends via
rexster, but the client API is the same.

jeffg

unread,
Feb 24, 2012, 4:39:26 PM2/24/12
to Gremlin-users
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();

Peter Neubauer

unread,
Feb 24, 2012, 4:45:54 PM2/24/12
to gremli...@googlegroups.com

In that case,
This should be classpath based, otherwise this forced you to have all stuff in your installation.

Sent from a device with crappy keyboard and autocorrection.

/peter

jeffg

unread,
Feb 27, 2012, 8:31:35 PM2/27/12
to Gremlin-users
Ya, will probably need to do some classpath checking to alert the user
to a missing library if they try to connect to a DB they don't have
the files for...

I uploaded what I have so far...
https://github.com/jeffg2k/BlueprintConnect

On Feb 24, 4:45 pm, Peter Neubauer <neubauer.pe...@gmail.com> wrote:
> In that case,
> This should be classpath based, otherwise this forced you to have all stuff
> in your installation.
>
> Sent from a device with crappy keyboard and autocorrection.
>
> /peter
Reply all
Reply to author
Forward
0 new messages