Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Platform 4.5+ が必要

...


SQL データソースへのアクセス

Nexaweb 4.5

...

では、アプリケーションをデータベースに接続して次の操作を実行可能にする SQL (JDBC (Java Database Connectivity

...

))

...

  • Populate and modify data in the client UI from the database
  • Populate and modify data in the database from the client UI

In order to use the SQL data service, you need to:

...

データサービスを提供します。
  • クライアント UI で、データベースからのデータを入力および変更する
  • データベースで、クライアント UI からのデータを入力および変更する
SQL データサービスを使用するには、次の作業を行う必要があります。
  • クライアントアプリケーションにデータサービス プラグインを追加する
  • サーバー上の nexaweb-sql.xml
  • file, on the server, to:
    • Specific external databases
    • A connection pool
    Define SQL statements:In the
  • ファイルで次のものへの接続を作成する
    • 特定の外部データベース
    • 接続プール
  • SQL 文を次の方法で定義する。
    • dataRequestDefinitions で参照するために nexaweb-sql.xml
  • , file to reference in dataRequestDefinitionsDirectly in dataRequestDefinitions in the
    • ファイルで定義する
    • nexaweb-data.xml
  • file
  • In embedded serviceRequests in the client UI file

Configuring the SQL Data Service

...

    • ファイルの dataRequestDefinitions で直接定義する
    • クライアント UI ファイルの埋め込みの serviceRequests で定義する
SQL データ サービスの構成

...


SQL データ サービスのコンフィギュレーション ファイル nexaweb-sql.xml

...

Configuration SectionDescription
connectionDefinitionsDefines connections over which client applications can execute sql data service requests to external data.
dataSourceConnectionDefinitionDefines a J2EE DataSource from which clients can obtain connections. A J2EE DataSource allows applications to leverage native driver connection pooling available through the JDBC optional javax.sql package.
statementDefinitionsLists sql statement types defined on the server that your application can use by reference to access external data.
Note: You can also specify sql statement types in the client UI within an embeddedServiceRequest
statementHandlerDefinitionsLists the defined statement handlers that you can use with any sql statements to transform data results when the statement executes.

Defining Connections

You can define connections as follows:

Connection Description
connectionDefinitionsDefines connections over which client applications can execute sql data service requests to external data.
dataSourceConnectionDefinitionDefines a J2EE DataSource from which clients can obtain connections. A J2EE DataSource allows applications to leverage native driver connection pooling available through the JDBC optional javax.sql package.

connectionDefinitions

A connectionDefinition tag includes the following attributes and child elements:

...

Child element:
property - specifies a property name and value for that property.

には、次のセクションが含まれます。
 
コンフィギュレーション セクション
説明
connectionDefinitions
クライアント アプリケーションが外部データへの SQL データ サービス リクエストを実行できるように接続を定義します。
dataSourceConnectionDefinition
クライアントが接続を取得できる J2EE データ ソースを定義します。J2EE データソースを使用すると、アプリケーションが JDBC オプションパッケージ javax.sql を通じて使用可能なネイティブ ドライバの接続プールを利用できるようになります。
statementDefinitions
サーバー上で定義された SQL 文のタイプを示します。このタイプは、アプリケーションが外部データにアクセスする際に参照によって使用できます。
メモ: SQL 文のタイプは、クライアント UI の embeddedServiceRequest 内で指定することもできます。
statementHandlerDefinitions
定義された文ハンドラを示します。このハンドラは、任意の SQL 文で文を実行した際のデータ結果を変換するために使用できます。

接続の定義


接続は次のように定義できます。
 
接続
説明
connectionDefinitions
クライアント アプリケーションが外部データへの SQL データ サービス リクエストを実行できるように接続を定義します。
dataSourceConnectionDefinition
クライアントが接続を取得できる J2EE データ ソースを定義します。J2EE データソースを使用すると、アプリケーションが JDBC オプションパッケージjavax.sqlを通じて使用可能なネイティブ ドライバの接続プールを利用できるようになります。

connectionDefinitions

connectionDefinitionタグには次の属性および子要素が含まれています。
 
要素
タイプ
説明
driver
属性
この接続で使用する driver クラスを指定します。
id
属性
この接続を識別するための ID を指定します。
url
属性
この接続でアクセスするデータベースへの URL。jdbc:subprotocol:subname の形式で指定されます。
properties
子要素
この接続のプロパティのリストを指定します。
子要素:
プロパティ - そのプロパティについてプロパティの名前と値を指定します。

例:
 
Code Block
<connectionDefinition id="engineering" driver="com.mysql.jdbc.Driver" 
  url="jdbc:mysql://dgnc/engineering">
  <properties>
    <property name="user">Ron</property>
    <property name="password">77$Lo</property>
  </properties>
</connectionDefinition>

dataSourceConnectionDefinitions

A dataSourceConnectionDefinition tag includes the following attributes:

...


dataSourceConnectionDefinition タグには次の属性が含まれています。
 
要素
タイプ
説明
id
Attribute
属性
Specifies an ID by which to identify this connection.
この接続を識別するための ID を指定します。
name
AttributeThe name of the dataSource resource to look up. For example
属性
検索する dataSource リソースの名前。例: java:comp/env/jdbc/SalesDB
password
AttributeThe password required to establish a connection with this datasource.
属性
このデータ ソースとの接続を確立するために必要なパスワード。
username
AttributeThe username required to establish a connection with this datasource.

...

属性
このデータ ソースとの接続を確立するために必要なユーザー名。

例:

 

Code Block

...

<dataSourceconnectionDefinition id="support"

...

 

...

name="java:comp/env/jdbc/SalesDB" password="P3aCh" username="BLame"> 
</

...

connectionDefinition>  

 

...

statementHandlerDefinitions

...

You can define statement handlers to process the results of SQL statements after a statement has executed.

You define statement handlers in the statementHandlerDefinitions section using the statementHandlerDefinition tag.

The statementHandlerDefinition tag includes the following attributes:

EelementTypeDescription
classAttributeSpecifies the implementing class.
defaultAttributeSpecifies whether all SQL statements use this statementHandlerDefinition as the default, if the statement does not inlcude any other statementHandlerDefinitions. True or false. True = Use this statementHandlerDefinition as the default.
idAttributeSpecifies a unique ID by which to identify this statementHandlerDefinition.

For example:

...

の定義


文ハンドラを定義すると、文を実行した後の SQL 文の結果を処理できます。

文ハンドラは、statementHandlerDefinitionsセクションで statementHandlerDefinition タグを使用して定義します。

statementHandlerDefinition タグには次の属性が含まれています。
 
要素
タイプ
説明
class
属性
実装クラスを指定します。
default
属性
文 にその他の statementHandlerDefinitions が含まれていない場合、すべての SQL 文でこの statementHandlerDefinition をデフォルトとして使用するかどうかを指定します。true または false。True = この statementHandlerDefinition をデフォルトとして使用します。
id
属性
この statementHandlerDefinition を識別するための一意の ID を指定します。

例:

 

Code Block
<statementHandlerDefinitions>
  <statementHandlerDefinition class="statementHandler" default="false"

...

 

...

id="NoItalics"> </

...

statementHandlerDefinition>
  <statementHandlerDefinition class="statementHandler" default="true"

...

 id="LowCase"> </

...

statementHandlerDefinition>
</statementHandlerDefinitions>

...

 

statementDefinitions

...

の定義


SQL 文を nexaweb-sql. xml

...

コンフィギュレーションファイルで定義すると、サーバー上でこれらを利用できるようになります。さらに、これらの SQL 文は nexaweb-data.xml

...

ファイルで定義された dataRequestDefinitions で参照できます。

...


statementDefinitions は、nexaweb-sql.xml

...

The SQL data service offers the following types of sql statements:

TagDescription
<sqlStatement>Specifies a generic sql statement, which contains a string to execute against a specified connection.
<sqlSelect>Specifies a simple syntax for making a query to a single table over a specified connection.
<sqlUpdate>Specifies a simple syntax for making an update to a single table over a specified connection.
<sqlInsert>Specifies a simple syntax for making a row insert to a single table over a specified connection.
<sqlDelete>Specifies a simple syntax for deleting rows from a single table over a specified connection.

statementDefinition includes the following elements:

EelementTypeDescriptionStatement TypeRequired/Optional
<connectionId>AttributeThe ID of the connectionDefinition to use to execute the statement against.AllRequired
<id>AttributeSpecifies an ID by which to identify this statementDefinition.AllRequired
<statementHandlerId>AttributeThe ID of a statementHandler to use for processing the statement after successful execution. If none specified, the data service uses the default statement handler. AllOptional
<statement>AttributeThe statement to execute.<sqlStatement>Required
<table>ChildSpecifies the table from which the statement retrieves or updates rows.<sqlSelect>, <sqlUpdate>, <sqlInsert>, <sqlDelete>Optional
<columns>ChildSpecifies the columns to retrieve or update. If none specified, retrieves or updates all columns.<sqlSelect>, <sqlUpdate>, <sqlInsert>Optional
<where>ChildClause identifying the rows to retrieve or update. <sqlSelect>, <sqlUpdate>, <sqlDelete>Optional

Using SQL Data Sources in a serviceRequest

You can specify a SQL statement to use in a data request in any of the following ways:

...

コンフィギュレーションファイルの statementDefinitions セクションで作成します。

SQL データサービスには、次のタイプの SQL 文が用意されています。
 
タグ
説明
<sqlStatement>
指定した接続に対して実行する文字列が含まれる、汎用の SQL 文を指定します。
<sqlSelect>
指定した接続を通じて 1 つのテーブルにクエリを実行するための単純なシンタックスを指定します。
<sqlUpdate>
指定した接続を通じて 1 つのテーブルに更新を実行するための単純なシンタックスを指定します。
<sqlInsert>
指定した接続を通じて 1 つのテーブルに行を挿入するための単純なシンタックスを指定します。
<sqlDelete>
指定した接続を通じて 1 つのテーブルから行を削除するための単純なシンタックスを指定します。
statementDefinition には次の要素が含まれています。

 

要素
タイプ
説明
文タイプ
必須/省略可能
<connectionId>
属性
文の実行に使用される connectionDefinition の ID。
すべて
必須
<id>
属性
この statementDefinition を識別するための ID を指定します。
すべて
必須
<statementHandlerId>
 
属性
正常に実行された後の文を処理するために使用される statementHandler の ID。指定されていない場合、データ サービスはデフォルトの文ハンドラを使用します。
すべて
省略可能
<statement>
属性
実行する文。
<sqlStatement>
必須
<table>
子要素
文が行を取得または更新するテーブルを指定します。
<sqlSelect>、<sqlUpdate>、<sqlInsert>、<sqlDelete>
省略可能
<columns>
子要素
取得または更新する列を指定します。指定されていない場合は、すべての列が取得または更新されます。
<sqlSelect>、<sqlUpdate>、<sqlInsert>
省略可能
<where>
子要素
取得または更新される行を特定する句。
<sqlSelect>、<sqlUpdate>、<sqlDelete>
省略可能

serviceRequestSQL データソースを使用する

データリクエストで使用するため、次の方法で SQL ステートメントを特定することができます :

位置説明
nexaweb-sql.xmlサーバー側の nexaweb-sql.xml 設定ファイルのstatementDefinitions セクションでステートメントを特定する。その後 nexaweb-data.xml ファイルの dataRequestDefinitionserviceResourceReference で参照する。(最終的に、クライアント UIファイルの serviceRequest dataRequestDefinitionを参照)
nexaweb-data.xmlSpecify a statement in a serviceResourceDefintion of a dataRequestDefinition in the nexaweb-data.xml file. (Then reference the dataRequestDefinition in a serviceRequest in the client UI file. ファイルの dataRequestDefinitionserviceResourceDefintion のステートメントを特定する。(その後クライアントUIファイルの serviceRequestdataRequestDefinition を参照)

Client UI
Specify a statement in an embeddedServiceRequest directly in the client UI file.

...

embeddedServiceRequest のステートメントをクライアント UI ファイルに直接指定する

クライアントサイドのデータリクエストPlug-in Examples

The following examples demonstrate the two ways that you can define an SQL statement in a UI file.

In-line Example

...

languagehtml/xml
linenumberstrue

次の例は UI ファイルで SQL ステートメントを定義することができる2つの方法を示しています。

Code Block
<dr:dataRequest id="getDepartmentRequest"”getDepartmentRequest” 
   target="dataSource”dataSource://myDocumentSource"myDocumentSource” 
   xmlns:dr="http”http://nexaweb/com/dataService/request">request”> 
  <ds:dataRequestDefinition xmlns:ds="http”http://nexaweb/com/dataService">dataService”> 
    <ds:dataServiceRequest> 
      <jdbc:jdbcStatement connectionId="engineering" 
         xmlns:jdbc="http”http://nexaweb/com/dataService/jdbc">jdbc”> 
      <jdbc:statement>
         SELECT * FROM department where dept={0}
      </jdbc:statement> 
      </ jdbc:jdbcStatement> 
    </ds:dataServiceRequest> 
  </ds:dataRequestDefinition>
</dr:dataRequest> dataRequest>

Shortcut Example

The following example of defining an SQL statement in a cient UI file is equivalent to the preceding In-line example.

true
Code Block
languagehtml/xml
linenumbers
 <jdbc:jdbcStatement id="getDepartmentRequest"”getDepartmentRequest” connectionId="engineering" 
  target="dataSource”dataSource://myDocumentSource"myDocumentSource” 
  xmlns:jdbc="http”http://nexaweb/com/dataService/jdbc">jdbc”>
  <statement>SELECT * FROM department where dept={0}</statement>
</jdbc:jdbcStatement>
<jdbcService xmlns=http://nexaweb.com/dataService/sql>
  <connectionDefinitions>
    <connectionDefinition id="engineering" driver="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://dgnco/engineering">
      <properties>
        <property name="user">venutian</property>
        <property name="password">venutian</property> 
      </properties> 
   </connectionDefinition>
     <connectionDefinition id="salesdata" driver="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://dgnco/sales?user=venutian&amp;password=venutian"/>
     </connectionDefinitions> 
  <statementHandlerDefinitions>
  </statementHandlerDefinitions> 
  <statementDefinitions> 
     <sqlStatement id="getCustomers" connectionId="salesdata"> 
     <statement>select * from customers</statement> 
     </jdbcStatement>
  </statementDefinitions>
</jdbcService>