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;
}
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;
}
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;
}
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;
}
Aggregations