Search in sources :

Example 81 with DBPDataSource

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

the class DataSourceInvalidateHandler method showConnectionLostDialog.

public static void showConnectionLostDialog(final Shell shell, final String message, final DBException error) {
    //log.debug(message);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            // Display the dialog
            DBPDataSource dataSource = error.getDataSource();
            if (dataSource == null) {
                throw new IllegalStateException("No data source in error");
            }
            String title = "Connection with [" + dataSource.getContainer().getName() + "] lost";
            ConnectionRecoverDialog dialog = new ConnectionRecoverDialog(shell, title, message == null ? title : message, error);
            dialog.open();
        }
    };
    DBeaverUI.syncExec(runnable);
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 82 with DBPDataSource

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

the class GenerateMultiSQLDialog method getContextFromObjects.

protected static <T extends DBSObject> DBCExecutionContext getContextFromObjects(@NotNull Collection<T> objects, boolean meta) {
    Iterator<T> iterator = objects.iterator();
    if (iterator.hasNext()) {
        T object = iterator.next();
        DBPDataSource dataSource = object.getDataSource();
        return dataSource == null ? null : dataSource.getDefaultContext(meta);
    }
    return null;
}
Also used : SWT(org.eclipse.swt.SWT) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 83 with DBPDataSource

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

the class GenerateSQLDialog method getSQLText.

@Override
protected String getSQLText() {
    DBPDataSource dataSource = executionContext.getDataSource();
    if (dataSource instanceof SQLDataSource) {
        String lineSeparator = GeneralUtils.getDefaultLineSeparator();
        String scriptDelimiter = ((SQLDataSource) dataSource).getSQLDialect().getScriptDelimiter() + lineSeparator;
        String[] scriptLines = generateSQLScript();
        StringBuilder sql = new StringBuilder(scriptLines.length * 64);
        for (String line : scriptLines) {
            sql.append(line).append(scriptDelimiter);
        }
        // Cut last line separator
        if (sql.length() > lineSeparator.length()) {
            sql.setLength(sql.length() - lineSeparator.length());
        }
        return sql.toString();
    } else {
        return SQLUtils.generateCommentLine(dataSource, "Non-SQL data source");
    }
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) SQLDataSource(org.jkiss.dbeaver.model.sql.SQLDataSource)

Example 84 with DBPDataSource

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

the class DatabaseConsumerPageMapping method showDDL.

private void showDDL(DatabaseMappingContainer mapping) {
    final DatabaseConsumerSettings settings = getWizard().getPageSettings(DatabaseConsumerPageMapping.this, DatabaseConsumerSettings.class);
    final DBSObjectContainer container = settings.getContainer();
    if (container == null) {
        return;
    }
    DBPDataSource dataSource = container.getDataSource();
    try {
        final String ddl = DatabaseTransferConsumer.generateTargetTableDDL(VoidProgressMonitor.INSTANCE, dataSource, container, mapping);
        ViewSQLDialog dialog = new ViewSQLDialog(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), dataSource.getDefaultContext(true), "Target DDL", null, ddl);
        dialog.open();
    } catch (DBException e) {
        UIUtils.showErrorDialog(getShell(), "Target DDL", "Error generatiung target DDL", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ViewSQLDialog(org.jkiss.dbeaver.ui.dialogs.sql.ViewSQLDialog) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 85 with DBPDataSource

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

the class DatabaseConsumerPageMapping method createMappingsTree.

private void createMappingsTree(Composite composite) {
    // Mapping table
    mappingViewer = new TreeViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    mappingViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    mappingViewer.getTree().setLinesVisible(true);
    mappingViewer.getTree().setHeaderVisible(true);
    TreeViewerColumn columnSource = new TreeViewerColumn(mappingViewer, SWT.LEFT);
    columnSource.setLabelProvider(new MappingLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
            cell.setText(DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI));
            if (mapping.getIcon() != null) {
                cell.setImage(DBeaverIcons.getImage(mapping.getIcon()));
            }
            super.update(cell);
        }
    });
    columnSource.getColumn().setText("Source");
    TreeViewerColumn columnTarget = new TreeViewerColumn(mappingViewer, SWT.LEFT);
    columnTarget.setLabelProvider(new MappingLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
            cell.setText(mapping.getTargetName());
            if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
                cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
            } else {
                cell.setBackground(null);
            }
            super.update(cell);
        }
    });
    columnTarget.getColumn().setText("Target");
    columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {

        @Override
        protected CellEditor getCellEditor(Object element) {
            try {
                return createTargetEditor(element);
            } catch (DBException e) {
                setErrorMessage(e.getMessage());
                return null;
            }
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected Object getValue(Object element) {
            DatabaseMappingObject mapping = (DatabaseMappingObject) element;
            if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
                return mapping.getSource().getName();
            }
            if (mapping instanceof DatabaseMappingContainer) {
                if (mapping.getMappingType() == DatabaseMappingType.existing) {
                    return ((DatabaseMappingContainer) mapping).getTarget();
                }
                return mapping.getTargetName();
            } else {
                if (mapping.getMappingType() == DatabaseMappingType.existing) {
                    return ((DatabaseMappingAttribute) mapping).getTarget();
                }
                return mapping.getTargetName();
            }
        }

        @Override
        protected void setValue(final Object element, Object value) {
            try {
                final DatabaseConsumerSettings settings = getWizard().getPageSettings(DatabaseConsumerPageMapping.this, DatabaseConsumerSettings.class);
                String name = CommonUtils.toString(value);
                DBPDataSource dataSource = settings.getTargetDataSource((DatabaseMappingObject) element);
                if (!name.equals(DatabaseMappingAttribute.TARGET_NAME_SKIP) && !name.equals(TARGET_NAME_BROWSE) && dataSource != null) {
                    name = DBObjectNameCaseTransformer.transformName(dataSource, name);
                }
                setMappingTarget((DatabaseMappingObject) element, name);
                //mappingViewer.setSelection(mappingViewer.getSelection());
                mappingViewer.update(element, null);
                updatePageCompletion();
            } catch (DBException e) {
                UIUtils.showDatabaseError(getShell(), "Mapping error", "Error setting target table", e);
            }
        }
    });
    //TreeViewerEditor.create(mappingViewer, new TreeViewerFocusCellManager(), ColumnViewerEditor.TABBING_CYCLE_IN_ROW);
    TreeViewerColumn columnMapping = new TreeViewerColumn(mappingViewer, SWT.LEFT);
    columnMapping.setLabelProvider(new MappingLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
            cell.setText(mapping.getMappingType().name());
            super.update(cell);
        }
    });
    columnMapping.getColumn().setText("Mapping");
    columnMapping.setEditingSupport(new EditingSupport(mappingViewer) {

        @Override
        protected CellEditor getCellEditor(Object element) {
            List<String> mappingTypes = new ArrayList<>();
            mappingTypes.add(DatabaseMappingType.skip.name());
            DatabaseMappingObject mapping = (DatabaseMappingObject) element;
            if (mapping instanceof DatabaseMappingAttribute) {
                mappingTypes.add(((DatabaseMappingAttribute) mapping).getParent().getMappingType().name());
            } else {
                mappingTypes.add(mapping.getMappingType().name());
            }
            return new CustomComboBoxCellEditor(mappingViewer.getTree(), mappingTypes.toArray(new String[mappingTypes.size()]), SWT.DROP_DOWN | SWT.READ_ONLY);
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected Object getValue(Object element) {
            DatabaseMappingObject mapping = (DatabaseMappingObject) element;
            return mapping.getMappingType().name();
        }

        @Override
        protected void setValue(Object element, Object value) {
            try {
                DatabaseMappingObject mapping = (DatabaseMappingObject) element;
                DatabaseMappingType mappingType = DatabaseMappingType.valueOf(value.toString());
                if (mapping instanceof DatabaseMappingAttribute) {
                    ((DatabaseMappingAttribute) mapping).setMappingType(mappingType);
                } else {
                    ((DatabaseMappingContainer) mapping).refreshMappingType(getWizard().getContainer(), mappingType);
                }
                mappingViewer.refresh();
                setErrorMessage(null);
            } catch (DBException e) {
                setErrorMessage(e.getMessage());
            }
        }
    });
    mappingViewer.setContentProvider(new TreeContentProvider() {

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof DatabaseMappingContainer;
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof DatabaseMappingContainer) {
                return ((DatabaseMappingContainer) parentElement).getAttributeMappings(getContainer()).toArray();
            }
            return null;
        }
    });
}
Also used : DBException(org.jkiss.dbeaver.DBException) CustomComboBoxCellEditor(org.jkiss.dbeaver.ui.controls.CustomComboBoxCellEditor) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) CustomComboBoxCellEditor(org.jkiss.dbeaver.ui.controls.CustomComboBoxCellEditor) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)154 DBException (org.jkiss.dbeaver.DBException)57 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)28 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)15 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)14 ArrayList (java.util.ArrayList)12 GridData (org.eclipse.swt.layout.GridData)12 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)12 SQLException (java.sql.SQLException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)10 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)10 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)8 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)8 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)8 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)8 ISelection (org.eclipse.jface.viewers.ISelection)6