16.2.1.1 Reading Entity Providers at the Same SCN
If you have a graph which consists of multiple vertex or edge tables or both, then you can read all the vertices and edges at the same System Change Number (SCN).
This helps to overcome issues such as reading edge providers at a later SCN than the SCN at which the vertices were read, as some edges may reference missing vertices.
Note that reading a graph from the database is still possible even if Flashback is not enabled on Oracle Database. In case of multiple databases, SCN can be used to maintain consistency for entity providers belonging to the same database only.
You can use the as_of
flag in the graph configuration to specify at what
SCN an entity provider must be read. The valid values for the as_of
flag are as follows:
Table 16-1 Valid values for "as_of" Key in Graph Configuration
Value | Description |
---|---|
A positive long value
|
This is a parseable SCN value. |
"<current-scn>" |
The current SCN is determined at the beginning of the graph loading. |
"<no-scn>" |
This is to disable SCN at the time of graph loading. |
null |
This defaults to "<current-scn>"
behavior.
|
If "as_of"
is omitted for a vertex or an edge provider in
the graph configuration file, then this follows the same behavior as "as_of":
null
.
Example 16-1 Graph Configuration Using
"as_of"
for Vertex and Edge Providers in the Same
Database
The following example configuration has three vertex providers and one edge provider pointing to the same database.
{
"name": "employee_graph",
"vertex_providers": [
{
"name": "Department",
"as_of": "<current-scn>",
"format": "rdbms",
"database_table_name": "DEPARTMENTS",
"key_column": "DEPARTMENT_ID",
"props": [
{
"name": "DEPARTMENT_NAME",
"type": "string"
}
]
},
{
"name": "Location",
"as_of": "28924323",
"format": "rdbms",
"database_table_name": "LOCATIONS",
"key_column": "LOCATION_ID",
"props": [
{
"name": "CITY",
"type": "string"
}
]
},
{
"name": "Region",
"as_of": "<no-scn>",
"format": "rdbms",
"database_table_name": "REGIONS",
"key_column": "REGION_ID",
"props": [
{
"name": "REGION_NAME",
"type": "string"
}
]
}
],
"edge_providers": [
{
"name": "LocatedAt",
"format": "rdbms",
"database_table_name": "DEPARTMENTS",
"key_column": "DEPARTMENT_ID",
"source_column": "DEPARTMENT_ID",
"destination_column": "LOCATION_ID",
"source_vertex_provider": "Department",
"destination_vertex_provider": "Location"
}
]
}
When reading the employee_graph
using the preceding
configuration file, the graph is read at the same SCN for the
Department
and LocatedAt
entity providers.
This is explained in the following table:
Table 16-2 Example Scenario Using "as_of"
Entity Provider | "as_of" |
SCN Value |
---|---|---|
Department |
"<current-scn>" |
SCN determined automatically |
Location |
"28924323" |
"28924323" used as SCN
|
Region |
"<no-scn>" |
No SCN used |
LocatedAt |
"as_of" flag is omitted
|
SCN determined automatically |
The current SCN value of the database can be determined using one of the following options:
- Querying
V$DATABASE
view:SELECT CURRENT_SCN FROM V$DATABASE;
- Using
DBMS_FLASHBACK
package:SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;
If you do not have the required privileges to perform either of the preceding operations, then you can use:
SELECT TIMESTAMP_TO_SCN(SYSDATE) FROM DUAL;
However, note that this option is less precise than the earlier two options.
You can then read the graph into the graph server using the JSON configuration file as shown:
opg4j> var g = session.readGraphWithProperties("employee_graph.json")
PgxGraph g = session.readGraphWithProperties("employee_graph.json");
g = session.read_graph_with_properties("employee_graph.json")