Search in sources :

Example 16 with DBDatasourceServiceException

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);
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 17 with DBDatasourceServiceException

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();
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Before(org.junit.Before)

Example 18 with DBDatasourceServiceException

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);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) HashMap(java.util.HashMap) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 19 with DBDatasourceServiceException

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);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) HashMap(java.util.HashMap) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 20 with DBDatasourceServiceException

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

Aggregations

DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)22 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)11 DataSource (javax.sql.DataSource)9 Test (org.junit.Test)7 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)6 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)5 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 NamingException (javax.naming.NamingException)3 Before (org.junit.Before)3 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)3 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)3 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 InitialContext (javax.naming.InitialContext)2 PoolingDataSource (org.apache.commons.dbcp.PoolingDataSource)2