DZone Forums
Go Back   DZone Forums > Community > Enterprise Development > BI & Reporting
Reload this Page Integrate a Custom Oda Driver in a Java Program?
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Aug 2009
Default Integrate a Custom Oda Driver in a Java Program? - 08-15-2009, 09:49 AM

Hello,

i programmed a ODA Driver and want integrate it in a Java program.

There is a great example to use the JDBC-Oda Driver in a Java class:
Java - Build Dynamic Table (BIRT) - Eclipsepedia

For my training, i would like to integrate the google_oda_driver:
(in order to know how to do it with my oda driver)

Here you can download the google oda driver:
http://individual.utoronto.ca/kuong/...-oda_1.0.0.zip

The both jar files (runtime and ui) i copied to the eclipse\plugins folder.

And changed the methods buildDataSource() and buildDataSets() class DECreateDynamicTable following:

Code:
	package Demo;

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 CopyOfDECreateDynamicTable
{
	ReportDesignHandle designHandle = null;
	ElementFactory designFactory = null;
	StructureFactory structFactory = null;	
 
	public static void main( String[] args )
	{
		try
		{
			CopyOfDECreateDynamicTable de = new CopyOfDECreateDynamicTable();
			ArrayList al = new ArrayList();
			al.add("Nr1");
			al.add("Nr2");
			al.add("Nr3");
			al.add("Nr4");
			al.add("Nr5");
			al.add("Nr6");
			al.add("Nr7");
			
			de.buildReport(al );
		}
		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", "google_oda_runtime" );
		dsHandle.setProperty( "username", "info@innoventsolutions.com" );
		dsHandle.setProperty( "password", "innovent2007" );

		designHandle.getDataSources( ).add( dsHandle );

	}

	void buildDataSet( ) throws SemanticException
	{
		
		OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
				"google_oda_runtime.impl" );
		dsHandle.setDataSource( "Data Source" );
		String qry = "http://spreadsheets.google.com/feeds/list/o05323973627365490072.7329113802600165656/od7/private/full";
 
		
		dsHandle.setQueryText( qry );

		designHandle.getDataSets( ).add( dsHandle );
		
 		
		
	}
	void buildReport(ArrayList cols ) throws IOException, SemanticException
	{


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

		config.setProperty("BIRT_HOME", "C:/java/birt-runtime-2_5_0/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.createDesign();

			designFactory = designHandle.getElementFactory( );
 
			buildDataSource();
 			buildDataSet( );
 
			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( "c:/tmp/VielleichtGehts.rptdesign" ); //$NON-NLS-1$
			designHandle.close( );
 			System.out.println("Finished");
		}catch (Exception e){
			e.printStackTrace();
		}		

	}
 }
Now, when i run the program, i get a java.lang.NullPointerException:

java.lang.NullPointerException
at Demo.CopyOfDECreateDynamicTable.buildDataSet(CopyO fDECreateDynamicTable.java:82)
at Demo.CopyOfDECreateDynamicTable.buildReport(CopyOf DECreateDynamicTable.java:126)
at Demo.CopyOfDECreateDynamicTable.main(CopyOfDECreat eDynamicTable.java:51)

I would be pleased to get help.

Thank you.

Best regards
Unicast
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create A Java Project in Eclipse by program or via an API dinoo Eclipse 1 11-10-2009 03:18 AM
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver mhd.cst Eclipse 2 03-24-2009 06:19 AM
Eclipse RCP + Apache Derby jdbc driver robich.ge Eclipse 5 05-27-2008 09:14 AM
Oracle Driver Problem BarryC Java 1 05-19-2008 09:43 AM
Integrate Infopath application in a view Piloufesse Eclipse 0 04-01-2008 09:25 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com