Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Static dataset in BIRT through design engine API
BIRT User
<p>Hi BIRT Guru's,</p>
<p>I am creating report design in Java through design engine API. I want to create static datasource and dataset through java.</p>
<p>My requirement is that i want to set the values of the dataset while creating it in JAVA.</p>
<p> </p>
<p>Is there a way to achieve it in BIRT API's?</p>
<p> </p>
<p>I am unable to find any methods from the API.</p>
<p> </p>
<p>It would you really great if someone could assist on this.</p>
<p> </p>
<p>I am using BIRT version 4.5.0.</p>
Find more posts tagged with
Comments
Matthew L.
<p>I've not build a data source/data set via pure Java, however I have using the DEAPI within a BIRT rptdesign file: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/35930-running-a-query-in-the-initalize/?p=133369'>http://developer.actuate.com/community/forum/index.php?/topic/35930-running-a-query-in-the-initalize/?p=133369</a></p>
;
<p> </p>
<p>It might be helpful for you.</p>
<p> </p>
<p>For reference (from yellow example):</p>
<pre class="_prettyXprint _lang-js">
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);
importPackage(Packages.org.eclipse.birt.report.model.elements.interfaces);
//Get element factory (No Editing Required)
reportDesignHandle = reportContext.getDesignHandle(); //Get report design handle
elementFactory = reportDesignHandle.getElementFactory(); //Get element factory
//Create scripted data source (Edit Name Here)
dataSourceHandle = elementFactory.newScriptDataSource("New Scripted Data Source"); //Create New Scripted Data Source
reportDesignHandle.getDataSources().add(dataSourceHandle); //Add new data source to report
//Create scripted data set (Edit Name Here)
dataSetHandle = elementFactory.newScriptDataSet("New Scripted Data Set"); //Create New Scripted Data Set
dataSetHandle.setDataSource(dataSourceHandle.getName()); //Set data source
reportDesignHandle.getDataSets().add(dataSetHandle); //Add new data set to report
//Set scripted data set column names and data types (Edit Here)
var columnNameArray = ["Column 1","Column 2"]; //Set scripted column names array
computedSet = dataSetHandle.getPropertyHandle(dataSetHandle.RESULT_SET_PROP); //Get PropertyHandle
for (i=0;i<columnNameArray.length;i++){ //Loop through each data in the array
resultColumn = StructureFactory.createResultSetColumn(); //ResultSetColumn
resultColumn.setColumnName(columnNameArray[i]); //Set the column name
resultColumn.setDataType("String"); //Set the data type of this column: Integer, String, Date Time, Decimal, Float, Boolean, Date, Time, Blob, Java Object
computedSet.addItem(resultColumn); //Add column to Data set
}
//Set data set open() (Edit Here)
dataSetHandle.setOpen("count=0; length=3; columnNameArray=['" + columnNameArray.join("','" ) + "'];"); //Note: Passing column name array
// Set data set fetch( ) (Edit Here)
dataSetHandle.setFetch("if(count < length) { "
+ "row[columnNameArray[0]] = \"Test Data 1\"; " //Assign value to first column from columnNameArray
+ "row[\"Column 2\"] = \"Test Data 2\"; " //Assign value to second column
+ "count++; "
+ "return true; "
+ "}else{ "
+ "return false; } ");
</pre>