Search in sources :

Example 6 with DBCStatement

use of org.jkiss.dbeaver.model.exec.DBCStatement in project dbeaver by serge-rider.

the class CompileHandler method compileUnit.

public static boolean compileUnit(DBRProgressMonitor monitor, DBCCompileLog compileLog, OracleSourceObject unit) throws DBCException {
    final DBEPersistAction[] compileActions = unit.getCompileActions();
    if (ArrayUtils.isEmpty(compileActions)) {
        return true;
    }
    try (JDBCSession session = DBUtils.openUtilSession(monitor, unit.getDataSource(), "Compile '" + unit.getName() + "'")) {
        boolean success = true;
        for (DBEPersistAction action : compileActions) {
            final String script = action.getScript();
            compileLog.trace(script);
            if (monitor.isCanceled()) {
                break;
            }
            try {
                try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, script, false, false, false)) {
                    dbStat.executeStatement();
                }
                action.handleExecute(session, null);
            } catch (DBCException e) {
                action.handleExecute(session, e);
                throw e;
            }
            if (action instanceof OracleObjectPersistAction) {
                if (!logObjectErrors(session, compileLog, unit, ((OracleObjectPersistAction) action).getObjectType())) {
                    success = false;
                }
            }
        }
        final DBSObjectState oldState = unit.getObjectState();
        unit.refreshObjectState(monitor);
        if (unit.getObjectState() != oldState) {
            unit.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, unit));
        }
        return success;
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBSObjectState(org.jkiss.dbeaver.model.struct.DBSObjectState) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPEvent(org.jkiss.dbeaver.model.DBPEvent) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) OracleObjectPersistAction(org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)

Example 7 with DBCStatement

use of org.jkiss.dbeaver.model.exec.DBCStatement in project dbeaver by serge-rider.

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
    return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (statement == null) {
                return;
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                try {
                    int warnNum = 0;
                    SQLWarning warning = ((JDBCStatement) statement).getWarnings();
                    while (warning != null) {
                        if (warnNum == 0) {
                            treeItem.setText(1, warning.getMessage());
                        } else {
                            TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
                            warnItem.setText(0, "");
                            warnItem.setText(1, warning.getMessage());
                        }
                        warnNum++;
                        warning = warning.getNextWarning();
                    }
                    if (warnNum == 0) {
                        treeItem.setText(1, "Done");
                    }
                } catch (SQLException e) {
                // ignore
                }
                treeItem.setExpanded(true);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
            super.endObjectProcessing(object, error);
            if (error != null) {
                TreeItem treeItem = getTreeItem(object);
                if (treeItem != null) {
                    treeItem.setText(1, error.getMessage());
                }
            }
        }
    };
}
Also used : SQLWarning(java.sql.SQLWarning) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 8 with DBCStatement

use of org.jkiss.dbeaver.model.exec.DBCStatement in project dbeaver by serge-rider.

the class AbstractObjectManager method executePersistAction.

@Override
public void executePersistAction(DBCSession session, DBECommand<OBJECT_TYPE> command, DBEPersistAction action) throws DBException {
    String script = action.getScript();
    if (script == null) {
        action.handleExecute(session, null);
    } else {
        DBCStatement dbStat = DBUtils.createStatement(session, script, false);
        try {
            dbStat.executeStatement();
            action.handleExecute(session, null);
        } catch (DBCException e) {
            action.handleExecute(session, e);
            throw e;
        } finally {
            dbStat.close();
        }
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement)

Aggregations

DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)8 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)6 NotNull (org.jkiss.code.NotNull)5 DBCException (org.jkiss.dbeaver.model.exec.DBCException)5 Tree (org.eclipse.swt.widgets.Tree)4 TreeColumn (org.eclipse.swt.widgets.TreeColumn)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 Nullable (org.jkiss.code.Nullable)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 SQLException (java.sql.SQLException)2 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 SQLWarning (java.sql.SQLWarning)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SWT (org.eclipse.swt.SWT)1 Font (org.eclipse.swt.graphics.Font)1 DB2Table (org.jkiss.dbeaver.ext.db2.model.DB2Table)1 MySQLTable (org.jkiss.dbeaver.ext.mysql.model.MySQLTable)1