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);
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations