use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceImplTest method testGetConnectionsPasswords.
@Test
public void testGetConnectionsPasswords() throws Exception {
doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
List<IDatabaseConnection> mockConnectionList = new ArrayList<>();
IDatabaseConnection mockConnection = new DatabaseConnection();
mockConnectionList.add(mockConnection);
mockConnection.setPassword("testPassword");
doReturn(mockConnectionList).when(connectionServiceImpl.datasourceMgmtSvc).getDatasources();
List<IDatabaseConnection> connectionList = connectionServiceImpl.getConnections();
verify(connectionServiceImpl).getConnections();
// Default getConnections() method does not hide password
assertEquals("testPassword", mockConnectionList.get(0).getPassword());
// Hide passwords
connectionList = connectionServiceImpl.getConnections(true);
verify(connectionServiceImpl).getConnections();
assertEquals(null, mockConnectionList.get(0).getPassword());
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testSqlQueries_AreNotSupported_PentahoDataServices.
@Test(expected = SqlQueriesNotSupportedException.class)
public void testSqlQueries_AreNotSupported_PentahoDataServices() throws Exception {
String connNameDataService = "connToDataService";
String dbTypeIdDataService = "Pentaho Data Services";
DatabaseType dbtype = new DatabaseType(dbTypeIdDataService, STRING_DEFAULT, null, 0, STRING_DEFAULT);
IDatabaseConnection connDataService = new DatabaseConnection();
connDataService.setDatabaseType(dbtype);
ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
doReturn(connDataService).when(connService).getConnectionByName(eq(connNameDataService));
DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
service.checkSqlQueriesSupported(connNameDataService);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testSqlQueries_Supported_PostgresDb.
@Test
public void testSqlQueries_Supported_PostgresDb() throws Exception {
String connNamePostgres = "connToPostgresDb";
String dbTypeIdPostgres = "PostgresDb";
IDatabaseConnection connDataService = new DatabaseConnection();
connDataService.setDatabaseType(new DatabaseType(dbTypeIdPostgres, STRING_DEFAULT, null, 0, STRING_DEFAULT));
ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
doReturn(connDataService).when(connService).getConnectionByName(eq(connNamePostgres));
DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
service.checkSqlQueriesSupported(connNamePostgres);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class AgileMartDatasourceLifecycleManager method startup.
@Override
public void startup() {
try {
String agileMartDatasourceName = PentahoSystem.getSystemSetting(SETTINGS_FILE, AGILE_MART_STAGING_DATASOURCE_NAME, null);
IDatabaseConnection agileMartDatasource = datasourceMgmtService.getDatasourceByName(agileMartDatasourceName);
IDatabaseConnection newAgileMartDatasource = agileMartDatasourceHelper.getAgileMartDatasource();
if (agileMartDatasource != null) {
newAgileMartDatasource.setId(agileMartDatasource.getId());
datasourceMgmtService.updateDatasourceByName(agileMartDatasource.getName(), newAgileMartDatasource);
} else {
datasourceMgmtService.createDatasource(newAgileMartDatasource);
}
} catch (Throwable th) {
log.warn("Error during the create/update of AgileMart Datasource", th);
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionService method createDatabaseConnection.
/**
* Create a database connection
*
* @param driver
* String name of the driver to use
* @param url
* String name of the url used to create the connection.
*
* @return IDatabaseConnection for the given parameters
*/
@GET
@Path("/createDatabaseConnection")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public IDatabaseConnection createDatabaseConnection(@QueryParam("driver") String driver, @QueryParam("url") String url) {
for (IDatabaseDialect dialect : dialectService.getDatabaseDialects()) {
if (dialect.getNativeDriver() != null && dialect.getNativeDriver().equals(driver)) {
if (dialect.getNativeJdbcPre() != null && url.startsWith(dialect.getNativeJdbcPre())) {
return dialect.createNativeConnection(url);
}
}
}
// if no native driver was found, create a custom dialect object.
IDatabaseConnection conn = genericDialect.createNativeConnection(url);
conn.getAttributes().put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, driver);
return conn;
}
Aggregations