use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class AnalysisImportDialogController method setRelationalConnections.
@Bindable
public void setRelationalConnections(List<IDatabaseConnection> connections) {
List<String> names = new ArrayList<String>();
for (IDatabaseConnection conn : connections) {
names.add(conn.getName());
}
firePropertyChange("connectionNames", null, names);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class AnalysisImportDialogController method reloadConnections.
private void reloadConnections() {
String cacheBuster = "?ts=" + new java.util.Date().getTime();
RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
listConnectionBuilder.setHeader("Content-Type", "application/json");
listConnectionBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
listConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
exception.printStackTrace();
MessageHandler.getInstance().showErrorDialog(exception.getMessage());
}
@Override
public void onResponseReceived(Request request, Response response) {
AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
List<IDatabaseConnection> databaseConnections = bean.as().getDatabaseConnections();
List<IDatabaseConnection> standardDatabaseConnections = new ArrayList();
// take anything except connections where STANDARD_CONNECTION == false
for (IDatabaseConnection databaseConnection : databaseConnections) {
if ((databaseConnection.getAttributes() == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
standardDatabaseConnections.add(databaseConnection);
}
}
importDialogModel.setConnectionList(standardDatabaseConnections);
}
});
} catch (RequestException e) {
MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class AutobeanUtilities method connectionBeanToImpl.
/**
* @param connectionBean - IDatabaseConnection backed by a Autobean implementation
* @return an IDatabaseConnection that is backed by a concrete DatabaseConnection
* <p/>
* This method will take an autobean implementation of IDatabaseConnection and return a DatabaseConnection
*/
public static IDatabaseConnection connectionBeanToImpl(IDatabaseConnection connectionBean) {
DatabaseConnection connectionImpl = new DatabaseConnection();
connectionImpl.setAccessType(connectionBean.getAccessType());
if (connectionImpl.getAccessType() != null) {
connectionImpl.setAccessTypeValue(connectionImpl.getAccessType().toString());
}
connectionImpl.setAttributes(mapBeanToImpl(connectionBean.getAttributes()));
connectionImpl.setConnectionPoolingProperties(mapBeanToImpl(connectionBean.getConnectionPoolingProperties()));
connectionImpl.setConnectSql(connectionBean.getConnectSql());
connectionImpl.setDatabaseName(connectionBean.getDatabaseName());
connectionImpl.setDatabasePort(connectionBean.getDatabasePort());
connectionImpl.setDatabaseType(dbTypeBeanToImpl(connectionBean.getDatabaseType()));
connectionImpl.setDataTablespace(connectionBean.getDataTablespace());
connectionImpl.setForcingIdentifiersToLowerCase(connectionBean.isForcingIdentifiersToLowerCase());
connectionImpl.setForcingIdentifiersToUpperCase(connectionBean.isForcingIdentifiersToUpperCase());
connectionImpl.setHostname(connectionBean.getHostname());
connectionImpl.setId(connectionBean.getId());
connectionImpl.setIndexTablespace(connectionBean.getIndexTablespace());
connectionImpl.setInformixServername(connectionBean.getInformixServername());
connectionImpl.setInitialPoolSize(connectionBean.getInitialPoolSize());
connectionImpl.setMaximumPoolSize(connectionBean.getMaximumPoolSize());
connectionImpl.setName(connectionBean.getName());
connectionImpl.setPartitioned(connectionBean.isPartitioned());
connectionImpl.setPartitioningInformation(connectionBean.getPartitioningInformation());
connectionImpl.setPassword(connectionBean.getPassword());
connectionImpl.setDatabasePort(connectionBean.getDatabasePort());
connectionImpl.setQuoteAllFields(connectionBean.isQuoteAllFields());
connectionImpl.setSQLServerInstance(connectionBean.getSQLServerInstance());
connectionImpl.setStreamingResults(connectionBean.isStreamingResults());
connectionImpl.setUsername(connectionBean.getUsername());
connectionImpl.setUsingConnectionPool(connectionBean.isUsingConnectionPool());
connectionImpl.setUsingDoubleDecimalAsSchemaTableSeparator(connectionBean.isUsingDoubleDecimalAsSchemaTableSeparator());
connectionImpl.setExtraOptions(mapBeanToImpl(connectionBean.getExtraOptions()));
connectionImpl.setExtraOptionsOrder(mapBeanToImpl(connectionBean.getExtraOptionsOrder()));
return connectionImpl;
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DatasourceInMemoryServiceHelper method getDataSourceConnection.
/**
* NOTE: caller is responsible for closing connection
*
* @param connectionName
* @return
* @throws DatasourceServiceException
*/
public static java.sql.Connection getDataSourceConnection(String connectionName) throws DatasourceServiceException {
IDatabaseConnection connection = null;
try {
ConnectionServiceImpl service = new ConnectionServiceImpl();
connection = service.getConnectionByName(connectionName);
} catch (ConnectionServiceException e1) {
// $NON-NLS-1$
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0008_CONNECTION_SERVICE_EXCEPTION"));
// we should return null because we do not able to use connection
return null;
}
java.sql.Connection conn = null;
DatabaseDialectService dialectService = new DatabaseDialectService();
IDatabaseDialect dialect = dialectService.getDialect(connection);
String driverClass = null;
if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
} else {
driverClass = dialect.getNativeDriver();
}
if (StringUtils.isEmpty(driverClass)) {
// $NON-NLS-1$
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0001_CONNECTION_ATTEMPT_FAILED"));
throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
"DatasourceInMemoryServiceHelper.ERROR_0001_CONNECTION_ATTEMPT_FAILED"));
}
Class<?> driverC = null;
try {
driverC = Class.forName(driverClass);
} catch (ClassNotFoundException e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", driverClass), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH"), // $NON-NLS-1$
e);
}
if (!Driver.class.isAssignableFrom(driverC)) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", // $NON-NLS-1$
driverClass));
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", // $NON-NLS-1$
driverClass));
}
Driver driver = null;
try {
driver = driverC.asSubclass(Driver.class).newInstance();
} catch (InstantiationException e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER", driverClass), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER"), // $NON-NLS-1$
e);
} catch (IllegalAccessException e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER", driverClass), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER"), // $NON-NLS-1$
e);
}
try {
DriverManager.registerDriver(driver);
conn = DriverManager.getConnection(dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword());
return conn;
} catch (SQLException e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), // $NON-NLS-1$
e);
} catch (DatabaseDialectException e) {
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), // $NON-NLS-1$
e);
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionController method handleDialogAccept.
@Bindable
public void handleDialogAccept() {
// first, test the connection
RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
testConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
saveConnectionConfirmationDialog.show();
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
// test is ok, now check if we are renaming
renameCheck();
} else {
// confirm if we should continu saving this invalid connection.
saveConnectionConfirmationDialog.show();
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
Aggregations