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