BackPrevious Page Next PageNext

Adding Hierarchical Data Sources to a Catalog

Adding a general HDS to a catalog

Example of adding a general HDS

Importing an HDS from an XML file to a catalog

The XSD file used for HDS

You have two ways to add an HDS to a JReport catalog: adding a general HDS or importing from an XML file.

Adding a general HDS to a catalog

  1. Create a catalog or open a catalog.
  2. In the Catalog Manager, right-click the node of a data source and choose New General Hierarchical Data Source from the shortcut menu.

    If you want to add the HDS to a new data source in the catalog, select any of the existing catalog data source, click New Data Source on the Catalog Manager toolbar, then in the New Data source dialog, specify the name of the data source, select the Hierarchical connection type and click OK.

  3. In the New General Hierarchical Data Source dialog, click the Browse button to specify the HDS class name.

    New General Hierarchical Data Source dialog

  4. Type a number or parameter string in the Parameter box. The parameter string must match the format defined in the HDS class.

    You can reference parameters and constant level formulas predefined in the current catalog data source in the format @FieldName and the special field User Name as @username in the PARAMETER string.

  5. Click Load Tree. The data source tree will then be parsed. Modify the column properties in the Columns box as required.
  6. Click OK to add the HDS.

Example of adding a general HDS

There are three classes used in this example. Their source code files are HierarchicalDataSource.java, HierarchicalDatasetMetaData.java, and HierarchicalDataset.java, which are available in <install_root>\help\samples\APIUDS\hierarchicalUDS. In this example, the HierarchicalDataSource.java will return the result set from the demo HSQL DB.

  1. Copy the above three files to <install_root>\help. Modify the demo HSQL DB path in both HierarchicalDatasetMetaData.java and HierarchicalDataset.java.
  2. Compile the Java files to generate HierarchicalDataSource.class, HierarchicalDatasetMetaData.class, and HierarchicalDataset.class.
  3. Append the path <install_root>\help into the ADDCLASSPATH variable of the batch file setenv.bat in <install_root>\bin, so that at runtime HierarchicalDataSource can be found.
  4. Start JReport Designer with the batch file you just modified and open an existing catalog.
  5. In the Catalog Manager, right-click the data source to which to add the HDS, then select New General Hierarchical Data Source from the shortcut menu. The appears.
  6. In the New General Hierarchical Data Source dialog, click the Browse button to find the class HierarchicalDataSource.class.
  7. Type a number in the Parameter box. Then, only the records whose employee ID is less than this number will be fetched.
  8. Click Load Tree. The data source tree will then be parsed.
  9. Modify the column properties in the Columns box as required.
  10. Click OK to add the HDS.

Importing an HDS from an XML file to a catalog

  1. Create a catalog or open a catalog.
  2. In the Catalog Manager, right-click the node of a data source and choose New XML Hierarchical Data Source from the shortcut menu.

    If you want to add the HDS to a new data source in the catalog, select any of the existing catalog data source, click New Data Source on the Catalog Manager toolbar, then in the New Data source dialog, specify the name of the data source, select the XML connection type, check the Hierarchical Data Source radio button and click OK.

  3. In the New XML Hierarchical Data Source dialog, click the Browse buttons to specify the XML URI and XSD URI as required. Click the Load Tree button to load the structure of the XML file, the root of the file is then be listed in the Root Name text box.

    New XML Hierarchical Data Source dialog

    JReport Designer supports all kinds of URI as the XML data source.

  4. Modify the column properties in the Columns box.

    When importing the XML file, you have to define the types of some data in the Format column. For example, if it is Date type, such as 1978-03-12, in the corresponding Format column, type in yyyy-MM-dd. If the data is $12,345.32, in the corresponding Format column, type in $##,###.##. By default, the value of the Scale column is 0, therefore, for decimal type data, you will have to specify the scale value in its corresponding Scale column, that is, modify this value to the number of digits that you want to appear to the right of the decimal point, for example, if the data is 123.23, then in the Scale column, modify this value to 2. For the Currency and Array columns, check them if required.

  5. Click OK to import the HDS into the catalog.

The XSD file used for HDS

When you import an XML format HDS with an XSD file, the XML file only provides the data to the JReport Designer reports, while the structure, data type, and so on of the data from the XML file is defined in the XSD file. That is, the structure of the HDS is determined by the XSD file. You should be aware of the following points about the XSD file in order to generate a correct report based on an XML format HDS with an XSD file.

Data type conversion

Before the data type defined in the XSD file can function with JReport Designer, it should first be converted into a corresponding data type when the XML format hierarchical data source is imported, following the rules in the conversion table below.

XML Data Type JReport Data Type
SchemaSymbols.ATTVAL_BOOLEAN java.sql.Types.BIT
SchemaSymbols.ATTVAL_INT java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_SHORT java.sql.Types.SMALLINT
SchemaSymbols.ATTVAL_BYTE java.sql.Types.TINYINT
SchemaSymbols.ATTVAL_INTEGER java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_NONPOSITIVEINTEGER java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_NEGATIVEINTEGER java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_NONNEGATIVEINTEGER java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_UNSIGNEDLONG java.sql.Types.BIGINT
SchemaSymbols.ATTVAL_LONG java.sql.Types.BIGINT
SchemaSymbols.ATTVAL_UNSIGNEDINT, //4294967295 java.sql.Types.BIGINT
SchemaSymbols.ATTVAL_UNSIGNEDSHORT, //65535  java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_UNSIGNEDBYTE, //255 java.sql.Types.SMALLINT
SchemaSymbols.ATTVAL_POSITIVEINTEGER java.sql.Types.INTEGER
SchemaSymbols.ATTVAL_FLOAT java.sql.Types.FLOAT
SchemaSymbols.ATTVAL_DOUBLE java.sql.Types.DOUBLE
SchemaSymbols.ATTVAL_DECIMAL java.sql.Types.DECIMAL
SchemaSymbols.ATTVAL_STRING java.sql.Types.VARCHAR
SchemaSymbols.ATTVAL_DATE java.sql.Types.DATE
SchemaSymbols.ATTVAL_TIME java.sql.Types.TIME
SchemaSymbols.ATTVAL_DATETIME java.sql.Types.TIMESTAMP
SchemaSymbols.ATTVAL_HEXBINARY java.sql.Types.LONGVARBINARY

XSD structure supported by JReport

In JReport Designer, not all XSD structures can be supported in HDS. The following diagrams show the supported structures.

Notes:

BackPrevious Page Next PageNext