use of org.jkiss.dbeaver.model.DBPDataSourceFolder in project dbeaver by serge-rider.
the class NavigatorHandlerLocalFolderCreate method createFolder.
public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
if (newName == null) {
newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
}
if (CommonUtils.isEmpty(newName)) {
return false;
}
// Create folder and refresh databases root
// DS container will reload folders on refresh
final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
for (DBNDataSource node : nodes) {
node.setFolder(folder);
}
if (parentFolder != null && activePart instanceof NavigatorViewBase) {
final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
if (viewer != null) {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
viewer.expandToLevel(parentFolder, 1);
}
});
}
}
DBNModel.updateConfigAndRefreshDatabases(databases);
return true;
}
use of org.jkiss.dbeaver.model.DBPDataSourceFolder 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.DBPDataSourceFolder in project dbeaver by dbeaver.
the class DBeaverInstanceServer method openDatabaseConnection.
@Override
public void openDatabaseConnection(String connectionSpec) throws RemoteException {
log.debug("Open external database connection [" + connectionSpec + "]");
final IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
DataSourceRegistry dsRegistry = DBeaverCore.getInstance().getProjectRegistry().getActiveDataSourceRegistry();
String driverName = null, url = null, host = null, port = null, server = null, database = null, user = null, password = null;
boolean makeConnect = true, openConsole = false, savePassword = true;
Boolean autoCommit = null;
Map<String, String> conProperties = new HashMap<>();
DBPDataSourceFolder folder = null;
String dsName = null;
String[] conParams = connectionSpec.split("\\|");
for (String cp : conParams) {
int divPos = cp.indexOf('=');
if (divPos == -1) {
continue;
}
String paramName = cp.substring(0, divPos);
String paramValue = cp.substring(divPos + 1);
switch(paramName) {
case "driver":
driverName = paramValue;
break;
case "name":
dsName = paramValue;
break;
case "url":
url = paramValue;
break;
case "host":
host = paramValue;
break;
case "port":
port = paramValue;
break;
case "server":
server = paramValue;
break;
case "database":
database = paramValue;
break;
case "user":
user = paramValue;
break;
case "password":
password = paramValue;
break;
case "savePassword":
savePassword = CommonUtils.toBoolean(paramValue);
break;
case "connect":
makeConnect = CommonUtils.toBoolean(paramValue);
break;
case "openConsole":
openConsole = CommonUtils.toBoolean(paramValue);
break;
case "folder":
folder = dsRegistry.getFolder(paramValue);
break;
case "autoCommit":
autoCommit = CommonUtils.toBoolean(paramValue);
break;
default:
if (paramName.length() > 5 && paramName.startsWith("prop.")) {
paramName = paramName.substring(5);
conProperties.put(paramName, paramValue);
}
}
}
if (driverName == null) {
log.error("Driver name not specified");
return;
}
DriverDescriptor driver = DataSourceProviderRegistry.getInstance().findDriver(driverName);
if (driver == null) {
log.error("Driver '" + driverName + "' not found");
return;
}
if (dsName == null) {
dsName = "Ext: " + driver.getName();
if (database != null) {
dsName += " - " + database;
} else if (server != null) {
dsName += " - " + server;
}
}
DBPConnectionConfiguration connConfig = new DBPConnectionConfiguration();
connConfig.setUrl(url);
connConfig.setHostName(host);
connConfig.setHostPort(port);
connConfig.setServerName(server);
connConfig.setDatabaseName(database);
connConfig.setUserName(user);
connConfig.setUserPassword(password);
connConfig.setProperties(conProperties);
if (autoCommit != null) {
connConfig.getBootstrap().setDefaultAutoCommit(autoCommit);
}
final DataSourceDescriptor ds = new DataSourceDescriptor(dsRegistry, DataSourceDescriptor.generateNewId(driver), driver, connConfig);
ds.setName(dsName);
ds.setTemporary(true);
if (savePassword) {
ds.setSavePassword(true);
}
if (folder != null) {
ds.setFolder(folder);
}
// ds.set
dsRegistry.addDataSource(ds);
if (openConsole) {
DBeaverUI.syncExec(() -> {
OpenHandler.openSQLConsole(workbenchWindow, ds, ds.getName(), "");
workbenchWindow.getShell().forceActive();
});
} else if (makeConnect) {
DataSourceHandler.connectToDataSource(null, ds, null);
}
}
use of org.jkiss.dbeaver.model.DBPDataSourceFolder in project dbeaver by serge-rider.
the class NavigatorHandlerLocalFolderCreate method createFolder.
public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
if (newName == null) {
newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
}
if (CommonUtils.isEmpty(newName)) {
return false;
}
// Create folder and refresh databases root
// DS container will reload folders on refresh
final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
for (DBNDataSource node : nodes) {
node.setFolder(folder);
}
if (parentFolder != null && activePart instanceof NavigatorViewBase) {
final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
if (viewer != null) {
UIUtils.asyncExec(() -> viewer.expandToLevel(parentFolder, 1));
}
}
DBNModel.updateConfigAndRefreshDatabases(databases);
return true;
}
use of org.jkiss.dbeaver.model.DBPDataSourceFolder in project dbeaver by serge-rider.
the class SQLEditorUtils method createNewScript.
public static IFile createNewScript(DBPProject project, @Nullable IFolder folder, @NotNull SQLNavigatorContext navigatorContext) throws CoreException {
final IProgressMonitor progressMonitor = new NullProgressMonitor();
// Get folder
final IFolder scriptsRootFolder = getScriptsFolder(project, true);
IFolder scriptsFolder = folder;
if (scriptsFolder == null) {
scriptsFolder = scriptsRootFolder;
}
if (!scriptsFolder.exists()) {
scriptsFolder.create(true, true, new NullProgressMonitor());
}
if (CommonUtils.equalObjects(scriptsRootFolder, scriptsFolder)) {
// We are in the root folder
DBPDataSourceContainer dataSourceContainer = navigatorContext.getDataSourceContainer();
if (dataSourceContainer != null) {
if (dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.SCRIPT_CREATE_CONNECTION_FOLDERS)) {
// Create script folders according to connection folders
DBPDataSourceFolder conFolder = dataSourceContainer.getFolder();
if (conFolder != null) {
List<DBPDataSourceFolder> conFolders = new ArrayList<>();
for (DBPDataSourceFolder f = conFolder; f != null; f = f.getParent()) {
conFolders.add(0, f);
}
for (DBPDataSourceFolder f : conFolders) {
IFolder dbFolder = scriptsFolder.getFolder(CommonUtils.escapeFileName(f.getName()));
if (dbFolder != null) {
if (!dbFolder.exists()) {
dbFolder.create(true, true, progressMonitor);
}
scriptsFolder = dbFolder;
}
}
}
}
if (dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.SCRIPT_AUTO_FOLDERS)) {
// Create special folder for connection
IFolder dbFolder = scriptsFolder.getFolder(CommonUtils.escapeFileName(dataSourceContainer.getName()));
if (dbFolder != null) {
if (!dbFolder.exists()) {
dbFolder.create(true, true, progressMonitor);
}
scriptsFolder = dbFolder;
}
}
}
}
// Make new script file
IFile tempFile = ContentUtils.getUniqueFile(scriptsFolder, "Script", SCRIPT_FILE_EXTENSION);
tempFile.create(new ByteArrayInputStream(new byte[] {}), true, progressMonitor);
// Save ds container reference
if (navigatorContext.getDataSourceContainer() != null) {
EditorUtils.setFileDataSource(tempFile, navigatorContext);
}
return tempFile;
}
Aggregations