Package net.sf.jasperreports.engine
Class JRResultSetDataSource
- java.lang.Object
-
- net.sf.jasperreports.engine.JRResultSetDataSource
-
- All Implemented Interfaces:
JRDataSource
public class JRResultSetDataSource extends java.lang.Object implements JRDataSource
This is a default implementation of theJRDataSourceinterface. Since most reports are generated using data from a relational database, JasperReports includes by default this implementation that wraps ajava.sql.ResultSetobject.This class can be instantiated intentionally to wrap already loaded result sets before passing them to the report-filling routines, but it is also used by the reporting engine to wrap the data retrieved from the database after having executed the report query (if present) through JDBC.
- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_CLOB_VALUE_READ_FAILUREstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_COLUMN_INDEX_OUT_OF_RANGEstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_FIELD_VALUE_NOT_RETRIEVEDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_METADATA_NOT_RETRIEVEDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_NEXT_RECORD_NOT_RETRIEVEDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_LABELstatic java.lang.StringEXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_NAMEstatic java.lang.StringINDEXED_COLUMN_PREFIXstatic java.lang.StringPROPERTY_FIELD_COLUMN_INDEXProperty specifying the result set column index for the dataset field.static java.lang.StringPROPERTY_FIELD_COLUMN_LABELProperty specifying the result set column label for the dataset field.static java.lang.StringPROPERTY_FIELD_COLUMN_NAMEProperty specifying the result set column name for the dataset field.
-
Constructor Summary
Constructors Constructor Description JRResultSetDataSource(java.sql.ResultSet resultSet)JRResultSetDataSource(JasperReportsContext jasperReportsContext, java.sql.ResultSet resultSet)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringclobToString(java.sql.Clob clob)protected java.util.CalendarcreateFieldCalendar(JRField field)protected java.io.CharArrayReadergetArrayReader(java.io.Reader reader, long size)protected java.util.CalendargetFieldCalendar(JRField field)java.lang.ObjectgetFieldValue(JRField field)Gets the field value for the current position.java.sql.ResultSetgetResultSet()Access the result set that this data source is based on.booleannext()Tries to position the cursor on the next element in the data source.protected byte[]readBytes(java.io.InputStream is, long size)protected byte[]readBytes(java.lang.Integer columnIndex)protected java.lang.ObjectreadDate(java.lang.Integer columnIndex, JRField field)protected java.lang.ObjectreadTime(java.lang.Integer columnIndex, JRField field)protected java.lang.ObjectreadTimestamp(java.lang.Integer columnIndex, JRField field)protected java.util.TimeZoneresolveTimeZone(java.lang.String timezoneId)protected java.lang.IntegersearchColumnByIndex(java.lang.String index)protected java.lang.IntegersearchColumnByIndex(JRField field)protected java.lang.IntegersearchColumnByLabel(java.lang.String label)protected java.lang.IntegersearchColumnByLabel(JRField field)protected java.lang.IntegersearchColumnByName(java.lang.String name)protected java.lang.IntegersearchColumnByName(JRField field)voidsetReportTimeZone(java.util.TimeZone reportTimeZone)Sets the report time zone, which is the one used to display datetime values in the report.voidsetTimeZone(java.util.TimeZone timeZone, boolean override)Sets the default time zone to be used for retrieving date/time values from the result set.
-
-
-
Field Detail
-
PROPERTY_FIELD_COLUMN_NAME
public static final java.lang.String PROPERTY_FIELD_COLUMN_NAME
Property specifying the result set column name for the dataset field.- See Also:
- Constant Field Values
-
PROPERTY_FIELD_COLUMN_LABEL
public static final java.lang.String PROPERTY_FIELD_COLUMN_LABEL
Property specifying the result set column label for the dataset field.- See Also:
- Constant Field Values
-
PROPERTY_FIELD_COLUMN_INDEX
public static final java.lang.String PROPERTY_FIELD_COLUMN_INDEX
Property specifying the result set column index for the dataset field.- See Also:
- Constant Field Values
-
INDEXED_COLUMN_PREFIX
public static final java.lang.String INDEXED_COLUMN_PREFIX
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_CLOB_VALUE_READ_FAILURE
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_CLOB_VALUE_READ_FAILURE
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_COLUMN_INDEX_OUT_OF_RANGE
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_COLUMN_INDEX_OUT_OF_RANGE
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_FIELD_VALUE_NOT_RETRIEVED
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_FIELD_VALUE_NOT_RETRIEVED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_METADATA_NOT_RETRIEVED
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_METADATA_NOT_RETRIEVED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_NAME
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_NAME
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_LABEL
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_UNKNOWN_COLUMN_LABEL
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_RESULT_SET_NEXT_RECORD_NOT_RETRIEVED
public static final java.lang.String EXCEPTION_MESSAGE_KEY_RESULT_SET_NEXT_RECORD_NOT_RETRIEVED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRResultSetDataSource
public JRResultSetDataSource(JasperReportsContext jasperReportsContext, java.sql.ResultSet resultSet)
-
JRResultSetDataSource
public JRResultSetDataSource(java.sql.ResultSet resultSet)
-
-
Method Detail
-
getResultSet
public java.sql.ResultSet getResultSet()
Access the result set that this data source is based on.- Returns:
- the result set used by this data source
-
next
public boolean next() throws JRExceptionDescription copied from interface:JRDataSourceTries to position the cursor on the next element in the data source.- Specified by:
nextin interfaceJRDataSource- Returns:
- true if there is a next record, false otherwise
- Throws:
JRException- if any error occurs while trying to move to the next element
-
getFieldValue
public java.lang.Object getFieldValue(JRField field) throws JRException
Description copied from interface:JRDataSourceGets the field value for the current position.- Specified by:
getFieldValuein interfaceJRDataSource- Returns:
- an object containing the field value. The object type must be the field object type.
- Throws:
JRException
-
readDate
protected java.lang.Object readDate(java.lang.Integer columnIndex, JRField field) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
readTimestamp
protected java.lang.Object readTimestamp(java.lang.Integer columnIndex, JRField field) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
readTime
protected java.lang.Object readTime(java.lang.Integer columnIndex, JRField field) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
searchColumnByName
protected java.lang.Integer searchColumnByName(JRField field) throws java.sql.SQLException, JRException
- Throws:
java.sql.SQLExceptionJRException
-
searchColumnByName
protected java.lang.Integer searchColumnByName(java.lang.String name) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
searchColumnByLabel
protected java.lang.Integer searchColumnByLabel(JRField field) throws java.sql.SQLException, JRException
- Throws:
java.sql.SQLExceptionJRException
-
searchColumnByLabel
protected java.lang.Integer searchColumnByLabel(java.lang.String label) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
searchColumnByIndex
protected java.lang.Integer searchColumnByIndex(JRField field) throws java.sql.SQLException, JRException
- Throws:
java.sql.SQLExceptionJRException
-
searchColumnByIndex
protected java.lang.Integer searchColumnByIndex(java.lang.String index) throws java.sql.SQLException, JRException- Throws:
java.sql.SQLExceptionJRException
-
clobToString
protected java.lang.String clobToString(java.sql.Clob clob) throws JRException- Throws:
JRException
-
getArrayReader
protected java.io.CharArrayReader getArrayReader(java.io.Reader reader, long size) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
protected byte[] readBytes(java.lang.Integer columnIndex) throws java.sql.SQLException, java.io.IOException- Throws:
java.sql.SQLExceptionjava.io.IOException
-
readBytes
protected byte[] readBytes(java.io.InputStream is, long size) throws java.io.IOException- Throws:
java.io.IOException
-
setTimeZone
public void setTimeZone(java.util.TimeZone timeZone, boolean override)Sets the default time zone to be used for retrieving date/time values from the result set. In most cases no explicit time zone conversion would be required for retrieving date/time values from the DB, and this parameter should be null.- Parameters:
timeZone- the default time zoneoverride- whether the default time zone overrides time zones specified as field-level properties- See Also:
JRJdbcQueryExecuterFactory.PROPERTY_TIME_ZONE
-
setReportTimeZone
public void setReportTimeZone(java.util.TimeZone reportTimeZone)
Sets the report time zone, which is the one used to display datetime values in the report. The time zone is used when theJRJdbcQueryExecuterFactory.PROPERTY_TIME_ZONEproperty is set to REPORT_TIME_ZONE.- Parameters:
reportTimeZone- the time zone used to display datetime values in the report
-
getFieldCalendar
protected java.util.Calendar getFieldCalendar(JRField field)
-
createFieldCalendar
protected java.util.Calendar createFieldCalendar(JRField field)
-
resolveTimeZone
protected java.util.TimeZone resolveTimeZone(java.lang.String timezoneId)
-
-