use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.
the class CursorViewDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
final IValueController valueController = getValueController();
value = (DBDCursor) valueController.getValue();
Composite dialogGroup = (Composite) super.createDialogArea(parent);
if (value != null) {
DBPPreferenceStore globalPreferenceStore = DBeaverCore.getGlobalPreferenceStore();
if (!globalPreferenceStore.getBoolean(DBeaverPreferences.KEEP_STATEMENT_OPEN)) {
if (ConfirmationDialog.showConfirmDialog(getShell(), DBeaverPreferences.CONFIRM_KEEP_STATEMENT_OPEN, ConfirmationDialog.QUESTION) == IDialogConstants.YES_ID) {
globalPreferenceStore.setValue(DBeaverPreferences.KEEP_STATEMENT_OPEN, true);
if (valueController.getValueSite().getPart() instanceof IResultSetContainer) {
IResultSetController rsv = ((IResultSetContainer) valueController.getValueSite().getPart()).getResultSetController();
if (rsv != null) {
rsv.refresh();
}
}
}
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
close();
}
});
}
}
resultSetViewer = new ResultSetViewer(dialogGroup, valueController.getValueSite(), this);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.grabExcessVerticalSpace = true;
resultSetViewer.getControl().setLayoutData(gd);
resultSetViewer.refresh();
return dialogGroup;
}
use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.
the class SpreadsheetCommandHandler method getActiveSpreadsheet.
public static Spreadsheet getActiveSpreadsheet(ExecutionEvent event) {
Object control = HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control instanceof Spreadsheet) {
return (Spreadsheet) control;
}
IResultSetController rsv = ResultSetCommandHandler.getActiveResultSet(HandlerUtil.getActivePart(event));
if (rsv != null) {
IResultSetPresentation activePresentation = rsv.getActivePresentation();
if (activePresentation instanceof SpreadsheetPresentation) {
return ((SpreadsheetPresentation) activePresentation).getSpreadsheet();
}
}
return null;
}
use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetController in project dbeaver by serge-rider.
the class GenerateSQLContributor method makeResultSetContributions.
private void makeResultSetContributions(List<IContributionItem> menu, IResultSetSelection rss) {
final IResultSetController rsv = rss.getController();
DBSDataContainer dataContainer = rsv.getDataContainer();
final List<DBDAttributeBinding> visibleAttributes = rsv.getModel().getVisibleAttributes();
final DBSEntity entity = rsv.getModel().getSingleSource();
if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null) {
final Collection<ResultSetRow> selectedRows = rss.getSelectedRows();
if (!CommonUtils.isEmpty(selectedRows)) {
menu.add(makeAction("SELECT by Unique Key", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {
@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
for (ResultSetRow firstRow : selectedRows) {
Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
sql.append("SELECT ");
boolean hasAttr = false;
for (DBSAttributeBase attr : getValueAttributes(monitor, object, keyAttributes)) {
if (hasAttr)
sql.append(", ");
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML));
hasAttr = true;
}
sql.append("\nFROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\nWHERE ");
hasAttr = false;
for (DBDAttributeBinding binding : keyAttributes) {
if (hasAttr)
sql.append(" AND ");
sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
appendAttributeValue(rsv, sql, binding, firstRow);
hasAttr = true;
}
sql.append(";\n");
}
}
}));
menu.add(makeAction("INSERT", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {
@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
for (ResultSetRow firstRow : selectedRows) {
Collection<? extends DBSAttributeBase> allAttributes = getAllAttributes(monitor, object);
sql.append("INSERT INTO ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\n(");
boolean hasAttr = false;
for (DBSAttributeBase attr : allAttributes) {
if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
continue;
}
if (hasAttr)
sql.append(", ");
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML));
hasAttr = true;
}
sql.append(")\nVALUES(");
hasAttr = false;
for (DBSAttributeBase attr : allAttributes) {
if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
continue;
}
if (hasAttr)
sql.append(", ");
DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
if (binding == null) {
appendDefaultValue(sql, attr);
} else {
appendAttributeValue(rsv, sql, binding, firstRow);
}
hasAttr = true;
}
sql.append(");\n");
}
}
}));
menu.add(makeAction("UPDATE", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {
@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
for (ResultSetRow firstRow : selectedRows) {
Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
Collection<? extends DBSAttributeBase> valueAttributes = getValueAttributes(monitor, object, keyAttributes);
sql.append("UPDATE ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\nSET ");
boolean hasAttr = false;
for (DBSAttributeBase attr : valueAttributes) {
if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
continue;
}
if (hasAttr)
sql.append(", ");
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
if (binding == null) {
appendDefaultValue(sql, attr);
} else {
appendAttributeValue(rsv, sql, binding, firstRow);
}
hasAttr = true;
}
sql.append("\nWHERE ");
hasAttr = false;
for (DBDAttributeBinding attr : keyAttributes) {
if (hasAttr)
sql.append(" AND ");
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
appendAttributeValue(rsv, sql, attr, firstRow);
hasAttr = true;
}
sql.append(";\n");
}
}
}));
menu.add(makeAction("DELETE by Unique Key", new ResultSetAnalysisRunner(dataContainer.getDataSource(), rsv.getModel()) {
@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, ResultSetModel object) throws DBException {
for (ResultSetRow firstRow : selectedRows) {
Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
sql.append("DELETE FROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\nWHERE ");
boolean hasAttr = false;
for (DBDAttributeBinding binding : keyAttributes) {
if (hasAttr)
sql.append(" AND ");
sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
appendAttributeValue(rsv, sql, binding, firstRow);
hasAttr = true;
}
sql.append(";\n");
}
}
}));
}
}
}
Aggregations