Search in sources :

Example 56 with DBPDataSourceContainer

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

the class ConnectionPageNetworkHandler method setConnectionConfigProfile.

private void setConnectionConfigProfile(String profileName) {
    activeProfile = CommonUtils.isEmpty(profileName) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileName);
    DBPDataSourceContainer dataSource = site.getActiveDataSource();
    DBPConnectionConfiguration cfg = dataSource.getConnectionConfiguration();
    String oldProfileId = cfg.getConfigProfileName();
    saveSettings(site.getActiveDataSource());
    if (activeProfile != null) {
        cfg.setConfigProfile(activeProfile);
        handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
        if (handlerConfiguration == null) {
            handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
        }
    } else {
        cfg.setConfigProfile(null);
    }
    site.firePropertyChange(this, PROP_CONFIG_PROFILE, oldProfileId, activeProfile == null ? null : activeProfile.getProfileName());
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 57 with DBPDataSourceContainer

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

the class FolderDisconnectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection treeSelection = (IStructuredSelection) selection;
        @SuppressWarnings("rawtypes") Iterator it = treeSelection.iterator();
        while (it.hasNext()) {
            Object el = it.next();
            if (el instanceof DBNLocalFolder) {
                DBNLocalFolder localFolder = (DBNLocalFolder) el;
                localFolder.getNestedDataSources().forEach(ds -> {
                    final DBPDataSourceContainer dataSourceContainer = ds.getObject();
                    if (ds != null && ds.getObject().isConnected()) {
                        DataSourceHandler.disconnectDataSource(dataSourceContainer, null);
                    }
                });
            }
        }
    }
    return null;
}
Also used : DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 58 with DBPDataSourceContainer

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

the class ScriptsImportWizardPage method getImportData.

public ScriptsImportData getImportData() {
    DBPDataSourceContainer dataSourceContainer = null;
    final int dsIndex = scriptsDataSources.getSelectionIndex();
    if (dsIndex >= 0) {
        dataSourceContainer = (DBPDataSourceContainer) scriptsDataSources.getItem(dsIndex);
    }
    final String outputDir = directoryText.getText();
    DBWorkbench.getPlatform().getPreferenceStore().setValue(ScriptsExportWizardPage.PREF_SCRIPTS_EXPORT_OUT_DIR, outputDir);
    return new ScriptsImportData(new File(outputDir), extensionsText.getText(), overwriteCheck.getSelection(), (DBNResource) importRoot, dataSourceContainer);
}
Also used : DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) File(java.io.File)

Example 59 with DBPDataSourceContainer

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

the class ProjectExportWizard method exportProjects.

private void exportProjects(DBRProgressMonitor monitor, final ProjectExportData exportData) throws IOException, CoreException, InterruptedException {
    if (!exportData.getOutputFolder().exists()) {
        if (!exportData.getOutputFolder().mkdirs()) {
            // $NON-NLS-2$
            throw new IOException("Cannot create directory '" + exportData.getOutputFolder().getAbsolutePath() + "'");
        }
    }
    String archiveName = exportData.getArchiveFileName() + ExportConstants.ARCHIVE_FILE_EXT;
    File archiveFile = new File(exportData.getOutputFolder(), archiveName);
    FileOutputStream exportStream = new FileOutputStream(archiveFile);
    try {
        ByteArrayOutputStream metaBuffer = new ByteArrayOutputStream(10000);
        ZipOutputStream archiveStream = new ZipOutputStream(exportStream);
        // Start meta
        XMLBuilder meta = new XMLBuilder(metaBuffer, GeneralUtils.UTF8_ENCODING);
        meta.startElement(ExportConstants.TAG_ARCHIVE);
        meta.addAttribute(ExportConstants.ATTR_VERSION, ExportConstants.ARCHIVE_VERSION_CURRENT);
        exportData.initExport(DBWorkbench.getPlatform().getWorkspace(), meta, archiveStream);
        {
            // Export source info
            meta.startElement(ExportConstants.TAG_SOURCE);
            meta.addAttribute(ExportConstants.ATTR_TIME, System.currentTimeMillis());
            meta.addAttribute(ExportConstants.ATTR_ADDRESS, InetAddress.getLocalHost().getHostAddress());
            meta.addAttribute(ExportConstants.ATTR_HOST, InetAddress.getLocalHost().getHostName());
            meta.endElement();
        }
        Map<DBPProject, Integer> resCountMap = new HashMap<>();
        monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_collect_info, exportData.getProjectsToExport().size());
        for (DBPProject project : exportData.getProjectsToExport()) {
            // Add used drivers to export data
            final DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
            if (dataSourceRegistry != null) {
                for (DBPDataSourceContainer dataSourceDescriptor : dataSourceRegistry.getDataSources()) {
                    exportData.usedDrivers.add(dataSourceDescriptor.getDriver());
                }
            }
            resCountMap.put(project, getChildCount(exportData, project.getEclipseProject()));
            monitor.worked(1);
        }
        monitor.done();
        {
            // Export projects
            exportData.meta.startElement(ExportConstants.TAG_PROJECTS);
            for (DBPProject project : exportData.getProjectsToExport()) {
                monitor.beginTask(NLS.bind(CoreMessages.dialog_project_export_wizard_monitor_export_project, project.getName()), resCountMap.get(project));
                try {
                    exportProject(monitor, exportData, project.getEclipseProject());
                } finally {
                    monitor.done();
                }
            }
            exportData.meta.endElement();
        }
        if (exportData.isExportDrivers()) {
            // Export driver libraries
            Set<File> libFiles = new HashSet<>();
            Map<String, File> libPathMap = new HashMap<>();
            for (DBPDriver driver : exportData.usedDrivers) {
                for (DBPDriverLibrary fileDescriptor : driver.getDriverLibraries()) {
                    final File libraryFile = fileDescriptor.getLocalFile();
                    if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
                        libFiles.add(libraryFile);
                        libPathMap.put(fileDescriptor.getPath(), libraryFile);
                    }
                }
            }
            if (!libFiles.isEmpty()) {
                monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_export_libraries, libFiles.size());
                // $NON-NLS-1$
                final ZipEntry driversFolder = new ZipEntry(ExportConstants.DIR_DRIVERS + "/");
                // $NON-NLS-1$
                driversFolder.setComment("Database driver libraries");
                exportData.archiveStream.putNextEntry(driversFolder);
                exportData.archiveStream.closeEntry();
                exportData.meta.startElement(ExportConstants.TAG_LIBRARIES);
                Set<String> libFileNames = new HashSet<>();
                for (String libPath : libPathMap.keySet()) {
                    final File libFile = libPathMap.get(libPath);
                    // Check for file name duplications
                    final String libFileName = libFile.getName();
                    if (libFileNames.contains(libFileName)) {
                        // $NON-NLS-1$
                        log.warn("Duplicate driver library file name: " + libFileName);
                        continue;
                    }
                    libFileNames.add(libFileName);
                    monitor.subTask(libFileName);
                    exportData.meta.startElement(RegistryConstants.TAG_FILE);
                    exportData.meta.addAttribute(ExportConstants.ATTR_PATH, libPath);
                    // $NON-NLS-1$
                    exportData.meta.addAttribute(ExportConstants.ATTR_FILE, "drivers/" + libFileName);
                    exportData.meta.endElement();
                    // $NON-NLS-1$
                    final ZipEntry driverFile = new ZipEntry(ExportConstants.DIR_DRIVERS + "/" + libFileName);
                    // $NON-NLS-1$
                    driverFile.setComment("Driver library");
                    exportData.archiveStream.putNextEntry(driverFile);
                    try (InputStream is = new FileInputStream(libFile)) {
                        IOUtils.copyStream(is, exportData.archiveStream, COPY_BUFFER_SIZE);
                    }
                    exportData.archiveStream.closeEntry();
                    monitor.worked(1);
                }
                exportData.meta.endElement();
                monitor.done();
            }
        }
        // Add meta to archive
        {
            exportData.meta.endElement();
            exportData.meta.flush();
            archiveStream.putNextEntry(new ZipEntry(ExportConstants.META_FILENAME));
            archiveStream.write(metaBuffer.toByteArray());
            archiveStream.closeEntry();
        }
        // Finish archive creation
        archiveStream.finish();
    } finally {
        ContentUtils.close(exportStream);
    }
}
Also used : HashMap(java.util.HashMap) ZipEntry(java.util.zip.ZipEntry) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) ZipOutputStream(java.util.zip.ZipOutputStream) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) IFile(org.eclipse.core.resources.IFile) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) HashSet(java.util.HashSet)

Example 60 with DBPDataSourceContainer

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

the class DataSourceAutoCommitHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    boolean autoCommit = true;
    DBPTransactionIsolation isolation = null;
    DBCExecutionContext context = getExecutionContextFromPart(activeEditor);
    if (context != null && context.isConnected()) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                // Change auto-commit mode
                autoCommit = txnManager.isAutoCommit();
                isolation = txnManager.getTransactionIsolation();
            } catch (DBCException e) {
                log.warn(e);
            }
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        if (container != null) {
            autoCommit = container.isDefaultAutoCommit();
            isolation = container.getActiveTransactionsIsolation();
        }
    }
    element.setChecked(autoCommit);
    // Update command image
    element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
    String isolationName = isolation == null ? "?" : isolation.getTitle();
    String text = autoCommit ? NLS.bind(CoreMessages.action_menu_transaction_manualcommit_name, isolationName) : CoreMessages.action_menu_transaction_autocommit_name;
    element.setText(text);
    element.setTooltip(text);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

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