Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package pt.webdetails.cda.dataaccess;
  
  
  import  org.apache.commons.lang.StringUtils;
  import  org.apache.commons.logging.Log;
 import  org.apache.commons.logging.LogFactory;
 import  org.dom4j.Element;
 import  org.pentaho.platform.api.engine.ObjectFactoryException;
 import  org.pentaho.platform.engine.core.system.PentahoSystem;
 import  org.pentaho.reporting.engine.classic.core.DataFactory;
 import  org.pentaho.reporting.engine.classic.core.ParameterDataRow;
 import  org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.AbstractNamedMDXDataFactory;
 import  org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.BandedMDXDataFactory;
 import  org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.DefaultCubeFileProvider;
 import  org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.MondrianConnectionProvider;
 import  org.pentaho.reporting.platform.plugin.connection.PentahoCubeFileProvider;
 import  org.pentaho.reporting.platform.plugin.connection.PentahoMondrianConnectionProvider;
Implementation of a DataAccess that will get data from a SQL database

User: pedro Date: Feb 3, 2010 Time: 12:18:05 PM

 
 public class MdxDataAccess extends PREDataAccess
 {
 
   private static final Log logger = LogFactory.getLog(MdxDataAccess.class);
 
   public enum BANDED_MODE
   {
 
     CLASSIC, COMPACT
   };
 
 
   public MdxDataAccess(final Element element)
   {
     super(element);
 
     try
     {
        = BANDED_MODE.valueOf(element.selectSingleNode("./BandedMode").getText().toUpperCase());
 
     }
     catch (Exception e)
     {
       // Getting defaults
       try
       {
         String _mode = CdaBoot.getInstance().getGlobalConfig().getConfigProperty("pt.webdetails.cda.BandedMDXMode");
         if (_mode != null)
         {
            = BANDED_MODE.valueOf(_mode);
         }
       }
       catch (Exception ex)
       {
         // ignore, let the default take it's place
       }
 
     }
 
 
   }
 
 
   public MdxDataAccess()
   {
   }
 
 
   protected AbstractNamedMDXDataFactory createDataFactory()
   {
     if (getBandedMode() == .)
     {
       return new BandedMDXDataFactory();
 
     }
     else
     {
       return new CompactBandedMDXDataFactory();
     }
   }
  {
    .debug("Creating BandedMDXDataFactory");
    final MondrianConnectionInfo mondrianConnectionInfo = connection.getConnectionInfo();
    final AbstractNamedMDXDataFactory mdxDataFactory = createDataFactory();
    mdxDataFactory.setDataSourceProvider(connection.getInitializedDataSourceProvider());
    mdxDataFactory.setJdbcPassword(mondrianConnectionInfo.getPass());
    mdxDataFactory.setJdbcUser(mondrianConnectionInfo.getUser());
    mdxDataFactory.setRole(mondrianConnectionInfo.getMondrianRole());
    mdxDataFactory.setRoleField(mondrianConnectionInfo.getRoleField());
    mdxDataFactory.setJdbcPasswordField(mondrianConnectionInfo.getPasswordField());
    mdxDataFactory.setJdbcUserField(mondrianConnectionInfo.getUserField());
    if (CdaEngine.getInstance().isStandalone())
    {
      mdxDataFactory.setCubeFileProvider(new DefaultCubeFileProvider(mondrianConnectionInfo.getCatalog()));
    }
    else
    {
      mdxDataFactory.setCubeFileProvider(new PentahoCubeFileProvider(mondrianConnectionInfo.getCatalog()));
      try{
        mdxDataFactory.setMondrianConnectionProvider((MondrianConnectionProvider) PentahoSystem.getObjectFactory().get(PentahoMondrianConnectionProvider.class"MondrianConnectionProvider"null));
      } catch(ObjectFactoryException e){//couldn't get object
        mdxDataFactory.setMondrianConnectionProvider(new PentahoMondrianConnectionProvider());
      }
    }
    mdxDataFactory.setQuery("query"getQuery());
    return mdxDataFactory;
  }
  {
    return ;
  }
  public String getType()
  {
    return "mdx";
  }
  {
    return .;
  }
  {
//    logger.debug("Determining if we need to transform the BandedMDXTableModel");
//
//    
//    if( tm instanceof BandedMDXDataFactory){
//    BandedMDXDataFactory df = (BandedMDXDataFactory) tm;
//    TableModel t = new CompactBandedMDXTableModel(df. (df., rowLimit)
//    }
     
    return tm;
  }
  {//TODO: is this necessary after role assembly in EvaluableConnection.evaluate()? 
    try
    {
    }
    catch (Exception e)
    {
      .error("Failed to get a connection info for cache key");
      mci = null;
    }
    return new ExtraCacheKey(mci.getMondrianRole());
  }
  protected static class ExtraCacheKey implements Serializable
  {
    private static final long serialVersionUID = 1L;
    private BANDED_MODE bandedMode;
    private String roles;
    public ExtraCacheKey(BANDED_MODE bandedModeString roles)
    {
      this. = bandedMode;
      this. = roles;
    }
    @Override
    public boolean equals(Object obj)
    {
      if (obj == null)
      {
        return false;
      }
      if (getClass() != obj.getClass())
      {
        return false;
      }
      final ExtraCacheKey other = (ExtraCacheKeyobj;
      if (this. != other.bandedMode && (this. == null || !this..equals(other.bandedMode)))
      {
        return false;
      }
      else if (this. == null ? other.roles != null : !this..equals(other.roles))
      {
        return false;
      }
      return true;
    }
      this. = (BANDED_MODEin.readObject();
      this. = (Stringin.readObject();
    }
    
    private void writeObject(java.io.ObjectOutputStream outthrows IOException {
      out.writeObject(this.);
      out.writeObject(this.);
    }
    @Override
    public int hashCode()
    {
      int hash = 7;
      hash = 83 * hash + (this. != null ? this..hashCode() : 0);
      hash = 83 * hash + (this. != null ? this..hashCode() : 0);
      return hash;
    }
  }
  {
    ArrayList<PropertyDescriptorproperties = super.getInterface();
    return properties;
  }
  
  //treat special cases: allow string[]
  protected IDataSourceQuery performRawQuery(final ParameterDataRow parameterDataRowthrows QueryException
  {
    final String MDX_MULTI_SEPARATOR = ",";
    
    String[] columnNames = parameterDataRow.getColumnNames();
    Object[] values = new Object[columnNames.length];
    
    for(int i=0; i<columnNames.length;i++){
      String colName = columnNames[i];
      Object value = parameterDataRow.get(colName);
      if(value != null && value.getClass().isArray()){
        //translate value
        value = StringUtils.join( (Object[]) valueMDX_MULTI_SEPARATOR);
      }
      values[i] = value;
    }
    
    return super.performRawQuery(new ParameterDataRow(columnNames, values));
  
  }
New to GrepCode? Check out our FAQ X