Search in sources :

Example 1 with PostgreRole

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreRole in project dbeaver by serge-rider.

the class PostgreSchemaManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final PostgreSchema schema = command.getObject();
    final StringBuilder script = new StringBuilder("CREATE SCHEMA " + DBUtils.getQuotedIdentifier(schema));
    try {
        final PostgreRole owner = schema.getOwner(VoidProgressMonitor.INSTANCE);
        if (owner != null) {
            script.append("\nAUTHORIZATION ").append(owner.getName());
        }
    } catch (DBException e) {
        log.error(e);
    }
    actions.add(//$NON-NLS-2$
    new SQLDatabasePersistAction("Create schema", script.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreRole(org.jkiss.dbeaver.ext.postgresql.model.PostgreRole) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with PostgreRole

use of org.jkiss.dbeaver.ext.postgresql.model.PostgreRole in project dbeaver by serge-rider.

the class PostgreCreateSchemaDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    final Composite composite = super.createDialogArea(parent);
    final Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    final Text nameText = UIUtils.createLabelText(group, "Schema name", "");
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            name = nameText.getText();
            getButton(IDialogConstants.OK_ID).setEnabled(!name.isEmpty());
        }
    });
    final Combo userCombo = UIUtils.createLabelCombo(group, "Owner", SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    userCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            owner = allUsers.get(userCombo.getSelectionIndex());
        }
    });
    new AbstractJob("Load users") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                final List<String> userNames = new ArrayList<>();
                allUsers = new ArrayList<>(database.getUsers(monitor));
                final PostgreRole dba = database.getDBA(monitor);
                final String defUserName = dba == null ? "" : dba.getName();
                DBeaverUI.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        for (PostgreRole authId : allUsers) {
                            String name = authId.getName();
                            userCombo.add(name);
                            if (name.equals(defUserName)) {
                                owner = authId;
                            }
                        }
                        userCombo.setText(defUserName);
                    }
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return composite;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) PostgreRole(org.jkiss.dbeaver.ext.postgresql.model.PostgreRole) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

DBException (org.jkiss.dbeaver.DBException)2 PostgreRole (org.jkiss.dbeaver.ext.postgresql.model.PostgreRole)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IStatus (org.eclipse.core.runtime.IStatus)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)1 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)1 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1