use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class DataSourceDescriptorManager method createNewObject.
@Override
public DataSourceDescriptor createNewObject(DBRProgressMonitor monitor, DBECommandContext commandContext, DBPObject parent, Object copyFrom) {
if (copyFrom != null) {
DataSourceDescriptor dsTpl = (DataSourceDescriptor) copyFrom;
DBPDataSourceRegistry registry;
DBPDataSourceFolder folder = null;
if (parent instanceof DataSourceRegistry) {
registry = (DBPDataSourceRegistry) parent;
} else if (parent instanceof DBPDataSourceFolder) {
folder = (DBPDataSourceFolder) parent;
registry = folder.getDataSourceRegistry();
} else {
registry = dsTpl.getRegistry();
}
DataSourceDescriptor dataSource = new DataSourceDescriptor(registry, DataSourceDescriptor.generateNewId(dsTpl.getDriver()), dsTpl.getDriver(), new DBPConnectionConfiguration(dsTpl.getConnectionConfiguration()));
dataSource.copyFrom(dsTpl);
if (folder != null) {
dataSource.setFolder(folder);
}
// Generate new name
String origName = dsTpl.getName();
String newName = origName;
for (int i = 0; ; i++) {
if (registry.findDataSourceByName(newName) == null) {
break;
}
newName = origName + " " + (i + 1);
}
dataSource.setName(newName);
registry.addDataSource(dataSource);
} else {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
CreateConnectionDialog dialog = new CreateConnectionDialog(DBeaverUI.getActiveWorkbenchWindow(), new NewConnectionWizard());
dialog.open();
}
});
}
return null;
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class DataSourceRegistry method saveDataSource.
private void saveDataSource(XMLBuilder xml, DataSourceDescriptor dataSource) throws IOException {
clearSecuredPasswords(dataSource);
xml.startElement(RegistryConstants.TAG_DATA_SOURCE);
xml.addAttribute(RegistryConstants.ATTR_ID, dataSource.getId());
xml.addAttribute(RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
xml.addAttribute(RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
xml.addAttribute(RegistryConstants.ATTR_NAME, dataSource.getName());
xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
if (dataSource.isShowSystemObjects()) {
xml.addAttribute(RegistryConstants.ATTR_SHOW_SYSTEM_OBJECTS, dataSource.isShowSystemObjects());
}
if (dataSource.isShowUtilityObjects()) {
xml.addAttribute(RegistryConstants.ATTR_SHOW_UTIL_OBJECTS, dataSource.isShowUtilityObjects());
}
xml.addAttribute(RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
if (dataSource.getFolder() != null) {
xml.addAttribute(RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
}
final String lockPasswordHash = dataSource.getLockPasswordHash();
if (!CommonUtils.isEmpty(lockPasswordHash)) {
xml.addAttribute(RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
}
{
// Connection info
DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
xml.startElement(RegistryConstants.TAG_CONNECTION);
if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
xml.addAttribute(RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
}
if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
xml.addAttribute(RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
}
xml.addAttribute(RegistryConstants.ATTR_SERVER, CommonUtils.notEmpty(connectionInfo.getServerName()));
xml.addAttribute(RegistryConstants.ATTR_DATABASE, CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
xml.addAttribute(RegistryConstants.ATTR_URL, CommonUtils.notEmpty(connectionInfo.getUrl()));
saveSecuredCredentials(xml, dataSource, null, connectionInfo.getUserName(), dataSource.isSavePassword() ? connectionInfo.getUserPassword() : null);
if (!CommonUtils.isEmpty(connectionInfo.getClientHomeId())) {
xml.addAttribute(RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
}
if (connectionInfo.getConnectionType() != null) {
xml.addAttribute(RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
}
if (connectionInfo.getConnectionColor() != null) {
xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
}
// Save other
if (connectionInfo.getKeepAliveInterval() > 0) {
xml.addAttribute(RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
}
for (Map.Entry<String, String> entry : connectionInfo.getProperties().entrySet()) {
xml.startElement(RegistryConstants.TAG_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
xml.endElement();
}
for (Map.Entry<String, String> entry : connectionInfo.getProviderProperties().entrySet()) {
xml.startElement(RegistryConstants.TAG_PROVIDER_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
xml.endElement();
}
// Save events
for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
DBRShellCommand command = connectionInfo.getEvent(eventType);
xml.startElement(RegistryConstants.TAG_EVENT);
xml.addAttribute(RegistryConstants.ATTR_TYPE, eventType.name());
xml.addAttribute(RegistryConstants.ATTR_ENABLED, command.isEnabled());
xml.addAttribute(RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
xml.addAttribute(RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
xml.addAttribute(RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
xml.addText(command.getCommand());
xml.endElement();
}
// Save network handlers' configurations
for (DBWHandlerConfiguration configuration : connectionInfo.getDeclaredHandlers()) {
xml.startElement(RegistryConstants.TAG_NETWORK_HANDLER);
xml.addAttribute(RegistryConstants.ATTR_TYPE, configuration.getType().name());
xml.addAttribute(RegistryConstants.ATTR_ID, CommonUtils.notEmpty(configuration.getId()));
xml.addAttribute(RegistryConstants.ATTR_ENABLED, configuration.isEnabled());
xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, configuration.isSavePassword());
if (!CommonUtils.isEmpty(configuration.getUserName())) {
saveSecuredCredentials(xml, dataSource, "network/" + configuration.getId(), configuration.getUserName(), configuration.isSavePassword() ? configuration.getPassword() : null);
}
for (Map.Entry<String, String> entry : configuration.getProperties().entrySet()) {
if (CommonUtils.isEmpty(entry.getValue())) {
continue;
}
xml.startElement(RegistryConstants.TAG_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, entry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.notEmpty(entry.getValue()));
xml.endElement();
}
xml.endElement();
}
// Save bootstrap info
{
DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
if (bootstrap.hasData()) {
xml.startElement(RegistryConstants.TAG_BOOTSTRAP);
if (bootstrap.getDefaultAutoCommit() != null) {
xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
}
if (bootstrap.getDefaultTransactionIsolation() != null) {
xml.addAttribute(RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
}
if (!CommonUtils.isEmpty(bootstrap.getDefaultObjectName())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_OBJECT, bootstrap.getDefaultObjectName());
}
if (bootstrap.isIgnoreErrors()) {
xml.addAttribute(RegistryConstants.ATTR_IGNORE_ERRORS, true);
}
for (String query : bootstrap.getInitQueries()) {
xml.startElement(RegistryConstants.TAG_QUERY);
xml.addText(query);
xml.endElement();
}
xml.endElement();
}
}
xml.endElement();
}
{
// Filters
Collection<DataSourceDescriptor.FilterMapping> filterMappings = dataSource.getObjectFilters();
if (!CommonUtils.isEmpty(filterMappings)) {
xml.startElement(RegistryConstants.TAG_FILTERS);
for (DataSourceDescriptor.FilterMapping filter : filterMappings) {
if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
saveObjectFiler(xml, filter.typeName, null, filter.defaultFilter);
}
for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
if (!cf.getValue().isEmpty()) {
saveObjectFiler(xml, filter.typeName, cf.getKey(), cf.getValue());
}
}
}
xml.endElement();
}
}
// Virtual model
if (dataSource.getVirtualModel().hasValuableData()) {
xml.startElement(RegistryConstants.TAG_VIRTUAL_META_DATA);
dataSource.getVirtualModel().serialize(xml);
xml.endElement();
}
// Preferences
{
// Save only properties who are differs from default values
SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
for (String propName : prefStore.preferenceNames()) {
String propValue = prefStore.getString(propName);
String defValue = prefStore.getDefaultString(propName);
if (propValue == null || CommonUtils.equalObjects(propValue, defValue)) {
continue;
}
xml.startElement(RegistryConstants.TAG_CUSTOM_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, propName);
xml.addAttribute(RegistryConstants.ATTR_VALUE, propValue);
xml.endElement();
}
}
if (!CommonUtils.isEmpty(dataSource.getDescription())) {
xml.startElement(RegistryConstants.TAG_DESCRIPTION);
xml.addText(dataSource.getDescription());
xml.endElement();
}
xml.endElement();
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class OracleScriptExecuteWizard method getCommandLine.
@Override
protected List<String> getCommandLine(OracleDataSource arg) throws IOException {
List<String> cmd = new ArrayList<>();
fillProcessParameters(cmd, arg);
DBPConnectionConfiguration conInfo = getConnectionInfo();
String url;
if ("TNS".equals(conInfo.getProviderProperty(OracleConstants.PROP_CONNECTION_TYPE))) {
//$NON-NLS-1$
url = conInfo.getServerName();
} else {
boolean isSID = OracleConnectionType.SID.name().equals(conInfo.getProviderProperty(OracleConstants.PROP_SID_SERVICE));
String port = conInfo.getHostPort();
if (isSID) {
url = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=" + conInfo.getHostName() + ")(Port=" + port + "))(CONNECT_DATA=(SID=" + conInfo.getDatabaseName() + ")))";
} else {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
url = "//" + conInfo.getHostName() + (port != null ? ":" + port : "") + "/" + conInfo.getDatabaseName();
}
}
final String role = conInfo.getProviderProperty(OracleConstants.PROP_INTERNAL_LOGON);
if (role != null) {
url += (" AS " + role);
}
//$NON-NLS-1$ //$NON-NLS-2$
cmd.add(conInfo.getUserName() + "/" + conInfo.getUserPassword() + "@" + url);
/*
if (toolWizard.isVerbose()) {
cmd.add("-v");
}
cmd.add("-q");
cmd.add(toolWizard.getDatabaseObjects().getName());
*/
return cmd;
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class PostgreToolScript method getPostgreToolCommandLine.
public static <BASE_OBJECT extends DBSObject, PROCESS_ARG> List<String> getPostgreToolCommandLine(AbstractToolWizard<BASE_OBJECT, PROCESS_ARG> toolWizard, PROCESS_ARG arg) throws IOException {
java.util.List<String> cmd = new ArrayList<>();
toolWizard.fillProcessParameters(cmd, arg);
if (toolWizard.isVerbose()) {
cmd.add("--verbose");
}
DBPConnectionConfiguration connectionInfo = toolWizard.getConnectionInfo();
cmd.add("--host=" + connectionInfo.getHostName());
if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
cmd.add("--port=" + connectionInfo.getHostPort());
}
cmd.add("--username=" + toolWizard.getToolUserName());
return cmd;
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class OracleDataSource method initialize.
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
super.initialize(monitor);
DBPConnectionConfiguration connectionInfo = getContainer().getConnectionConfiguration();
{
String useRuleHintProp = connectionInfo.getProviderProperty(OracleConstants.PROP_USE_RULE_HINT);
if (useRuleHintProp != null) {
useRuleHint = CommonUtils.getBoolean(useRuleHintProp, false);
}
}
this.publicSchema = new OracleSchema(this, 1, OracleConstants.USER_PUBLIC);
{
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load data source meta info")) {
// Check DBA role
this.isAdmin = "YES".equals(JDBCUtils.queryString(session, "SELECT 'YES' FROM USER_ROLE_PRIVS WHERE GRANTED_ROLE='DBA'"));
this.isAdminVisible = isAdmin;
if (!isAdminVisible) {
String showAdmin = connectionInfo.getProviderProperty(OracleConstants.PROP_ALWAYS_SHOW_DBA);
if (showAdmin != null) {
isAdminVisible = CommonUtils.getBoolean(showAdmin, false);
}
}
// Get active schema
this.activeSchemaName = OracleUtils.getCurrentSchema(session);
if (this.activeSchemaName != null) {
if (this.activeSchemaName.isEmpty()) {
this.activeSchemaName = null;
}
}
} catch (SQLException e) {
//throw new DBException(e);
log.warn(e);
}
}
// Cache data types
this.dataTypeCache.getAllObjects(monitor, this);
}
Aggregations