public static File getFile(String filePath) { URL url = IoUtil.class.getClassLoader().getResource(filePath); try { return new File(url.toURI()); } catch (Exception e) { throw new FlowableException("Couldn't get file " + filePath + ": " + e.getMessage()); } }
protected void logException() { if (exception instanceof FlowableException && !((FlowableException) exception).isLogged()) { return; } if (exception instanceof FlowableOptimisticLockingException) { // reduce log level, as normally we're not interested in logging this exception LOGGER.debug("Optimistic locking exception : {}", exception.getMessage(), exception); } else if (exception instanceof FlowableException && ((FlowableException) exception).isReduceLogLevel()) { // reduce log level, because this may have been caused because of job deletion due to cancelActiviti="true" LOGGER.info("Error while closing command context", exception); } else { LOGGER.error("Error while closing command context", exception); } }
public void initDatabaseType() { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData databaseMetaData = connection.getMetaData(); String databaseProductName = databaseMetaData.getDatabaseProductName(); LOGGER.debug("database product name: '{}'", databaseProductName); databaseType = databaseTypeMappings.getProperty(databaseProductName); if (databaseType == null) { throw new FlowableException("couldn't deduct database type from database product name '" + databaseProductName + "'"); } LOGGER.debug("using database type: {}", databaseType); } catch (SQLException e) { LOGGER.error("Exception while initializing Database connection", e); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOGGER.error("Exception while closing the Database connection", e); } } // Special care for MSSQL, as it has a hard limit of 2000 params per statement (incl bulk statement). // Especially with executions, with 100 as default, this limit is passed. if (DATABASE_TYPE_MSSQL.equals(databaseType)) { maxNrOfStatementsInBulkInsert = DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER; } }
DbSqlSession dbSqlSession = getDbSqlSession(); try { Connection connection = dbSqlSession.getSqlSession().getConnection(); Exception exception = null; byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); if (dbSqlSession.getDbSqlSessionFactory().isMysql()) { DatabaseMetaData databaseMetaData = connection.getMetaData(); int majorVersion = databaseMetaData.getDatabaseMajorVersion(); int minorVersion = databaseMetaData.getDatabaseMinorVersion(); LOGGER.info("Found MySQL: majorVersion={} minorVersion={}", majorVersion, minorVersion); dbUpgradeStep = (DbUpgradeStep) ReflectUtil.instantiate(upgradestepClassName); } catch (FlowableException e) { throw new FlowableException("database update java class '" + upgradestepClassName + "' can't be instantiated: " + e.getMessage(), e); dbUpgradeStep.execute(); } catch (Exception e) { throw new FlowableException("error while executing database update java class '" + upgradestepClassName + "': " + e.getMessage(), e); if (dbSqlSession.getDbSqlSessionFactory().isOracle() && line.startsWith("begin")) { inOraclePlsqlBlock = true; sqlStatement = addSqlStatementPiece(sqlStatement, line); Statement jdbcStatement = connection.createStatement(); try { throw new FlowableException("couldn't " + operation + " db schema: " + exceptionSqlStatement, e);
DbSqlSessionFactory dbSqlSessionFactory = dbSqlSession.getDbSqlSessionFactory(); if (!dbSqlSession.getDbSqlSessionFactory().isTablePrefixIsSchema()) { tableName = prependDatabaseTablePrefix(tableName); connection = dbSqlSession.getSqlSession().getConnection(); DatabaseMetaData databaseMetaData = connection.getMetaData(); ResultSet tables = null; String catalog = dbSqlSession.getConnectionMetadataDefaultCatalog(); if (dbSqlSessionFactory.getDatabaseCatalog() != null && dbSqlSessionFactory.getDatabaseCatalog().length() > 0) { catalog = dbSqlSessionFactory.getDatabaseCatalog(); tables = databaseMetaData.getTables(catalog, schema, tableName, JDBC_METADATA_TABLE_TYPES); return tables.next(); } finally { throw new FlowableException("couldn't check if tables are already present using metadata: " + e.getMessage(), e);
@Override public Session openSession(CommandContext commandContext) { DbSqlSession dbSqlSession = createDbSqlSession(); if (getDatabaseSchema() != null && getDatabaseSchema().length() > 0) { try { dbSqlSession.getSqlSession().getConnection().setSchema(getDatabaseSchema()); } catch (SQLException e) { throw new FlowableException("Could not set database schema on connection", e); } } if (getDatabaseCatalog() != null && getDatabaseCatalog().length() > 0) { try { dbSqlSession.getSqlSession().getConnection().setCatalog(getDatabaseCatalog()); } catch (SQLException e) { throw new FlowableException("Could not set database catalog on connection", e); } } if (dbSqlSession.getSqlSession().getConnection() == null) { throw new FlowableException("Invalid dbSqlSession: no active connection found"); } return dbSqlSession; }
protected void flushRegularInsert(Entity entity, Class<? extends Entity> clazz) { String insertStatement = dbSqlSessionFactory.getInsertStatement(entity); insertStatement = dbSqlSessionFactory.mapStatement(insertStatement); if (insertStatement == null) { throw new FlowableException("no insert statement for " + entity.getClass() + " in the ibatis mapping files"); } LOGGER.debug("inserting: {}", entity); sqlSession.insert(insertStatement, entity); // See https://activiti.atlassian.net/browse/ACT-1290 if (entity instanceof HasRevision) { incrementRevision(entity); } }
protected void flushBulkInsert(Collection<Entity> entities, Class<? extends Entity> clazz) { String insertStatement = dbSqlSessionFactory.getBulkInsertStatement(clazz); insertStatement = dbSqlSessionFactory.mapStatement(insertStatement); if (insertStatement == null) { throw new FlowableException("no insert statement for " + entities.iterator().next().getClass() + " in the ibatis mapping files"); } Iterator<Entity> entityIterator = entities.iterator(); Boolean hasRevision = null; while (entityIterator.hasNext()) { List<Entity> subList = new ArrayList<>(); int index = 0; while (entityIterator.hasNext() && index < dbSqlSessionFactory.getMaxNrOfStatementsInBulkInsert()) { Entity entity = entityIterator.next(); subList.add(entity); if (hasRevision == null) { hasRevision = entity instanceof HasRevision; } index++; } sqlSession.insert(insertStatement, subList); } if (hasRevision != null && hasRevision) { entityIterator = entities.iterator(); while (entityIterator.hasNext()) { incrementRevision(entityIterator.next()); } } }
protected void flushDeleteEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToDelete) { for (Entity entity : entitiesToDelete) { String deleteStatement = dbSqlSessionFactory.getDeleteStatement(entity.getClass()); deleteStatement = dbSqlSessionFactory.mapStatement(deleteStatement); if (deleteStatement == null) { throw new FlowableException("no delete statement for " + entity.getClass() + " in the ibatis mapping files"); } // It only makes sense to check for optimistic locking exceptions // for objects that actually have a revision if (entity instanceof HasRevision) { int nrOfRowsDeleted = sqlSession.delete(deleteStatement, entity); if (nrOfRowsDeleted == 0) { throw new FlowableOptimisticLockingException(entity + " was updated by another transaction concurrently"); } } else { sqlSession.delete(deleteStatement, entity); } } }
protected void flushUpdates() { for (Entity updatedObject : updatedObjects) { String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject); updateStatement = dbSqlSessionFactory.mapStatement(updateStatement); if (updateStatement == null) { throw new FlowableException("no update statement for " + updatedObject.getClass() + " in the ibatis mapping files"); } LOGGER.debug("updating: {}", updatedObject); int updatedRecords = sqlSession.update(updateStatement, updatedObject); if (updatedRecords == 0) { throw new FlowableOptimisticLockingException(updatedObject + " was updated by another transaction concurrently"); } // See https://activiti.atlassian.net/browse/ACT-1290 if (updatedObject instanceof HasRevision) { ((HasRevision) updatedObject).setRevision(((HasRevision) updatedObject).getRevisionNext()); } } updatedObjects.clear(); }
@Override public Set<Object> keySet() { throw new FlowableException("unsupported operation on configuration beans"); // List<String> beanNames = // Arrays.asList(beanFactory.getBeanDefinitionNames()); // return new HashSet<Object>(beanNames); }
@Override public Collection<Object> values() { throw new FlowableException("unsupported operation on configuration beans"); } }
@Override public Object put(Object key, Object value) { throw new FlowableException("unsupported operation on configuration beans"); }
protected void rethrowExceptionIfNeeded() throws Error { if (exception instanceof Error) { throw (Error) exception; } else if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } else { throw new FlowableException("exception while executing command " + command, exception); } }
@Override public Object remove(Object key) { throw new FlowableException("unsupported operation on configuration beans"); }
@Override public void clear() { throw new FlowableException("can't clear configuration beans"); }
@Override public boolean containsValue(Object value) { throw new FlowableException("can't search values in configuration beans"); }
@Override public Set<Map.Entry<Object, Object>> entrySet() { throw new FlowableException("unsupported operation on configuration beans"); }
@Override public boolean isEmpty() { throw new FlowableException("unsupported operation on configuration beans"); }
@Override public void putAll(Map<? extends Object, ? extends Object> m) { throw new FlowableException("unsupported operation on configuration beans"); }