TinkerPop Blueprints standard doesn’t define a proper "Factory" to get graph instances. For this reason OrientDB users that wanted to use a pool of instances had to mix 2 different API: Graph and Document one. Example:
ODatabaseDocumentPool pool = new ODatabaseDocumentPool("plocal:/temp/mydb");
OrientGraph g = new OrientGraph(pool.acquire());
NOTE: You could also use a OGraphDatabase instance in place of ODatabaseDocumentPool, but this API has been deprecated since a long time and will be removed in v1.7.
Now everything is simpler, thanks to the new OrientGraphFactory class to manage graphs in easy way (Issue #1971). These are the main features:
This is the basic way to create the factory, by using the default "admin" user (with "admin" password by default):
OrientGraphFactory factory = new OrientGraphFactory("plocal:/temp/mydb");
But you can also pass user and password:
OrientGraphFactory factory = new OrientGraphFactory("plocal:/temp/mydb", "jayminer", "amigarocks");
To work with a recyclable pool of instances with minimum 1, maximum 10 instances:
OrientGraphFactory factory = new OrientGraphFactory("plocal:/temp/mydb").setupPool(1, 10);
Once the factory is configured you can get a Graph instance to start working. OrientGraphFactory has 2 methods to retrieve a Transactional and Non-Transactional instance:
OrientGraph txGraph = factory.getTx();
OrientGraphNoTx noTxGraph = factory.getNoTx();
Or again you can configure in the factory the instances you want and use the get() method everytime:
factory.setTransactional(false);
OrientGraphNoTx noTxGraph = (OrientGraphNoTx) factory.get();
Once finished to free all the resources (in case of pool usage), call the close():
factory.close();