Union Between Multiple DataSets [message #207000] |
Mon, 18 December 2006 07:56  |
Eclipse User |
|
|
|
Originally posted by: leonardo.pinho.gmail.com
Hi All,
I'd like to know if it`s possible did the union between two or more
datasets. I can't do this using sql query because the data belong to
differents datasets.
Thanks in advance,
Leo
|
|
|
|
|
|
|
|
Re: Union Between Multiple DataSets [message #209811 is a reply to message #209181] |
Mon, 08 January 2007 10:46  |
Eclipse User |
|
|
|
This is a somewhat crude example of using the data engine api.
You could also add a table and set the visibility to hide and use the data
exatract task.
Jason
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.data.engine.api.DataEngine;
import org.eclipse.birt.data.engine.api.DataEngineContext;
import org.eclipse.birt.data.engine.api.IPreparedQuery;
import org.eclipse.birt.data.engine.api.IQueryResults;
import org.eclipse.birt.data.engine.api.IResultIterator;
import org.eclipse.birt.data.engine.api.IResultMetaData;
import org.eclipse.birt.data.engine.api.querydefn.OdaDataSetDesign;
import org.eclipse.birt.data.engine.api.querydefn.OdaDataSourceDesi gn;
import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import com.ibm.icu.util.ULocale;
/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/
public class DataEngineExample {
public static void main( String[] args )
{
try
{
extract( );
}
catch ( Exception e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.
static void extract( ) throws Exception
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );
config.setProperty("BIRT_HOME",
"C:/birt-runtime-2_1_1/birt-runtime-2_1_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 ) ;
// Create a new report design.
ReportDesignHandle design =
session.openDesign("c:/tmp/dataextract.rptdesign");
OdaDataSourceHandle sourceHandle = (OdaDataSourceHandle)
design.findDataSource( "Data Source" );
OdaDataSetHandle dsh = (OdaDataSetHandle)design.findDataSet("dataset");
OdaDataSourceDesign odaDataSource;
DataEngine de=null;
//config.setRourcePath()
de = DataEngine.newDataEngine( DataEngineContext.newInstance(
DataEngineContext.DIRECT_PRESENTATION,
null,
null,
null ) );
odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );
odaDataSource.addPublicProperty( "odaURL",
sourceHandle.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass",
sourceHandle.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser",
sourceHandle.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );
OdaDataSetDesign odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID(
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( dsh.getQueryText() );
de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );
QueryDefinition queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);
IPreparedQuery pq = de.prepare( queryDefinition );
IQueryResults qr = pq.execute( null );
IResultIterator ri = qr.getResultIterator( );
int cc = ri.getResultMetaData().getColumnCount();
IResultMetaData rsmd = ri.getResultMetaData();
while ( ri.next( ) )
{
for ( int i = 0; i < cc; i++ )
System.out.print(ri.getValue(rsmd.getColumnName(i+1)) + " ");
System.out.println("");
}
ri.close( );
qr.close( );
de.shutdown( );
System.out.println("Finished");
// We're done!
}
}
"Leonardo Pinho" <leonardo.pinho@gmail.com> wrote in message
news:fe1c154da9bd4c88712905ab1e87f298$1@www.eclipse.org...
> Do you know how I can access the results of a dataset using the Report
> API? I'm afraid that`s not possible...
>
> Thanks again!
>
|
|
|
Powered by
FUDForum. Page generated in 0.04217 seconds