Similarities and differences between a set computing report and a rundry report when processing a dynamic report.

Source: Internet
Author: User
Tags comparison table

Similarities and differences between a set computing report and a rundry report when processing a dynamic report.

The centralized report inherits the macro mechanism of the rundry report to process dynamic reports. It is very convenient to use the macro implementation for simple dynamic reports. For complex dynamic reports, computation reports also provide script datasets to process dynamic reports. This is suitable for scenarios where macros cannot be implemented, to implement complex dynamic reports, you need to write custom datasets. The following examples are used to compare the similarities and differences between a set computing report and a dynamic report.

Similarities

Both the centralized computing report and the rundry report provide macros, which are used in almost the same way and contain common macros and dynamic macros.

Normal macroIt is often used for static content replacement. For example, if you only want to view the salary or bonus in the employee table at the same time, developing two reports is obviously redundant. It is very easy to use a common macro to complete one report. The following report:


Input parameters and macros of the preview report:

When the arg1 value is BONUS and the macro value is BONUS, the following report result is displayed:

When the arg1 value is SALARY and the macro value is SALARY, the following report result is displayed:

A relatively common macro can only replace static content,Dynamic macroYou can write a dynamic expression to replace the dynamic content and create a dynamic report. For example, in a dynamic report, a query is performed on a specified table based on the fields and conditions selected by the user. The selected fields and their data are displayed in the report. Because the fields and conditions are dynamic, You need to spell out the SQL statements in the report before submitting them to the database for query. In this case, you need to splice them in the dynamic macro. The following reports:

The report parameters and macros are set:

Enter the cols value: Order ID, customer ID, order date, delivery date, arrival date, and shipping fee

Enter the where value: where region = 'North China' and main city in ('beijing', 'tianjin ', 'zhangjiakou', 'qinhuangdao ')

The value is "select" + cols + "from order" + where, and the macro type is dynamic macro.

Set the dataset SQL to $ {SQL}. You can preview the report and obtain the following dynamic report results:

The above is a dynamic report that uses macros (Common macros and dynamic macros) for relatively simple development (only static content or completed through simple expressions). For complex dynamic reports, complex computation is often required, and Macros in such complex cases are often difficult or even unable to be used. In this case, the processing method of the computing report and the statement of profit report is very different.

Differences

A set computing Report provides a script dataset to complete the development of complex dynamic reports mentioned above. Due to the built-in script and simple syntax, it is easy to process such reports. Rundry reports can only be completed in JAVA through custom data sources, and the ease of use is slightly inferior. The following is an example.

The User specifies the selection columns and conditions for a specific table. For example, when the user selects a column in the order table, the Order ID, employee ID, and order date are mandatory columns, even if the user does not select, it is still displayed after the query. This requires you to determine in advance whether the required columns are in the user's selected columns when splicing SQL statements. If not, you must add the required columns later and ensure the order of the columns selected by the user.

The difficulty of macro implementation lies in the fact that it is necessary to determine whether each required column is in the list of fields selected by the user. If not, the number of required columns to be appended must be compared several times, it is complex when many columns are required.

The following shows how a computing report is implemented through a script dataset (the report parameters and expressions are consistent with the preceding example ):

In A2, the preceding script merges the selected field set with the required field set to obtain all query fields. After splicing the SQL statement for query, the result set is returned for the report. The process is very simple.

 

In this case, the rundry report usually uses a custom dataset. below is the implementation of the rundry report through the custom dataset (main code ):

<Span style = "font-size: 14px;"> public class QueryData implements IDataSetFactory {public DataSet createDataSet (Context ctx, DataSetConfig dsc, boolean isinput) {Map map = ctx. getParamMap (false); // obtain all parameters of the current report. Comparison Table String cols = ""; String where = ""; if (map! = Null) {Iterator it = map. entrySet (). iterator (); cols = map. get ("cols "). toString (); // obtain the parameter value where = map. get ("where "). toString (); // get 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.exe cuteQuery (SQL); ResultSetMetaData r Smd = rs. getMetaData (); int colCount = rsmd. getColumnCount (); // set the column name for (int I = 1; I <= colCount; I ++) {ds1.addCol (rsmd. getColumnName (I);} // set the dataset data if (rs! = Null) {while (rs. next () {Row rr = ds1.addRow (); for (int I = 1; I <= colCount; I ++) {rr. setData (I, rs. getObject (I) ;}}} rs. close (); stmt. close (); con. close ();} catch (Exception ex) {ex. printStackTrace () ;}return ds1 ;}</span>

The preceding custom dataset first obtains the connection between the report parameters and the current data source, Concatenates the SQL statements based on the parameters, and then sets the column name and data for the dataset Based on the obtained ResultSet, the created dataset is returned. In use, put the compiled class (QueryData. class) into the classpath of the application.

Through the above implementation process, we can see that for complex dynamic reports (such as), it is easier to use script datasets, except for its concise syntax, the script dataset is built into the report without additional program files, making it easier.



Related Article

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.