Report Engine API Development Primer-EJB Program Data source

Source: Internet
Author: User

We talked about a few data sources, and today we're going to talk about the EJB data source, and this part 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. 650) this.width=650; "src=" http://img.blog.csdn.net/20150901093251310 "alt=" 20150901093251310 "/>

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;    }     //  implement 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 that only once        is executed   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)  {                 //  Saving data with objects                 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                   &nBsp;  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.
650) this.width=650; "src=" http://img.blog.csdn.net/20150901093318244 "alt=" 20150901093318244 "/>
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
650) this.width=650; "src=" http://img.blog.csdn.net/20150901093321757 "alt=" 20150901093321757 "/>
Save the template to the EJB project environment, launch the examples server server, preview the template will be able to successfully access the template!


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.