14.5.1.1.1 頂点プロバイダのロード

alterationBuilder.addVertexProvider(EntityProviderConfig vertexProviderConfig)をコールすることで、頂点プロバイダを追加できます。

vertexProviderConfigは、頂点プロバイダ構成であり、次のような構成詳細を提供します。
  • ロード元となるデータソースの場所
  • 格納形式
  • 頂点プロバイダのプロパティ

JSON構成からの頂点プロバイダの追加

alterationBuilder.addVertexProvider(String pathToVertexProviderConfig)をコールすることでプロバイダを追加できます。ここで、 pathToVertexProviderConfigは、頂点プロバイダ構成のJSON表現を含む、クライアントからアクセス可能なファイルを指します。

たとえば、頂点プロバイダ構成は、次のようにJSONファイルに格納できます。

{
  "name": "Accounts",
  "format": "rdbms",
  "database_table_name": "BANK_ACCOUNTS",
  "key_column": "ID",
  "key_type": "integer",
  "props": [
    {
      "name": "ID",
      "type": "integer"
    },
    {
      "name": "NAME",
      "type": "string"
    }
  ]
}

その後、次の例で示すように、頂点プロバイダを追加できます。

// 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>");

APIの使用によるプログラムでの頂点プロバイダの追加

または、頂点プロバイダ構成をプログラムで作成することもできます。

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);