Search in sources :

Example 6 with DBSObjectState

use of org.jkiss.dbeaver.model.struct.DBSObjectState in project dbeaver by serge-rider.

the class JobRunHandler method runJob.

public static boolean runJob(DBRProgressMonitor monitor, DBCCompileLog compileLog, OracleSchedulerJob job) throws DBCException {
    final DBEPersistAction[] compileActions = job.getRunActions();
    if (ArrayUtils.isEmpty(compileActions)) {
        return true;
    }
    try (JDBCSession session = DBUtils.openUtilSession(monitor, job, "Run '" + job.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.SCRIPT, script, false, false, false)) {
                    action.beforeExecute(session);
                    dbStat.executeStatement();
                }
                action.afterExecute(session, null);
            } catch (DBCException e) {
                action.afterExecute(session, e);
                throw e;
            }
            if (action instanceof OracleObjectPersistAction) {
                if (!logObjectErrors(session, compileLog, job, ((OracleObjectPersistAction) action).getObjectType())) {
                    success = false;
                }
            }
        }
        final DBSObjectState oldState = job.getObjectState();
        job.refreshObjectState(monitor);
        if (job.getObjectState() != oldState) {
            job.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, job));
        }
        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)

Aggregations

OracleObjectPersistAction (org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)6 DBPEvent (org.jkiss.dbeaver.model.DBPEvent)6 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)6 DBCException (org.jkiss.dbeaver.model.exec.DBCException)6 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)6 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)6 DBSObjectState (org.jkiss.dbeaver.model.struct.DBSObjectState)6