Search in sources :

Example 1 with ExasolTableUniqueKey

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey in project dbeaver by dbeaver.

the class ExasolCreateForeignKeyDialog method handleRefTableSelect.

private void handleRefTableSelect(ISelection selection) {
    DBNDatabaseNode refTableNode = null;
    if (!selection.isEmpty() && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
        final Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof DBNDatabaseNode && ((DBNDatabaseNode) element).getObject() instanceof DBSTable && ((DBNDatabaseNode) element).getObject().isPersisted()) {
            refTableNode = (DBNDatabaseNode) element;
        }
    }
    if (refTableNode != null) {
        if (refTableNode.getObject() == curRefTable) {
            // The same selection
            return;
        } else {
            curRefTable = (ExasolTable) refTableNode.getObject();
        }
    }
    uniqueKeyCombo.removeAll();
    try {
        curConstraints = new ArrayList<>();
        curConstraint = null;
        if (refTableNode != null) {
            final ExasolTable refTable = (ExasolTable) refTableNode.getObject();
            DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        // Cache own table columns
                        ownTable.getAttributes(monitor);
                        // Cache ref table columns
                        refTable.getAttributes(monitor);
                        // Get constraints
                        final Collection<? extends ExasolTableUniqueKey> constraints = refTable.getConstraints(monitor);
                        if (!CommonUtils.isEmpty(constraints)) {
                            for (ExasolTableUniqueKey constraint : constraints) {
                                if (constraint.getConstraintType().isUnique()) {
                                    curConstraints.add(constraint);
                                }
                            }
                        }
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            });
        }
        for (DBSTableConstraint constraint : curConstraints) {
            uniqueKeyCombo.add(constraint.getName());
        }
        uniqueKeyCombo.select(0);
        uniqueKeyCombo.setEnabled(curConstraints.size() > 1);
        if (curConstraints.size() == 1) {
            curConstraint = curConstraints.get(0);
        }
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_edit_fk_error_load_constraints_title, CoreMessages.dialog_struct_edit_fk_error_load_constraints_message, e.getTargetException());
    } catch (InterruptedException e) {
    // do nothing
    }
    handleUniqueKeySelect();
    updatePageState();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSTableConstraint(org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraint) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) ExasolTableUniqueKey(org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable)

Example 2 with ExasolTableUniqueKey

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey in project dbeaver by serge-rider.

the class ExasolPrimaryKeyManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final ExasolTableUniqueKey key = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename PK", "ALTER TABLE " + DBUtils.getObjectFullName(key.getTable(), DBPEvaluationContext.DDL) + " RENAME CONSTRAINT " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getOldName()) + " to " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getNewName())));
}
Also used : ExasolTableUniqueKey(org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 3 with ExasolTableUniqueKey

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey in project dbeaver by dbeaver.

the class ExasolPrimaryKeyManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final ExasolTableUniqueKey key = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename PK", "ALTER TABLE " + DBUtils.getObjectFullName(key.getTable(), DBPEvaluationContext.DDL) + " RENAME CONSTRAINT " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getOldName()) + " to " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getNewName())));
}
Also used : ExasolTableUniqueKey(org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 4 with ExasolTableUniqueKey

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey in project dbeaver by dbeaver.

the class ExasolPrimaryKeyManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final ExasolTableUniqueKey key = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename PK", "ALTER TABLE " + DBUtils.getObjectFullName(key.getTable(), DBPEvaluationContext.DDL) + " RENAME CONSTRAINT " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getOldName()) + " to " + DBUtils.getQuotedIdentifier(key.getDataSource(), command.getNewName())));
}
Also used : ExasolTableUniqueKey(org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

ExasolTableUniqueKey (org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey)4 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 DBException (org.jkiss.dbeaver.DBException)1 ExasolTable (org.jkiss.dbeaver.ext.exasol.model.ExasolTable)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSTable (org.jkiss.dbeaver.model.struct.rdb.DBSTable)1 DBSTableConstraint (org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraint)1