Search in sources :

Example 51 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class PostgreFDWConfigWizardPageConfig method refreshFDWProperties.

private void refreshFDWProperties() {
    {
        // Fill options
        DBPDataSourceContainer targetDataSource = getWizard().getSelectedDataSource();
        PostgreFDWConfigWizard.FDWInfo selectedFDW = getWizard().getSelectedFDW();
        PropertySourceCustom propertySource = getWizard().getFdwPropertySource();
        propertySource.setDefValueResolver(targetDataSource.getVariablesResolver(false));
        propertySource.removeAll();
        if (selectedFDW != null && selectedFDW.fdwDescriptor != null) {
            propertySource.addProperties(selectedFDW.fdwDescriptor.getProperties());
        } else if (selectedFDW != null) {
            // Add some default props
            propertySource.addProperty(new PropertyDescriptor(null, "host", "host", "Remote database host", false, String.class, "${host}", null));
            propertySource.addProperty(new PropertyDescriptor(null, "port", "port", "Remote database port", false, String.class, "${port}", null));
            propertySource.addProperty(new PropertyDescriptor(null, "dbname", "dbname", "Remote database name", false, String.class, "${database}", null));
        }
        propsEditor.loadProperties(propertySource);
    }
}
Also used : PropertySourceCustom(org.jkiss.dbeaver.runtime.properties.PropertySourceCustom) PropertyDescriptor(org.jkiss.dbeaver.model.impl.PropertyDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 52 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class KeepAliveListenerJob method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    if (platform.isShuttingDown()) {
        return Status.OK_STATUS;
    }
    if (lastPingTime > 0 && System.currentTimeMillis() - lastPingTime > SYSTEM_SUSPEND_INTERVAL) {
        log.debug("System suspend detected! Reinitialize all remote connections.");
    }
    lastPingTime = System.currentTimeMillis();
    final DBPWorkspace workspace = platform.getWorkspace();
    for (DBPProject project : workspace.getProjects()) {
        if (project.isOpen() && project.isRegistryLoaded()) {
            DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
            for (DBPDataSourceContainer ds : dataSourceRegistry.getDataSources()) {
                checkDataSourceAlive(ds);
            }
        }
    }
    if (!platform.isShuttingDown()) {
        scheduleMonitor();
    }
    return Status.OK_STATUS;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 53 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DashboardOpenTool method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    // Just open dashboard view
    if (objects.isEmpty()) {
        return;
    }
    DBSObject object = objects.iterator().next();
    DBPDataSourceContainer dataSourceContainer = object.getDataSource().getContainer();
    if (dataSourceContainer == null) {
        return;
    }
    DashboardView.openView(window, dataSourceContainer);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 54 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class HandlerDashboardOpen method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    DBPDataSourceContainer dataSourceContainer = getActiveDataSourceContainer(event, false);
    if (dataSourceContainer == null) {
        dataSourceContainer = getActiveDataSourceContainer(event, true);
    }
    if (dataSourceContainer == null) {
        DBWorkbench.getPlatformUI().showError(UIDashboardMessages.error_dashboard_view_no_connection_title, UIDashboardMessages.error_dashboard_view_no_connection_msg);
        return null;
    }
    DashboardView.openView(workbenchWindow, dataSourceContainer);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 55 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer 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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) ArrayList(java.util.ArrayList) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)230 DBException (org.jkiss.dbeaver.DBException)32 ArrayList (java.util.ArrayList)31 IFile (org.eclipse.core.resources.IFile)30 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)27 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)22 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)19 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)18 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)18 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 GridData (org.eclipse.swt.layout.GridData)16 IEditorPart (org.eclipse.ui.IEditorPart)16 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)16 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13