Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * This program is free software; you can redistribute it and/or modify it under the 
   * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
   * Foundation.
   * You should have received a copy of the GNU Lesser General Public License along with this 
   * program; if not, you can obtain a copy at 
   * or from the Free Software Foundation, Inc., 
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU Lesser General Public License for more details.
  * Copyright 2006 - 2009 Pentaho Corporation.  All rights reserved.
 package org.pentaho.platform.plugin.action.jfreereport.helper;
The PentahoTableDataFactory class implements JFreeReport's data factory and manages the TableModels provided to JFreeReport. The primary difference between this class and JFreeReport's standard TableDataFactory is the "getTableIterator" method, which allows the Platform to clean up and table model resources after their use. Also, we support Pentaho's IPreparedComponent interface which allows a prepared component to generate a result set when requested.

Will Gorman
 public class PentahoTableDataFactory implements DataFactoryCloneable {

map of tables to keep track of
 	private HashMap tables;
 	private HashMap components;

default constructor
 		this. = new HashMap();
 		this. = new HashMap();

constructor with one time call to addTable for convenience.

name table name
tableModel instance of table model
 	public PentahoTableDataFactory(final String name,
 			final TableModel tableModel) {

add a table to the map

name table name
tableModel instance of table model
 	public void addTable(final String namefinal TableModel tableModel) {

add a prepared component to the map

name prepared component name
component instance of prepared component
 	public void addPreparedComponent(final String name,
 			final IPreparedComponent component) {

remove a table from the map

name table name
	public void removeTable(final String name) {

Queries a datasource. The string 'query' defines the name of the query. The Parameterset given here may contain more data than actually needed.

The dataset may change between two calls, do not assume anything!

query the name of the table.
parameters are ignored for this factory.
the report data or null.
	public TableModel queryData(final String queryfinal DataRow parameters) {
		TableModel model = (TableModel.get(query);
		if (model == null) {
			final IPreparedComponent component = (IPreparedComponent) 
			if (component != null) {
				final HashMap map = new HashMap();
				if (parameters != null) {
					String[] columnNames = parameters.getColumnNames();
					for (String columnName : columnNames) {
				final IPentahoResultSet rs = component.executePrepared(map);
				model = new PentahoTableModel(rs);
		return model;
	public void open() {
	public void close() {
		// this gets called too frequently for the old implementation
		// the reporting engine seems to call this method during each stage
		// of report generation, breaking our data
	public void finalize() {
		// this is the old implementation of 'close'
		final Iterator iter = .values().iterator();
		while (iter.hasNext()) {
			final TableModel model = (;
			if (model instanceof CloseableTableModel) {
				final CloseableTableModel closeableTableModel = (CloseableTableModelmodel;

Derives a freshly initialized report data factory, which is independend of the original data factory. Opening or Closing one data factory must not affect the other factories.

		try {
			return (DataFactoryclone();
							.getErrorString("PentahoTableDataFactory.ERROR_0001_CLONE_SHOULD_NOT_FAIL")); //$NON-NLS-1$
		final PentahoTableDataFactory dataFactory = (PentahoTableDataFactorysuper
		dataFactory.tables = (HashMap.clone();
		return dataFactory;
	public String[] getQueryNames() {
	    String[] queryNames = (String[]) .keySet().toArray(new String[.size()]);
	    return queryNames;
	public boolean isQueryExecutable(String queryDataRow parameters) {
		boolean queryExecutable = .containsKey(query);
		return queryExecutable;
New to GrepCode? Check out our FAQ X