提交 7c89694a 编写于 作者: J jurgen

Bootstrap SQL queries edit

上级 0e38e3be
...@@ -50,6 +50,11 @@ public class DBPConnectionBootstrap ...@@ -50,6 +50,11 @@ public class DBPConnectionBootstrap
return initQueries; return initQueries;
} }
public void setInitQueries(Collection<String> queries) {
initQueries.clear();
initQueries.addAll(queries);
}
public String getDefaultObjectName() { public String getDefaultObjectName() {
return defaultObjectName; return defaultObjectName;
} }
......
...@@ -77,8 +77,6 @@ public interface DBSDataSourceContainer extends DBSObject, DBDPreferences ...@@ -77,8 +77,6 @@ public interface DBSDataSourceContainer extends DBSObject, DBDPreferences
void setDefaultTransactionsIsolation(DBPTransactionIsolation isolationLevel); void setDefaultTransactionsIsolation(DBPTransactionIsolation isolationLevel);
String getDefaultActiveObject();
/** /**
* Search for object filter which corresponds specified object type and parent object. * Search for object filter which corresponds specified object type and parent object.
* Search filter which match any super class or interface implemented by specified type. * Search filter which match any super class or interface implemented by specified type.
......
...@@ -328,7 +328,6 @@ public class DataSourceDescriptor ...@@ -328,7 +328,6 @@ public class DataSourceDescriptor
connectionInfo.getBootstrap().setDefaultAutoCommit(null); connectionInfo.getBootstrap().setDefaultAutoCommit(null);
} else { } else {
connectionInfo.getBootstrap().setDefaultAutoCommit(autoCommit); connectionInfo.getBootstrap().setDefaultAutoCommit(autoCommit);
//preferenceStore.setValue(DBeaverPreferences.DEFAULT_AUTO_COMMIT, autoCommit);
} }
} }
...@@ -352,9 +351,6 @@ public class DataSourceDescriptor ...@@ -352,9 +351,6 @@ public class DataSourceDescriptor
@Override @Override
public Integer getDefaultTransactionsIsolation() { public Integer getDefaultTransactionsIsolation() {
// if (preferenceStore.contains(DBeaverPreferences.DEFAULT_ISOLATION)) {
// return preferenceStore.getInt(DBeaverPreferences.DEFAULT_ISOLATION);
// }
return connectionInfo.getBootstrap().getDefaultTransactionIsolation(); return connectionInfo.getBootstrap().getDefaultTransactionIsolation();
} }
...@@ -364,10 +360,8 @@ public class DataSourceDescriptor ...@@ -364,10 +360,8 @@ public class DataSourceDescriptor
try { try {
if (isolationLevel == null) { if (isolationLevel == null) {
connectionInfo.getBootstrap().setDefaultTransactionIsolation(null); connectionInfo.getBootstrap().setDefaultTransactionIsolation(null);
//preferenceStore.setToDefault(DBeaverPreferences.DEFAULT_ISOLATION);
} else { } else {
connectionInfo.getBootstrap().setDefaultTransactionIsolation(isolationLevel.getCode()); connectionInfo.getBootstrap().setDefaultTransactionIsolation(isolationLevel.getCode());
//preferenceStore.setValue(DBeaverPreferences.DEFAULT_ISOLATION, isolationLevel.getCode());
if (dataSource != null) { if (dataSource != null) {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() { DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override @Override
...@@ -397,14 +391,8 @@ public class DataSourceDescriptor ...@@ -397,14 +391,8 @@ public class DataSourceDescriptor
} }
} }
@Override
public String getDefaultActiveObject() {
return connectionInfo.getBootstrap().getDefaultObjectName();//preferenceStore.getString(DBeaverPreferences.DEFAULT_ACTIVE_OBJECT);
}
public void setDefaultActiveObject(String defaultActiveObject) { public void setDefaultActiveObject(String defaultActiveObject) {
connectionInfo.getBootstrap().setDefaultObjectName(defaultActiveObject); connectionInfo.getBootstrap().setDefaultObjectName(defaultActiveObject);
//preferenceStore.setValue(DBeaverPreferences.DEFAULT_ACTIVE_OBJECT, defaultActiveObject);
} }
public Collection<FilterMapping> getObjectFilters() public Collection<FilterMapping> getObjectFilters()
......
...@@ -44,6 +44,7 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSTable; ...@@ -44,6 +44,7 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.registry.DataSourceDescriptor; import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry; import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.runtime.AbstractJob; import org.jkiss.dbeaver.runtime.AbstractJob;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.IHelpContextIds; import org.jkiss.dbeaver.ui.IHelpContextIds;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CImageCombo; import org.jkiss.dbeaver.ui.controls.CImageCombo;
...@@ -51,9 +52,7 @@ import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage; ...@@ -51,9 +52,7 @@ import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage;
import org.jkiss.dbeaver.ui.preferences.PrefPageConnectionTypes; import org.jkiss.dbeaver.ui.preferences.PrefPageConnectionTypes;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.StringTokenizer;
/** /**
* General connection page (common for all connection types) * General connection page (common for all connection types)
...@@ -79,6 +78,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -79,6 +78,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
private Group filtersGroup; private Group filtersGroup;
private boolean activated = false; private boolean activated = false;
private java.util.List<DBPTransactionIsolation> supportedLevels = new ArrayList<DBPTransactionIsolation>(); private java.util.List<DBPTransactionIsolation> supportedLevels = new ArrayList<DBPTransactionIsolation>();
private java.util.List<String> bootstrapQueries;
private boolean ignoreBootstrapErrors;
private static class FilterInfo { private static class FilterInfo {
final Class<?> type; final Class<?> type;
...@@ -103,6 +104,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -103,6 +104,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
filters.add(new FilterInfo(DBSCatalog.class, CoreMessages.dialog_connection_wizard_final_filter_catalogs)); filters.add(new FilterInfo(DBSCatalog.class, CoreMessages.dialog_connection_wizard_final_filter_catalogs));
filters.add(new FilterInfo(DBSSchema.class, CoreMessages.dialog_connection_wizard_final_filter_schemas_users)); filters.add(new FilterInfo(DBSSchema.class, CoreMessages.dialog_connection_wizard_final_filter_schemas_users));
filters.add(new FilterInfo(DBSTable.class, CoreMessages.dialog_connection_wizard_final_filter_tables)); filters.add(new FilterInfo(DBSTable.class, CoreMessages.dialog_connection_wizard_final_filter_tables));
bootstrapQueries = new ArrayList<String>();
} }
ConnectionPageGeneral(ConnectionWizard wizard, DataSourceDescriptor dataSourceDescriptor) ConnectionPageGeneral(ConnectionWizard wizard, DataSourceDescriptor dataSourceDescriptor)
...@@ -113,6 +116,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -113,6 +116,8 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
for (FilterInfo filterInfo : filters) { for (FilterInfo filterInfo : filters) {
filterInfo.filter = dataSourceDescriptor.getObjectFilter(filterInfo.type, null, false); filterInfo.filter = dataSourceDescriptor.getObjectFilter(filterInfo.type, null, false);
} }
bootstrapQueries = dataSourceDescriptor.getConnectionConfiguration().getBootstrap().getInitQueries();
ignoreBootstrapErrors = dataSourceDescriptor.getConnectionConfiguration().getBootstrap().isIgnoreErrors();
} }
@Override @Override
...@@ -356,9 +361,28 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -356,9 +361,28 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
isolationLevel = UIUtils.createLabelCombo(txnGroup, "Isolation level", SWT.DROP_DOWN | SWT.READ_ONLY); isolationLevel = UIUtils.createLabelCombo(txnGroup, "Isolation level", SWT.DROP_DOWN | SWT.READ_ONLY);
isolationLevel.setToolTipText( isolationLevel.setToolTipText(
"Default transaction isolation level."); "Default transaction isolation level.");
defaultSchema = UIUtils.createLabelCombo(txnGroup, "Default schema/catalog", SWT.DROP_DOWN); defaultSchema = UIUtils.createLabelCombo(txnGroup, "Default schema", SWT.DROP_DOWN);
defaultSchema.setToolTipText( defaultSchema.setToolTipText(
"Name of schema or catalog which will be set as default."); "Name of schema or catalog which will be set as default.");
UIUtils.createControlLabel(txnGroup, "Bootstrap queries");
Button queriesConfigButton = UIUtils.createPushButton(txnGroup, "Configure ...", DBeaverIcons.getImage(DBIcon.SQL_SCRIPT));
if (dataSourceDescriptor != null && !CommonUtils.isEmpty(dataSourceDescriptor.getConnectionConfiguration().getBootstrap().getInitQueries())) {
queriesConfigButton.setFont(boldFont);
}
queriesConfigButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditBootstrapQueriesDialog dialog = new EditBootstrapQueriesDialog(
getShell(),
bootstrapQueries,
ignoreBootstrapErrors);
if (dialog.open() == IDialogConstants.OK_ID) {
bootstrapQueries = dialog.getQueries();
ignoreBootstrapErrors = dialog.isIgnoreErrors();
}
}
});
} }
{ {
...@@ -395,7 +419,6 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -395,7 +419,6 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
filterInfo.link.addSelectionListener(new SelectionAdapter() { filterInfo.link.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
//DBSObjectFilter filter =
EditObjectFilterDialog dialog = new EditObjectFilterDialog( EditObjectFilterDialog dialog = new EditObjectFilterDialog(
getShell(), getShell(),
filterInfo.title, filterInfo.title,
...@@ -496,6 +519,9 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> { ...@@ -496,6 +519,9 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter); dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter);
} }
} }
DBPConnectionBootstrap bootstrap = dataSource.getConnectionConfiguration().getBootstrap();
bootstrap.setIgnoreErrors(ignoreBootstrapErrors);
bootstrap.setInitQueries(bootstrapQueries);
} }
private void configureEvents() private void configureEvents()
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ui.dialogs.connection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.ui.IHelpContextIds;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CustomTableEditor;
import org.jkiss.dbeaver.ui.dialogs.EditTextDialog;
import org.jkiss.dbeaver.ui.dialogs.HelpEnabledDialog;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Object filter edit dialog
*/
public class EditBootstrapQueriesDialog extends HelpEnabledDialog {
public static final int SHOW_GLOBAL_FILTERS_ID = 1000;
private List<String> queries;
private boolean ignoreErrors;
private Table queriesTable;
private Button ignoreErrorButton;
public EditBootstrapQueriesDialog(Shell shell, Collection<String> queries, boolean ignoreErrors) {
super(shell, IHelpContextIds.CTX_EDIT_OBJECT_FILTERS);
this.queries = new ArrayList<String>(queries);
this.ignoreErrors = ignoreErrors;
}
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText("Bootstrap SQL queries");
Composite composite = (Composite) super.createDialogArea(parent);
Group group = UIUtils.createControlGroup(composite, "SQL Queries", 2, GridData.FILL_BOTH, 0);
queriesTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = 100;
queriesTable.setLayoutData(gd);
queriesTable.setLinesVisible(true);
final TableColumn valueColumn = UIUtils.createTableColumn(queriesTable, SWT.LEFT, "SQL");
valueColumn.setWidth(300);
for (String value : queries) {
new TableItem(queriesTable, SWT.LEFT).setText(value);
}
final CustomTableEditor tableEditor = new CustomTableEditor(queriesTable) {
@Override
protected Control createEditor(Table table, int index, TableItem item) {
Text editor = new Text(table, SWT.BORDER);
editor.setText(item.getText());
return editor;
}
@Override
protected void saveEditorValue(Control control, int index, TableItem item) {
item.setText(((Text) control).getText());
}
};
Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
final Button addButton = new Button(buttonsGroup, SWT.PUSH);
addButton.setText(CoreMessages.dialog_filter_button_add);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
tableEditor.closeEditor();
String sql = EditTextDialog.editText(getShell(), "Enter SQL", "");
if (sql != null) {
TableItem newItem = new TableItem(queriesTable, SWT.LEFT);
newItem.setText(sql);
queriesTable.setSelection(newItem);
UIUtils.packColumns(queriesTable, true);
}
}
});
final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
removeButton.setText(CoreMessages.dialog_filter_button_remove);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = queriesTable.getSelectionIndex();
if (selectionIndex >= 0) {
tableEditor.closeEditor();
queriesTable.remove(selectionIndex);
removeButton.setEnabled(queriesTable.getSelectionIndex() >= 0);
}
}
});
removeButton.setEnabled(false);
queriesTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = queriesTable.getSelectionIndex();
removeButton.setEnabled(selectionIndex >= 0);
}
});
ignoreErrorButton = UIUtils.createCheckbox(composite, "Ignore SQL errors", ignoreErrors);
UIUtils.packColumns(queriesTable, true);
return composite;
}
private List<String> collectValues(Table table) {
List<String> values = new ArrayList<String>();
for (TableItem item : table.getItems()) {
String value = item.getText().trim();
if (value.isEmpty() || value.equals("%")) { //$NON-NLS-1$
continue;
}
values.add(value);
}
return values;
}
@Override
protected void okPressed() {
ignoreErrors = ignoreErrorButton.getSelection();
queries = collectValues(queriesTable);
super.okPressed();
}
@Override
protected void cancelPressed() {
super.cancelPressed();
}
public List<String> getQueries() {
return queries;
}
public boolean isIgnoreErrors() {
return ignoreErrors;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册