Report Engine API Development Primer-EJB Program Data source

Source: Internet
Author: User

We've talked a couple of data sources before, so let's talk about it today. EJB data source, this section of our data source is finished. data connections do not require direct access to the database, but instead use EJBS as data sources. Fr uses EJB's related classes to define the program dataset to get to the EJB data source, and then the two-dimensional table inside us is used as a report data source for presentation. For example, get the template that is made to the EJB data as follows.

First, the realization principle

The data source for a Finereport report can be any type of data, because Finereport reads the data source through Abstracttabledata abstract classes, so that users simply implement the Abstracttabledata abstract class, You can also use a custom type of program DataSet, and the Finereport report engine can read the defined data source as a report data source. The Abstracttabledata abstract class has 5 main methods, which can be used to refer to the development of the report Engine API-a simple program data set. The EJB program data source prepares the data using the Method init (), obtains the JavaBean to the EJB, and saves the data to ArrayList.

Ii. Steps of implementation

2.1 Defining the program data source
Define the Datamodeldemo class code as follows:

Package Com.fr.data;import Javax.naming.*;import Javax.ejb.*;import java.rmi.*;import java.util.*;import Com.fr.data.abstracttabledata;import examples.ejb.ejb20.basic.beanmanaged.*;p ublic class DataModelDemo extends    Abstracttabledata {private string[] columnnames;    Private ArrayList valueList = null;        Public Datamodeldemo () {string[] ColumnNames = {"Name", "Score"};    This.columnnames = ColumnNames;    }//Implementation of the other four methods public int getColumnCount () {return columnnames.length;    } public String getcolumnname (int columnindex) {return columnnames[columnindex];        } public int GetRowCount () {init ();    return Valuelist.size ();        } public Object getvalueat (int rowIndex, int columnindex) {init ();    Return ((object[]) Valuelist.get (RowIndex)) [ColumnIndex];        }//Prepare data public void init () {//Ensure only once if (valueList! = null) {return; }//Saved result set valueList = new ARRAylist ();        Context CTX = null;        account AC = null;        Accounthome home = null;            try {//Contact the Accountbean container (the "accounthome") through//JNDI.            CTX = new InitialContext ();            Home = (accounthome) ctx. Lookup ("JAVA:/COMP/ENV/BEANMANAGEDACCOUNTEJB");            Double Balancegreaterthan = 100;            Collection col = home.findbigaccounts (Balancegreaterthan);                if (col! = null) {//Save data with Object object[] Objarray = null;                Iterator iter = Col.iterator ();                    while (Iter.hasnext ()) {Account Bigaccount = (account) Iter.next ();                    Objarray = new Object[2];                    Objarray[0] = Bigaccount.getprimarykey ();                    OBJARRAY[1] = new Double (Bigaccount.balance ());                Add this line of data to ValueList Valuelist.add (Objarray);     }            }   } catch (Exception ex) {ex.printstacktrace (); }    }}


Note: You need to import the EJB jar package before using
2.2 Compiling the program data source
Put the compiled datamodeldemo.class into the classes directory under the project's Web-inf, because Datamodeldemo.java belongs to the package Com.fr.data, so Datamodeldemo.class needs to be put into classes The \com\fr\data directory.
2.3 Configuration Program Data source
Create a new report, create a new program data source in the report dataset, select a program dataset that we have defined, such as a name that can be customized, such as pro.

2.4 Using the program data source
After you have configured your program data source, you can use the defined Pro program DataSet, which is the same as other types of datasets, and you can use the drag-and-drop method to implement cell data column bindings. Such as

Save the template to the EJB project environment, launch the examples server server, preview the template will be able to successfully access the template!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Report Engine API Development Primer-EJB Program Data source

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.