Search in sources :

Example 1 with DBCSession

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

the class SpreadsheetPresentation method pasteFromClipboard.

@Override
public void pasteFromClipboard(boolean extended) {
    try {
        if (extended) {
            DBPDataSource dataSource = getDataSource();
            String strValue;
            Clipboard clipboard = new Clipboard(Display.getCurrent());
            try {
                strValue = (String) clipboard.getContents(TextTransfer.getInstance());
            } finally {
                clipboard.dispose();
            }
            if (CommonUtils.isEmpty(strValue)) {
                return;
            }
            GridPos focusPos = spreadsheet.getFocusPos();
            int rowNum = focusPos.row;
            if (rowNum < 0 || rowNum >= spreadsheet.getItemCount()) {
                return;
            }
            try (DBCSession session = DBUtils.openUtilSession(VoidProgressMonitor.INSTANCE, dataSource, "Advanced paste")) {
                for (String[] line : parseGridLines(strValue)) {
                    int colNum = focusPos.col;
                    Object rowElement = spreadsheet.getRowElement(rowNum);
                    for (String value : line) {
                        if (colNum >= spreadsheet.getColumnCount()) {
                            break;
                        }
                        Object colElement = spreadsheet.getColumnElement(colNum);
                        final DBDAttributeBinding attr = (DBDAttributeBinding) (controller.isRecordMode() ? rowElement : colElement);
                        final ResultSetRow row = (ResultSetRow) (controller.isRecordMode() ? colElement : rowElement);
                        if (controller.isAttributeReadOnly(attr)) {
                            continue;
                        }
                        Object newValue = attr.getValueHandler().getValueFromObject(session, attr.getAttribute(), value, true);
                        new SpreadsheetValueController(controller, attr, row, IValueController.EditType.NONE, null).updateValue(newValue, true);
                        colNum++;
                    }
                    rowNum++;
                    if (rowNum >= spreadsheet.getItemCount()) {
                        break;
                    }
                }
            }
        } else {
            DBDAttributeBinding attr = getFocusAttribute();
            ResultSetRow row = controller.getCurrentRow();
            if (attr == null || row == null) {
                return;
            }
            if (controller.isAttributeReadOnly(attr)) {
                // No inline editors for readonly columns
                return;
            }
            Object newValue = ResultSetUtils.getAttributeValueFromClipboard(attr);
            if (newValue == null) {
                return;
            }
            new SpreadsheetValueController(controller, attr, row, IValueController.EditType.NONE, null).updateValue(newValue, true);
        }
    } catch (Exception e) {
        UIUtils.showErrorDialog(spreadsheet.getShell(), "Cannot replace cell value", null, e);
    }
}
Also used : GridPos(org.jkiss.dbeaver.ui.controls.lightgrid.GridPos) Clipboard(org.eclipse.swt.dnd.Clipboard) DBException(org.jkiss.dbeaver.DBException) MalformedURLException(java.net.MalformedURLException) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 2 with DBCSession

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

the class MySQLCommandChangeUser method getPersistActions.

@Override
public DBEPersistAction[] getPersistActions() {
    List<DBEPersistAction> actions = new ArrayList<>();
    boolean newUser = !getObject().isPersisted();
    if (newUser) {
        actions.add(new //$NON-NLS-2$
        SQLDatabasePersistAction(//$NON-NLS-2$
        MySQLMessages.edit_command_change_user_action_create_new_user, //$NON-NLS-2$
        "CREATE USER " + getObject().getFullName()) {

            @Override
            public void handleExecute(DBCSession session, Throwable error) {
                if (error == null) {
                    getObject().setPersisted(true);
                }
            }
        });
    }
    StringBuilder script = new StringBuilder();
    boolean hasSet;
    final MySQLDataSource dataSource = getObject().getDataSource();
    if (!dataSource.isMariaDB() && dataSource.isServerVersionAtLeast(5, 7)) {
        hasSet = generateAlterScript(script);
    } else {
        hasSet = generateUpdateScript(script);
    }
    if (hasSet) {
        actions.add(new SQLDatabasePersistAction(MySQLMessages.edit_command_change_user_action_update_user_record, script.toString()));
    }
    return actions.toArray(new DBEPersistAction[actions.size()]);
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ArrayList(java.util.ArrayList) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 3 with DBCSession

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

the class ResultSetJobDataRead method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    error = null;
    final ProgressLoaderVisualizer<Object> visualizer = new ProgressLoaderVisualizer<>(this, progressControl);
    progressMonitor = visualizer.overwriteMonitor(monitor);
    DBCExecutionPurpose purpose = DBCExecutionPurpose.USER;
    if (dataFilter != null && dataFilter.hasFilters()) {
        purpose = DBCExecutionPurpose.USER_FILTERED;
    }
    new PumpVisualizer(visualizer).schedule(PROGRESS_VISUALIZE_PERIOD * 2);
    try (DBCSession session = getExecutionContext().openSession(progressMonitor, purpose, NLS.bind(CoreMessages.controls_rs_pump_job_context_name, dataContainer.toString()))) {
        statistics = dataContainer.readData(this, session, controller.getDataReceiver(), dataFilter, offset, maxRows, DBSDataContainer.FLAG_READ_PSEUDO);
    } catch (DBException e) {
        error = e;
    } finally {
        visualizer.completeLoading(null);
    }
    return Status.OK_STATUS;
}
Also used : DBException(org.jkiss.dbeaver.DBException) ProgressLoaderVisualizer(org.jkiss.dbeaver.ui.controls.ProgressLoaderVisualizer) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 4 with DBCSession

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

the class TextViewDialog method extractEditorValue.

@Override
public Object extractEditorValue() {
    Object prevValue = getValueController().getValue();
    Object rawValue;
    if (prevValue instanceof DBDContent) {
        if (ContentUtils.isTextContent((DBDContent) prevValue)) {
            rawValue = isTextEditorActive() ? textEdit.getText() : getBinaryString();
        } else {
            rawValue = isTextEditorActive() ? GeneralUtils.convertToBytes(textEdit.getText()) : getBinaryContent();
        }
    } else {
        if (isTextEditorActive()) {
            rawValue = textEdit.getText();
        } else {
            rawValue = getBinaryString();
        }
    }
    try (DBCSession session = getValueController().getExecutionContext().openSession(VoidProgressMonitor.INSTANCE, DBCExecutionPurpose.UTIL, "Make text value from editor")) {
        return getValueController().getValueHandler().getValueFromObject(session, getValueController().getValueType(), rawValue, false);
    } catch (Exception e) {
        UIUtils.showErrorDialog(getShell(), "Extract editor value", "Can't extract editor value", e);
        return null;
    }
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 5 with DBCSession

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

the class JDBCCollection method getArrayValue.

public Array getArrayValue() throws DBCException {
    Object[] attrs = new Object[contents.length];
    for (int i = 0; i < contents.length; i++) {
        Object attr = contents[i];
        if (attr instanceof DBDValue) {
            attr = ((DBDValue) attr).getRawValue();
        }
        attrs[i] = attr;
    }
    final DBSDataType dataType = getComponentType();
    try (DBCSession session = DBUtils.openUtilSession(VoidProgressMonitor.INSTANCE, dataType.getDataSource(), "Create JDBC array")) {
        if (session instanceof Connection) {
            return ((Connection) session).createArrayOf(dataType.getTypeName(), attrs);
        } else {
            return new JDBCArrayImpl(dataType.getTypeName(), dataType.getTypeID(), attrs);
        }
    } catch (Throwable e) {
        throw new DBCException("Error creating struct", e);
    }
}
Also used : JDBCArrayImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) Connection(java.sql.Connection) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)

Aggregations

DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)7 DBException (org.jkiss.dbeaver.DBException)3 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)1 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)1 DBDValue (org.jkiss.dbeaver.model.data.DBDValue)1 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)1 DBCExecutionPurpose (org.jkiss.dbeaver.model.exec.DBCExecutionPurpose)1 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)1 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)1 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)1 JDBCArrayImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl)1 JDBCStructImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCStructImpl)1