A.4.8 Opening and Closing a Property Graph Instance
When describing a property graph, use these Oracle Property Graph classes to open and close the property graph instance properly:
-
OraclePropertyGraph.getInstance
: Opens an instance of an Oracle property graph. This method has two parameters, the connection information and the graph name. -
OraclePropertyGraph.clearRepository
: Removes all vertices and edges from the property graph instance. -
OraclePropertyGraph.shutdown
: Closes the graph instance.
For Oracle Database, the OraclePropertyGraph.getInstance
method uses an Oracle instance to manage the database connection. OraclePropertyGraph
has a set of constructors that let you set the graph name, number of hash partitions, degree of parallelism, tablespace, and options for storage (such as compression). For example:
import oracle.pg.rdbms.*;
Oracle oracle = new Oracle(jdbcURL, username, password);
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(oracle, graphName);
opg.clearRepository();
// .
// . Graph description
// .
// Close the graph instance
opg.shutdown();
If the in-memory analyst functions are required for an application, you should use GraphConfigBuilder
to create a graph for Oracle Database, and instantiate OraclePropertyGraph
with that graph name as an argument. For example, the following code snippet constructs a graph config
, gets an OraclePropertyGraph
instance, loads some data into that graph, and gets an in-memory analyst.
import oracle.pgx.config.*;
import oracle.pgx.api.*;
import oracle.pgx.common.types.*;
...
PgNosqlGraphConfig cfg = GraphConfigBuilder. forPropertyGraphRdbms ()
.setJdbcUrl("jdbc:oracle:thin:@<hostname>:1521:<sid>")
.setUsername("<username>").setPassword("<password>")
.setName(szGraphName)
.setMaxNumConnections(8)
.addEdgeProperty("lbl", PropertyType.STRING, "lbl")
.addEdgeProperty("weight", PropertyType.DOUBLE, "1000000")
.build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
String szOPVFile = "../../data/connections.opv";
String szOPEFile = "../../data/connections.ope";
// perform a parallel data load
OraclePropertyGraphDataLoader opgdl = OraclePropertyGraphDataLoader.getInstance();
opgdl.loadData(opg, szOPVFile, szOPEFile, 2 /* dop */, 1000, true, "PDML=T,PDDL=T,NO_DUP=T,");
...
PgxSession session = Pgx.createSession("session-id-1");
PgxGraph g = session.readGraphWithProperties(cfg);
Analyst analyst = session.createAnalyst();
...
Parent topic: Using Java APIs for Property Graph Data