Jump to content
Changes to the Jaspersoft community edition download ×

custom data source


Recommended Posts

By: Ilievski Bozidar - bobi1978

custom data source

2002-06-12 23:25

Hi Teodor.

 

I'm just looking into your CustomDataSource example.

But I can't figure out how do you use THAT Data Source into your report (DataSourceReport.xml).

I don't see any reference to this data source into the report design?

Can you explain how this works?

 

Thanks...

Bobi.

 

 

By: Teodor Danciu - teodord

RE: custom data source

2002-06-13 00:10

 

Hi,

 

Look into the DataSourceApp.java at line 89.

You will find this:

 

JasperFillManager.fillReportToFile(fileName, parameters, new CustomDataSource());

 

The report design itself never refers to its data source.

 

Thank you,

Teodor

 

 

 

By: Ilievski Bozidar - bobi1978

Re: RE: custom data source

2002-06-13 03:46

Thanks Teodor.

 

I have another question for you.

I've implemented JRDataSource and here is my custom DataSource:

 

// Copyright © 2001 CodEx Computers

package pckFin;

 

 

import dori.jasper.engine.*;

import java.util.*;

import javax.infobus.*;

 

 

 

public class PrimerDataSource implements JRDataSource

{

ScrollableRowsetAccess sra;

 

public PrimerDataSource(ScrollableRowsetAccess rs)

{

try

{

sra = rs.newCursor();

sra.first();

}

catch(Exception e)

{

e.printStackTrace();

}

}//constructor PrimerDataSource

 

 

public boolean next() throws JRException

{

boolean b = true;

try

{

b = sra.next();

}

catch(Exception e)

{

e.printStackTrace();

}

return b;

}//next

 

 

public Object getFieldValue(JRField field) throws JRException

{

Object value = null;

try

{

ImmediateAccess im = (ImmediateAccess)sra.getColumnItem(field.getName());

value = im.getValueAsObject();

}

catch(Exception e)

{

e.printStackTrace();

}

return value;

}//getFieldValue

 

 

}//class PrimerDataSource

 

///////////////////////////////////////////////////

In the application I invoke this DataSource:

 

JasperManager.fillReportToFile(jasper,jasperPrint,parameters,new PrimerDataSource(someScrollableRowsetAccess));

JasperViewer.viewReport(jasperPrint,false);

////////////////////////////////

but in the report THE FIRST ROW of the ScrollableRowsetAccess IS MISSING.

 

Any idea why?

 

 

By: Teodor Danciu - teodord

Re: RE: custom data source

2002-06-13 04:12

 

Hi,

 

The report engine assumes that when receiving

the data source object, the cursor is BEFORE

the first row of data.

 

You have explicitly positioned the cursor on the

first row by calling the first() method on your

ScrollableRowsetAccess object.

 

So, when the repot engine will call the next()

method on your data source, the cursor will be

moved to the second row.

 

The solution would be to use a flag in your data

source to indicate that when the next() method is

called for the first time, it should call the first()

method of your ScrollableRowsetAccess object

and not next() as usual.

 

Good luck!

Teodor

 

 

 

By: Ilievski Bozidar - bobi1978

RE: custom data source

2002-06-13 14:44

Thanks Teodor.

That was a nice sugestion.

It works now.

 

But there is another problem when usin ScrollableRowsetAccess as a DataSource:

It works OK for fields of type VARCHAR , but when I try to print a NUMERIC field (from ScrollableRowsetAccess) I receive this exception:

-----------------------------------------------------------------

java.lang.ClassCastException: java.math.BigDecimal

java.lang.Object dori.jasper.engine.fill.JRCalculator.evaluate(dori.jasper.engine.JRExpression)

java.lang.Object dori.jasper.engine.fill.JRCalculator.evaluate(dori.jasper.engine.JRExpression, byte)

void dori.jasper.engine.fill.JRFillTextField.evaluateText(byte)

void dori.jasper.engine.fill.JRFillTextField.evaluate(byte)

void dori.jasper.engine.fill.JRFillBand.evaluate(byte)

void dori.jasper.engine.fill.JRVerticalFiller.fillColumnBand(dori.jasper.engine.fill.JRFillBand, byte)

void dori.jasper.engine.fill.JRVerticalFiller.fillDetail()

void dori.jasper.engine.fill.JRVerticalFiller.fillReportStart()

void dori.jasper.engine.fill.JRVerticalFiller.fillReport()

dori.jasper.engine.JasperPrint dori.jasper.engine.fill.JRBaseFiller.fill(java.util.Map, dori.jasper.engine.JRDataSource)

.

.

.

------------------------------------------------------------

Have any idea why I receive this ClassCastException?

 

 

By: Teodor Danciu - teodord

RE2: custom data source

2002-06-14 01:03

 

Hi,

 

I think you should declare your numeric field of

java.math.BigDecimal type.

If not, you have to treat it in order to truncate it in

order to use a less precise type like java.lang.Float

or java.lang.Double.

 

You can use java.math.BigDecimal fields only with

the new 0.3.2 version.

 

Good luck!

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...