10.3 Loading a Graph by Defining a Graph Configuration Object

You can load a graph from Oracle Database by first defining the graph configuration object using the GraphConfigBuilder class and then reading the graph into the graph server (PGX).

The following example loads a PGQL property graph into memory, authenticating as <database user>/<database password> with the database:

opg4j> var vertexConfig = new RdbmsEntityProviderConfigBuilder().
...>                                         setName("Account").
...>                                         setKeyColumn("ID").
...>                                         setParallelHintDegree(3).
...>                                         setDatabaseTableName("BANK_ACCOUNTS").
...>                                         addProperty("ID", PropertyType.INTEGER).
...>                                         build()

opg4j> var edgeConfig = new RdbmsEntityProviderConfigBuilder().
...>                                    setName("Transfer").
...>                                    setKeyColumn("TXN_ID").
...>                                    setSourceColumn("FROM_ACCT_ID").
...>                                    setDestinationColumn("TO_ACCT_ID").
...>                                    setSourceVertexProvider("Account").
...>                                    setDestinationVertexProvider("Account").
...>                                    setParallelHintDegree(3).
...>                                    createKeyMapping(true).
...>                                    setDatabaseTableName("BANK_TXNS").
...>                                    addProperty("FROM_ACCT_ID", PropertyType.INTEGER).
...>                                    addProperty("TO_ACCT_ID", PropertyType.INTEGER).
...>                                    addProperty("AMOUNT", PropertyType.FLOAT).
...>                                    build()

opg4j> var cfg = GraphConfigBuilder.forPartitioned().
...>                  setJdbcUrl("jdbc:oracle:thin:@localhost:1521/orclpdb").
...>                  setUsername("graphuser").
...>                  setPassword("<password>").
...>                  setName("bank_graph").
...>                  setSourceName("bank_graph").
...>                  setSourceType(SourceType.PG_VIEW).
...>                  setVertexIdType(IdType.INTEGER).
...>                  addVertexProvider(vertexConfig).
...>                  addEdgeProvider(edgeConfig).
...>                  build()

opg4j> var g = session.readGraphWithProperties(cfg)
g ==> PgxGraph[name=bank_graph,N=999,E=4993,created=1676806306348]
// Build the vertex provider
RdbmsEntityProviderConfig vertexConfig = new RdbmsEntityProviderConfigBuilder()
                                              .setName("Account")
                                              .setKeyColumn("ID")
                                              .setParallelHintDegree(3)
                                              .setDatabaseTableName("BANK_ACCOUNTS")
                                              .addProperty("ID", PropertyType.INTEGER)
                                              .build();
// Build the edge provider
RdbmsEntityProviderConfig edgeConfig = new RdbmsEntityProviderConfigBuilder()
                                              .setName("Transfer")
                                              .setKeyColumn("TXN_ID")
                                              .setSourceColumn("FROM_ACCT_ID")
                                              .setDestinationColumn("TO_ACCT_ID")
                                              .setSourceVertexProvider("Account")
                                              .setDestinationVertexProvider("Account")
                                              .setParallelHintDegree(3)
                                              .createKeyMapping(true)
                                              .setDatabaseTableName("BANK_TXNS")
                                              .addProperty("FROM_ACCT_ID", PropertyType.INTEGER)
                                              .addProperty("TO_ACCT_ID", PropertyType.INTEGER)
                                              .addProperty("AMOUNT", PropertyType.FLOAT)
                                              .build();
// Build the graph 
GraphConfig cfg = GraphConfigBuilder.forPartitioned()
                           .setJdbcUrl("jdbc:oracle:thin:@localhost:1521/orclpdb")
                           .setUsername("graphuser")
                           .setPassword("<password>")
                           .setName("bank_graph")
                           .setSourceName("bank_graph")
                           .setSourceType(SourceType.PG_VIEW)
                           .setVertexIdType(IdType.INTEGER)
                           .addVertexProvider(vertexConfig)
                           .addEdgeProvider(edgeConfig)
                           .build();

PgxGraph g = session.readGraphWithProperties(cfg);