Search in sources :

Example 1 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.

the class NonPooledDatasourceSystemListener method startup.

public boolean startup(final IPentahoSession session) {
    try {
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: called for startup ...");
        ICacheManager cacheManager = addCacheRegions();
        List<IDatabaseConnection> databaseConnections = getListOfDatabaseConnections(session);
        String dsName = "";
        DataSource ds = null;
        for (IDatabaseConnection databaseConnection : databaseConnections) {
            if (databaseConnection != null) {
                // $NON-NLS-1$
                Logger.debug(this, "  Setting up datasource - " + databaseConnection);
                dsName = databaseConnection.getName();
                // http://jira.pentaho.com/browse/BISERVER-12244
                if (!databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
                    // if connection's port used by server there is no sense to get DataSource for this
                    ds = isPortUsedByServer(databaseConnection) ? null : setupDataSourceForConnection(databaseConnection);
                } else {
                    Logger.debug(this, // $NON-NLS-1$
                    "(Datasource \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                    "\" not cached)");
                    continue;
                }
                cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
                Logger.debug(this, // $NON-NLS-1$
                "(Storing datasource under key \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                "\")");
            }
        }
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: Completed startup.");
        return true;
    } catch (ObjectFactoryException objface) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0001_UNABLE_TO_INSTANTIATE_OBJECT"), // $NON-NLS-1$
        objface);
        return false;
    } catch (DatasourceMgmtServiceException dmse) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
        dmse);
        return false;
    }
}
Also used : ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 2 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.

the class DynamicConnectionDatasourceServiceTest 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);
    DynamicallyPooledOrJndiDatasourceService dynamic = new DynamicallyPooledOrJndiDatasourceService();
    dynamic.setNonPooledDatasourceService(nonPooledSpyService);
    dynamic.setPooledDatasourceService(pooledSpyService);
    spyService = spy(dynamic);
    try {
        when(mockMgmtService.getDatasourceByName(dsName)).thenReturn(mockConnection);
    } catch (DatasourceMgmtServiceException e) {
        e.printStackTrace();
    }
    try {
        doReturn(mockDs).when(nonPooledSpyService).resolveDatabaseConnection(mockConnection);
        doReturn(mockDs).when(pooledSpyService).resolveDatabaseConnection(mockConnection);
    } catch (DBDatasourceServiceException e) {
        e.printStackTrace();
    }
    doReturn(mockMgmtService).when(nonPooledSpyService).getDatasourceMgmtService();
    doReturn(mockMgmtService).when(pooledSpyService).getDatasourceMgmtService();
    doReturn(mockMgmtService).when(spyService).getDatasourceMgmtService();
    spyService.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 3 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.

the class JNDIDatasourceServiceTest method setUp.

@Before
public void setUp() {
    IDatabaseConnection mockConnection = mock(IDatabaseConnection.class);
    // Set it up - this is a JNDI connection
    when(mockConnection.getAccessType()).thenReturn(DatabaseAccessType.JNDI);
    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).getJndiDataSource(dsName);
    } 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 4 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method getDatasourceIds.

public List<String> getDatasourceIds() throws DatasourceMgmtServiceException {
    try {
        List<String> datasourceList = new ArrayList<String>();
        List<RepositoryFile> repositoryFiles = getRepositoryFiles();
        if (repositoryFiles != null) {
            for (RepositoryFile file : repositoryFiles) {
                datasourceList.add(file.getId().toString());
            }
        }
        return datasourceList;
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", ure.getLocalizedMessage()), // $NON-NLS-1$ //$NON-NLS-2$
        ure);
    }
}
Also used : ArrayList(java.util.ArrayList) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 5 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method updateDatasource.

private String updateDatasource(RepositoryFile file, IDatabaseConnection databaseConnection) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
    try {
        if (file != null) {
            file = new RepositoryFile.Builder(file).versionId(file.getVersionId()).id(file.getId()).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).build();
            file = repository.updateFile(file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
            renameIfNecessary(databaseConnection, file);
            return file.getId().toString();
        } else {
            throw new NonExistingDatasourceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0006_DATASOURCE_DOES_NOT_EXIST", // $NON-NLS-1$
            databaseConnection.getName()));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Aggregations

DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)19 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)11 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)7 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 DataSource (javax.sql.DataSource)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 Before (org.junit.Before)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)4 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 URL (java.net.URL)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1