JDBC Driver for REST

Build 22.0.8479

スキーマのカスタマイズ

自動スキーマ検出 で検出されたテーブルスキーマをカスタマイズして、カラム名やデータ型を変更したり、更新機能を有効にしたりできます。CData JDBC Driver for REST の処理操作は、データの処理およびリモートデータソースとの通信の複雑さを解決しながら、カスタムスキーマを介してこれらのレイヤーを制御することも可能です。

カスタムスキーマは、コンフィギュレーションファイルで定義されます。この章では、これらのファイルの構造を概説します。

スキーマファイルの生成

スキーマファイルの生成 を使用すると、自動スキーマ検出 で検出された動的スキーマを永続化およびカスタマイズできます。

スキーマファイルの編集

テーブルとビューは、APIScript でスキーマファイルを作成することによって定義されます。APIScript は、テーブルのカラムとその動作を定義するシンプルなAPIScript コンフィギュレーション言語にて書かれています。また、REST を処理可能にするビルトインオペレーションがあります。これらのデータ処理構造に加えて、APIScript は、条件分岐やループなどに対応して構成されているフル機能の言語です。ただし、サンプルスキーマに示すように、ほとんどのテーブル定義ではこれらの機能を使用する必要はありません。

スキーマ例

以下は、Raw データ 例のpeople ドキュメントをモデル化し、SQL をJSON/XML データソースに実行するために必要なすべてのコンポーネントを含む、完全に機能的なテーブルスキーマです。

スキーマは次の接続文字列を反映します。これにより、指定されたXPaths によって記述されたデータを含む単一のテーブルが返されます。異なるDataModel 設定についてのガイドは、階層データの解析 を参照してください。

DataModel=FLATTENEDDOCUMENTS;URI=C:\people.xml;XPath='/root/people;/root/people/vehicles;/root/people/vehicles/maintenance';Location=C:\myschemas;GenerateSchemaFiles=OnStart;Format=XML;

スキーマの各コンポーネントの詳細は、カラム定義SELECT 実行INSERT 実行UPDATE 実行、およびDELETE 実行 で確認できます。ストアドプロシージャを作成して、SELECT、INSERT、UPDATE、またはDELETE ステートメントとしてモデル化できないAPI の機能を実装することもできます。詳しくは、ストアドプロシージャの定義 を参照してください。

  <api:script>
     <api:info title="Persons" desc="Parse the OData Persons feed.">
    <!-- You can modify the name, type, and column size here. -->
    <!-- See Column Definitions to specify column behavior and use XPaths to extract column values from XML. -->
      <attr name="ID"           xs:type="int" key="true" readonly="false"   other:xPath="/feed/entry/content/properties/ID" />
      <attr name="EmployeeID"   xs:type="int"            readonly="true"    other:xPath="/feed/entry/content/properties/EmployeeID" />
      <attr name="Name"         xs:type="string"         readonly="false"   other:xPath="/feed/entry/content/properties/Name" />
      <attr name="TotalExpense" xs:type="double"         readonly="true"    other:xPath="/feed/entry/content/properties/TotalExpense" />
      <attr name="HireDate"     xs:type="datetime"       readonly="true"    other:xPath="/feed/entry/content/properties/HireDate" />
      <attr name="Salary"       xs:type="int"            readonly="true"    other:xPath="/feed/entry/content/properties/Salary" />
    </api:info>
    
    <api:set attr="uri" value="http://services.odata.org/V4/OData/(S(5cunewekdibfhpvoh21u2all))/OData.svc/Persons" /> 
  
    <!-- The XPath attribute of a schema is the path to a repeating element that defines the separation of rows -->
    <api:set attr="XPath" value="/feed/entry/" />
  
    <!-- See the xmlproviderGet page in the Operations subchapter to set any needed HTTP parameters. -->
    <api:set attr="ContentType"   value="application/atom+xml" />
  
  <!-- The GET method corresponds to SELECT. Here you can change the parameters of the request for data. The results of processing are pushed to the schema's output. See SELECT Execution for more information. -->
  <api:script method="GET">
    <api:call op="xmlproviderGet">
      <api:push/>
    </api:call>
  </api:script>
  
  <!-- To add support for INSERTS please see the INSERT Execution page within the help for further information and examples. -->
  <api:script method="POST">
    <api:set attr="method" value="POST"/>
    <api:call op="xmlproviderGet">
      <api:throw code="500" desc="Inserts are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

  <!-- To add support for UPDATES please see the UPDATE Execution page within the help for further information and examples. -->
  <api:script method="MERGE">
    <api:set attr="method" value="PUT"/>
    <api:call op="xmlproviderGet">
      <api:throw code="500" desc="Updates are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

  <!-- To add support for DELETES please see the DELETE Execution page within the help for further information and examples. -->
  <api:script method="DELETE">
    <api:set attr="method" value="DELETE"/>
    <api:call op="xmlproviderGet">
      <api:throw code="500" desc="Deletes are not currently supported."/>
      <api:push/>
    </api:call>
  </api:script>

  </api:script> 

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479