Search in sources :

Example 6 with MySQLDataSource

use of org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource in project dbeaver by dbeaver.

the class MySQLSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<MySQLSession>(this, parent, new MySQLSessionManager((MySQLDataSource) executionContext.getDataSource())) {

        private boolean hideSleeping;

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(killSessionAction);
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
            contributionManager.add(new ControlContribution("MySQLSessionHideSleep") {

                @Override
                protected Control createControl(Composite parent) {
                    Button hideSleepingCheck = UIUtils.createCheckbox(parent, "Hide sleeping", "Show only active connections", hideSleeping, 0);
                    hideSleepingCheck.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            hideSleeping = hideSleepingCheck.getSelection();
                            refreshPart(MySQLSessionEditor.this, true);
                        }
                    });
                    return hideSleepingCheck;
                }
            });
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            killSessionAction.setEnabled(session != null);
            terminateQueryAction.setEnabled(session != null && !CommonUtils.isEmpty(session.getActiveQuery()));
        }

        @Override
        public Map<String, Object> getSessionOptions() {
            if (hideSleeping) {
                return Collections.singletonMap(MySQLSessionManager.OPTION_HIDE_SLEEPING, true);
            }
            return super.getSessionOptions();
        }
    };
}
Also used : DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ControlContribution(org.eclipse.jface.action.ControlContribution) SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) Control(org.eclipse.swt.widgets.Control) MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) Button(org.eclipse.swt.widgets.Button) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MySQLSessionManager(org.jkiss.dbeaver.ext.mysql.model.session.MySQLSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 7 with MySQLDataSource

use of org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource in project dbeaver by serge-rider.

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Example 8 with MySQLDataSource

use of org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource in project dbeaver by serge-rider.

the class MySQLExportWizardPageObjects method loadSettings.

private void loadSettings() {
    checkedObjects.clear();
    catalogTable.removeAll();
    boolean hasViews = false;
    MySQLDataSource dataSource = null;
    Set<MySQLCatalog> activeCatalogs = new LinkedHashSet<>();
    for (MySQLDatabaseExportInfo info : wizard.getSettings().getExportObjects()) {
        activeCatalogs.add(info.getDatabase());
        dataSource = info.getDatabase().getDataSource();
        if (!CommonUtils.isEmpty(info.getTables())) {
            Set<MySQLTableBase> tables = checkedObjects.computeIfAbsent(info.getDatabase(), k -> new HashSet<>());
            for (MySQLTableBase table : info.getTables()) {
                tables.add(table);
                if (table.isView()) {
                    hasViews = true;
                }
            }
        }
    }
    if (hasViews) {
        wizard.getSettings().setShowViews(true);
        exportViewsCheck.setSelection(true);
    }
    if (dataSource != null) {
        boolean tablesLoaded = false;
        for (MySQLCatalog catalog : dataSource.getCatalogs()) {
            TableItem item = new TableItem(catalogTable, SWT.NONE);
            item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
            item.setText(0, catalog.getName());
            item.setData(catalog);
            if (activeCatalogs.contains(catalog)) {
                item.setChecked(true);
                catalogTable.select(catalogTable.indexOf(item));
                if (!tablesLoaded) {
                    loadTables(catalog);
                    tablesLoaded = true;
                }
            }
        }
    }
    updateState();
}
Also used : MySQLTableBase(org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase) MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) MySQLCatalog(org.jkiss.dbeaver.ext.mysql.model.MySQLCatalog) MySQLDatabaseExportInfo(org.jkiss.dbeaver.ext.mysql.tasks.MySQLDatabaseExportInfo)

Example 9 with MySQLDataSource

use of org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource in project dbeaver by dbeaver.

the class MySQLExportWizardPageObjects method loadSettings.

private void loadSettings() {
    checkedObjects.clear();
    catalogTable.removeAll();
    boolean hasViews = false;
    MySQLDataSource dataSource = null;
    Set<MySQLCatalog> activeCatalogs = new LinkedHashSet<>();
    for (MySQLDatabaseExportInfo info : wizard.getSettings().getExportObjects()) {
        activeCatalogs.add(info.getDatabase());
        dataSource = info.getDatabase().getDataSource();
        if (!CommonUtils.isEmpty(info.getTables())) {
            Set<MySQLTableBase> tables = checkedObjects.computeIfAbsent(info.getDatabase(), k -> new HashSet<>());
            for (MySQLTableBase table : info.getTables()) {
                tables.add(table);
                if (table.isView()) {
                    hasViews = true;
                }
            }
        }
    }
    if (hasViews) {
        wizard.getSettings().setShowViews(true);
        exportViewsCheck.setSelection(true);
    }
    if (dataSource != null) {
        boolean tablesLoaded = false;
        for (MySQLCatalog catalog : dataSource.getCatalogs()) {
            TableItem item = new TableItem(catalogTable, SWT.NONE);
            item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
            item.setText(0, catalog.getName());
            item.setData(catalog);
            if (activeCatalogs.contains(catalog)) {
                item.setChecked(true);
                catalogTable.select(catalogTable.indexOf(item));
                if (!tablesLoaded) {
                    loadTables(catalog);
                    tablesLoaded = true;
                }
            }
        }
    }
    updateState();
}
Also used : MySQLTableBase(org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase) MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) MySQLCatalog(org.jkiss.dbeaver.ext.mysql.model.MySQLCatalog) MySQLDatabaseExportInfo(org.jkiss.dbeaver.ext.mysql.tasks.MySQLDatabaseExportInfo)

Example 10 with MySQLDataSource

use of org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource in project dbeaver by dbeaver.

the class MySQLCommandChangeUser method getPersistActions.

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

            @Override
            public void afterExecute(DBCSession session, Throwable error) {
                if (error == null) {
                    getObject().setPersisted(true);
                }
            }
        });
    }
    boolean hasSet;
    final MySQLDataSource dataSource = getObject().getDataSource();
    if (MySQLUtils.isAlterUSerSupported(dataSource)) {
        StringBuilder script = new StringBuilder();
        if (generateAlterScript(script)) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, script.toString()));
        }
    } else {
        String updateSQL = generateUpdateScript();
        if (updateSQL != null) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
        }
        updateSQL = generatePasswordSet();
        if (updateSQL != null) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
        }
    }
    return actions.toArray(new DBEPersistAction[0]);
}
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)

Aggregations

MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)12 ArrayList (java.util.ArrayList)4 IContributionManager (org.eclipse.jface.action.IContributionManager)4 Separator (org.eclipse.jface.action.Separator)4 MySQLSessionManager (org.jkiss.dbeaver.ext.mysql.model.session.MySQLSessionManager)4 DBAServerSession (org.jkiss.dbeaver.model.admin.sessions.DBAServerSession)4 DBAServerSessionManager (org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager)4 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)4 DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)4 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)4 SessionManagerViewer (org.jkiss.dbeaver.ui.views.session.SessionManagerViewer)4 Action (org.eclipse.jface.action.Action)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 MySQLCatalog (org.jkiss.dbeaver.ext.mysql.model.MySQLCatalog)2 MySQLTableBase (org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase)2 MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)2 MySQLTableConstraint (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)2 MySQLTableConstraintColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)2 MySQLDatabaseExportInfo (org.jkiss.dbeaver.ext.mysql.tasks.MySQLDatabaseExportInfo)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)2