Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » UNION ALL - XML(Create an UnionAll Dataset with several XML files)
UNION ALL - XML [message #1792000] Mon, 09 July 2018 15:12
Attack Wave is currently offline Attack WaveFriend
Messages: 1
Registered: July 2018
Junior Member
Hi,

some time ago I had the problem of linking several XML files (datasets) with UNION ALL. Here is my solution. Maybe it's useful for one or the other.

Maybe you have suggestions for improvement.



1. Prepare XML Datasources

2. Add Datasets for XML Datsources and create an UnionAll Dataset
with Code

Example:
Datasources:

  • Datasource XML 1
  • Datasource XML 2
  • Datasource XML 3

Datasets:

  • Dataset XML 1
  • Dataset XML 2
  • Dataset XML 3
  • Dataset UnionAll


Dataset UnionAll Code:
Method open:
// DO NOT EDIT
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.report.data.adapter.api);
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);

// Context Init
myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
des = DataRequestSession.newSession(myconfig, new DataSessionContext(3));

// ResultIterators
ri = new Array(datasetList.length);
for (i=0; i<datasetList.length; i++) {
	qd = new QueryDefinition();
	qd.setDataSetName(datasetList[i][0]);
	qd.setAutoBinding(true);
	qd.setColumnProjection(columnList);
	dsrc = reportContext.getDesignHandle().findDataSource(datasetList[i][1]);
	dset = reportContext.getDesignHandle().findDataSet(datasetList[i][0]);
	des.defineDataSource(des.getModelAdaptor().adaptDataSource(dsrc));
	des.defineDataSet(des.getModelAdaptor().adaptDataSet(dset));
	pq = des.prepare(qd);
	qr = pq.execute(null);
	ri[i] = qr.getResultIterator();
}

rimax = ri.length;
ricnt = 0;
rownum = 0;



Method fetch:
// DO NOT EDIT
if ( ri[ricnt].next() ) {
	for (i=0; i<columnList.length; i++) {
		row[columnList[i]] = ri[ricnt].getString(columnList[i]);
	}
	return true;
} else {
	ricnt++;
	while ( ricnt < rimax ) {
		if ( ri[ricnt].next() ) {
			for (i=0; i<columnList.length; i++) {
				row[columnList[i]] = ri[ricnt].getString(columnList[i]);
			}
			return true;
		} else {
			ricnr++;
		}
	}
}


Method close:
// DO NOT EDIT
for (i=0; i<ri.length; i++) {
	ri[i].close();
}
pq.close();
des.closeAll(false);


Method beforeOpen:
//-------------- USER SETTINGS -------------------------------

datasetList = [
	["Dataset XML 1", "Datasource XML 1"],
	["Dataset XML 2", "Datasource XML 2"],
	["Dataset XML 3", "Datasource XML 3"],
];

columnList = ["column1", "column2", "column3", "column4"];

//-------------- USER SETTINGS -------------------------------


Previous Topic:Hiding Table Columns within script
Next Topic:BIRT 4.8 not available in Eclipse Repository
Goto Forum:
  


Current Time: Tue Apr 16 09:42:22 GMT 2024

Powered by FUDForum. Page generated in 0.18572 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top