Search in sources :

Example 11 with IDBDatasourceService

use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method addToCatalog.

public static int addToCatalog(String baseUrl, boolean enableXmla, String schemaSolutionPath, IPentahoSession session, String jndiName, boolean overwrite) {
    IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
    PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
    String dsUrl = baseUrl;
    if (!dsUrl.endsWith("/")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        dsUrl += "/";
    }
    // $NON-NLS-1$
    dsUrl += "Xmla";
    // $NON-NLS-1$
    String catDef = "solution:" + schemaSolutionPath;
    MondrianSchema mondrianSchema = mondrianCatalogService.loadMondrianSchema(catDef, session);
    String catName = mondrianSchema.getName();
    String[] roleNames = mondrianSchema.getRoleNames();
    // verify JNDI
    try {
        IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        datasourceService.getDSBoundName(jndiName);
    } catch (ObjectFactoryException objface) {
        Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0006_UNABLE_TO_FACTORY_OBJECT", jndiName), objface);
    } catch (DBDatasourceServiceException dse) {
        Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0001_JNDI_NAMING_ERROR", jndiName), dse);
        return -1;
    }
    // used in both the catalog and the catalog datasource
    // Note: we use the unbound JNDI name here, the PentahoXmlaServlet resolves the JNDI name
    // $NON-NLS-1$
    String catConnectStr = "Provider=mondrian;DataSource=" + jndiName;
    // MB - 12/2009 - TODO: Figure out the empty list
    // Curious why we aren't adding the cubes from the read schema into the created schema.
    MondrianCatalog cat = new MondrianCatalog(catName, catConnectStr, catDef, new MondrianSchema(catName, new ArrayList<MondrianCube>(), roleNames));
    try {
        mondrianCatalogService.addCatalog(cat, overwrite, session);
    } catch (MondrianCatalogServiceException e) {
        Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0002_EXCEPTION_OCCURRED"), e);
        return -1;
    }
    return 0;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ArrayList(java.util.ArrayList) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Example 12 with IDBDatasourceService

use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.

the class PlatformKettleDataSourceProvider method getNamedDataSourceFromService.

protected <T extends IDBDatasourceService> DataSource getNamedDataSourceFromService(Class<T> dataSourceServiceInterface, String dataSourceName) throws DataSourceNamingException {
    T datasourceService = PentahoSystem.get(dataSourceServiceInterface, null);
    IDBDatasourceService service = (datasourceService == null) ? PentahoSystem.get(IDBDatasourceService.class, null) : datasourceService;
    if (service != null) {
        try {
            return service.getDataSource(dataSourceName);
        } catch (DBDatasourceServiceException ex) {
            throw new DataSourceNamingException(ex);
        }
    }
    return null;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DataSourceNamingException(org.pentaho.di.core.database.DataSourceNamingException) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Example 13 with IDBDatasourceService

use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.

the class ReportWizardSpecComponent method getResultSet.

public IPentahoResultSet getResultSet(final ReportSpec reportSpec) throws Exception {
    String jndiName = reportSpec.getReportSpecChoice().getJndiSource();
    IPentahoConnection connection = null;
    if (reportSpec.getIsMDX()) {
        // did this ever work??
        // $NON-NLS-1$
        String connectStr = "";
        IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        String dsName = datasourceService.getDSBoundName(jndiName);
        if (dsName != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            connectStr = "dataSource=" + dsName + "; Catalog=mondrian";
        } else {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
            return null;
        }
        Properties props = new Properties();
        props.setProperty(IPentahoConnection.CONNECTION, connectStr);
        props.setProperty(IPentahoConnection.PROVIDER, reportSpec.getMondrianCubeDefinitionPath());
        connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
    } else {
        connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this);
    }
    String query = ReportParameterUtility.setupParametersForActionSequence(reportSpec.getQuery());
    query = setupQueryParameters(query);
    IPentahoResultSet res = connection.executeQuery(query);
    return res;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Example 14 with IDBDatasourceService

use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.

the class JFreeReportGenerateDefinitionComponent method getResultSet.

public IPentahoResultSet getResultSet(final ReportSpec reportSpec) throws Exception {
    String jndiName = reportSpec.getReportSpecChoice().getJndiSource();
    IPentahoConnection connection = null;
    if (reportSpec.getIsMDX()) {
        // did this ever work??
        // $NON-NLS-1$
        String connectStr = "";
        IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        String dsName = datasourceService.getDSBoundName(jndiName);
        if (dsName != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            connectStr = "dataSource=" + dsName + "; Catalog=mondrian";
        } else {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
            return null;
        }
        Properties props = new Properties();
        props.setProperty(IPentahoConnection.CONNECTION, connectStr);
        props.setProperty(IPentahoConnection.PROVIDER, reportSpec.getMondrianCubeDefinitionPath());
        connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
    } else {
        connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this);
    }
    String query = ReportParameterUtility.setupParametersForActionSequence(reportSpec.getQuery());
    query = setupQueryParameters(query);
    IPentahoResultSet res = connection.executeQuery(query);
    return res;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Aggregations

IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)14 DataSource (javax.sql.DataSource)6 Properties (java.util.Properties)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)5 SQLException (java.sql.SQLException)3 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)3 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 DataSourceNamingException (org.pentaho.di.core.database.DataSourceNamingException)2 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InitialContext (javax.naming.InitialContext)1 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)1 Configuration (org.hibernate.cfg.Configuration)1 Test (org.junit.Test)1 ActionInputConstant (org.pentaho.actionsequence.dom.ActionInputConstant)1 MdxConnectionAction (org.pentaho.actionsequence.dom.actions.MdxConnectionAction)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1