use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.
the class AuditConnection method initialize.
public void initialize() {
if (!initialized) {
try {
IDBDatasourceService datasourceService = getDBDatasourceService();
auditDs = datasourceService.getDataSource(AuditConnection.AUDIT_JNDI);
if (auditDs != null) {
AuditConnection.logger.debug(Messages.getInstance().getString("AUDCONN.DEBUG_LOOKUP_FOUND_CLASS", // $NON-NLS-1$
auditDs.getClass().getName()));
}
} catch (Exception dsException) {
AuditConnection.logger.error(Messages.getInstance().getErrorString("AUDCONN.ERROR_0001_COULD_NOT_GET_DATASOURCE"), // $NON-NLS-1$
dsException);
}
if (auditDs != null) {
initialized = true;
} else {
try {
// $NON-NLS-1$
AuditConnection.logger.warn(Messages.getInstance().getString("AUDCONN.WARN_FALLING_BACK_TO_DRIVERMGR"));
Class.forName(DRIVER_CLASS).newInstance();
initialized = true;
} catch (IllegalAccessException ex) {
AuditConnection.logger.error(Messages.getInstance().getErrorString("AUDCONN.ERROR_0002_INSTANCE_DRIVER"), // $NON-NLS-1$
ex);
} catch (ClassNotFoundException cfe) {
AuditConnection.logger.error(Messages.getInstance().getErrorString("AUDCONN.ERROR_0002_INSTANCE_DRIVER"), // $NON-NLS-1$
cfe);
} catch (InstantiationException ie) {
AuditConnection.logger.error(Messages.getInstance().getErrorString("AUDCONN.ERROR_0002_INSTANCE_DRIVER"), // $NON-NLS-1$
ie);
}
}
}
}
use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.
the class MDXConnection method init.
protected void init(Util.PropertyList properties) {
try {
if (nativeConnection != null) {
// Assume we're open
close();
}
// This is required if mondrian.i18n.LocalizingDynamicSchemaProcessor is being used
if (properties.get(RolapConnectionProperties.Locale.name()) == null) {
properties.put(RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString());
}
String dataSourceName = properties.get(RolapConnectionProperties.DataSource.name());
mapPlatformRolesToMondrianRoles(properties);
if (dataSourceName != null) {
IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
DataSource dataSourceImpl = datasourceService.getDataSource(dataSourceName);
if (dataSourceImpl != null) {
properties.remove(RolapConnectionProperties.DataSource.name());
nativeConnection = DriverManager.getConnection(properties, null, dataSourceImpl);
} else {
nativeConnection = DriverManager.getConnection(properties, null);
}
} else {
nativeConnection = DriverManager.getConnection(properties, null);
}
if (nativeConnection != null) {
if (role != null) {
nativeConnection.setRole(role);
}
}
if (nativeConnection == null) {
logger.error(Messages.getInstance().getErrorString("MDXConnection.ERROR_0002_INVALID_CONNECTION", // $NON-NLS-1$ //$NON-NLS-2$
properties != null ? properties.toString() : "null"));
}
} catch (Throwable t) {
if (logger != null) {
logger.error(Messages.getInstance().getErrorString("MDXConnection.ERROR_0002_INVALID_CONNECTION", properties != null ? properties.toString() : "null"), // $NON-NLS-1$ //$NON-NLS-2$
t);
} else {
Logger.error(this.getClass().getName(), Messages.getInstance().getErrorString("MDXConnection.ERROR_0002_INVALID_CONNECTION", properties != null ? properties.toString() : "null"), // $NON-NLS-1$ //$NON-NLS-2$
t);
}
}
}
use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.
the class PentahoDataSourceResolver method lookup.
public DataSource lookup(String dataSourceName) throws Exception {
javax.sql.DataSource datasource = null;
String unboundDsName = null;
IDBDatasourceService datasourceSvc = null;
try {
datasourceSvc = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, PentahoSessionHolder.getSession());
unboundDsName = datasourceSvc.getDSUnboundName(dataSourceName);
datasource = datasourceSvc.getDataSource(unboundDsName);
} catch (ObjectFactoryException e) {
// $NON-NLS-1$
logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), e);
throw e;
} catch (DBDatasourceServiceException e) {
/* We tried to find the datasource using unbound name.
** Now as a fall back we will attempt to find this datasource as it is.
** For example jboss/datasource/Hibernate. The unbound name ends up to be Hibernate
** We will first look for Hibernate and if we fail then look for jboss/datasource/Hibernate */
logger.warn(Messages.getInstance().getString("PentahoXmlaServlet.WARN_0001_UNABLE_TO_FIND_UNBOUND_NAME", dataSourceName, unboundDsName), // $NON-NLS-1$
e);
try {
datasource = datasourceSvc.getDataSource(dataSourceName);
} catch (DBDatasourceServiceException dbse) {
logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), // $NON-NLS-1$
e);
throw dbse;
}
}
return datasource;
}
use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.
the class MDXBaseComponentTest method shouldAddSolutionPrefixIfFileExistsInRepository.
@Test
@SuppressWarnings("unchecked")
public void shouldAddSolutionPrefixIfFileExistsInRepository() throws ObjectFactoryException, DBDatasourceServiceException {
mdxBaseComponent.setActionDefinition(connAction);
when(connAction.getMdxConnectionString()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getConnectionProps()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getConnection()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getJndi()).thenReturn(new ActionInputConstant("", null));
when(connAction.getLocation()).thenReturn(new ActionInputConstant("", null));
when(connAction.getRole()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getCatalog()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getUserId()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getPassword()).thenReturn(IActionInput.NULL_INPUT);
when(connAction.getCatalogResource()).thenReturn(catalogResource);
when(catalogResource.getName()).thenReturn("catalog name");
PentahoSystem.registerObject(mdxConnection);
PentahoSystem.registerPrimaryObjectFactory(objFactory);
PentahoSessionHolder.setSession(session);
when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
IDBDatasourceService datasourceService = mock(IDBDatasourceService.class);
when(objFactory.objectDefined("IDBDatasourceService")).thenReturn(true);
when(objFactory.get(any(Class.class), eq("IDBDatasourceService"), any(IPentahoSession.class))).thenReturn(datasourceService);
DataSource dataSource = mock(DataSource.class);
when(datasourceService.getDataSource(anyString())).thenReturn(dataSource);
mdxBaseComponent.setRuntimeContext(runtimeContext);
when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
MondrianCatalog mc = mock(MondrianCatalog.class);
doReturn(mc).when(mdxBaseComponent).getMondrianCatalog(anyString());
// using the same prepared environment for several checks...
// if file exists in repository, then the "solution:" prefix should be added
when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
doReturn(true).when(mdxBaseComponent).fileExistsInRepository("fileName");
mdxBaseComponent.getConnectionOrig();
verify(mdxBaseComponent).getMondrianCatalog("solution:fileName");
verify(mdxBaseComponent, times(1)).fileExistsInRepository(anyString());
// if file exists in repository, then the "solution:" prefix should NOT be added,
// and the file therefore should be read from file system further
when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
doReturn(false).when(mdxBaseComponent).fileExistsInRepository("fileName");
mdxBaseComponent.getConnectionOrig();
verify(mdxBaseComponent).getMondrianCatalog("fileName");
verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
// if filename already starts from "solution:" prefix,
// then no need to check file existence in repository
when(catalogActionSeqRes.getAddress()).thenReturn("solution:fileName");
mdxBaseComponent.getConnectionOrig();
verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
// same here: if the resource is http link, then no need to check it in repository
when(catalogActionSeqRes.getAddress()).thenReturn("http:fileName");
mdxBaseComponent.getConnectionOrig();
verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
}
use of org.pentaho.platform.api.data.IDBDatasourceService in project pentaho-platform by pentaho.
the class EmbeddedQuartzSystemListener method startup.
public boolean startup(final IPentahoSession session) {
boolean result = true;
Properties quartzProps = null;
if (quartzPropertiesFile != null) {
quartzProps = PentahoSystem.getSystemSettings().getSystemSettingsProperties(quartzPropertiesFile);
} else if (quartzProperties != null) {
quartzProps = quartzProperties;
}
try {
if (quartzProps == null) {
quartzProps = findPropertiesInClasspath();
}
if (quartzProps == null) {
result = false;
} else {
// $NON-NLS-1$
String dsName = quartzProps.getProperty("org.quartz.dataSource.myDS.jndiURL");
if (dsName != null) {
IDBDatasourceService datasourceService = getQuartzDatasourceService(session);
String boundDsName = datasourceService.getDSBoundName(dsName);
if (boundDsName != null) {
// $NON-NLS-1$
quartzProps.setProperty("org.quartz.dataSource.myDS.jndiURL", boundDsName);
}
DataSource ds = datasourceService.getDataSource(dsName);
result = verifyQuartzIsConfigured(ds);
}
// $NON-NLS-1$
QuartzScheduler scheduler = (QuartzScheduler) PentahoSystem.get(IScheduler.class, "IScheduler2", null);
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("Quartz configured with properties");
// $NON-NLS-1$
quartzProps.store(System.out, "debugging");
}
scheduler.setQuartzSchedulerFactory(new org.quartz.impl.StdSchedulerFactory(quartzProps));
if (logger.isDebugEnabled()) {
logger.debug(scheduler.getQuartzScheduler().getSchedulerName());
}
scheduler.start();
}
} catch (IOException ex) {
result = false;
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0004_LOAD_PROPERTIES_FROM_CLASSPATH"), // $NON-NLS-1$
ex);
} catch (ObjectFactoryException objface) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0005_UNABLE_TO_INSTANTIATE_OBJECT", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
objface);
result = false;
} catch (DBDatasourceServiceException dse) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0006_UNABLE_TO_GET_DATASOURCE", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
dse);
result = false;
} catch (SQLException sqle) {
// $NON-NLS-1$
logger.error("EmbeddedQuartzSystemListener.ERROR_0007_SQLERROR", sqle);
result = false;
} catch (SchedulerException e) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
e);
result = false;
} catch (org.pentaho.platform.api.scheduler2.SchedulerException e) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
e);
result = false;
}
return result;
}
Aggregations