Search in sources :

Example 11 with DatasourceMgmtServiceException

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

the class NonPooledOrJndiDatasourceService method retrieve.

@Override
protected DataSource retrieve(String dsName) throws DBDatasourceServiceException {
    DataSource ds = null;
    requestedDatasourceName = dsName;
    try {
        IDatasourceMgmtService datasourceMgmtSvc = getDatasourceMgmtService();
        IDatabaseConnection databaseConnection = datasourceMgmtSvc.getDatasourceByName(dsName);
        if (databaseConnection != null && !databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
            ds = resolveDatabaseConnection(databaseConnection);
        // Database does not have the datasource, look in jndi now
        } else {
            try {
                ds = getJndiDataSource(dsName);
            } catch (DBDatasourceServiceException e) {
            // Ignore, Maybe jndi name is specified as database name in the connection
            }
        }
        if (ds == null && databaseConnection != null) {
            ds = getJndiDataSource(databaseConnection.getDatabaseName());
        }
        // if the resulting datasource is not null then store it in the cache
        if (ds != null) {
            cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
        }
    } catch (DatasourceMgmtServiceException daoe) {
        log.debug(Messages.getInstance().getErrorString("DatasourceService.DEBUG_0001_UNABLE_TO_FIND_DATASOURCE_IN_REPOSITORY", daoe.getLocalizedMessage()), daoe);
        try {
            return getJndiDataSource(dsName);
        } catch (DBDatasourceServiceException dse) {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("DatasourceService.ERROR_0003_UNABLE_TO_GET_JNDI_DATASOURCE"), // $NON-NLS-1$
            dse);
        }
    }
    return ds;
}
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)

Example 12 with DatasourceMgmtServiceException

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

the class JcrBackedDatasourceMgmtService method deleteDatasourceByName.

public void deleteDatasourceByName(String name) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
    RepositoryFile fileToDelete = null;
    try {
        fileToDelete = repository.getFile(getPath(name));
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", fileToDelete.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
    deleteDatasource(fileToDelete);
}
Also used : 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 13 with DatasourceMgmtServiceException

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

the class JcrBackedDatasourceMgmtService method getDatasources.

public List<IDatabaseConnection> getDatasources() throws DatasourceMgmtServiceException {
    try {
        List<IDatabaseConnection> datasourceList = new ArrayList<IDatabaseConnection>();
        List<RepositoryFile> repositoryFiles = getRepositoryFiles();
        if (repositoryFiles != null) {
            for (RepositoryFile file : repositoryFiles) {
                NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
                IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
                // IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
                // PentahoSessionHolder.getSession());
                // databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
                datasourceList.add(databaseConnection);
            }
        }
        return datasourceList;
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } 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 : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) ArrayList(java.util.ArrayList) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 14 with DatasourceMgmtServiceException

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

the class JcrBackedDatasourceMgmtService method createDatasource.

public String createDatasource(IDatabaseConnection databaseConnection) throws DuplicateDatasourceException, DatasourceMgmtServiceException {
    try {
        // IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
        // PentahoSessionHolder.getSession());
        // databaseMeta.setPassword(passwordService.encrypt(databaseMeta.getPassword()));
        RepositoryFile file = new RepositoryFile.Builder(RepositoryFilenameUtils.escape(databaseConnection.getName() + RepositoryObjectType.DATABASE.getExtension(), cachedReservedChars)).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).versioned(true).build();
        file = repository.createFile(getDatabaseParentFolderId(), file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
        if (file != null && file.getId() != null) {
            return file.getId().toString();
        } else {
            return null;
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString(
    // "DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        if (ure.getCause().toString().contains("ItemExistsException")) {
            throw new DuplicateDatasourceException();
        }
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) 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 15 with DatasourceMgmtServiceException

use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException 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)

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