Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package pt.webdetails.cda.dataaccess;
  
  import java.util.Locale;
  import java.util.TimeZone;
  
  import  org.apache.commons.logging.Log;
  import  org.apache.commons.logging.LogFactory;
 import  org.dom4j.Element;
 import  org.pentaho.platform.api.repository.ISolutionRepository;
 import  org.pentaho.platform.engine.core.system.PentahoSessionHolder;
 import  org.pentaho.platform.engine.core.system.PentahoSystem;
 import  org.pentaho.platform.engine.services.solution.SolutionReposHelper;
 import  org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
 import  org.pentaho.reporting.engine.classic.core.DataFactory;
 import  org.pentaho.reporting.engine.classic.core.DefaultReportEnvironment;
 import  org.pentaho.reporting.engine.classic.core.ParameterDataRow;
 import  org.pentaho.reporting.engine.classic.core.ReportDataFactoryException;
 import  org.pentaho.reporting.engine.classic.core.ReportEnvironmentDataRow;
 import  org.pentaho.reporting.engine.classic.core.parameters.CompoundDataRow;
 import  org.pentaho.reporting.engine.classic.core.states.CachingDataFactory;
 import  org.pentaho.reporting.engine.classic.core.util.CloseableTableModel;
 import  org.pentaho.reporting.engine.classic.core.util.LibLoaderResourceBundleFactory;
 import  org.pentaho.reporting.libraries.base.config.Configuration;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceKey;
 import  org.pentaho.reporting.libraries.resourceloader.ResourceManager;
 import  org.pentaho.reporting.platform.plugin.PentahoReportEnvironment;
This is the DataAccess implementation for PentahoReportingEngine based queries.

User: pedro Date: Feb 3, 2010 Time: 2:18:19 PM

 
 public abstract class PREDataAccess extends SimpleDataAccess
 {
 
 //  private static final Log logger = LogFactory.getLog(PREDataAccess.class);
 
 
   public PREDataAccess()
   {
   }
 
 
   public PREDataAccess(final Element element)
   {
 
     super(element);
 
   }


  

Parameters:
id
name
connectionId
query
 
   public PREDataAccess(String idString nameString connectionIdString query)
   {
     super(idnameconnectionIdquery);
   }
 
 
   public abstract DataFactory getDataFactory() throws UnknownConnectionExceptionInvalidConnectionException;
 
   
   protected static class PREDataSourceQuery implements IDataSourceQuery{
 
     private TableModel tableModel;
     private CachingDataFactory localDataFactory;
     
     public PREDataSourceQuery(TableModel tm, CachingDataFactory df){
       this. = tm;
       this. = df;
     }
     
     public TableModel getTableModel() {
       return ;
     }
 
     public void closeDataSource() throws QueryException {
       if ( == null)
       {
         return;
       }
 
       // and at the end, close your tablemodel if it holds on to resources like a resultset
       if (getTableModel() instanceof CloseableTableModel)
       {
         final CloseableTableModel ctm = (CloseableTableModel) getTableModel();
         ctm.close();
      }
      // and finally shut down the datafactory to free any connection that may be open.
      .close();
       = null;
    }
    
  }
  
  protected IDataSourceQuery performRawQuery(final ParameterDataRow parameterDataRowthrows QueryException
  {
    
    boolean threadVarSet = false;
    
    try
    {
      final CachingDataFactory dataFactory = new CachingDataFactory(getDataFactory());
      final ResourceManager resourceManager = new ResourceManager();
      resourceManager.registerDefaults();
      final ResourceKey contextKey = getCdaSettings().getContextKey();
      final Configuration configuration = ClassicEngineBoot.getInstance().getGlobalConfig();
      dataFactory.initialize(configurationresourceManagercontextKey,
              new LibLoaderResourceBundleFactory(resourceManagercontextKey, Locale.getDefault(), TimeZone.getDefault()));
      dataFactory.open();
      // fire the query. you always get a tablemodel or an exception.
      final ReportEnvironmentDataRow environmentDataRow;
      if (CdaEngine.getInstance().isStandalone())
      {
        environmentDataRow = new ReportEnvironmentDataRow(new DefaultReportEnvironment(configuration));
      }
      else
      {
        // Make sure we have the env. correctly inited
        if (SolutionReposHelper.getSolutionRepositoryThreadVariable() == null && PentahoSystem.getObjectFactory().objectDefined(ISolutionRepository.class.getSimpleName()))
        {
          threadVarSet = true;
          SolutionReposHelper.setSolutionRepositoryThreadVariable(PentahoSystem.get(ISolutionRepository.class, PentahoSessionHolder.getSession()));
        }
        environmentDataRow = new ReportEnvironmentDataRow(new PentahoReportEnvironment(configuration));
      }
      final TableModel tm = dataFactory.queryData("query",
              new CompoundDataRow(environmentDataRowparameterDataRow));
      //  Store this variable so that we can close it later
      PREDataSourceQuery queryExecution = new PREDataSourceQuery(tmdataFactory);
      return queryExecution;
    }
    catch (UnknownConnectionException e)
    {
      throw new QueryException("Unknown connection"e);
    }
    catch (InvalidConnectionException e)
    {
      throw new QueryException("Unknown connection"e);
    }
    catch (ReportDataFactoryException e)
    {
      throw new QueryException("ReportDataFactoryException : " + e.getMessage()
              + ((e.getParentThrowable() == null) ? "" : ("; Parent exception: " + e.getParentThrowable().getMessage())) + "\n" +
              ((e.getParentThrowable() != null && e.getParentThrowable().getCause() != null)?e.getParentThrowable().getCause().getMessage() :"") + "\n"
              , e);
    }
    finally
    {
      //leave thread variable as it was
      if(threadVarSet) SolutionReposHelper.setSolutionRepositoryThreadVariable(null);
    }
  }
//  public void closeDataSource() throws QueryException
//  {
//
//    if (localDataFactory == null)
//    {
//      return;
//    }
//
//    // and at the end, close your tablemodel if it holds on to resources like a resultset
//    if (getTableModel() instanceof CloseableTableModel)
//    {
//      final CloseableTableModel ctm = (CloseableTableModel) getTableModel();
//      ctm.close();
//    }
//
//    // and finally shut down the datafactory to free any connection that may be open.
//    getLocalDataFactory().close();
//
//    localDataFactory = null;
//  }
//  public TableModel getTableModel()
//  {
//    return tableModel;
//  }
//
//
//  public void setTableModel(final TableModel tableModel)
//  {
//    this.tableModel = tableModel;
//  }
//
//
//  public CachingDataFactory getLocalDataFactory()
//  {
//    return localDataFactory;
//  }
//
//
//  public void setLocalDataFactory(final CachingDataFactory localDataFactory)
//  {
//    this.localDataFactory = localDataFactory;
//  }
  /*
  public static ArrayList<DataAccessConnectionDescriptor> getDataAccessConnectionDescriptors() {
  ArrayList<DataAccessConnectionDescriptor> descriptor = new ArrayList<DataAccessConnectionDescriptor>();
  DataAccessConnectionDescriptor proto = new DataAccessConnectionDescriptor();
  proto.addDataAccessProperty(new PropertyDescriptor("Query",PropertyDescriptor.TYPE.STRING,PropertyDescriptor.SOURCE.DATAACCESS));
  descriptor.add(proto);
  return descriptor;
  }
   */
  {
    ArrayList<PropertyDescriptorproperties = super.getInterface();
    return properties;
  }
New to GrepCode? Check out our FAQ X