Search in sources :

Example 6 with DBException

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

the class ConnectionPageNetwork method activatePage.

@Override
public void activatePage() {
    DataSourceDescriptor dataSource = wizard.getPageSettings().getActiveDataSource();
    DriverDescriptor driver = wizard.getSelectedDriver();
    NetworkHandlerRegistry registry = NetworkHandlerRegistry.getInstance();
    if (prevDataSource == null || prevDataSource != dataSource) {
        for (TabItem item : handlersFolder.getItems()) {
            item.dispose();
        }
        for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
            try {
                createHandlerTab(descriptor);
            } catch (DBException e) {
                log.warn(e);
            }
        }
        prevDataSource = dataSource;
        handlersFolder.layout();
        for (TabItem item : handlersFolder.getItems()) {
            ((Composite) item.getControl()).layout();
        }
    }
    TabItem selectItem = null;
    for (NetworkHandlerDescriptor descriptor : registry.getDescriptors(dataSource)) {
        DBWHandlerConfiguration configuration = dataSource.getConnectionConfiguration().getHandler(descriptor.getId());
        if (configuration == null) {
            configuration = new DBWHandlerConfiguration(descriptor, driver);
        }
        HandlerBlock handlerBlock = configurations.get(descriptor);
        if (handlerBlock == null) {
            continue;
        }
        //handlerBlock.useHandlerCheck.setSelection(configuration.isEnabled());
        if (selectItem == null && configuration.isEnabled()) {
            selectItem = handlerBlock.tabItem;
        }
        if (!handlerBlock.loadedConfigs.containsKey(dataSource.getId())) {
            handlerBlock.configurator.loadSettings(configuration);
            handlerBlock.loadedConfigs.put(dataSource.getId(), configuration);
        }
        enableHandlerContent(descriptor);
    }
    if (selectItem != null) {
        handlersFolder.setSelection(selectItem);
    } else {
        handlersFolder.setSelection(0);
    }
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) DBException(org.jkiss.dbeaver.DBException) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) Composite(org.eclipse.swt.widgets.Composite) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) NetworkHandlerRegistry(org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 7 with DBException

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

the class DefaultValueViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    Label label = new Label(dialogGroup, SWT.NONE);
    label.setText(CoreMessages.dialog_data_label_value);
    Composite editorPlaceholder = UIUtils.createPlaceholder(dialogGroup, 1);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumHeight = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + 4;
    editorPlaceholder.setLayoutData(gd);
    editorPlaceholder.setLayout(new FillLayout());
    try {
        panelEditor = createPanelEditor(editorPlaceholder);
        if (panelEditor == null) {
            return dialogGroup;
        }
        panelEditor.primeEditorValue(getValueController().getValue());
    } catch (DBException e) {
        log.error(e);
        return dialogGroup;
    }
    ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
    if (referenceValueEditor.isReferenceValue()) {
        referenceValueEditor.createEditorSelector(dialogGroup);
    }
    return dialogGroup;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)

Example 8 with DBException

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

the class GotoObjectDialog method fillContentProvider.

@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, context.getDataSource());
    if (structureAssistant == null) {
        return;
    }
    String nameMask = ((ObjectFilter) itemsFilter).getNameMask();
    DBRProgressMonitor monitor = RuntimeUtils.makeMonitor(progressMonitor);
    try {
        monitor.beginTask("Search for '" + nameMask + "'", 100);
        List<DBSObjectType> typesToSearch = new ArrayList<>();
        for (DBSObjectType type : structureAssistant.getSupportedObjectTypes()) {
            Class<? extends DBSObject> typeClass = type.getTypeClass();
            if (DBSEntityElement.class.isAssignableFrom(typeClass)) {
                // Skipp attributes (columns), methods, etc
                continue;
            }
            typesToSearch.add(type);
        }
        Collection<DBSObjectReference> result = structureAssistant.findObjectsByMask(monitor, container, typesToSearch.toArray(new DBSObjectType[typesToSearch.size()]), nameMask, false, true, 1000);
        DBPDataSourceContainer dsContainer = context.getDataSource().getContainer();
        for (DBSObjectReference ref : result) {
            DBSObjectFilter filter = dsContainer.getObjectFilter(ref.getObjectClass(), ref.getContainer(), true);
            if (filter == null || !filter.isEnabled() || filter.matches(ref.getName())) {
                contentProvider.add(ref, itemsFilter);
            }
        }
    } catch (DBException e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    } finally {
        monitor.done();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) CoreException(org.eclipse.core.runtime.CoreException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 9 with DBException

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

the class ContentValueManager method contributeContentActions.

public static void contributeContentActions(@NotNull IContributionManager manager, @NotNull final IValueController controller, final IValueEditor activeEditor) throws DBCException {
    if (controller.getValue() instanceof DBDContent && !((DBDContent) controller.getValue()).isNull()) {
        manager.add(new Action(CoreMessages.model_jdbc_save_to_file_, DBeaverIcons.getImageDescriptor(UIIcon.SAVE_AS)) {

            @Override
            public void run() {
                DialogUtils.saveToFile(controller);
            }
        });
    }
    manager.add(new Action(CoreMessages.model_jdbc_load_from_file_, DBeaverIcons.getImageDescriptor(UIIcon.LOAD)) {

        @Override
        public void run() {
            if (DialogUtils.loadFromFile(controller)) {
                try {
                    activeEditor.primeEditorValue(controller.getValue());
                } catch (DBException e) {
                    UIUtils.showErrorDialog(null, "Load from file", "Error loading contents from file", e);
                }
            }
        }
    });
    manager.add(new Separator());
}
Also used : DBException(org.jkiss.dbeaver.DBException) Action(org.eclipse.jface.action.Action) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) Separator(org.eclipse.jface.action.Separator)

Example 10 with DBException

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

the class BinaryPanelEditor method primeEditorValue.

@Override
public void primeEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull HexEditControl control, @NotNull DBDContent value) throws DBException {
    monitor.beginTask("Prime content value", 1);
    try {
        DBDContentStorage data = value.getContents(monitor);
        String charset = null;
        monitor.subTask("Read binary value");
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        if (data != null) {
            try (InputStream contentStream = data.getContentStream()) {
                ContentUtils.copyStreams(contentStream, -1, buffer, monitor);
            }
            charset = data.getCharset();
        } else {
            charset = DBValueFormatting.getDefaultBinaryFileEncoding(value.getDataSource());
        }
        control.setContent(buffer.toByteArray(), charset);
    } catch (IOException e) {
        throw new DBException("Error reading stream value", e);
    } finally {
        monitor.done();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage)

Aggregations

DBException (org.jkiss.dbeaver.DBException)232 SQLException (java.sql.SQLException)58 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)51 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)50 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)43 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)42 ArrayList (java.util.ArrayList)37 InvocationTargetException (java.lang.reflect.InvocationTargetException)23 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)16 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)14 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)13 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)13 GridData (org.eclipse.swt.layout.GridData)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)12 CoreException (org.eclipse.core.runtime.CoreException)11 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 IStatus (org.eclipse.core.runtime.IStatus)9 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)8 XMLException (org.jkiss.utils.xml.XMLException)8