4.5.2 Building Graph Configuration Using the GraphConfigBuilder API

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 are a few examples to read a property graph into memory, authenticating as <database user>/<database password> with the database:

Loading a Graph from Property Graph Schema Using GraphConfigBuilder

opg4j> var config = GraphConfigBuilder.forPropertyGraphRdbms().
...>     setName("bank_graph").
...>     setJdbcUrl("jdbc:oracle:thin:@localhost:1521/orclpdb").
...>     setUsername("graphuser").
...>     setPassword("graphuser").
...>     addVertexProperty("ID", PropertyType.STRING).
...>     addVertexProperty("NAME", PropertyType.STRING).
...>     addEdgeProperty("AMOUNT", PropertyType.FLOAT).
...>     addEdgeProperty("DESCRIPTION", PropertyType.STRING).
...>     setPartitionWhileLoading(PartitionWhileLoading.BY_LABEL).
...>     setLoadVertexLabels(true).
...>     setLoadEdgeLabel(true).
...>     build()
config ==> {"error_handling":{},"name":"bank_graph","vertex_id_type":"long","loading":{"load_vertex_labels":true,"load_edge_label":true},"password":"*******","format":"pg","edge_props":[{"name":"AMOUNT","dimension":0,"type":"float"},{"name":"DESCRIPTION","dimension":0,"type":"string"}],"jdbc_url":"jdbc:oracle:thin:@localhost:1521/orclpdb","vertex_props":[{"name":"ID","dimension":0,"type":"string"},{"name":"NAME","dimension":0,"type":"string"}],"partition_while_loading":"BY_LABEL","attributes":{},"db_engine":"RDBMS","username":"graphuser"}
opg4j> PgxGraph g = session.readGraphWithProperties(config)
g ==> PgxGraph[name=bank_graph,N=1000,E=5001,created=1632825497751]
GraphConfig config = GraphConfigBuilder.forPropertyGraphRdbms()
                                 .setName("bank_graph")
                                 .setJdbcUrl("jdbc:oracle:thin:@localhost:1521/orclpdb")
                                 .setUsername("graphuser")
                                 .setPassword("graphuser")
                                 .addVertexProperty("ID", PropertyType.STRING)
                                 .addVertexProperty("NAME", PropertyType.STRING)
                                 .addEdgeProperty("AMOUNT", PropertyType.FLOAT)
                                 .addEdgeProperty("DESCRIPTION", PropertyType.STRING)
                                 .setPartitionWhileLoading(PartitionWhileLoading.BY_LABEL)
                                 .setLoadVertexLabels(true)
                                 .setLoadEdgeLabel(true)
                                 .build();

PgxGraph g = session.readGraphWithProperties(config);

Loading a Partitioned Graph into the Graph Server (PGX) Using GraphConfigBuilder

opg4j> var vertexConfig = new RdbmsEntityProviderConfigBuilder(). // build the vertex provider
...>                                              setName("node").
...>                                              setKeyColumn("ID").
...>                                              setDatabaseTableName("BANK_ACCOUNTS").
...>                                              addProperty("ID", PropertyType.INTEGER).
...>                                              build()
vertexConfig ==> {"name":"node","error_handling":{},"key_type":"long","attributes":{},"props":[{"dimension":0,"name":"ID","type":"integer"}],"loading":{"create_key_mapping":true},"format":"rdbms",
"database_table_name":"BANK_ACCOUNTS","key_column":"ID"}
opg4j> var edgeConfig = new RdbmsEntityProviderConfigBuilder(). // build the edge provider
...>                                              setName("transfer").
...>                                              setKeyColumn("ID").
...>                                              setSourceColumn("FROM_ACCT_ID").
...>                                              setDestinationColumn("TO_ACCT_ID").
...>                                              setSourceVertexProvider("node").
...>                                              setDestinationVertexProvider("node").
...>                                              createKeyMapping(true).
...>                                              setDatabaseTableName("BANK_TXNS").
...>                                              addProperty("FROM_ACCT_ID", PropertyType.LONG).
...>                                              addProperty("TO_ACCT_ID", PropertyType.LONG).
...>                                              addProperty("AMOUNT", PropertyType.LONG).
...>                                              build()
edgeConfig ==> {"name":"transfer","destination_vertex_provider":"node","attributes":{},"props":[{"dimension":0,"name":"FROM_ACCT_ID","type":"long"},{"dimension":0,"name":"TO_ACCT_ID","type":"long"},
{"dimension":0,"name":"AMOUNT","type":"long"}],"loading":{"create_key_mapping":true},"database_table_name":"BANK_TXNS","key_column":"ID","destination_column":"TO_ACCT_ID","source_vertex_provider":"node",
"error_handling":{},"key_type":"long","source_column":"FROM_ACCT_ID","format":"rdbms"}
opg4j> var cfg = GraphConfigBuilder.forPartitioned(). //build the partitioned graph
...>                       setJdbcUrl("jdbc:oracle:thin:@localhost:1521/orclpdb").
...>                       setUsername("graphuser").
...>                       setPassword("graphuser").
...>                       setName("bank_graph_partitioned").
...>                       setVertexIdType(IdType.LONG).
...>                       addVertexProvider(vertexConfig).
...>                       addEdgeProvider(edgeConfig).
...>                       build()

opg4j> var g = session.readGraphWithProperties(cfg)
g ==> PgxGraph[name=bank_graph_partitioned_2,N=1000,E=5001,created=1632837214584]
// Build the vertex provider
RdbmsEntityProviderConfig vertexConfig = new RdbmsEntityProviderConfigBuilder()
                                             .setName("node")
                                             .setKeyColumn("ID")
                                             .setDatabaseTableName("BANK_ACCOUNTS")
                                             .addProperty("ID", PropertyType.INTEGER)
                                             .build();
// Build the edge provider
RdbmsEntityProviderConfig edgeConfig = new RdbmsEntityProviderConfigBuilder()
                                             .setName("transfer")
                                             .setKeyColumn("ID")
                                             .setSourceColumn("FROM_ACCT_ID")
                                             .setDestinationColumn("TO_ACCT_ID")
                                             .setSourceVertexProvider("node")
                                             .setDestinationVertexProvider("node")
                                             .createKeyMapping(true)
                                             .setDatabaseTableName("BANK_TXNS")
                                             .addProperty("FROM_ACCT_ID", PropertyType.LONG)
                                             .addProperty("TO_ACCT_ID", PropertyType.LONG)
                                             .addProperty("AMOUNT", PropertyType.LONG)
                                             .build();
// Build the partitioned graph 
GraphConfig cfg = GraphConfigBuilder.forPartitioned()
                      .setJdbcUrl("jdbc:oracle:thin:@<host>:<port>/<service_name>")
                      .setUsername("<username>")
                      .setPassword("<password>")
                      .setName("bank_graph_partitioned")
                      .setVertexIdType(IdType.LONG)
                      .addVertexProvider(vertexConfig)
                      .addEdgeProvider(edgeConfig)
                      .build();

PgxGraph g = session.readGraphWithProperties(cfg);