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);
}
}
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()]);
}
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;
}
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;
}
}
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);
}
}
Aggregations