Search in sources :

Example 51 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class DB2SchemaManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(List<DBEPersistAction> actions, ObjectDeleteCommand command) {
    String schemaName = command.getObject().getName();
    DBEPersistAction action = new SQLDatabasePersistAction("Drop schema (SQL)", String.format(SQL_DROP_SCHEMA, DBUtils.getQuotedIdentifier(command.getObject())));
    actions.add(action);
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 52 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class ExasolTableManager method addStructObjectCreateActions.

@Override
public void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command) {
    super.addStructObjectCreateActions(actions, command);
    // Eventually add Comment
    DBEPersistAction commentAction = buildCommentAction(command.getObject());
    if (commentAction != null) {
        actions.add(commentAction);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction)

Example 53 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class ExasolTableManager method addObjectModifyActions.

// ------
// Alter
// ------
@Override
public void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
    ExasolTable exasolTable = command.getObject();
    if (command.getProperties().size() > 1) {
        StringBuilder sb = new StringBuilder(128);
        sb.append(SQL_ALTER);
        sb.append(exasolTable.getFullyQualifiedName(DBPEvaluationContext.DDL));
        sb.append(" ");
        appendTableModifiers(command.getObject(), command, sb);
        actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
    }
    DBEPersistAction commentAction = buildCommentAction(exasolTable);
    if (commentAction != null) {
        actionList.add(commentAction);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 54 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class JDBCUtils method generateTableDDL.

public static String generateTableDDL(@NotNull DBRProgressMonitor monitor, @NotNull JDBCTable table, boolean addComments) throws DBException {
    final DBERegistry editorsRegistry = table.getDataSource().getContainer().getPlatform().getEditorsRegistry();
    final SQLObjectEditor entityEditor = editorsRegistry.getObjectManager(table.getClass(), SQLObjectEditor.class);
    if (entityEditor instanceof SQLTableManager) {
        DBEPersistAction[] ddlActions = ((SQLTableManager) entityEditor).getTableDDL(monitor, table);
        return SQLUtils.generateScript(table.getDataSource(), ddlActions, addComments);
    }
    log.debug("Table editor not found for " + table.getClass().getName());
    return SQLUtils.generateCommentLine(table.getDataSource(), "Can't generate DDL: table editor not found for " + table.getClass().getName());
}
Also used : SQLTableManager(org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager) DBERegistry(org.jkiss.dbeaver.model.edit.DBERegistry) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLObjectEditor(org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor)

Example 55 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class SQLTableManager method addStructObjectCreateActions.

@Override
protected void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command) {
    final OBJECT_TYPE table = command.getObject();
    final NestedObjectCommand tableProps = command.getObjectCommands().get(table);
    if (tableProps == null) {
        //$NON-NLS-1$
        log.warn("Object change command not found");
        return;
    }
    final String tableName = table.getFullyQualifiedName(DBPEvaluationContext.DDL);
    final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
    StringBuilder createQuery = new StringBuilder(100);
    //$NON-NLS-1$ //$NON-NLS-2$
    createQuery.append("CREATE TABLE ").append(tableName).append(" (").append(lineSeparator);
    boolean hasNestedDeclarations = false;
    final Collection<NestedObjectCommand> orderedCommands = getNestedOrderedCommands(command);
    for (NestedObjectCommand nestedCommand : orderedCommands) {
        if (nestedCommand.getObject() == table) {
            continue;
        }
        if (excludeFromDDL(nestedCommand, orderedCommands)) {
            continue;
        }
        final String nestedDeclaration = nestedCommand.getNestedDeclaration(table);
        if (!CommonUtils.isEmpty(nestedDeclaration)) {
            // Insert nested declaration
            if (hasNestedDeclarations) {
                //$NON-NLS-1$
                createQuery.append(",").append(lineSeparator);
            }
            //$NON-NLS-1$
            createQuery.append("\t").append(nestedDeclaration);
            hasNestedDeclarations = true;
        } else {
            // This command should be executed separately
            final DBEPersistAction[] nestedActions = nestedCommand.getPersistActions();
            if (nestedActions != null) {
                Collections.addAll(actions, nestedActions);
            }
        }
    }
    //$NON-NLS-1$
    createQuery.append(lineSeparator).append(")");
    appendTableModifiers(table, tableProps, createQuery);
    actions.add(0, new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_table, createQuery.toString()));
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)94 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)44 DBException (org.jkiss.dbeaver.DBException)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 ArrayList (java.util.ArrayList)14 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)10 UIServiceSQL (org.jkiss.dbeaver.runtime.ui.UIServiceSQL)10 DBERegistry (org.jkiss.dbeaver.model.edit.DBERegistry)8 OracleObjectPersistAction (org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)6 DBPEvent (org.jkiss.dbeaver.model.DBPEvent)6 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)6 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)6 DBCException (org.jkiss.dbeaver.model.exec.DBCException)6 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)6 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)6 SQLDatabasePersistActionComment (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment)6 SQLObjectEditor (org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 DBSObjectState (org.jkiss.dbeaver.model.struct.DBSObjectState)6 SQLException (java.sql.SQLException)4