Search in sources :

Example 21 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DbSqlSession method executeSchemaResource.

private void executeSchemaResource(String operation, String component, String resourceName, InputStream inputStream) {
    log.info("performing {} on {} with resource {}", operation, component, resourceName);
    String sqlStatement = null;
    String exceptionSqlStatement = null;
    try {
        Connection connection = sqlSession.getConnection();
        Exception exception = null;
        byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
        String ddlStatements = new String(bytes);
        String databaseType = dbSqlSessionFactory.getDatabaseType();
        // Special DDL handling for certain databases
        try {
            if ("mysql".equals(databaseType)) {
                DatabaseMetaData databaseMetaData = connection.getMetaData();
                int majorVersion = databaseMetaData.getDatabaseMajorVersion();
                int minorVersion = databaseMetaData.getDatabaseMinorVersion();
                log.info("Found MySQL: majorVersion=" + majorVersion + " minorVersion=" + minorVersion);
                // Special care for MySQL < 5.6
                if (majorVersion <= 5 && minorVersion < 6) {
                    ddlStatements = updateDdlForMySqlVersionLowerThan56(ddlStatements);
                }
            }
        } catch (Exception e) {
            log.info("Could not get database metadata", e);
        }
        BufferedReader reader = new BufferedReader(new StringReader(ddlStatements));
        String line = readNextTrimmedLine(reader);
        boolean inOraclePlsqlBlock = false;
        while (line != null) {
            if (line.startsWith("# ")) {
                log.debug(line.substring(2));
            } else if (line.startsWith("-- ")) {
                log.debug(line.substring(3));
            } else if (line.startsWith("execute java ")) {
                String upgradestepClassName = line.substring(13).trim();
                DbUpgradeStep dbUpgradeStep = null;
                try {
                    dbUpgradeStep = (DbUpgradeStep) ReflectUtil.instantiate(upgradestepClassName);
                } catch (ActivitiException e) {
                    throw new ActivitiException("database update java class '" + upgradestepClassName + "' can't be instantiated: " + e.getMessage(), e);
                }
                try {
                    log.debug("executing upgrade step java class {}", upgradestepClassName);
                    dbUpgradeStep.execute(this);
                } catch (Exception e) {
                    throw new ActivitiException("error while executing database update java class '" + upgradestepClassName + "': " + e.getMessage(), e);
                }
            } else if (line.length() > 0) {
                if ("oracle".equals(databaseType) && line.startsWith("begin")) {
                    inOraclePlsqlBlock = true;
                    sqlStatement = addSqlStatementPiece(sqlStatement, line);
                } else if ((line.endsWith(";") && inOraclePlsqlBlock == false) || (line.startsWith("/") && inOraclePlsqlBlock == true)) {
                    if (inOraclePlsqlBlock) {
                        inOraclePlsqlBlock = false;
                    } else {
                        sqlStatement = addSqlStatementPiece(sqlStatement, line.substring(0, line.length() - 1));
                    }
                    Statement jdbcStatement = connection.createStatement();
                    try {
                        // no logging needed as the connection will log it
                        log.debug("SQL: {}", sqlStatement);
                        jdbcStatement.execute(sqlStatement);
                        jdbcStatement.close();
                    } catch (Exception e) {
                        if (exception == null) {
                            exception = e;
                            exceptionSqlStatement = sqlStatement;
                        }
                        log.error("problem during schema {}, statement {}", operation, sqlStatement, e);
                    } finally {
                        sqlStatement = null;
                    }
                } else {
                    sqlStatement = addSqlStatementPiece(sqlStatement, line);
                }
            }
            line = readNextTrimmedLine(reader);
        }
        if (exception != null) {
            throw exception;
        }
        log.debug("activiti db schema {} for component {} successful", operation, component);
    } catch (Exception e) {
        throw new ActivitiException("couldn't " + operation + " db schema: " + exceptionSqlStatement, e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Statement(java.sql.Statement) Connection(java.sql.Connection) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) DatabaseMetaData(java.sql.DatabaseMetaData) DbUpgradeStep(org.activiti.engine.impl.db.upgrade.DbUpgradeStep) ActivitiException(org.activiti.engine.ActivitiException) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) IOException(java.io.IOException)

Example 22 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DbSqlSession method dbSchemaUpdate.

public String dbSchemaUpdate() {
    String feedback = null;
    boolean isUpgradeNeeded = false;
    int matchingVersionIndex = -1;
    if (isEngineTablePresent()) {
        PropertyEntity dbVersionProperty = selectById(PropertyEntity.class, "schema.version");
        String dbVersion = dbVersionProperty.getValue();
        // Determine index in the sequence of Activiti releases
        int index = 0;
        while (matchingVersionIndex < 0 && index < ACTIVITI_VERSIONS.size()) {
            if (ACTIVITI_VERSIONS.get(index).matches(dbVersion)) {
                matchingVersionIndex = index;
            } else {
                index++;
            }
        }
        // Exception when no match was found: unknown/unsupported version
        if (matchingVersionIndex < 0) {
            throw new ActivitiException("Could not update Activiti database schema: unknown version from database: '" + dbVersion + "'");
        }
        isUpgradeNeeded = (matchingVersionIndex != (ACTIVITI_VERSIONS.size() - 1));
        if (isUpgradeNeeded) {
            dbVersionProperty.setValue(ProcessEngine.VERSION);
            PropertyEntity dbHistoryProperty;
            if ("5.0".equals(dbVersion)) {
                dbHistoryProperty = new PropertyEntity("schema.history", "create(5.0)");
                insert(dbHistoryProperty);
            } else {
                dbHistoryProperty = selectById(PropertyEntity.class, "schema.history");
            }
            // Set upgrade history
            String dbHistoryValue = dbHistoryProperty.getValue() + " upgrade(" + dbVersion + "->" + ProcessEngine.VERSION + ")";
            dbHistoryProperty.setValue(dbHistoryValue);
            // Engine upgrade
            dbSchemaUpgrade("engine", matchingVersionIndex);
            feedback = "upgraded Activiti from " + dbVersion + " to " + ProcessEngine.VERSION;
        }
    } else {
        dbSchemaCreateEngine();
    }
    if (isHistoryTablePresent()) {
        if (isUpgradeNeeded) {
            dbSchemaUpgrade("history", matchingVersionIndex);
        }
    } else if (dbSqlSessionFactory.isDbHistoryUsed()) {
        dbSchemaCreateHistory();
    }
    if (isIdentityTablePresent()) {
        if (isUpgradeNeeded) {
            dbSchemaUpgrade("identity", matchingVersionIndex);
        }
    } else if (dbSqlSessionFactory.isDbIdentityUsed()) {
        dbSchemaCreateIdentity();
    }
    return feedback;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) PropertyEntity(org.activiti.engine.impl.persistence.entity.PropertyEntity)

Example 23 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class IbatisVariableTypeHandler method getResult.

public VariableType getResult(ResultSet rs, String columnName) throws SQLException {
    String typeName = rs.getString(columnName);
    VariableType type = getVariableTypes().getVariableType(typeName);
    if (type == null && typeName != null) {
        throw new ActivitiException("unknown variable type name " + typeName);
    }
    return type;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) VariableType(org.activiti.engine.impl.variable.VariableType)

Example 24 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class ExecuteJobsCmd method execute.

public Object execute(CommandContext commandContext) {
    if (jobId == null && job == null) {
        throw new ActivitiIllegalArgumentException("jobId and job is null");
    }
    if (job == null) {
        job = commandContext.getJobEntityManager().findJobById(jobId);
    }
    if (job == null) {
        throw new JobNotFoundException(jobId);
    }
    if (log.isDebugEnabled()) {
        log.debug("Executing job {}", job.getId());
    }
    JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
    if (jobExecutorContext != null) {
        // if null, then we are not called by the job executor     
        jobExecutorContext.setCurrentJob(job);
    }
    FailedJobListener failedJobListener = null;
    try {
        // When transaction is rolled back, decrement retries
        failedJobListener = new FailedJobListener(commandContext.getProcessEngineConfiguration().getCommandExecutor(), jobId);
        commandContext.getTransactionContext().addTransactionListener(TransactionState.ROLLED_BACK, failedJobListener);
        job.execute(commandContext);
        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_EXECUTION_SUCCESS, job));
        }
    } catch (Throwable exception) {
        failedJobListener.setException(exception);
        // exception to be swallowed
        if (commandContext.getEventDispatcher().isEnabled()) {
            try {
                commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityExceptionEvent(ActivitiEventType.JOB_EXECUTION_FAILURE, job, exception));
            } catch (Throwable ignore) {
                log.warn("Exception occured while dispatching job failure event, ignoring.", ignore);
            }
        }
        // Finally, Throw the exception to indicate the ExecuteJobCmd failed
        throw new ActivitiException("Job " + jobId + " failed", exception);
    } finally {
        if (jobExecutorContext != null) {
            jobExecutorContext.setCurrentJob(null);
        }
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JobExecutorContext(org.activiti.engine.impl.jobexecutor.JobExecutorContext) JobNotFoundException(org.activiti.engine.JobNotFoundException) FailedJobListener(org.activiti.engine.impl.jobexecutor.FailedJobListener)

Example 25 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JuelExpression method setValue.

public void setValue(Object value, VariableScope variableScope) {
    ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);
    try {
        ExpressionSetInvocation invocation = new ExpressionSetInvocation(valueExpression, elContext, value);
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
    } catch (Exception e) {
        throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ELContext(org.activiti.engine.impl.javax.el.ELContext) ExpressionSetInvocation(org.activiti.engine.impl.delegate.ExpressionSetInvocation) ActivitiException(org.activiti.engine.ActivitiException) PropertyNotFoundException(org.activiti.engine.impl.javax.el.PropertyNotFoundException) MethodNotFoundException(org.activiti.engine.impl.javax.el.MethodNotFoundException) ELException(org.activiti.engine.impl.javax.el.ELException)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)247 Deployment (org.activiti.engine.test.Deployment)38 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)36 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)35 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)31 IOException (java.io.IOException)28 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ArrayList (java.util.ArrayList)20 TaskQuery (org.activiti.engine.task.TaskQuery)16 HashMap (java.util.HashMap)14 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)14 Task (org.activiti.engine.task.Task)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ObjectOutputStream (java.io.ObjectOutputStream)10 Date (java.util.Date)10 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)10 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9