• 検索結果がありません。

Bean データソース

ドキュメント内 JasperReports Server CP User Guide JP (ページ 114-117)

4.7 データソース

4.7.4 Bean データソース

Bean データソースタイプは、キー拡張となります。これにより、レポートで必要とされる任意のカスタムデータまたは珍しい データを扱うことが可能になります。Bean データソースは、Spring で定義されている bean と JasperReport とをつなぐブリッ ジの役割を勤めます。Spring bean には、レポートに必要となるすべてのデータやパラメータを提供する責任があります。

The bean data source type is a key extension because it allows you to make use of any custom or exotic data that you might need to report on. Bean data sources serve as a bridge between a Spring-defined bean and a JasperReport. The Spring bean is responsible for providing the data or parameters that fill the report.

Bean データソースを使うには、初めに、基礎となる Spring beanの設定を⾏い、サーバのWeb アプリケーションコンテキス トとして利⽤可能にする必要があります。例えば、bean の定義情報を「WEB-INF/applicationContext*.xml」ファイルのい ずれかに追加する、などです。

To use a bean data source, you must first configure the underlying Spring bean and make it available in the server’s web application context. For example, you would add a bean definition to one of the

WEB-INF/applicationContext*.xml files.

Bean は、直接または引数のないファクトリメソッドを用いてReportDataSourceServiceインスタンスを解決しなければなりま せん。データソースサービス bean に対しては、任意の Springのインスタンス化メソッド(例えばコンストラクタやファクト リ)や、beanのスコープ(例えばシングルトンやプロトタイプ)を使うことができます。

The bean must resolve to a ReportDataSourceService instance, either directly or by way of a factory no-argument method. You can use any Spring instantiation method (for example, a constructor or factory) and bean scope (for example, singleton or prototype) for the data source service bean.

ReportDataSourceService インスタンスには、データソースパラメータを JasperReport に提供する責任があります。

ReportDataSourceServiceのカスタム実装では、以下の 2 つのアプローチをとることができます。

The ReportDataSourceService instance is responsible for supplying data source parameters to the JasperReport.

Custom ReportDataSourceService implementations can follow two approaches:

その実装でレポートが必要とするデータをすべて提供できる場合は、そのデータをJRDataSource実装に合わせてラップし、

REPORT_DATA_SOURCEパラメータを使ってそのデータを渡す必要があります。

If the implementation can provide the data to fill a report, it needs to wrap the data into a suitable JRDataSource implementation and pass the data using the REPORT_DATA_SOURCE report parameter.

JasperReports クエリエグゼキュータとしてレポートクエリを使ってデータを取得する場合は、データソースサービスは、

そのクエリエグゼキュータにより定義されているコネクションパラメータに値を設定しなければなりません。コネクショ ンパラメータは、通常、データソースサービスインスタンスのプロパティから取得されます。

If the data comes from the report query by way of a JasperReports query executor, the data source service must set values for the connection parameters defined by the query executor. The connection parameters are usually obtained from the properties of the data source service instance.

例えば、セッションファクトリに挿入されるであろう Hibernate データソースサービスを実装することができます。ファクト リは、HIBERNATE_SESSIONパラメータの値として渡される Hibernate セッションを作成します。次に、JasperReports Hibernate クエリエグゼキュータは、そのパラメータを使って HQLレポートクエリを実⾏します。

For example, you could implement a Hibernate data source service that would be injected in a session factory. The factory would create a Hibernate session that is passed as a value for the HIBERNATE_SESSION parameter. The JasperReports Hibernate query executor then uses the parameter to run the HQL report query.

ReportDataSourceServiceインターフェースには2つのメソッドが含まれます。setReportParameterValuesとcloseConnection です。前者はデータとコネクションパラメータを提供し、後者は、setReportParameterValues メソッドを呼び出している間に 作成された任意のリソースまたはコネクションを閉じて解放します。

The ReportDataSourceService interface contains two methods: setReportParameterValues and closeConnection. The former provides data and connection parameter values; the latter is required to close and release any resources or connections created during the call to setReportParameterValues.

Springを通じて⼀度データソースサービスbeanが⼀度利⽤可能になれば、リポジトリにbean データソースを追加することが できます。

Once the data source service bean is available through Spring, you can add the bean data source to the repository.

Bean データソースを追加するには:

1. 管理者としてログインします。

Log in as an administrator.

2. [表示] > [リポジトリ] をクリックし、フォルダツリーを展開してデータソースを作成したいフォルダに移動します。サ ンプルデータをインストールしている場合は、「Data Sources」フォルダをお勧めします。

Click View > Repository and expand the folder tree to locate the folder in which you want to create the data source. If you installed the sample data, the suggested folder is Data Sources.

3. フォルダを右クリックし、コンテクストメニューから [リソースの追加] > [データ ソース] を選択します。

図 4-15に⾒られるように、「データ ソースの追加」ページが表示されます。

Right-click the folder and select Add Resource > Data Source from the context menu.

The Add Data Source page appears, as shown in Figure 4-15 on page 89.

4. 「タイプ」欄で、[Bean データ ソース] を選択します。

ページ上の情報が、Bean データソースを定義するためのものに変化します。

In the Type field, select Bean Data Source.

The information on the page changes to prompt you to define a bean data source.

5. オプション情報に従って、必要な欄を⼊⼒します。

データソースサービスが Spring bean のファクトリメソッドを通じてインスタンス化される場合は、「Bean メソッド」欄 も⼊⼒する必要があります。

Fill in the required fields, along with any optional information.

If the data source service is to be instantiated through a factory method of the Spring bean, you should also enter the name of the method.

6. [テスト接続] ボタンをクリックし、データソースの確認を⾏います。

確認に失敗した場合、⼊⼒した値が正しいかどうか、bean がクラスパスの中にあるかを確認します。

Click Test Connection to validate the data source.

If the validation fails, ensure that the values you entered are correct and that the bean is in the classpath.

7. テストに成功したら、[送信] ボタンをクリックします。

When the test is successful, click Submit.

図 4-15 Bean データソースのページ

第 5 章 テーマ

JasperReports Server 4.0 では新しいルック&フィールが導入されましたが、より重要なことは、ユーザインターフェース(UI)

の体裁の修正が容易になる完全な仕組みが導⼊されたということです。この仕組みは「テーマ」と呼ばれ、カスケードスタイル シート(CSS)、HTML コンテンツの体裁で定義されるWeb 標準に基づいています。

JasperReports Server 4.0 introduces a new look and feel, and more importantly, a complete mechanism to easily modify the appearance of the user interface (UI). This mechanism called themes is based on Cascading Style Sheets (CSS), the web standard for defining the appearance of HTML content.

ユーザインターフェースの体裁を定義するすべての CSS ファイルと画像ファイルのセットが、「テーマ」です。テーマはファイ ルリソースとしてリポジトリ内のフォルダに格納されており、テーマをアクティブにする・アップロードする・ダウンロードす るための特別なメニューが付与されます。リポジトリには任意の数のテーマを格納することができ、管理者は、それらを切り替 えることができ、規定の体裁をあなたの好みに合わせて簡単かつ迅速に提供することができます。

The set of all CSS files and associated images that define the appearance of the user interface is a theme. Themes are stored as file resources in folders in the repository, with special menus on theme folders for activating, uploading, and downloading a theme. You can store any number of themes in the repository, and administrators can switch between them, providing an easy and quick way to change the default appearance to suit your needs.

本章では、以下のテーマについて紹介します。

This chapter contains the following sections:

イントロダクション テーマの動作 テーマを管理する CSS ファイルを使う Introduction How Themes Work Administering Themes Working With CSS Files

ドキュメント内 JasperReports Server CP User Guide JP (ページ 114-117)