14.5.1.1.1 Loading Vertex Providers
You can add a vertex provider by calling
alterationBuilder.addVertexProvider(EntityProviderConfig
vertexProviderConfig)
.
vertexProviderConfig
is a vertex provider configuration and it
provides configuration details such as:
- location of the datasource to load from
- the stored format
- properties of the vertex provider
Adding a Vertex Provider from a JSON Configuration
You can add the provider by calling
alterationBuilder.addVertexProvider(String pathToVertexProviderConfig)
where pathToVertexProviderConfig
points to a file accessible from the
client that contains a JSON representation of a vertex provider configuration.
For example, a vertex provider configuration can be stored in a JSON file as shown:
{
"name": "Accounts",
"format": "rdbms",
"database_table_name": "BANK_ACCOUNTS",
"key_column": "ID",
"key_type": "integer",
"props": [
{
"name": "ID",
"type": "integer"
},
{
"name": "NAME",
"type": "string"
}
]
}
You can then add the vertex provider as shown in the following example:
// Loading by indicating the path to the JSON file
opg4j> alterationBuilder.addVertexProvider("<path-to-vertex-provider-configuration>")
$9 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@48d464cf
// Or by first loading the content of a JSON file into an EntityProviderConfig object
opg4j> EntityProviderConfig vertexProviderConfig = new AnyFormatEntityProviderConfigFactory().fromPath("<path-to-vertex-provider-configuration>")
vertexProviderConfig ==> {"format":"rdbms","name":"Accounts","database_table_name":"BANK_ACCOUNTS","loading":{"create_key_mapping":true},"key_type":"integer","props":[{"type":"integer","name":"ID"},{"type":"string","name":"NAME"}],"key_column":"ID"}
opg4j> alterationBuilder.addVertexProvider(vertexProviderConfig)
$15 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@77e2a5d3
// Loading by indicating the path to the JSON file
alterationBuilder.addVertexProvider("<path-to-vertex-provider-configuration>");
// Or by first loading the content of a JSON file into an EntityProviderConfig object
EntityProviderConfig vertexProviderConfig = new AnyFormatEntityProviderConfigFactory().fromPath("<path-to-vertex-provider-configuration>");
alterationBuilder.addVertexProvider(vertexProviderConfig);
# Loading by indicating the path to the JSON file
alterationBuilder.add_vertex_provider("<path-to-vertex-provider-configuration>");
Adding a Vertex Provider Programmatically Using an API
Alternatively, the vertex provider configuration can be built programmatically:
opg4j> RdbmsEntityProviderConfigBuilder vertexProviderConfigBuilder = new RdbmsEntityProviderConfigBuilder().
...> setName("Accounts").
...> setKeyColumn("ID").
...> setDatabaseTableName("BANK_ACCOUNTS").
...> addProperty("ID", PropertyType.INTEGER)
vertexProviderConfigBuilder ==> oracle.pgx.config.RdbmsEntityProviderConfigBuilder@8ff4d2b
opg4j> EntityProviderConfig vertexProviderConfig = vertexProviderConfigBuilder.build()
vertexProviderConfig ==> {"error_handling":{},"format":"rdbms","name":"Accounts","database_table_name":"BANK_ACCOUNTS","loading":{"create_key_mapping":true},"attributes":{},"key_type":"long","props":
[{"dimension":0,"type":"integer","name":"ID"}],"key_column":"ID"}
opg4j> alterationBuilder.addVertexProvider(vertexProviderConfig)
$24 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@7b303608
RdbmsEntityProviderConfigBuilder vertexProviderConfigBuilder = new RdbmsEntityProviderConfigBuilder()
.setName("Accounts")
.setKeyColumn("ID")
.setDatabaseTableName("BANK_ACCOUNTS")
.addProperty("ID", PropertyType.INTEGER);
EntityProviderConfig vertexProviderConfig = vertexProviderConfigBuilder.build();
alterationBuilder.addVertexProvider(vertexProviderConfig);
Parent topic: Loading Or Removing Additional Vertex or Edge Providers