use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class SQLConnection method connect.
public boolean connect(final Properties props) {
close();
String jndiName = props.getProperty(IPentahoConnection.JNDI_NAME_KEY);
if ((jndiName != null) && (jndiName.length() > 0)) {
initWithJNDI(jndiName);
} else {
String connectionName = props.getProperty(IPentahoConnection.CONNECTION_NAME);
if ((connectionName != null) && (connectionName.length() > 0)) {
IDatabaseConnection databaseConnection = (IDatabaseConnection) props.get(IPentahoConnection.CONNECTION);
initDataSource(databaseConnection);
} else {
String driver = props.getProperty(IPentahoConnection.DRIVER_KEY);
String provider = props.getProperty(IPentahoConnection.LOCATION_KEY);
String userName = props.getProperty(IPentahoConnection.USERNAME_KEY);
String password = props.getProperty(IPentahoConnection.PASSWORD_KEY);
init(driver, provider, userName, password);
String query = props.getProperty(IPentahoConnection.QUERY_KEY);
if ((query != null) && (query.length() > 0)) {
try {
executeQuery(query);
} catch (Exception e) {
logger.error("Can't execute query", e);
}
}
}
}
return ((nativeConnection != null) && !isClosed());
}
use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportDatasources.
@Test
public void testExportDatasources() throws Exception {
IDatasourceMgmtService svc = mock(IDatasourceMgmtService.class);
exporterSpy.setDatasourceMgmtService(svc);
List<IDatabaseConnection> datasources = new ArrayList<>();
IDatabaseConnection conn = mock(DatabaseConnection.class);
IDatabaseConnection icon = mock(IDatabaseConnection.class);
datasources.add(conn);
datasources.add(icon);
when(svc.getDatasources()).thenReturn(datasources);
exporterSpy.exportDatasources();
assertEquals(1, exporterSpy.getExportManifest().getDatasourceList().size());
assertEquals(conn, exporterSpy.getExportManifest().getDatasourceList().get(0));
}
use of org.pentaho.database.model.IDatabaseConnection 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.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class DatabaseHelperTest method testDataNodeToDatabaseConnection.
@Test
public void testDataNodeToDatabaseConnection() {
IDatabaseConnection name = databaseHelper.dataNodeToDatabaseConnection(null, "name", createDataNode());
Map<String, String> extraOptionsOrder = name.getExtraOptionsOrder();
assertNotNull(extraOptionsOrder);
assertTrue(extraOptionsOrder.size() > 0);
}
use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testUpdateDatasourceWithName.
@Test
public void testUpdateDatasourceWithName() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
// stub out update file which requires a file to be returned
doReturn(f).when(repo).updateFile(any(RepositoryFile.class), any(NodeRepositoryFileData.class), anyString());
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection databaseConnection = createDatabaseConnection(EXP_DBMETA_NAME);
updateDatabaseConnection(databaseConnection);
datasourceMgmtService.updateDatasourceByName(EXP_DBMETA_NAME, databaseConnection);
verify(repo).updateFile(argThat(isLikeFile(new RepositoryFile.Builder(EXP_DBMETA_NAME + ".kdb").build())), argThat(hasData(pathPropertyPair("/databaseMeta/HOST_NAME", EXP_UPDATED_DBMETA_HOSTNAME))), anyString());
}
Aggregations