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