use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class DynamicallyPooledDatasourceSystemListenerTest method testGetDataSourceHandleDBDatasourceServiceException.
@Test
public void testGetDataSourceHandleDBDatasourceServiceException() throws Exception {
when(listener.getDatasourceService()).thenReturn(datasourceService);
when(datasourceService.getDataSource(CONNECTION_NAME)).thenThrow(new DBDatasourceServiceException());
DataSource ds = listener.getDataSource(connection);
assertNull(ds);
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PentahoConnectionDatasourceServiceTest method setUp.
@Before
public void setUp() {
mockConnection = mock(IDatabaseConnection.class);
// Set it up - this is a NATIVE connection
when(mockConnection.getAccessType()).thenReturn(DatabaseAccessType.NATIVE);
when(mockConnection.getDatabaseName()).thenReturn(dsName);
DataSource mockDs = mock(DataSource.class);
IDatasourceMgmtService mockMgmtService = mock(IDatasourceMgmtService.class);
spyService = spy(service);
try {
when(mockMgmtService.getDatasourceByName(dsName)).thenReturn(mockConnection);
} catch (DatasourceMgmtServiceException e) {
e.printStackTrace();
}
try {
doReturn(mockDs).when(spyService).resolveDatabaseConnection(mockConnection);
} catch (DBDatasourceServiceException e) {
e.printStackTrace();
}
doReturn(mockMgmtService).when(spyService).getDatasourceMgmtService();
service.clearCache();
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreatePoolNoDialectService.
@Test
public void testCreatePoolNoDialectService() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName("GENERIC"));
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.postgresql.Driver");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.setupPooledDataSource(con);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreatePoolNoDialect.
@Test
public void testCreatePoolNoDialect() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
mp = new MicroPlatform(SOLUTION_PATH);
mp.defineInstance(IDatabaseDialectService.class, dialectService);
mp.start();
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.setupPooledDataSource(con);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException 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;
}
Aggregations