2010-07-14 14 views
11

मेरे पास एक बीआईआरटी रिपोर्ट है जो हमारे परीक्षण डेटाबेस से जुड़ती है। उत्पादक माहौल में मैं एक डेटासोर्स आपूर्ति करना चाहता हूं जो कंटेनर द्वारा जेएनडीआई द्वारा प्रदान किया जाता है।बीआईआरटी रिपोर्ट प्रोग्रामेटिक रूप से डेटासेट कैसे सेट करें?

मैं दी गई रिपोर्ट के लिए डेटासेट को प्रोग्रामेटिक रूप से कैसे सेट करूं?

... 
    IReportRunnable design = birtEngine.openReportDesign (new File (properties.getProperty ("reportPath"), report + ".rptdesign").getAbsolutePath()); 
    IRunAndRenderTask task = birtEngine.createRunAndRenderTask (design); 

    PDFRenderOption options = new PDFRenderOption(); 
    options.setOutputFormat (PDFRenderOption.OUTPUT_FORMAT_PDF); 
    options.setOutputStream (out); 
    task.setRenderOption (options); 
    for (Entry<String, Object> entry : parameters.entrySet()) 
    { 
     task.setParameterValue (entry.getKey(), entry.getValue()); 
    } 

    task.run(); 
    task.close(); 
    ... 

मैं मैं design को संशोधित करने के लिए होता है लेकिन दूसरी ओर task पर एक विधि setDataSource है, लेकिन है कि मैं कुछ एक्सएमएल डोम तत्वों की आपूर्ति करने के लिए होता है कि एक सा लग रहा है लगता है।

उत्तर

2

रन-टाइम पर केवल डेटा स्रोत सेट करना समस्याग्रस्त हो जाएगा क्योंकि डेटा सेट एक डेटा स्रोत से जुड़ा हुआ है और रिपोर्ट पर आपके नियंत्रण तब एक विशिष्ट डेटा सेट से बंधे होते हैं। रिपोर्ट के चलते हर बार कोशिश करने और खुद को बनाने के लिए यह पदानुक्रम सुंदर चिपचिपा होगा।

आप डेटा स्रोत परिभाषा के सभी पहलुओं को पैरामीटर कर सकते हैं जो आपके डिज़ाइन को सभी वातावरण के माध्यम से पोर्टेबल बनाते हैं। अपने डेटा स्रोत को संपादित करते समय, बाईं ओर संपत्ति बाध्यकारी समूह को देखें। यह आपको अपने डेटा स्रोत को अधिक पोर्टेबल बनाने के लिए पर्याप्त लचीलापन देना चाहिए। आप जेडीबीसी यूआरएल तत्वों या रन-टाइम जेएनडीआई प्रोफाइल के लिए रन-टाइम पैरामीटर निर्दिष्ट कर सकते हैं।

उम्मीद है कि इससे मदद मिलती है।

3

आप डेटाबेस कनेक्शन स्ट्रिंग के लिए रिपोर्ट पैरामीटर बना सकते हैं।

फिर, डेटा स्रोत के तहत JNDI URL सेट -> संपत्ति बाइंडिंग - के रूप में> JNDI यूआरएल,:। पैरामीटर [ "डेटाबेस"] मूल्य

5
(कहाँ "डेटाबेस" रिपोर्ट पैरामीटर का नाम है)

निम्नलिखित कोड को देखें, आपको रनटाइम पर डेटा स्रोत प्रदान करने में कुछ मदद मिल सकती है।

मेरी आवश्यकताओं के लिए यह ठीक काम करता है।

मुझे कुछ साइट से यह याद नहीं आया।

import java.io.IOException; 
import java.util.ArrayList; 

import org.eclipse.birt.core.framework.Platform; 
import org.eclipse.birt.report.model.api.CellHandle; 
import org.eclipse.birt.report.model.api.DataItemHandle; 
import org.eclipse.birt.report.model.api.DesignConfig; 
import org.eclipse.birt.report.model.api.ElementFactory; 
import org.eclipse.birt.report.model.api.IDesignEngine; 
import org.eclipse.birt.report.model.api.IDesignEngineFactory; 
import org.eclipse.birt.report.model.api.LabelHandle; 
import org.eclipse.birt.report.model.api.OdaDataSetHandle; 
import org.eclipse.birt.report.model.api.OdaDataSourceHandle; 
import org.eclipse.birt.report.model.api.PropertyHandle; 
import org.eclipse.birt.report.model.api.ReportDesignHandle; 
import org.eclipse.birt.report.model.api.RowHandle; 
import org.eclipse.birt.report.model.api.SessionHandle; 
import org.eclipse.birt.report.model.api.StructureFactory; 
import org.eclipse.birt.report.model.api.TableHandle; 
import org.eclipse.birt.report.model.api.activity.SemanticException; 
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn; 

import com.ibm.icu.util.ULocale; 

/** 
* Dynamic Table BIRT Design Engine API (DEAPI) demo. 
*/ 

public class DECreateDynamicTable 
{ 
    ReportDesignHandle designHandle = null; 
    ElementFactory designFactory = null; 
    StructureFactory structFactory = null; 

    public static void main(String[] args) 
    { 
     try 
     { 
      DECreateDynamicTable de = new DECreateDynamicTable(); 
      ArrayList al = new ArrayList(); 
      al.add("USERNAME"); 
      al.add("COUNTRY"); 
      de.buildReport(al, "From GTM_REPORT_APP_USER"); 
     } 
     catch (IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (SemanticException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    void buildDataSource() throws SemanticException 
    { 

     OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
       "Data Source", "org.eclipse.birt.report.data.oda.jdbc"); 
     dsHandle.setProperty("odaDriverClass", 
       "oracle.jdbc.driver.OracleDriver"); 
     dsHandle.setProperty("odaURL", "jdbc:oracle:thin:@xeon:1521:ora9i"); 
     dsHandle.setProperty("odaUser", "AIMS_GTMNE"); 
     dsHandle.setProperty("odaPassword", "AIMS_GTMNE"); 

     designHandle.getDataSources().add(dsHandle); 

    } 

    void buildDataSet(ArrayList cols, String fromClause) throws SemanticException 
    { 

     OdaDataSetHandle dsHandle = designFactory.newOdaDataSet("ds", 
       "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet"); 
     dsHandle.setDataSource("Data Source"); 
     String qry = "Select "; 
     for(int i=0; i < cols.size(); i++){ 
      qry += " " + cols.get(i); 
      if(i != (cols.size() -1)){ 
       qry += ","; 
      } 

     } 
     qry += " " + fromClause; 

     dsHandle.setQueryText(qry); 

     designHandle.getDataSets().add(dsHandle); 



    } 
    void buildReport(ArrayList cols, String fromClause) throws IOException, SemanticException 
    { 


     //Configure the Engine and start the Platform 
     DesignConfig config = new DesignConfig(); 

     config.setProperty("BIRT_HOME", "D:/Softwares/Frame Works - APIs-Tools/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine"); 

     IDesignEngine engine = null; 
     try{ 


      Platform.startup(config); 
      IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY); 
      engine = factory.createDesignEngine(config); 

     }catch(Exception ex){ 
      ex.printStackTrace(); 
     }  


     SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH) ; 



     try{ 
      //open a design or a template 

      designHandle = session.openDesign("D:/tempBirtReport/test.rptdesign"); 

      designFactory = designHandle.getElementFactory(); 

      buildDataSource(); 
      buildDataSet(cols, fromClause); 

      TableHandle table = designFactory.newTableItem("table", cols.size()); 
      table.setWidth("100%"); 
      table.setDataSet(designHandle.findDataSet("ds")); 


      PropertyHandle computedSet = table.getColumnBindings(); 
      ComputedColumn cs1 = null; 

      for(int i=0; i < cols.size(); i++){ 
       cs1 = StructureFactory.createComputedColumn(); 
       cs1.setName((String)cols.get(i)); 
       cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]"); 
       computedSet.addItem(cs1); 
      } 


      // table header 
      RowHandle tableheader = (RowHandle) table.getHeader().get(0); 


      for(int i=0; i < cols.size(); i++){ 
       LabelHandle label1 = designFactory.newLabel((String)cols.get(i)); 
       label1.setText((String)cols.get(i)); 
       CellHandle cell = (CellHandle) tableheader.getCells().get(i); 
       cell.getContent().add(label1); 
      }       

      // table detail 
      RowHandle tabledetail = (RowHandle) table.getDetail().get(0); 
      for(int i=0; i < cols.size(); i++){ 
       CellHandle cell = (CellHandle) tabledetail.getCells().get(i); 
       DataItemHandle data = designFactory.newDataItem("data_"+(String)cols.get(i)); 
       data.setResultSetColumn((String)cols.get(i)); 
       cell.getContent().add(data); 
      } 

      designHandle.getBody().add(table); 

      // Save the design and close it. 

      designHandle.saveAs("D:/tempBirtReport/test.rptdesign"); //$NON-NLS-1$ 
      designHandle.close(); 
      System.out.println("Finished"); 
     }catch (Exception e){ 
      e.printStackTrace(); 
     }  

    } 
} 
1

मुझे एडम्स दृष्टिकोण पसंद है। ,

/* 
* Change the data sources in the .rptdesign 
*/ 
void changeDataSource(ElementFactory designFactory, 
     ReportDesignHandle designHandle, String userConnect) 
     throws SemanticException { 

    SlotHandle datasources = designHandle.getDataSources(); 
    SlotIterator iter = (SlotIterator) datasources.iterator(); 
    while (iter.hasNext()) { 
     DesignElementHandle dsHandle = (DesignElementHandle) iter.next(); 
     if (dsHandle instanceof OdaDataSourceHandle && dsHandle.getName().equals("lisa")) { 
      log.debug("changeDataSource: Changing datasource " 
        + dsHandle.getName() + " new url=" + getLisaDbUrl()); 
      dsHandle.setProperty("odaDriverClass", 
        "oracle.jdbc.driver.OracleDriver"); 
      dsHandle.setProperty("odaURL", getLisaDbUrl()); 
      dsHandle.setProperty("odaUser", getLisaUser()); 
      dsHandle.setProperty("odaPassword", getLisaPassword()); 
     } else { 
      log.debug("changeDataSource: Ignoring DS " + dsHandle.getName()); 
     } 
    } 
} 

यहाँ "लिसा" IST वह डेटा स्रोत का नाम हम कार्यावधि में परिवर्तन करना चाहते हैं: यहाँ कैसे हम यह कर रहे हैं। प्राप्त करें ... फ़ंक्शन "उत्पादन" रन टाइम पर आवश्यक मानों को वापस कर देता है।

0

यह मेरे लिए काम किया। मुझे संदर्भ मिला और संदर्भ से डेटा स्रोत मिला और

Context initialContext = new InitialContext(); 
    if (initialContext == null){ 
    System.out.println("JNDI problem. Cannot get InitialContext."); 
     } 
     DataSource datasource = (DataSource)initialContext.lookup("java:/datasources/SAMPLE"); 
    task.getAppContext().put("OdaJDBCDriverPassInConnection", datasource.getConnection()); 
जैसे बिर्ट रिपोर्ट से कनेक्शन पारित किया गया