BackPrevious Page Next PageNext

JReport Catalog API

Installing the Catalog API

Preparations before using the Catalog API

Using the Catalog API

Creating a connection

Inserting a table/view/synonym

Inserting a stored procedure

Importing an SQL file

Inserting a UDS

Inserting a business view

Inserting a formula, summary, parameter or a WHERE portion

Creating and modifying a query

Inserting, getting and deleting objects in a catalog

Refreshing the reference table of a catalog

Saving a catalog

Catalog API samples

JReport Catalog API is intended for those who want to work with a catalog programmatically. You can create a catalog and manage the objects in it with the methods provided by the Catalog API instead of using the GUI in JReport Designer. Compared with the Catalog Bean, the Catalog API offers greater functionality. As with a catalog in JReport Designer, the Catalog API provides methods which enable you to create a connection, add and delete objects such as tables, queries, business views in a catalog and so on, as shown in the following diagram.

Catalog API diagram

The combination of the Catalog API and the Design API provides you with a Java development environment that enables you to create any report to meet your requirements.

Installing the Catalog API

When you install JReport Designer, the Catalog API is also installed at the same time. After installation, you will have the following components in <install_root>\lib:

The Catalog API class is stored in the archive file report.jar. You will need to do the following steps before you can compile and run the program:

  1. Set the class path environment variable. Append the following string to your class path that starts the Catalog API (make sure that the path of the file JREngine.jar is before that of the file report.jar):

    <install_root>\lib\report.jar;<install_root>\lib\sac-1.3.jar;<install_root>\lib\JREngine.jar;<install_root>\lib\log4j-core-2.10.0.jar;<install_root>\lib\log4j-api-2.10.0.jar

  2. In your Java program you must set the licensed user and Design API license key.

    DesignerUserInfo userInfo=new DesignerUserInfo("UID","Design API Key");

  3. Set the reporthome parameter equal to the root path of JReport Designer. You can set this in your environment or with the -Dreporthome argument to your JVM.

JReport Server also includes the Catalog API. If you prefer to use the libraries from JReport Server, include the jar file <server_install_root>\lib\JRESServlets.jar in your class path instead of report.jar. You would then need to use the Server Design API license key rather than the Design API license key.

Preparations before using the Catalog API

Before you can use the Catalog API to perform tasks, you will have to create a Designer object and then get a Catalog API instance.

To create a Designer object:

To create a Designer object, use the constructor Designer(String path, String name, DesignerUserInfo user) in the Design API. The constructor has three parameters: the catalog path, catalog name, and the user ID and license key provided by Jinfonet.

The path needs to be a valid path to an existiing directory. The catalog name can be the name of an existing catalog when you want to open a catalog, or the name of a new catalog when you want to create a catalog. If you want to create a new catalog, the path directory should not already contain a catalog file.

To create the DesignerUserInfo instance, use the following constructor providing the user ID and the Server Designer License Key or Designer License Key you received when you purchased JReport.

DesignerUserInfo userInfo=new DesignerUserInfo(Uid, key);

To get a Catalog API instance

To get a Catalog API instance, use the method getCatalogAPI() in the Design API. You need to first get an instance from Designer as follows.

Designer desg = new Designer(catalogPath, catalogName, userInfo);
CatalogAPI catalog = desg.getCatalogAPI();

Using with the Catalog API

The Catalog API provides methods which enable you to create a connection, add and delete objects such as tables, queries, business views in a catalog, and so on.

Reference: For details about the Catalog API methods, refer to the JReport Javadoc jet.api package in <install_root>\help\api, which includes all the documents generated by Javadoc.

Creating a connection

The following methods are used to insert a database connection and return the handle of the newly inserted connection. If not successful, a null value is returned:

Parameters

Inserting a table/view/synonym

The following methods are used to insert a table, view or synonym into a catalog and to return the handle of the newly inserted object:

Parameters

Inserting a stored procedure

The following methods are used to insert a stored procedure into a connection and to return the handle of the newly inserted procedure.

Parameters

Importing an SQL file

The following methods are used to import an SQL file and to return the handle of the newly inserted SQL file:

Parameters

Inserting a UDS

The following methods are used to insert a user defined data source and to return the handle of the newly inserted UDS:

Parameters

Inserting a business view

To insert a business view, use the following method:

Parameters

When you have a business view created successfully, you can then add elements into it. A business view can contain the following elements: categories, group objects, aggregation objects and detail objects.

The following methods are used to insert a view element into a business view and to return the handle of the newly inserted object if it is inserted successfully, otherwise null if there is a failure:

Parameters

Inserting a formula, summary, parameter or a WHERE portion

The following methods are used to insert a formula, summary, parameter or a WHERE portion into a catalog and to return the handle of the newly inserted object:

Parameters

Creating and modifying a query

You can perform the following on a query with the Catalog API.

Inserting a query into a catalog

The following methods are used to insert a query into a catalog and to return the handle of the newly inserted query:

Parameters:

Adding or deleting tables in a query

Note: The tables that are to be added should exist in the specified catalog.

Parameters

Adding or deleting fields in a query

Parameters

Adding or deleting joins in a query

Parameters

Adding or deleting QBE conditions in a query

Parameters

Adding or deleting where conditions in a query

Parameters

Inserting, getting and deleting objects in a catalog

Parameters

Refreshing the reference table of a catalog

You can use the method public boolean refreshReference() to refresh the reference table of a catalog.

Saving a catalog

Catalog API samples

The sample programs TestCatalogAPI.java and TestCatalogBV.java in <install_root>\help\samples\APICatalog demonstrate how to use the Catalog API to create a catalog and to create business views in a catalog.

To compile and run the samples, you should add the required classes to the class path (make sure that the path of the file JREngine.jar is before that of the file report.jar).

For example, you can use the following command to compile and run the sample program TestCatalogAPI.java. After running the program, a new catalog file MyReports.cat will be created in C:\JReport\Designer\Demo\MyReports. Be sure to create this empty directory first.

C:\JReport\Designer\help\samples\APICatalog>javac -classpath "C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\sac-1.3.jar;C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\log4j-core-2.10.0.jar;C:\JReport\Designer\lib\log4j-api-2.10.0.jar;C:\test\classes" TestCatalogAPI.java

C:\JReport\Designer\help\samples\APICatalog>java -classpath "C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac-1.3.jar;C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\log4j-core-2.10.0.jar;C:\JReport\Designer\lib\log4j-api-2.10.0.jar;C:\JReport\Designer\help;C:\test\classes" -Dreporthome=C:\JReport\Designer TestCatalogAPI -path=C:\JReport\Designer\Demo\MyReports -catalog=MyReports.cat -log=C:\JReport\Designer\logs\designer.log

BackPrevious Page Next PageNext