The similarities and differences between the collection report and the run-Dry report processing dynamic report

Source: Internet
Author: User

The collection report inherits the macro mechanism of the dry report to handle the dynamic report, which is very convenient for simple dynamic report using macro. For some complex dynamic reports, the collection report also provides a script dataset to handle dynamic reports, suitable for scenarios where macros cannot be implemented, and a custom dataset is required to implement complex dynamic reports in a dry report. Here are a few examples to compare the same and different points in the processing of dynamic reports in a detailed comparison of the set-up report and the run-dry report.

same Point

Both the collection report and the dry report provide macros that are almost identical in usage and contain both normal macros and dynamic macros.

Ordinary macros are often used for static content substitution, such as in the employee table only want to see the salary or bonus, the development of two reports is obviously cumbersome, using ordinary macro in a report to complete the very simple, the following report:


previewing report input parameters and macros:

when the arg1 value of the parameter is bonus, the macro macroscopic value is bonus, the following report results can be obtained:

when the arg1 value of the parameter is salary, the macro macroscopic value is salary, the following report results can be obtained:

Relative ordinary macro can only replace static content, dynamic macro can write dynamic expression, complete the dynamic content replacement, so as to complete the dynamic report production. For example, a dynamic report that displays the selected field and its data for a specified table based on the fields and criteria selected by the user. Because the fields and conditions are dynamic, you need to make the SQL in the report and then to the database to query, you need to be in the dynamic macro splicing. The following report:

where report parameters and macros are set to:

Enter cols value: Order ID, Customer ID, order date, delivery date, arrival date, delivery fee

Enter where value: where cargo area = ' North ' and Shipper city in (' Beijing ', ' Tianjin ', ' Zhangjiakou ', ' Qinhuangdao ')

The value is: "Select" +cols+ "from Order" +where, the macro type is a dynamic macro.

Set the DataSet SQL to: ${sql}, preview the report to get the following dynamic report results:

The above is a dynamic report that uses macros (normal macros and dynamic macros) to develop relatively simple (static content or complete with simple expressions), whereas complex dynamic reports often require complex computations to be completed, which can be difficult or even impossible to accomplish with such complex situations. At this time the collection of reports and dry report processing methods are very different.

different points

The collection report provides a script dataset to complete the development of the complex dynamic reports mentioned above, which are easy to handle due to the built-in script and the simple syntax. The dry report can only be done in Java with a custom data source, and the ease of use is slightly less. Let's take a look at the following example.

Select columns and conditions are specified by the user for a specific table, such as when a user selects a column in the Orders table, the order ID, employee ID, and order date are required columns, even though the user does not have a selection and is still displayed after the query. This needs to be in the stitching of SQL in advance to determine whether the required column in the user's chosen column, if not, then add later, and to ensure that the user to select the order of the column.

The difficulty with macro implementation is that, because it is necessary to determine whether each required column is in the list of user-selected fields, if not, how many required columns are compared several times and are very complex when the required columns are large.

The following is an implementation of a set of calculated reports through a script dataset (report parameters and expressions are consistent with the previous example):

The script above A2 the selected field collection and the required field collection in the list to get all the query fields, and the process is simple to return the result set for the report after stitching up SQL for querying.

and run dry report in this case generally use a custom data set, the following is the implementation of the dry report through a custom dataset (main code):

<span style= "FONT-SIZE:14PX;" >public class Querydata implements Idatasetfactory {public DataSet createdataset (Context ctx, Datasetconfig DSC, Boole An isinput) {map map = Ctx.getparammap (false);//Get all parameters of the current report by string cols = ""; String where = "", if (map! = null) {Iterator it = Map.entryset (). Iterator (); cols = Map.get ("cols"). ToString (); Gets the parameter value where = Map.get ("where"). ToString (); Gets the parameter value}dataset DS1 = new DataSet ("DS1"); Connection con = null;try {con = ctx.getconnectionfactory ("demo"). getconnection (); Statement stmt = Con.createstatement (); String sql = "Select" + cols + "from order" + where; ResultSet rs = stmt.executequery (SQL); ResultSetMetaData RSMD = Rs.getmetadata (); int colcount = Rsmd.getcolumncount ();//Set column name for (int i = 1; I <= colcount; i++ ) {Ds1.addcol (Rsmd.getcolumnname (i));} Sets the data Set data if (rs! = null) {while (Rs.next ()) {Row rr = Ds1.addrow (); for (int i = 1; I <= colcount; i++) {Rr.setdata (I, R S.getobject (i));}} Rs.close (); Stmt.close (); Con.close ();} catch (Exception Ex) {ex.printstacktrace ();} return DS1;}} </span>

The above custom data set first obtains the report parameter and the current data source connection, next according to the parameter stitching out to execute the SQL, then sets the column name and the data separately according to the obtained resultset for the dataset, finally returns the created dataset. When used, the compiled class (Querydata.class) is placed in the application's classpath to be completed by the Chinese side.  

As you can see from the implementation process above, for complex dynamic reports (such as the previous example), it is much easier to implement a script dataset, except that it has a concise syntax, and that the script dataset is built into the report without additional program files attached.



The similarities and differences between the collection report and the run-Dry report processing dynamic report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.