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:@<host>:<port>/<service_name>").
...> setUsername("<username>").
...> setPassword("<password>").
...> 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:@<host>:<port>/<service_name>")
.setUsername("<username>")
.setPassword("<password>")
.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().
...> setName("node").
...> setKeyColumn("ID").
...> setParallelHintDegree(3).
...> setDatabaseTableName("BANK_ACCOUNTS").
...> addProperty("ID", PropertyType.LONG).
...> build()
vertexConfig ==> {"loading":{"create_key_mapping":true},"format":"rdbms","parallel_hint_degree":3,"key_column":"ID","props":[{"name":"ID","dimension":0,"type":"
long"}],"key_type":"integer","attributes":{},"error_handling":{},"name":"node","database_table_name":"BANK_ACCOUNTS"}
opg4j> var edgeConfig = new RdbmsEntityProviderConfigBuilder().
...> setName("transfer").
...> setKeyColumn("TXN_ID").
...> setSourceColumn("FROM_ACCT_ID").
...> setDestinationColumn("TO_ACCT_ID").
...> setSourceVertexProvider("node").
...> setDestinationVertexProvider("node").
...> setParallelHintDegree(3).
...> createKeyMapping(true).
...> setDatabaseTableName("BANK_TXNS").
...> addProperty("FROM_ACCT_ID", PropertyType.LONG).
...> addProperty("TO_ACCT_ID", PropertyType.LONG).
...> addProperty("AMOUNT", PropertyType.LONG).
...> build()
edgeConfig ==> {"format":"rdbms","parallel_hint_degree":3,"key_column":"TXN_ID","props":[{"name":"FROM_ACCT_ID","dimension":0,"type":"long"},
{"name":"TO_ACCT_ID","dimension":0,"type":"long"},{"name":"AMOUNT","dimension":0,"type":"long"}],"name":"transfer","destination_vertex_provider":"node",
"loading":{"create_key_mapping":true},"key_type":"long","attributes":{},"error_handling":{},"destination_column":"TO_ACCT_ID","source_column":"FROM_ACCT_ID",
"source_vertex_provider":"node","database_table_name":"BANK_TXNS"}
opg4j> var cfg = GraphConfigBuilder.forPartitioned(). //build the partitioned graph
...> setJdbcUrl("jdbc:oracle:thin:@<host>:<port>/<service_name>").
...> setUsername("<username>").
...> setPassword("<password>").
...> setName("bank_graph_partitioned").
...> setVertexIdType(IdType.INTEGER).
...> 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")
.setParallelHintDegree(3)
.setDatabaseTableName("BANK_ACCOUNTS")
.addProperty("ID", PropertyType.LONG)
.build();
// Build the edge provider
RdbmsEntityProviderConfig edgeConfig = new RdbmsEntityProviderConfigBuilder()
.setName("transfer")
.setKeyColumn("TXN_ID")
.setSourceColumn("FROM_ACCT_ID")
.setDestinationColumn("TO_ACCT_ID")
.setSourceVertexProvider("node")
.setDestinationVertexProvider("node")
.setParallelHintDegree(3)
.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.INTEGER)
.addVertexProvider(vertexConfig)
.addEdgeProvider(edgeConfig)
.build();
PgxGraph g = session.readGraphWithProperties(cfg);