Search in sources :

Example 56 with DBRProgressMonitor

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

the class DataSourceHandler method checkAndCloseActiveTransaction.

public static boolean checkAndCloseActiveTransaction(DBCExecutionContext[] contexts) {
    if (contexts == null) {
        return true;
    }
    Boolean commitTxn = null;
    for (final DBCExecutionContext context : contexts) {
        // First rollback active transaction
        try {
            if (QMUtils.isTransactionActive(context)) {
                if (commitTxn == null) {
                    // Ask for confirmation
                    TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer(context.getDataSource().getContainer().getName());
                    DBeaverUI.syncExec(closeConfirmer);
                    switch(closeConfirmer.result) {
                        case IDialogConstants.YES_ID:
                            commitTxn = true;
                            break;
                        case IDialogConstants.NO_ID:
                            commitTxn = false;
                            break;
                        default:
                            return false;
                    }
                }
                final boolean commit = commitTxn;
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        closeActiveTransaction(monitor, context, commit);
                    }
                });
            }
        } catch (Throwable e) {
            log.warn("Can't rollback active transaction before disconnect", e);
        }
    }
    return true;
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 57 with DBRProgressMonitor

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

the class DataTransferWizard method performFinish.

@Override
public boolean performFinish() {
    // Save settings
    getSettings().saveTo(getDialogSettings());
    // Start consumers
    try {
        DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (DataTransferPipe pipe : settings.getDataPipes()) {
                        pipe.getConsumer().startTransfer(monitor);
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(getShell(), "Transfer init failed", "Can't start data transfer", e.getTargetException());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    // Run export jobs
    executeJobs();
    // Done
    return true;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 58 with DBRProgressMonitor

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

the class ContentEditorInput method updateContentFromFile.

public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
    if (valueController.isReadOnly()) {
        throw new DBCException("Can't update read-only value");
    }
    DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
    DBDContent content = getContent();
    DBDContentStorage storage = content.getContents(localMonitor);
    if (storage instanceof DBDContentStorageLocal) {
        // Nothing to update - we user content's storage
        contentDetached = true;
    } else if (storage instanceof DBDContentCached) {
        // Create new storage and pass it to content
        try (FileInputStream is = new FileInputStream(contentFile)) {
            if (storage instanceof StringContentStorage) {
                try (Reader reader = new InputStreamReader(is, fileCharset)) {
                    storage = StringContentStorage.createFromReader(reader);
                }
            } else {
                storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
            }
            //StringContentStorage.
            contentDetached = content.updateContents(localMonitor, storage);
        } catch (IOException e) {
            throw new DBException("Error reading content from file", e);
        }
    } else {
        // Create new storage and pass it to content
        storage = new TemporaryContentStorage(DBeaverCore.getInstance(), contentFile, fileCharset);
        contentDetached = content.updateContents(localMonitor, storage);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage)

Example 59 with DBRProgressMonitor

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

the class AttributeEditPage method createPageContents.

@Override
protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);
    //$NON-NLS-2$
    final Text nameText = UIUtils.createLabelText(propsGroup, "Name", attribute.getName());
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
                ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
        }
    });
    UIUtils.createControlLabel(propsGroup, "Properties").setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute) {

        @Override
        public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
            super.setPropertyValue(monitor, editableValue, prop, newValue);
        /*
                if (prop.getId().equals("dataType")) {
                    newValue = getPropertyValue(monitor, editableValue, prop);
                    if (newValue instanceof DBSDataType) {
                        DBPPropertyDescriptor lengthProp = getProperty("maxLength");
                        if (lengthProp instanceof ObjectPropertyDescriptor) {
                            DBPDataKind dataKind = ((DBSDataType) newValue).getDataKind();
                            if (dataKind == DBPDataKind.STRING) {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, 100);
                            } else {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, null);
                            }
                            propertyViewer.update(lengthProp, null);
                        }
                    }
                }
*/
        }
    };
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
        if (prop instanceof ObjectPropertyDescriptor) {
            if (((ObjectPropertyDescriptor) prop).isEditPossible() && !((ObjectPropertyDescriptor) prop).isNameProperty()) {
                continue;
            }
        }
        pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);
    return propsGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) GridData(org.eclipse.swt.layout.GridData) PropertySourceAbstract(org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Nullable(org.jkiss.code.Nullable)

Example 60 with DBRProgressMonitor

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

the class AttributesSelectorPage method fillAttributes.

protected void fillAttributes(final DBSEntity entity) {
    // Collect attributes
    final List<DBSEntityAttribute> attributes = new ArrayList<>();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
                        if (!DBUtils.isHiddenObject(attr)) {
                            attributes.add(attr);
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(getShell(), CoreMessages.dialog_struct_columns_select_error_load_columns_title, CoreMessages.dialog_struct_columns_select_error_load_columns_message, e.getTargetException());
    } catch (InterruptedException e) {
    // do nothing
    }
    for (DBSEntityAttribute attribute : attributes) {
        TableItem columnItem = new TableItem(columnsTable, SWT.NONE);
        AttributeInfo col = new AttributeInfo(attribute);
        this.attributes.add(col);
        DBNDatabaseNode attributeNode = DBeaverCore.getInstance().getNavigatorModel().findNode(attribute);
        if (attributeNode != null) {
            columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon()));
        }
        fillAttributeColumns(attribute, col, columnItem);
        columnItem.setData(col);
        if (isColumnSelected(attribute)) {
            columnItem.setChecked(true);
            handleItemSelect(columnItem, false);
        }
    }
    UIUtils.packColumns(columnsTable);
    updateToggleButton();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)79 DBException (org.jkiss.dbeaver.DBException)45 InvocationTargetException (java.lang.reflect.InvocationTargetException)36 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)30 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 ArrayList (java.util.ArrayList)8 IStatus (org.eclipse.core.runtime.IStatus)8 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 List (java.util.List)5 NotNull (org.jkiss.code.NotNull)5 File (java.io.File)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4