Skip to main content



      Home
Home » Archived » BIRT » Create a dynamic table with scripted data source???
Create a dynamic table with scripted data source??? [message #259444] Thu, 25 October 2007 09:05 Go to next message
Eclipse UserFriend
Originally posted by: ycai.serena.com

Hi, all
The example "Java - Build Dynamic Table (BIRT)" is using a JDBC data
source. Could anyone tell me if it is possible to use Scripted Data Source
to create a dynamic table (i.e., the number of columns and table heads are
determined at runtime)? Thanks.
Re: Create a dynamic table with scripted data source??? [message #259455 is a reply to message #259444] Thu, 25 October 2007 10:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaron.douglas.centare.com

I would say no since crosstabs are based on cubes which are supplied
data by a data set. It may be possible to create a cube through the API
and feed that to a crosstab using Java. Out of the box, it appears
you're stuck with standard data sets.

Aaron

alias-A wrote:
> Hi, all
> The example "Java - Build Dynamic Table (BIRT)" is using a JDBC data
> source. Could anyone tell me if it is possible to use Scripted Data
> Source to create a dynamic table (i.e., the number of columns and table
> heads are determined at runtime)? Thanks.
>
Re: Create a dynamic table with scripted data source??? [message #259471 is a reply to message #259444] Thu, 25 October 2007 10:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

If you want to modify that example you should be able to swap out the
jdbc datasource with a scripted data source using this code:

//Scripted Data Set

private void createDataSources( ) throws SemanticException
{
ScriptDataSourceHandle dataSourceHandle =
elementFactory.newScriptDataSource( "Data Source" );
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
}

private void createDataSets( ) throws SemanticException
{



ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet(
"Data Set" );//$NON-NLS-1$
dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$

// Set open( ) in code
dataSetHandle.setOpen( "i=0;"
);

// Set fetch( ) in code
dataSetHandle.setFetch( "if ( i < 20 ){"
+ "row[\"Month\"] = 1;"
+ "row[\"Product\"] = 'My Product' + parseInt(i/3);"
+ "row[\"Amount\"] = i;"
+ "i++;"
+ "return true;}" + "else return false;" );


// Set computed columns
cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "Month" );//$NON-NLS-1$
cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
cs1.setDataType( "integer" );//$NON-NLS-1$

cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "Product" );//$NON-NLS-1$
cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
cs2.setDataType( "string" );//$NON-NLS-1$

cs3 = StructureFactory.createComputedColumn( );
cs3.setName( "Amount" );//$NON-NLS-1$
cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
cs3.setDataType( "integer" );//$NON-NLS-1$

PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
computedSet.addItem( cs1 );
computedSet.addItem( cs2 );
computedSet.addItem( cs3 );

reportDesignHandle.getDataSets( ).add( dataSetHandle );


}

Jason

alias-A wrote:
> Hi, all
> The example "Java - Build Dynamic Table (BIRT)" is using a JDBC data
> source. Could anyone tell me if it is possible to use Scripted Data
> Source to create a dynamic table (i.e., the number of columns and table
> heads are determined at runtime)? Thanks.
>
Re: Create a dynamic table with scripted data source??? [message #259480 is a reply to message #259444] Thu, 25 October 2007 10:38 Go to previous messageGo to next message
Eclipse UserFriend
alias-A,

Sorry, hit the send a bit prematurely.

There is an example of doing this in my API Examples. You will need to have
a Subversion client to checkout the project, I recommend subclipse (use their
update site at: http://subclipse.tigris.org/update_1.2.x). Once you have
the client you need to go to my examples repository at:

http://longlake.minnovent.com/repos/birt_example

Then you need to checkout two projects:

birt_api_example contains the actual examples
birt_runtime_lib packages the runtime library as a plug-in so that it
is easy to use

Inside the birt_api_project in src/deapi you will find an example of using
a ScriptedDataSource in the SalesReport class.

Scott Rosenbaum

> Hi, all
> The example "Java - Build Dynamic Table (BIRT)" is using a JDBC data
> source. Could anyone tell me if it is possible to use Scripted Data
> Source
> to create a dynamic table (i.e., the number of columns and table heads
> are
> determined at runtime)? Thanks.
Re: Create a dynamic table with scripted data source??? [message #259499 is a reply to message #259471] Thu, 25 October 2007 11:20 Go to previous message
Eclipse UserFriend
Originally posted by: ycai.serena.com

Jason Weathersby wrote:
> If you want to modify that example you should be able to swap out the
> jdbc datasource with a scripted data source using this code:
>
> //Scripted Data Set
>
> private void createDataSources( ) throws SemanticException
> {
> ScriptDataSourceHandle dataSourceHandle =
> elementFactory.newScriptDataSource( "Data Source" );
> reportDesignHandle.getDataSources( ).add( dataSourceHandle );
> }
>
> private void createDataSets( ) throws SemanticException
> {
>
>
>
> ScriptDataSetHandle dataSetHandle =
> elementFactory.newScriptDataSet( "Data Set" );//$NON-NLS-1$
> dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
>
> // Set open( ) in code
> dataSetHandle.setOpen( "i=0;"
> );
>
> // Set fetch( ) in code
> dataSetHandle.setFetch( "if ( i < 20 ){"
> + "row[\"Month\"] = 1;"
> + "row[\"Product\"] = 'My Product' + parseInt(i/3);"
> + "row[\"Amount\"] = i;"
> + "i++;"
> + "return true;}" + "else return false;" );
>
>
> // Set computed columns
> cs1 = StructureFactory.createComputedColumn( );
> cs1.setName( "Month" );//$NON-NLS-1$
> cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
> cs1.setDataType( "integer" );//$NON-NLS-1$
>
> cs2 = StructureFactory.createComputedColumn( );
> cs2.setName( "Product" );//$NON-NLS-1$
> cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
> cs2.setDataType( "string" );//$NON-NLS-1$
>
> cs3 = StructureFactory.createComputedColumn( );
> cs3.setName( "Amount" );//$NON-NLS-1$
> cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
> cs3.setDataType( "integer" );//$NON-NLS-1$
>
> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
> ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
> computedSet.addItem( cs1 );
> computedSet.addItem( cs2 );
> computedSet.addItem( cs3 );
>
> reportDesignHandle.getDataSets( ).add( dataSetHandle );
>
>
> }
>
> Jason
>
> alias-A wrote:
>> Hi, all
>> The example "Java - Build Dynamic Table (BIRT)" is using a JDBC data
>> source. Could anyone tell me if it is possible to use Scripted Data
>> Source to create a dynamic table (i.e., the number of columns and
>> table heads are determined at runtime)? Thanks.
>>

Jason and Scott

Thank you for your help.

I think the best strategy could be 1) create a report design on eclipse
using a sample scripted data source 2) copy and modify the open and
fetch scripts to my java class plus using the DEAPI.

ycai
Previous Topic:X in Red circle by dynamic text
Next Topic:How to add very top header in first column in cross tab?
Goto Forum:
  


Current Time: Fri May 09 18:05:35 EDT 2025

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

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

Back to the top