use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class TablesSelectionStep method fetchTables.
protected void fetchTables() {
showWaitingDialog();
IDatabaseConnection connection = ((MultiTableDatasource) parentDatasource).getConnection();
processAvailableTables(connection, schemas.getValue());
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class InMemoryConnectionServiceImplTest method testGetConnections.
@Test
public void testGetConnections() {
try {
InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
List<IDatabaseConnection> conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 0);
IDatabaseConnection connection = new DatabaseConnection();
connection.setName("Connection 1");
serv.addConnection(connection);
conns = serv.getConnections();
assertTrue(conns != null && conns.size() > 0);
} catch (Exception ex) {
fail();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class InMemoryConnectionServiceImplTest method testUpdateConnection.
@Test
public void testUpdateConnection() {
try {
InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
List<IDatabaseConnection> conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 0);
IDatabaseConnection connection = new DatabaseConnection();
connection.setName("Connection 1");
connection.setUsername("admin");
connection.setPassword("password");
serv.addConnection(connection);
conns = serv.getConnections();
assertTrue(conns.get(0).getUsername().equals("admin"));
assertTrue(conns.get(0).getPassword().equals("password"));
connection = new DatabaseConnection();
connection.setName("Connection 1");
connection.setUsername("root");
connection.setPassword("pass");
serv.updateConnection(connection);
List<IDatabaseConnection> conns1 = serv.getConnections();
assertTrue(conns1 != null && conns1.size() > 0);
assertTrue(conns1.size() == conns.size());
assertTrue(conns1.get(0).getUsername().equals("root"));
assertTrue(conns1.get(0).getPassword().equals("pass"));
} catch (Exception ex) {
fail();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DatasourceInMemoryServiceHelperTest method setUp.
@Before
public void setUp() throws Exception {
URL resource = getClass().getClassLoader().getResource(getClass().getPackage().getName().replace(".", "/") + "/DatasourceInMemoryServiceHelperTest.csv");
csvFile = resource.getPath();
sqlConnection = mock(Connection.class);
when(resultSet.getMetaData()).thenReturn(rsMetaData);
when(statment.executeQuery(eq(SAMPLE_VALID_QUERY))).thenReturn(resultSet);
when(sqlConnection.createStatement(anyInt(), anyInt())).thenReturn(statment);
Map<String, String> attributesPrivateDriver = new HashMap<>();
attributesPrivateDriver.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, PrivateSQLDriver.class.getName());
when(genericConnPrivateDriver.getAttributes()).thenReturn(attributesPrivateDriver);
when(genericConnPrivateDriver.getDatabaseType()).thenReturn(genericDBType);
Map<String, String> attributesWithNoExistClass = new HashMap<>();
attributesWithNoExistClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.test.NoExistDriver");
when(genericConnWithNoExistClass.getAttributes()).thenReturn(attributesWithNoExistClass);
when(genericConnWithNoExistClass.getDatabaseType()).thenReturn(genericDBType);
Map<String, String> attributesNonDriverClass = new HashMap<>();
attributesNonDriverClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, String.class.getName());
when(genericConnWithNoDriverClass.getAttributes()).thenReturn(attributesNonDriverClass);
when(genericConnWithNoDriverClass.getDatabaseType()).thenReturn(genericDBType);
Map<String, String> attributesWithoutClass = new HashMap<>();
attributesWithoutClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
when(genericConnWithoutClass.getAttributes()).thenReturn(attributesWithoutClass);
when(genericConnWithoutClass.getDatabaseType()).thenReturn(genericDBType);
Map<String, String> attributesWithClass = new HashMap<>();
attributesWithClass.put(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, TestSQLDriver.class.getName());
when(genericConnWithClass.getAttributes()).thenReturn(attributesWithClass);
when(genericConnWithClass.getDatabaseType()).thenReturn(genericDBType);
when(service.getDatasourceByName(anyString())).thenAnswer(new Answer<IDatabaseConnection>() {
@Override
public IDatabaseConnection answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(GENERIC_CONN_PRIVATE_DRIVER)) {
return genericConnPrivateDriver;
}
if (invocation.getArguments()[0].equals(GENERIC_CONN_NOT_DRIVER_CLASS)) {
return genericConnWithNoDriverClass;
}
if (invocation.getArguments()[0].equals(GENERIC_CONN_NOT_FOUND_CLASS)) {
return genericConnWithNoExistClass;
}
if (invocation.getArguments()[0].equals(GENERIC_CONN_WITHOUT_DRIVER_CLASS)) {
return genericConnWithoutClass;
}
if (invocation.getArguments()[0].equals(GENERIC_CONN_DRIVER_CLASS)) {
return genericConnWithClass;
}
if (invocation.getArguments()[0].equals(CONN_CAN_NOT_PREPARED)) {
return null;
}
// throw exception for check if we get exception from getting connection
throw new DatasourceMgmtServiceException();
}
});
when(resLoader.getPluginSetting(this.anyClass(), anyString(), anyString())).thenReturn(SimpleDataAccessPermissionHandler.class.getName());
when(policy.isAllowed(anyString())).thenReturn(true);
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IDatasourceMgmtService.class)) {
return service;
}
if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
return policy;
}
if (invocation.getArguments()[0].equals(IPluginResourceLoader.class)) {
return resLoader;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class AnalysisImportDialogController method init.
public void init() {
try {
connectionAutoBeanFactory = GWT.create(IConnectionAutoBeanFactory.class);
resBundle = (ResourceBundle) super.getXulDomContainer().getResourceBundles().get(0);
// connectionService = new ConnectionServiceGwtImpl();
importDialogModel = new AnalysisImportDialogModel();
connectionList = (XulMenuList) document.getElementById("connectionList");
analysisParametersTree = (XulTree) document.getElementById("analysisParametersTree");
importDialog = (XulDialog) document.getElementById("importDialog");
analysisParametersDialog = (XulDialog) document.getElementById("analysisParametersDialog");
paramNameTextBox = (XulTextbox) document.getElementById("paramNameTextBox");
paramNameTextBox.addPropertyChangeListener(new ParametersChangeListener());
paramValueTextBox = (XulTextbox) document.getElementById("paramValueTextBox");
paramValueTextBox.addPropertyChangeListener(new ParametersChangeListener());
analysisPreferencesDeck = (XulDeck) document.getElementById("analysisPreferencesDeck");
availableRadio = (XulRadio) document.getElementById("availableRadio");
manualRadio = (XulRadio) document.getElementById("manualRadio");
hiddenArea = (XulVbox) document.getElementById("analysisImportCard");
schemaNameLabel = (XulLabel) document.getElementById("schemaNameLabel");
analysisFileLabel = (XulLabel) document.getElementById("analysisFileLabel");
uploadAnalysisButton = (XulButton) document.getElementById("uploadAnalysisButton");
acceptButton = (XulButton) document.getElementById("importDialog_accept");
acceptButton.setDisabled(true);
parametersAcceptButton = (XulButton) document.getElementById("analysisParametersDialog_accept");
parametersAcceptButton.setDisabled(true);
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(connectionList, "selectedIndex", importDialogModel, "connection", new BindingConvertor<Integer, IDatabaseConnection>() {
@Override
public Integer targetToSource(IDatabaseConnection connection) {
return -1;
}
@Override
public IDatabaseConnection sourceToTarget(Integer value) {
if (value >= 0) {
return importDialogModel.getConnectionList().get(value);
}
return null;
}
});
bf.createBinding(manualRadio, "checked", this, "preference", new PreferencesBindingConvertor());
bf.createBinding(this, "connectionNames", connectionList, "elements");
Binding domainBinding = bf.createBinding(importDialogModel, "connectionList", this, "relationalConnections");
Binding analysisParametersBinding = bf.createBinding(importDialogModel, "analysisParameters", analysisParametersTree, "elements");
domainBinding.fireSourceChanged();
analysisParametersBinding.fireSourceChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations