Flowable源码地址:https://github.com/flowable/flowable-engine
AbstractEngineConfiguration引擎配置抽象类
public abstract class AbstractEngineConfiguration {
protected final Logger logger = LoggerFactory.getLogger(getClass());
/** 表示“无租户”的租户id */
public static final String NO_TENANT_ID = "";
/**
* 在创建表单引擎时,对照库检查DB模式的版本,如果版本不匹配,则引发异常。
*/
public static final String DB_SCHEMA_UPDATE_FALSE = "false";
public static final String DB_SCHEMA_UPDATE_CREATE = "create";
public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";
/**
* 在创建表单引擎时创建模式,在关闭表单引擎时删除模式.
*/
public static final String DB_SCHEMA_UPDATE_DROP_CREATE = "drop-create";
/**
* 构建流程引擎后,将执行检查,并在必要时更新模式.
*/
public static final String DB_SCHEMA_UPDATE_TRUE = "true";
protected boolean forceCloseMybatisConnectionPool = true;
protected String databaseType;
protected String jdbcDriver = "org.h2.Driver";
protected String jdbcUrl = "jdbc:h2:tcp://localhost/~/flowable";
protected String jdbcUsername = "sa";
protected String jdbcPassword = "";
protected String dataSourceJndiName;
protected int jdbcMaxActiveConnections = 16;
protected int jdbcMaxIdleConnections = 8;
protected int jdbcMaxCheckoutTime;
protected int jdbcMaxWaitTime;
protected boolean jdbcPingEnabled;
protected String jdbcPingQuery;
protected int jdbcPingConnectionNotUsedFor;
protected int jdbcDefaultTransactionIsolationLevel;
protected DataSource dataSource;
protected SchemaManager commonSchemaManager;
protected SchemaManager schemaManager;
protected Command<Void> schemaManagementCmd;
protected String databaseSchemaUpdate = DB_SCHEMA_UPDATE_FALSE;
/**
* 执行数据库模式创建或更新操作时是否使用锁.
*/
protected boolean useLockForDatabaseSchemaUpdate = false;
protected String xmlEncoding = "UTF-8";
// 命令执行器 ///
protected CommandExecutor commandExecutor;
protected Collection<? extends CommandInterceptor> defaultCommandInterceptors;
protected CommandConfig defaultCommandConfig;
protected CommandConfig schemaCommandConfig;
protected CommandContextFactory commandContextFactory;
protected CommandInterceptor commandInvoker;
protected AgendaOperationRunner agendaOperationRunner = (commandContext, runnable) -> runnable.run();
protected List<CommandInterceptor> customPreCommandInterceptors;
protected List<CommandInterceptor> customPostCommandInterceptors;
protected List<CommandInterceptor> commandInterceptors;
protected Map<String, AbstractEngineConfiguration> engineConfigurations = new HashMap<>();
protected Map<String, AbstractServiceConfiguration> serviceConfigurations = new HashMap<>();
protected ClassLoader classLoader;
/**
* 使用Clas.forname方法或者ClassLoader.loadClass方法加载类。查看http://forums.activiti.org/content/reflectutilloadclass-and-custom- classloader
*/
protected boolean useClassForNameClassLoading = true;
protected List<EngineLifecycleListener> engineLifecycleListeners;
// 事件注册 //
protected Map<String, EventRegistryEventConsumer> eventRegistryEventConsumers = new HashMap<>();
// MYBATIS SQL SESSION 工厂 /
protected boolean isDbHistoryUsed = true;
protected DbSqlSessionFactory dbSqlSessionFactory;
protected SqlSessionFactory sqlSessionFactory;
protected TransactionFactory transactionFactory;
protected TransactionContextFactory transactionContextFactory;
/**
* 如果设置为true,则启用批量插入(将sql插入分组在一起)。默认为true.
* 对于某些数据库(例如DB2+z/OS),需要将其设置为false.
*/
protected boolean isBulkInsertEnabled = true;
/**
* 一些数据库对一条sql insert的参数有限制(例如sql Server,最多2000个参数(不等于插入语句))。如果异常很多时,请调整此参数
* 放入到一个大容量插入中,或者如果数据库能够处理,并且有大量数据需要插入,则将其提高.
* 默认情况下:100(mssql server为55,因为它在语句中有2000个参数的硬限制)
*/
protected int maxNrOfStatementsInBulkInsert = 100;
public int DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER = 55; // 目前执行的参数最多(35). 2000 / 35 = 57.
protected String mybatisMappingFile;
protected Set<Class<?>> customMybatisMappers;
protected Set<String> customMybatisXMLMappers;
protected List<Interceptor> customMybatisInterceptors;
protected Set<String> dependentEngineMyBatisXmlMappers;
protected List<MybatisTypeAliasConfigurator> dependentEngineMybatisTypeAliasConfigs;
protected List<MybatisTypeHandlerConfigurator> dependentEngineMybatisTypeHandlerConfigs;
// SESSION 工厂 ///
protected List<SessionFactory> customSessionFactories;
protected Map<Class<?>, SessionFactory> sessionFactories;
protected boolean enableEventDispatcher = true;
protected FlowableEventDispatcher eventDispatcher;
protected List<FlowableEventListener> eventListeners;
protected Map<String, List<FlowableEventListener>> typedEventListeners;
protected List<EventDispatchAction> additionalEventDispatchActions;
protected LoggingListener loggingListener;
protected boolean transactionsExternallyManaged;
/**
* 使用可设置为配置或不配置关系数据库的标志。这对于完全不使用关系数据库的自定义实现非常有用.
*
* 如果为true(默认值),将使用{@link AbstractEngineConfiguration#getDatabaseSchemaUpdate()}值来确定数据库模式需要执行的操作.
*
* 如果为false,则不会进行验证或模式创建。这意味着之前必须“手动”创建数据库模式,但引擎不会验证该模式是否正确。将不使用{@link AbstractEngineConfiguration#getDatabaseSchemaUpdate()}值.
*/
protected boolean usingRelationalDatabase = true;
/**
* 可设置为配置是否使用模式的标志。这对于完全不使用关系数据库的自定义实现非常有用.
* 将{@link#usingRelationalDatabase}设置为true将自动意味着使用模式.
*/
protected boolean usingSchemaMgmt = true;
/**
*允许配置用于process engine所有运行时操作的数据库表前缀。例如,如果指定一个名为“PRE1”的前缀,Flowable将通过'PRE1.ACT_RU_EXECUTION_'表查询执行情况.
*
* 注意:自动数据库模式管理不考虑前缀。如果使用{@link AbstractEngineConfiguration#DB_SCHEMA_UPDATE_CREATE_DROP}或{@link AbstractEngineConfiguration#DB_SCHEMA_UPDATE_TRUE},Flowable将使用默认名称创建数据库表,而不考虑此处配置的前缀.
*/
protected String databaseTablePrefix = "";
/**
* 用于进行通配符搜索的转义字符.
*
* 这将添加到包含LIKE子句查询的末尾。例如:SELECT * FROM table WHERE column LIKE '%\%%' 的转义符'\';
*/
protected String databaseWildcardEscapeCharacter;
/**
* 要使用的数据库目录
*/
protected String databaseCatalog = "";
/**
* 在某些情况下,如果数据库元数据没有正确返回,您需要设置用于表检查/生成的模式, 查看 https://jira.codehaus.org/browse/ACT-1220,
* https://jira.codehaus.org/browse/ACT-1062
*/
protected String databaseSchema;
/**
* 如果定义的databaseTablePrefix是模式名,而不是实际的表名前缀,则设置为true。这与检查是否存在Flowable表(databaseTablePrefix)有关。如果已经考虑了模式,就不会再使用-,为表检查添加前缀将导致错误的表名.
*/
protected boolean tablePrefixIsSchema;
/**
* 如果最新版本的定义可被恢复,则设置为true,忽略可能的父级部署ID值
*/
protected boolean alwaysLookupLatestDefinitionVersion;
/**
* 默认查找应退回到默认租户,则设置为true(默认情况下为空字符串或定义的租户值)
*/
protected boolean fallbackToDefaultTenant;
/**
* 默认租户提供程序,在全局或本地回退到默认租户值为true的情况下,在查找定义时执行
*/
protected DefaultTenantProvider defaultTenantProvider = (tenantId, scope, scopeKey) -> NO_TENANT_ID;
/**
* 启用记录sql语句执行时间的MyBatis插件.
*/
protected boolean enableLogSqlExecutionTime;
protected Properties databaseTypeMappings = getDefaultDatabaseTypeMappings();
/**
* 获取锁时检查之间的持续时间.
*/
protected Duration lockPollRate = Duration.ofSeconds(10);
/**
* 在放弃之前等待DB模式锁定的持续时间.
*/
protected Duration schemaLockWaitTime = Duration.ofMinutes(5);
// 数据管理器 //
protected PropertyDataManager propertyDataManager;
protected ByteArrayDataManager byteArrayDataManager;
protected TableDataManager tableDataManager;
// 实体管理器
protected PropertyEntityManager propertyEntityManager;
protected ByteArrayEntityManager byteArrayEntityManager;
protected List<EngineDeployer> customPreDeployers;
protected List<EngineDeployer> customPostDeployers;
protected List<EngineDeployer> deployers;
// 配置程序
protected boolean enableConfiguratorServiceLoader = true; // 默认情况下启用。在某些环境中,这应该设置为false(例如osgi)
protected List<EngineConfigurator> configurators; // 注入式配置器
protected List<EngineConfigurator> allConfigurators; // 包括自动发现的配置程序
protected EngineConfigurator idmEngineConfigurator;
protected EngineConfigurator eventRegistryConfigurator;
public static final String PRODUCT_NAME_POSTGRES = "PostgreSQL";
public static final String PRODUCT_NAME_CRDB = "CockroachDB";
public static final String DATABASE_TYPE_H2 = "h2";
public static final String DATABASE_TYPE_HSQL = "hsql";
public static final String DATABASE_TYPE_MYSQL = "mysql";
public static final String DATABASE_TYPE_ORACLE = "oracle";
public static final String DATABASE_TYPE_POSTGRES = "postgres";
public static final String DATABASE_TYPE_MSSQL = "mssql";
public static final String DATABASE_TYPE_DB2 = "db2";
public static final String DATABASE_TYPE_COCKROACHDB = "cockroachdb";
public static Properties getDefaultDatabaseTypeMappings() {
Properties databaseTypeMappings = new Properties();
databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);
databaseTypeMappings.setProperty("HSQL Database Engine", DATABASE_TYPE_HSQL);
databaseTypeMappings.setProperty("MySQL", DATABASE_TYPE_MYSQL);
databaseTypeMappings.setProperty("MariaDB", DATABASE_TYPE_MYSQL);
databaseTypeMappings.setProperty("Oracle", DATABASE_TYPE_ORACLE);
databaseTypeMappings.setProperty(PRODUCT_NAME_POSTGRES, DATABASE_TYPE_POSTGRES);
databaseTypeMappings.setProperty("Microsoft SQL Server", DATABASE_TYPE_MSSQL);
databaseTypeMappings.setProperty(DATABASE_TYPE_DB2, DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/NT", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/NT64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2 UDP", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUX", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUX390", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUXX8664", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUXZ64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUXPPC64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/LINUXPPC64LE", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/400 SQL", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/6000", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2 UDB iSeries", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/AIX64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/HPUX", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/HP64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/SUN", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/SUN64", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/PTX", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2/2", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty("DB2 UDB AS400", DATABASE_TYPE_DB2);
databaseTypeMappings.setProperty(PRODUCT_NAME_CRDB, DATABASE_TYPE_COCKROACHDB);
return databaseTypeMappings;
}
protected Map<Object, Object> beans;
protected IdGenerator idGenerator;
protected boolean usePrefixId;
protected Clock clock;
protected ObjectMapper objectMapper;
// 变量
public static final int DEFAULT_GENERIC_MAX_LENGTH_STRING = 4000;
public static final int DEFAULT_ORACLE_MAX_LENGTH_STRING = 2000;
/**
* 定义在数据库中存储字符串变量类型的最大长度。主要用于Oracle NVARCHAR2 2000个字符的限制
*/
protected int maxLengthStringVariableType = -1;
protected void initEngineConfigurations() {
addEngineConfiguration(getEngineCfgKey(), getEngineScopeType(), this);
}
// 数据源
// ///
protected void initDataSource() {
if (dataSource == null) {
if (dataSourceJndiName != null) {
try {
dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
} catch (Exception e) {
throw new FlowableException("couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
}
} else if (jdbcUrl != null) {
if ((jdbcDriver == null) || (jdbcUsername == null)) {
throw new FlowableException("DataSource or JDBC properties have to be specified in a process engine configuration");
}
logger.debug("initializing datasource to db: {}", jdbcUrl);
if (logger.isInfoEnabled()) {
logger.info("Configuring Datasource with following properties (omitted password for security)");
logger.info("datasource driver : {}", jdbcDriver);
logger.info("datasource url : {}", jdbcUrl);
logger.info("datasource user name : {}", jdbcUsername);
}
PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);
if (jdbcMaxActiveConnections > 0) {
pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
}
if (jdbcMaxIdleConnections > 0) {
pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
}
if (jdbcMaxCheckoutTime > 0) {
pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
}
if (jdbcMaxWaitTime > 0) {
pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
}
if (jdbcPingEnabled) {
pooledDataSource.setPoolPingEnabled(true);
if (jdbcPingQuery != null) {
pooledDataSource.setPoolPingQuery(jdbcPingQuery);
}
pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
}
if (jdbcDefaultTransactionIsolationLevel > 0) {
pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
}
dataSource = pooledDataSource;
}
}
if (databaseType == null) {
initDatabaseType();
}
}
public void initDatabaseType() {
Connection connection = null;
try {
connection = dataSource.getConnection();
DatabaseMetaData databaseMetaData = connection.getMetaData();
String databaseProductName = databaseMetaData.getDatabaseProductName();
logger.debug("database product name: '{}'", databaseProductName);
// CRDB不会通过jdbc驱动程序公开这个版本,所以我们需要通过version()获取它.
if (PRODUCT_NAME_POSTGRES.equalsIgnoreCase(databaseProductName)) {
try (PreparedStatement preparedStatement = connection.prepareStatement("select version() as version;");
ResultSet resultSet = preparedStatement.executeQuery()) {
String version = null;
if (resultSet.next()) {
version = resultSet.getString("version");
}
if (StringUtils.isNotEmpty(version) && version.toLowerCase().startsWith(PRODUCT_NAME_CRDB.toLowerCase())) {
databaseProductName = PRODUCT_NAME_CRDB;
logger.info("CockroachDB version '{}' detected", version);
}
}
}
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) {
throw new RuntimeException("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);
}
}
// 特别注意MSSQL,因为每个语句(包括批量语句)有2000个参数的硬限制.
// 特别是在执行时,默认值为100,这一限制就超过了.
if (DATABASE_TYPE_MSSQL.equals(databaseType)) {
maxNrOfStatementsInBulkInsert = DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER;
}
}
public void initSchemaManager() {
if (this.commonSchemaManager == null) {
this.commonSchemaManager = new CommonDbSchemaManager();
}
}
// session 工厂
public void addSessionFactory(SessionFactory sessionFactory) {
sessionFactories.put(sessionFactory.getSessionType(), sessionFactory);
}
public void initCommandContextFactory() {
if (commandContextFactory == null) {
commandContextFactory = new CommandContextFactory();
}
}
public void initTransactionContextFactory() {
if (transactionContextFactory == null) {
transactionContextFactory = new StandaloneMybatisTransactionContextFactory();
}
}
public void initCommandExecutors() {
initDefaultCommandConfig();
initSchemaCommandConfig();
initCommandInvoker();
initCommandInterceptors();
initCommandExecutor();
}
public void initDefaultCommandConfig() {
if (defaultCommandConfig == null) {
defaultCommandConfig = new CommandConfig();
}
}
public void initSchemaCommandConfig() {
if (schemaCommandConfig == null) {
schemaCommandConfig = new CommandConfig();
}
}
public void initCommandInvoker() {
if (commandInvoker == null) {
commandInvoker = new DefaultCommandInvoker();
}
}
public void initCommandInterceptors() {
if (commandInterceptors == null) {
commandInterceptors = new ArrayList<>();
if (customPreCommandInterceptors != null) {
commandInterceptors.addAll(customPreCommandInterceptors);
}
commandInterceptors.addAll(getDefaultCommandInterceptors());
if (customPostCommandInterceptors != null) {
commandInterceptors.addAll(customPostCommandInterceptors);
}
commandInterceptors.add(commandInvoker);
}
}
public Collection<? extends CommandInterceptor> getDefaultCommandInterceptors() {
if (defaultCommandInterceptors == null) {
List<CommandInterceptor> interceptors = new ArrayList<>();
interceptors.add(new LogInterceptor());
if (DATABASE_TYPE_COCKROACHDB.equals(databaseType)) {
interceptors.add(new CrDbRetryInterceptor());
}
CommandInterceptor transactionInterceptor = createTransactionInterceptor();
if (transactionInterceptor != null) {
interceptors.add(transactionInterceptor);
}
if (commandContextFactory != null) {
String engineCfgKey = getEngineCfgKey();
CommandContextInterceptor commandContextInterceptor = new CommandContextInterceptor(commandContextFactory,
classLoader, useClassForNameClassLoading, clock, objectMapper);
engineConfigurations.put(engineCfgKey, this);
commandContextInterceptor.setEngineCfgKey(engineCfgKey);
commandContextInterceptor.setEngineConfigurations(engineConfigurations);
interceptors.add(commandContextInterceptor);
}
if (transactionContextFactory != null) {
interceptors.add(new TransactionContextInterceptor(transactionContextFactory));
}
List<CommandInterceptor> additionalCommandInterceptors = getAdditionalDefaultCommandInterceptors();
if (additionalCommandInterceptors != null) {
interceptors.addAll(additionalCommandInterceptors);
}
defaultCommandInterceptors = interceptors;
}
return defaultCommandInterceptors;
}
public abstract String getEngineCfgKey();
public abstract String getEngineScopeType();
public List<CommandInterceptor> getAdditionalDefaultCommandInterceptors() {
return null;
}
public void initCommandExecutor() {
if (commandExecutor == null) {
CommandInterceptor first = initInterceptorChain(commandInterceptors);
commandExecutor = new CommandExecutorImpl(getDefaultCommandConfig(), first);
}
}
public CommandInterceptor initInterceptorChain(List<CommandInterceptor> chain) {
if (chain == null || chain.isEmpty()) {
throw new FlowableException("invalid command interceptor chain configuration: " + chain);
}
for (int i = 0; i < chain.size() - 1; i++) {
chain.get(i).setNext(chain.get(i + 1));
}
return chain.get(0);
}
public abstract CommandInterceptor createTransactionInterceptor();
public void initBeans() {
if (beans == null) {
beans = new HashMap<>();
}
}
// ID生成器
// /
public void initIdGenerator() {
if (idGenerator == null) {
idGenerator = new StrongUuidGenerator();
}
}
public void initObjectMapper() {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
}
public void initClock() {
if (clock == null) {
clock = new DefaultClockImpl();
}
}
// 数据管理器 ///
public void initDataManagers() {
if (propertyDataManager == null) {
propertyDataManager = new MybatisPropertyDataManager(idGenerator);
}
if (byteArrayDataManager == null) {
byteArrayDataManager = new MybatisByteArrayDataManager(idGenerator);
}
}
// 实体管理器 //
public void initEntityManagers() {
if (propertyEntityManager == null) {
propertyEntityManager = new PropertyEntityManagerImpl(this, propertyDataManager);
}
if (byteArrayEntityManager == null) {
byteArrayEntityManager = new ByteArrayEntityManagerImpl(byteArrayDataManager, getEngineCfgKey(), this::getEventDispatcher);
}
if (tableDataManager == null) {
tableDataManager = new TableDataManagerImpl(this);
}
}
// services
// /
protected void initService(Object service) {
if (service instanceof CommonEngineServiceImpl) {
((CommonEngineServiceImpl) service).setCommandExecutor(commandExecutor);
}
}
// myBatis SqlSessionFactory
//
public void initSessionFactories() {
if (sessionFactories == null) {
sessionFactories = new HashMap<>();
if (usingRelationalDatabase) {
initDbSqlSessionFactory();
}
addSessionFactory(new GenericManagerFactory(EntityCache.class, EntityCacheImpl.class));
if (isLoggingSessionEnabled()) {
if (!sessionFactories.containsKey(LoggingSession.class)) {
LoggingSessionFactory loggingSessionFactory = new LoggingSessionFactory();
loggingSessionFactory.setLoggingListener(loggingListener);
loggingSessionFactory.setObjectMapper(objectMapper);
sessionFactories.put(LoggingSession.class, loggingSessionFactory);
}
}
commandContextFactory.setSessionFactories(sessionFactories);
} else {
if (usingRelationalDatabase) {
initDbSqlSessionFactoryEntitySettings();
}
}
if (customSessionFactories != null) {
for (SessionFactory sessionFactory : customSessionFactories) {
addSessionFactory(sessionFactory);
}
}
}
public void initDbSqlSessionFactory() {
if (dbSqlSessionFactory == null) {
dbSqlSessionFactory = createDbSqlSessionFactory();
}
dbSqlSessionFactory.setDatabaseType(databaseType);
dbSqlSessionFactory.setSqlSessionFactory(sqlSessionFactory);
dbSqlSessionFactory.setDbHistoryUsed(isDbHistoryUsed);
dbSqlSessionFactory.setDatabaseTablePrefix(databaseTablePrefix);
dbSqlSessionFactory.setTablePrefixIsSchema(tablePrefixIsSchema);
dbSqlSessionFactory.setDatabaseCatalog(databaseCatalog);
dbSqlSessionFactory.setDatabaseSchema(databaseSchema);
dbSqlSessionFactory.setMaxNrOfStatementsInBulkInsert(maxNrOfStatementsInBulkInsert);
initDbSqlSessionFactoryEntitySettings();
addSessionFactory(dbSqlSessionFactory);
}
public DbSqlSessionFactory createDbSqlSessionFactory() {
return new DbSqlSessionFactory(usePrefixId);
}
protected abstract void initDbSqlSessionFactoryEntitySettings();
protected void defaultInitDbSqlSessionFactoryEntitySettings(List<Class<? extends Entity>> insertOrder, List<Class<? extends Entity>> deleteOrder) {
if (insertOrder != null) {
for (Class<? extends Entity> clazz : insertOrder) {
dbSqlSessionFactory.getInsertionOrder().add(clazz);
if (isBulkInsertEnabled) {
dbSqlSessionFactory.getBulkInserteableEntityClasses().add(clazz);
}
}
}
if (deleteOrder != null) {
for (Class<? extends Entity> clazz : deleteOrder) {
dbSqlSessionFactory.getDeletionOrder().add(clazz);
}
}
}
public void initTransactionFactory() {
if (transactionFactory == null) {
if (transactionsExternallyManaged) {
transactionFactory = new ManagedTransactionFactory();
Properties properties = new Properties();
properties.put("closeConnection", "false");
this.transactionFactory.setProperties(properties);
} else {
transactionFactory = new JdbcTransactionFactory();
}
}
}
public void initSqlSessionFactory() {
if (sqlSessionFactory == null) {
InputStream inputStream = null;
try {
inputStream = getMyBatisXmlConfigurationStream();
Environment environment = new Environment("default", transactionFactory, dataSource);
Reader reader = new InputStreamReader(inputStream);
Properties properties = new Properties();
properties.put("prefix", databaseTablePrefix);
String wildcardEscapeClause = "";
if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
}
properties.put("wildcardEscapeClause", wildcardEscapeClause);
// set default properties
properties.put("limitBefore", "");
properties.put("limitAfter", "");
properties.put("limitBetween", "");
properties.put("limitBeforeNativeQuery", "");
properties.put("limitAfterNativeQuery", "");
properties.put("blobType", "BLOB");
properties.put("boolValue", "TRUE");
if (databaseType != null) {
properties.load(getResourceAsStream(pathToEngineDbProperties()));
}
Configuration configuration = initMybatisConfiguration(environment, reader, properties);
sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
} catch (Exception e) {
throw new FlowableException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
} finally {
IoUtil.closeSilently(inputStream);
}
}
}
public String pathToEngineDbProperties() {
return "org/flowable/common/db/properties/" + databaseType + ".properties";
}
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
Configuration configuration = parser.getConfiguration();
if (databaseType != null) {
configuration.setDatabaseId(databaseType);
}
configuration.setEnvironment(environment);
initCustomMybatisMappers(configuration);
initMybatisTypeHandlers(configuration);
initCustomMybatisInterceptors(configuration);
if (isEnableLogSqlExecutionTime()) {
initMyBatisLogSqlExecutionTimePlugin(configuration);
}
configuration = parseMybatisConfiguration(parser);
return configuration;
}
public void initCustomMybatisMappers(Configuration configuration) {
if (getCustomMybatisMappers() != null) {
for (Class<?> clazz : getCustomMybatisMappers()) {
configuration.addMapper(clazz);
}
}
}
public void initMybatisTypeHandlers(Configuration configuration) {
// MyBatis当前存在问题映射到Map<String,Object>.
// 它将返回特定于驱动程序的对象.
// 因此,我们正在Object.class和特殊jdbc类型间映射.
// 更多信息 https://github.com/mybatis/mybatis-3/issues/2216
TypeHandlerRegistry handlerRegistry = configuration.getTypeHandlerRegistry();
handlerRegistry.register(Object.class, JdbcType.BOOLEAN, new BooleanTypeHandler());
handlerRegistry.register(Object.class, JdbcType.BIT, new BooleanTypeHandler());
handlerRegistry.register(Object.class, JdbcType.TINYINT, new ByteTypeHandler());
handlerRegistry.register(Object.class, JdbcType.SMALLINT, new ShortTypeHandler());
handlerRegistry.register(Object.class, JdbcType.INTEGER, new IntegerTypeHandler());
handlerRegistry.register(Object.class, JdbcType.FLOAT, new FloatTypeHandler());
handlerRegistry.register(Object.class, JdbcType.DOUBLE, new DoubleTypeHandler());
handlerRegistry.register(Object.class, JdbcType.CHAR, new StringTypeHandler());
handlerRegistry.register(Object.class, JdbcType.CLOB, new ClobTypeHandler());
handlerRegistry.register(Object.class, JdbcType.VARCHAR, new StringTypeHandler());
handlerRegistry.register(Object.class, JdbcType.LONGVARCHAR, new StringTypeHandler());
handlerRegistry.register(Object.class, JdbcType.NVARCHAR, new NStringTypeHandler());
handlerRegistry.register(Object.class, JdbcType.NCHAR, new NStringTypeHandler());
handlerRegistry.register(Object.class, JdbcType.NCLOB, new NClobTypeHandler());
handlerRegistry.register(Object.class, JdbcType.ARRAY, new ArrayTypeHandler());
handlerRegistry.register(Object.class, JdbcType.BIGINT, new LongTypeHandler());
handlerRegistry.register(Object.class, JdbcType.REAL, new BigDecimalTypeHandler());
handlerRegistry.register(Object.class, JdbcType.DECIMAL, new BigDecimalTypeHandler());
handlerRegistry.register(Object.class, JdbcType.NUMERIC, new BigDecimalTypeHandler());
handlerRegistry.register(Object.class, JdbcType.BLOB, new BlobInputStreamTypeHandler());
handlerRegistry.register(Object.class, JdbcType.LONGVARCHAR, new BlobByteObjectArrayTypeHandler());
handlerRegistry.register(Object.class, JdbcType.DATE, new DateOnlyTypeHandler());
handlerRegistry.register(Object.class, JdbcType.TIME, new TimeOnlyTypeHandler());
handlerRegistry.register(Object.class, JdbcType.TIMESTAMP, new DateTypeHandler());
handlerRegistry.register(Object.class, JdbcType.SQLXML, new SqlxmlTypeHandler());
}
public void initCustomMybatisInterceptors(Configuration configuration) {
if (customMybatisInterceptors!=null){
for (Interceptor interceptor :customMybatisInterceptors){
configuration.addInterceptor(interceptor);
}
}
}
public void initMyBatisLogSqlExecutionTimePlugin(Configuration configuration) {
configuration.addInterceptor(new LogSqlExecutionTimePlugin());
}
public Configuration parseMybatisConfiguration(XMLConfigBuilder parser) {
Configuration configuration = parser.parse();
if (dependentEngineMybatisTypeAliasConfigs != null) {
for (MybatisTypeAliasConfigurator typeAliasConfig : dependentEngineMybatisTypeAliasConfigs) {
typeAliasConfig.configure(configuration.getTypeAliasRegistry());
}
}
if (dependentEngineMybatisTypeHandlerConfigs != null) {
for (MybatisTypeHandlerConfigurator typeHandlerConfig : dependentEngineMybatisTypeHandlerConfigs) {
typeHandlerConfig.configure(configuration.getTypeHandlerRegistry());
}
}
parseDependentEngineMybatisXMLMappers(configuration);
parseCustomMybatisXMLMappers(configuration);
return configuration;
}
public void parseCustomMybatisXMLMappers(Configuration configuration) {
if (getCustomMybatisXMLMappers() != null) {
for (String resource : getCustomMybatisXMLMappers()) {
parseMybatisXmlMapping(configuration, resource);
}
}
}
public void parseDependentEngineMybatisXMLMappers(Configuration configuration) {
if (getDependentEngineMyBatisXmlMappers() != null) {
for (String resource : getDependentEngineMyBatisXmlMappers()) {
parseMybatisXmlMapping(configuration, resource);
}
}
}
protected void parseMybatisXmlMapping(Configuration configuration, String resource) {
// 查看 XMLConfigBuilder.mapperElement()
XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments());
mapperParser.parse();
}
protected InputStream getResourceAsStream(String resource) {
ClassLoader classLoader = getClassLoader();
if (classLoader != null) {
return getClassLoader().getResourceAsStream(resource);
} else {
return this.getClass().getClassLoader().getResourceAsStream(resource);
}
}
public void setMybatisMappingFile(String file) {
this.mybatisMappingFile = file;
}
public String getMybatisMappingFile() {
return mybatisMappingFile;
}
public abstract InputStream getMyBatisXmlConfigurationStream();
public void initConfigurators() {
allConfigurators = new ArrayList<>();
allConfigurators.addAll(getEngineSpecificEngineConfigurators());
// 显式添加到配置中的配置程序
if (configurators != null) {
allConfigurators.addAll(configurators);
}
// 通过ServiceLoader自动发现
if (enableConfiguratorServiceLoader) {
ClassLoader classLoader = getClassLoader();
if (classLoader == null) {
classLoader = ReflectUtil.getClassLoader();
}
ServiceLoader<EngineConfigurator> configuratorServiceLoader = ServiceLoader.load(EngineConfigurator.class, classLoader);
int nrOfServiceLoadedConfigurators = 0;
for (EngineConfigurator configurator : configuratorServiceLoader) {
allConfigurators.add(configurator);
nrOfServiceLoadedConfigurators++;
}
if (nrOfServiceLoadedConfigurators > 0) {
logger.info("Found {} auto-discoverable Process Engine Configurator{}", nrOfServiceLoadedConfigurators, nrOfServiceLoadedConfigurators > 1 ? "s" : "");
}
if (!allConfigurators.isEmpty()) {
// 根据优先顺序排列(对依赖型配置器有用)
allConfigurators.sort(new Comparator<EngineConfigurator>() {
@Override
public int compare(EngineConfigurator configurator1, EngineConfigurator configurator2) {
int priority1 = configurator1.getPriority();
int priority2 = configurator2.getPriority();
if (priority1 < priority2) {
return -1;
} else if (priority1 > priority2) {
return 1;
}
return 0;
}
});
// 执行配置程序
logger.info("Found {} Engine Configurators in total:", allConfigurators.size());
for (EngineConfigurator configurator : allConfigurators) {
logger.info("{} (priority:{})", configurator.getClass(), configurator.getPriority());
}
}
}
}
public void close() {
if (forceCloseMybatisConnectionPool && dataSource instanceof PooledDataSource) {
/*
* 当数据源由Flowable引擎创建 (i.e. 它是PooledDataSource的实例),
* 关闭引擎时,需要关闭连接池.
* 请注意,多次调用forceCloseAll()是可以的(与使用多个引擎运行时的情况相同).
*/
((PooledDataSource) dataSource).forceCloseAll();
}
}
protected List<EngineConfigurator> getEngineSpecificEngineConfigurators() {
// 如果需要的话可以被覆盖
return Collections.emptyList();
}
public void configuratorsBeforeInit() {
for (EngineConfigurator configurator : allConfigurators) {
logger.info("Executing beforeInit() of {} (priority:{})", configurator.getClass(), configurator.getPriority());
configurator.beforeInit(this);
}
}
public void configuratorsAfterInit() {
for (EngineConfigurator configurator : allConfigurators) {
logger.info("Executing configure() of {} (priority:{})", configurator.getClass(), configurator.getPriority());
configurator.configure(this);
}
}
public LockManager getLockManager(String lockName) {
return new LockManagerImpl(commandExecutor, lockName, getLockPollRate(), getEngineCfgKey());
}
// getters and setters方法
// //
public abstract String getEngineName();
public ClassLoader getClassLoader() {
return classLoader;
}
public AbstractEngineConfiguration setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
return this;
}
public boolean isUseClassForNameClassLoading() {
return useClassForNameClassLoading;
}
public AbstractEngineConfiguration setUseClassForNameClassLoading(boolean useClassForNameClassLoading) {
this.useClassForNameClassLoading = useClassForNameClassLoading;
return this;
}
public void addEngineLifecycleListener(EngineLifecycleListener engineLifecycleListener) {
if (this.engineLifecycleListeners == null) {
this.engineLifecycleListeners = new ArrayList<>();
}
this.engineLifecycleListeners.add(engineLifecycleListener);
}
public List<EngineLifecycleListener> getEngineLifecycleListeners() {
return engineLifecycleListeners;
}
public AbstractEngineConfiguration setEngineLifecycleListeners(List<EngineLifecycleListener> engineLifecycleListeners) {
this.engineLifecycleListeners = engineLifecycleListeners;
return this;
}
public String getDatabaseType() {
return databaseType;
}
public AbstractEngineConfiguration setDatabaseType(String databaseType) {
this.databaseType = databaseType;
return this;
}
public DataSource getDataSource() {
return dataSource;
}
public AbstractEngineConfiguration setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
return this;
}
public SchemaManager getSchemaManager() {
return schemaManager;
}
public AbstractEngineConfiguration setSchemaManager(SchemaManager schemaManager) {
this.schemaManager = schemaManager;
return this;
}
public SchemaManager getCommonSchemaManager() {
return commonSchemaManager;
}
public AbstractEngineConfiguration setCommonSchemaManager(SchemaManager commonSchemaManager) {
this.commonSchemaManager = commonSchemaManager;
return this;
}
public Command<Void> getSchemaManagementCmd() {
return schemaManagementCmd;
}
public AbstractEngineConfiguration setSchemaManagementCmd(Command<Void> schemaManagementCmd) {
this.schemaManagementCmd = schemaManagementCmd;
return this;
}
public String getJdbcDriver() {
return jdbcDriver;
}
public AbstractEngineConfiguration setJdbcDriver(String jdbcDriver) {
this.jdbcDriver = jdbcDriver;
return this;
}
public String getJdbcUrl() {
return jdbcUrl;
}
public AbstractEngineConfiguration setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
return this;
}
public String getJdbcUsername() {
return jdbcUsername;
}
public AbstractEngineConfiguration setJdbcUsername(String jdbcUsername) {
this.jdbcUsername = jdbcUsername;
return this;
}
public String getJdbcPassword() {
return jdbcPassword;
}
public AbstractEngineConfiguration setJdbcPassword(String jdbcPassword) {
this.jdbcPassword = jdbcPassword;
return this;
}
public int getJdbcMaxActiveConnections() {
return jdbcMaxActiveConnections;
}
public AbstractEngineConfiguration setJdbcMaxActiveConnections(int jdbcMaxActiveConnections) {
this.jdbcMaxActiveConnections = jdbcMaxActiveConnections;
return this;
}
public int getJdbcMaxIdleConnections() {
return jdbcMaxIdleConnections;
}
public AbstractEngineConfiguration setJdbcMaxIdleConnections(int jdbcMaxIdleConnections) {
this.jdbcMaxIdleConnections = jdbcMaxIdleConnections;
return this;
}
public int getJdbcMaxCheckoutTime() {
return jdbcMaxCheckoutTime;
}
public AbstractEngineConfiguration setJdbcMaxCheckoutTime(int jdbcMaxCheckoutTime) {
this.jdbcMaxCheckoutTime = jdbcMaxCheckoutTime;
return this;
}
public int getJdbcMaxWaitTime() {
return jdbcMaxWaitTime;
}
public AbstractEngineConfiguration setJdbcMaxWaitTime(int jdbcMaxWaitTime) {
this.jdbcMaxWaitTime = jdbcMaxWaitTime;
return this;
}
public boolean isJdbcPingEnabled() {
return jdbcPingEnabled;
}
public AbstractEngineConfiguration setJdbcPingEnabled(boolean jdbcPingEnabled) {
this.jdbcPingEnabled = jdbcPingEnabled;
return this;
}
public int getJdbcPingConnectionNotUsedFor() {
return jdbcPingConnectionNotUsedFor;
}
public AbstractEngineConfiguration setJdbcPingConnectionNotUsedFor(int jdbcPingConnectionNotUsedFor) {
this.jdbcPingConnectionNotUsedFor = jdbcPingConnectionNotUsedFor;
return this;
}
public int getJdbcDefaultTransactionIsolationLevel() {
return jdbcDefaultTransactionIsolationLevel;
}
public AbstractEngineConfiguration setJdbcDefaultTransactionIsolationLevel(int jdbcDefaultTransactionIsolationLevel) {
this.jdbcDefaultTransactionIsolationLevel = jdbcDefaultTransactionIsolationLevel;
return this;
}
public String getJdbcPingQuery() {
return jdbcPingQuery;
}
public AbstractEngineConfiguration setJdbcPingQuery(String jdbcPingQuery) {
this.jdbcPingQuery = jdbcPingQuery;
return this;
}
public String getDataSourceJndiName() {
return dataSourceJndiName;
}
public AbstractEngineConfiguration setDataSourceJndiName(String dataSourceJndiName) {
this.dataSourceJndiName = dataSourceJndiName;
return this;
}
public CommandConfig getSchemaCommandConfig() {
return schemaCommandConfig;
}
public AbstractEngineConfiguration setSchemaCommandConfig(CommandConfig schemaCommandConfig) {
this.schemaCommandConfig = schemaCommandConfig;
return this;
}
public boolean isTransactionsExternallyManaged() {
return transactionsExternallyManaged;
}
public AbstractEngineConfiguration setTransactionsExternallyManaged(boolean transactionsExternallyManaged) {
this.transactionsExternallyManaged = transactionsExternallyManaged;
return this;
}
public Map<Object, Object> getBeans() {
return beans;
}
public AbstractEngineConfiguration setBeans(Map<Object, Object> beans) {
this.beans = beans;
return this;
}
public IdGenerator getIdGenerator() {
return idGenerator;
}
public AbstractEngineConfiguration setIdGenerator(IdGenerator idGenerator) {
this.idGenerator = idGenerator;
return this;
}
public boolean isUsePrefixId() {
return usePrefixId;
}
public AbstractEngineConfiguration setUsePrefixId(boolean usePrefixId) {
this.usePrefixId = usePrefixId;
return this;
}
public String getXmlEncoding() {
return xmlEncoding;
}
public AbstractEngineConfiguration setXmlEncoding(String xmlEncoding) {
this.xmlEncoding = xmlEncoding;
return this;
}
public CommandConfig getDefaultCommandConfig() {
return defaultCommandConfig;
}
public AbstractEngineConfiguration setDefaultCommandConfig(CommandConfig defaultCommandConfig) {
this.defaultCommandConfig = defaultCommandConfig;
return this;
}
public CommandExecutor getCommandExecutor() {
return commandExecutor;
}
public AbstractEngineConfiguration setCommandExecutor(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
return this;
}
public CommandContextFactory getCommandContextFactory() {
return commandContextFactory;
}
public AbstractEngineConfiguration setCommandContextFactory(CommandContextFactory commandContextFactory) {
this.commandContextFactory = commandContextFactory;
return this;
}
public CommandInterceptor getCommandInvoker() {
return commandInvoker;
}
public AbstractEngineConfiguration setCommandInvoker(CommandInterceptor commandInvoker) {
this.commandInvoker = commandInvoker;
return this;
}
public AgendaOperationRunner getAgendaOperationRunner() {
return agendaOperationRunner;
}
public AbstractEngineConfiguration setAgendaOperationRunner(AgendaOperationRunner agendaOperationRunner) {
this.agendaOperationRunner = agendaOperationRunner;
return this;
}
public List<CommandInterceptor> getCustomPreCommandInterceptors() {
return customPreCommandInterceptors;
}
public AbstractEngineConfiguration setCustomPreCommandInterceptors(List<CommandInterceptor> customPreCommandInterceptors) {
this.customPreCommandInterceptors = customPreCommandInterceptors;
return this;
}
public List<CommandInterceptor> getCustomPostCommandInterceptors() {
return customPostCommandInterceptors;
}
public AbstractEngineConfiguration setCustomPostCommandInterceptors(List<CommandInterceptor> customPostCommandInterceptors) {
this.customPostCommandInterceptors = customPostCommandInterceptors;
return this;
}
public List<CommandInterceptor> getCommandInterceptors() {
return commandInterceptors;
}
public AbstractEngineConfiguration setCommandInterceptors(List<CommandInterceptor> commandInterceptors) {
this.commandInterceptors = commandInterceptors;
return this;
}
public Map<String, AbstractEngineConfiguration> getEngineConfigurations() {
return engineConfigurations;
}
public AbstractEngineConfiguration setEngineConfigurations(Map<String, AbstractEngineConfiguration> engineConfigurations) {
this.engineConfigurations = engineConfigurations;
return this;
}
public void addEngineConfiguration(String key, String scopeType, AbstractEngineConfiguration engineConfiguration) {
if (engineConfigurations == null) {
engineConfigurations = new HashMap<>();
}
engineConfigurations.put(key, engineConfiguration);
engineConfigurations.put(scopeType, engineConfiguration);
}
public Map<String, AbstractServiceConfiguration> getServiceConfigurations() {
return serviceConfigurations;
}
public AbstractEngineConfiguration setServiceConfigurations(Map<String, AbstractServiceConfiguration> serviceConfigurations) {
this.serviceConfigurations = serviceConfigurations;
return this;
}
public void addServiceConfiguration(String key, AbstractServiceConfiguration serviceConfiguration) {
if (serviceConfigurations == null) {
serviceConfigurations = new HashMap<>();
}
serviceConfigurations.put(key, serviceConfiguration);
}
public Map<String, EventRegistryEventConsumer> getEventRegistryEventConsumers() {
return eventRegistryEventConsumers;
}
public AbstractEngineConfiguration setEventRegistryEventConsumers(Map<String, EventRegistryEventConsumer> eventRegistryEventConsumers) {
this.eventRegistryEventConsumers = eventRegistryEventConsumers;
return this;
}
public void addEventRegistryEventConsumer(String key, EventRegistryEventConsumer eventRegistryEventConsumer) {
if (eventRegistryEventConsumers == null) {
eventRegistryEventConsumers = new HashMap<>();
}
eventRegistryEventConsumers.put(key, eventRegistryEventConsumer);
}
public AbstractEngineConfiguration setDefaultCommandInterceptors(Collection<? extends CommandInterceptor> defaultCommandInterceptors) {
this.defaultCommandInterceptors = defaultCommandInterceptors;
return this;
}
public SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}
public AbstractEngineConfiguration setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
this.sqlSessionFactory = sqlSessionFactory;
return this;
}
public boolean isDbHistoryUsed() {
return isDbHistoryUsed;
}
public AbstractEngineConfiguration setDbHistoryUsed(boolean isDbHistoryUsed) {
this.isDbHistoryUsed = isDbHistoryUsed;
return this;
}
public DbSqlSessionFactory getDbSqlSessionFactory() {
return dbSqlSessionFactory;
}
public AbstractEngineConfiguration setDbSqlSessionFactory(DbSqlSessionFactory dbSqlSessionFactory) {
this.dbSqlSessionFactory = dbSqlSessionFactory;
return this;
}
public TransactionFactory getTransactionFactory() {
return transactionFactory;
}
public AbstractEngineConfiguration setTransactionFactory(TransactionFactory transactionFactory) {
this.transactionFactory = transactionFactory;
return this;
}
public TransactionContextFactory getTransactionContextFactory() {
return transactionContextFactory;
}
public AbstractEngineConfiguration setTransactionContextFactory(TransactionContextFactory transactionContextFactory) {
this.transactionContextFactory = transactionContextFactory;
return this;
}
public int getMaxNrOfStatementsInBulkInsert() {
return maxNrOfStatementsInBulkInsert;
}
public AbstractEngineConfiguration setMaxNrOfStatementsInBulkInsert(int maxNrOfStatementsInBulkInsert) {
this.maxNrOfStatementsInBulkInsert = maxNrOfStatementsInBulkInsert;
return this;
}
public boolean isBulkInsertEnabled() {
return isBulkInsertEnabled;
}
public AbstractEngineConfiguration setBulkInsertEnabled(boolean isBulkInsertEnabled) {
this.isBulkInsertEnabled = isBulkInsertEnabled;
return this;
}
public Set<Class<?>> getCustomMybatisMappers() {
return customMybatisMappers;
}
public AbstractEngineConfiguration setCustomMybatisMappers(Set<Class<?>> customMybatisMappers) {
this.customMybatisMappers = customMybatisMappers;
return this;
}
public Set<String> getCustomMybatisXMLMappers() {
return customMybatisXMLMappers;
}
public AbstractEngineConfiguration setCustomMybatisXMLMappers(Set<String> customMybatisXMLMappers) {
this.customMybatisXMLMappers = customMybatisXMLMappers;
return this;
}
public Set<String> getDependentEngineMyBatisXmlMappers() {
return dependentEngineMyBatisXmlMappers;
}
public AbstractEngineConfiguration setCustomMybatisInterceptors(List<Interceptor> customMybatisInterceptors) {
this.customMybatisInterceptors = customMybatisInterceptors;
return this;
}
public List<Interceptor> getCustomMybatisInterceptors() {
return customMybatisInterceptors;
}
public AbstractEngineConfiguration setDependentEngineMyBatisXmlMappers(Set<String> dependentEngineMyBatisXmlMappers) {
this.dependentEngineMyBatisXmlMappers = dependentEngineMyBatisXmlMappers;
return this;
}
public List<MybatisTypeAliasConfigurator> getDependentEngineMybatisTypeAliasConfigs() {
return dependentEngineMybatisTypeAliasConfigs;
}
public AbstractEngineConfiguration setDependentEngineMybatisTypeAliasConfigs(List<MybatisTypeAliasConfigurator> dependentEngineMybatisTypeAliasConfigs) {
this.dependentEngineMybatisTypeAliasConfigs = dependentEngineMybatisTypeAliasConfigs;
return this;
}
public List<MybatisTypeHandlerConfigurator> getDependentEngineMybatisTypeHandlerConfigs() {
return dependentEngineMybatisTypeHandlerConfigs;
}
public AbstractEngineConfiguration setDependentEngineMybatisTypeHandlerConfigs(List<MybatisTypeHandlerConfigurator> dependentEngineMybatisTypeHandlerConfigs) {
this.dependentEngineMybatisTypeHandlerConfigs = dependentEngineMybatisTypeHandlerConfigs;
return this;
}
public List<SessionFactory> getCustomSessionFactories() {
return customSessionFactories;
}
public AbstractEngineConfiguration addCustomSessionFactory(SessionFactory sessionFactory) {
if (customSessionFactories == null) {
customSessionFactories = new ArrayList<>();
}
customSessionFactories.add(sessionFactory);
return this;
}
public AbstractEngineConfiguration setCustomSessionFactories(List<SessionFactory> customSessionFactories) {
this.customSessionFactories = customSessionFactories;
return this;
}
public boolean isUsingRelationalDatabase() {
return usingRelationalDatabase;
}
public AbstractEngineConfiguration setUsingRelationalDatabase(boolean usingRelationalDatabase) {
this.usingRelationalDatabase = usingRelationalDatabase;
return this;
}
public boolean isUsingSchemaMgmt() {
return usingSchemaMgmt;
}
public AbstractEngineConfiguration setUsingSchemaMgmt(boolean usingSchema) {
this.usingSchemaMgmt = usingSchema;
return this;
}
public String getDatabaseTablePrefix() {
return databaseTablePrefix;
}
public AbstractEngineConfiguration setDatabaseTablePrefix(String databaseTablePrefix) {
this.databaseTablePrefix = databaseTablePrefix;
return this;
}
public String getDatabaseWildcardEscapeCharacter() {
return databaseWildcardEscapeCharacter;
}
public AbstractEngineConfiguration setDatabaseWildcardEscapeCharacter(String databaseWildcardEscapeCharacter) {
this.databaseWildcardEscapeCharacter = databaseWildcardEscapeCharacter;
return this;
}
public String getDatabaseCatalog() {
return databaseCatalog;
}
public AbstractEngineConfiguration setDatabaseCatalog(String databaseCatalog) {
this.databaseCatalog = databaseCatalog;
return this;
}
public String getDatabaseSchema() {
return databaseSchema;
}
public AbstractEngineConfiguration setDatabaseSchema(String databaseSchema) {
this.databaseSchema = databaseSchema;
return this;
}
public boolean isTablePrefixIsSchema() {
return tablePrefixIsSchema;
}
public AbstractEngineConfiguration setTablePrefixIsSchema(boolean tablePrefixIsSchema) {
this.tablePrefixIsSchema = tablePrefixIsSchema;
return this;
}
public boolean isAlwaysLookupLatestDefinitionVersion() {
return alwaysLookupLatestDefinitionVersion;
}
public AbstractEngineConfiguration setAlwaysLookupLatestDefinitionVersion(boolean alwaysLookupLatestDefinitionVersion) {
this.alwaysLookupLatestDefinitionVersion = alwaysLookupLatestDefinitionVersion;
return this;
}
public boolean isFallbackToDefaultTenant() {
return fallbackToDefaultTenant;
}
public AbstractEngineConfiguration setFallbackToDefaultTenant(boolean fallbackToDefaultTenant) {
this.fallbackToDefaultTenant = fallbackToDefaultTenant;
return this;
}
/**
* @return 默认租户的名称
* @废弃方法 使用 {@link AbstractEngineConfiguration#getDefaultTenantProvider()} 替代
*/
@Deprecated
public String getDefaultTenantValue() {
return getDefaultTenantProvider().getDefaultTenant(null, null, null);
}
public AbstractEngineConfiguration setDefaultTenantValue(String defaultTenantValue) {
this.defaultTenantProvider = (tenantId, scope, scopeKey) -> defaultTenantValue;
return this;
}
public DefaultTenantProvider getDefaultTenantProvider() {
return defaultTenantProvider;
}
public AbstractEngineConfiguration setDefaultTenantProvider(DefaultTenantProvider defaultTenantProvider) {
this.defaultTenantProvider = defaultTenantProvider;
return this;
}
public boolean isEnableLogSqlExecutionTime() {
return enableLogSqlExecutionTime;
}
public void setEnableLogSqlExecutionTime(boolean enableLogSqlExecutionTime) {
this.enableLogSqlExecutionTime = enableLogSqlExecutionTime;
}
public Map<Class<?>, SessionFactory> getSessionFactories() {
return sessionFactories;
}
public AbstractEngineConfiguration setSessionFactories(Map<Class<?>, SessionFactory> sessionFactories) {
this.sessionFactories = sessionFactories;
return this;
}
public String getDatabaseSchemaUpdate() {
return databaseSchemaUpdate;
}
public AbstractEngineConfiguration setDatabaseSchemaUpdate(String databaseSchemaUpdate) {
this.databaseSchemaUpdate = databaseSchemaUpdate;
return this;
}
public boolean isUseLockForDatabaseSchemaUpdate() {
return useLockForDatabaseSchemaUpdate;
}
public AbstractEngineConfiguration setUseLockForDatabaseSchemaUpdate(boolean useLockForDatabaseSchemaUpdate) {
this.useLockForDatabaseSchemaUpdate = useLockForDatabaseSchemaUpdate;
return this;
}
public boolean isEnableEventDispatcher() {
return enableEventDispatcher;
}
public AbstractEngineConfiguration setEnableEventDispatcher(boolean enableEventDispatcher) {
this.enableEventDispatcher = enableEventDispatcher;
return this;
}
public FlowableEventDispatcher getEventDispatcher() {
return eventDispatcher;
}
public AbstractEngineConfiguration setEventDispatcher(FlowableEventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
return this;
}
public List<FlowableEventListener> getEventListeners() {
return eventListeners;
}
public AbstractEngineConfiguration setEventListeners(List<FlowableEventListener> eventListeners) {
this.eventListeners = eventListeners;
return this;
}
public Map<String, List<FlowableEventListener>> getTypedEventListeners() {
return typedEventListeners;
}
public AbstractEngineConfiguration setTypedEventListeners(Map<String, List<FlowableEventListener>> typedEventListeners) {
this.typedEventListeners = typedEventListeners;
return this;
}
public List<EventDispatchAction> getAdditionalEventDispatchActions() {
return additionalEventDispatchActions;
}
public AbstractEngineConfiguration setAdditionalEventDispatchActions(List<EventDispatchAction> additionalEventDispatchActions) {
this.additionalEventDispatchActions = additionalEventDispatchActions;
return this;
}
public void initEventDispatcher() {
if (this.eventDispatcher == null) {
this.eventDispatcher = new FlowableEventDispatcherImpl();
}
initAdditionalEventDispatchActions();
this.eventDispatcher.setEnabled(enableEventDispatcher);
initEventListeners();
initTypedEventListeners();
}
protected void initEventListeners() {
if (eventListeners != null) {
for (FlowableEventListener listenerToAdd : eventListeners) {
this.eventDispatcher.addEventListener(listenerToAdd);
}
}
}
protected void initAdditionalEventDispatchActions() {
if (this.additionalEventDispatchActions == null) {
this.additionalEventDispatchActions = new ArrayList<>();
}
}
protected void initTypedEventListeners() {
if (typedEventListeners != null) {
for (Map.Entry<String, List<FlowableEventListener>> listenersToAdd : typedEventListeners.entrySet()) {
// 从给定字符串中提取类型
FlowableEngineEventType[] types = FlowableEngineEventType.getTypesFromString(listenersToAdd.getKey());
for (FlowableEventListener listenerToAdd : listenersToAdd.getValue()) {
this.eventDispatcher.addEventListener(listenerToAdd, types);
}
}
}
}
public boolean isLoggingSessionEnabled() {
return loggingListener != null;
}
public LoggingListener getLoggingListener() {
return loggingListener;
}
public void setLoggingListener(LoggingListener loggingListener) {
this.loggingListener = loggingListener;
}
public Clock getClock() {
return clock;
}
public AbstractEngineConfiguration setClock(Clock clock) {
this.clock = clock;
return this;
}
public ObjectMapper getObjectMapper() {
return objectMapper;
}
public AbstractEngineConfiguration setObjectMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
return this;
}
public int getMaxLengthString() {
if (maxLengthStringVariableType == -1) {
if ("oracle".equalsIgnoreCase(databaseType)) {
return DEFAULT_ORACLE_MAX_LENGTH_STRING;
} else {
return DEFAULT_GENERIC_MAX_LENGTH_STRING;
}
} else {
return maxLengthStringVariableType;
}
}
public int getMaxLengthStringVariableType() {
return maxLengthStringVariableType;
}
public AbstractEngineConfiguration setMaxLengthStringVariableType(int maxLengthStringVariableType) {
this.maxLengthStringVariableType = maxLengthStringVariableType;
return this;
}
public PropertyDataManager getPropertyDataManager() {
return propertyDataManager;
}
public Duration getLockPollRate() {
return lockPollRate;
}
public AbstractEngineConfiguration setLockPollRate(Duration lockPollRate) {
this.lockPollRate = lockPollRate;
return this;
}
public Duration getSchemaLockWaitTime() {
return schemaLockWaitTime;
}
public void setSchemaLockWaitTime(Duration schemaLockWaitTime) {
this.schemaLockWaitTime = schemaLockWaitTime;
}
public AbstractEngineConfiguration setPropertyDataManager(PropertyDataManager propertyDataManager) {
this.propertyDataManager = propertyDataManager;
return this;
}
public PropertyEntityManager getPropertyEntityManager() {
return propertyEntityManager;
}
public AbstractEngineConfiguration setPropertyEntityManager(PropertyEntityManager propertyEntityManager) {
this.propertyEntityManager = propertyEntityManager;
return this;
}
public ByteArrayDataManager getByteArrayDataManager() {
return byteArrayDataManager;
}
public AbstractEngineConfiguration setByteArrayDataManager(ByteArrayDataManager byteArrayDataManager) {
this.byteArrayDataManager = byteArrayDataManager;
return this;
}
public ByteArrayEntityManager getByteArrayEntityManager() {
return byteArrayEntityManager;
}
public AbstractEngineConfiguration setByteArrayEntityManager(ByteArrayEntityManager byteArrayEntityManager) {
this.byteArrayEntityManager = byteArrayEntityManager;
return this;
}
public TableDataManager getTableDataManager() {
return tableDataManager;
}
public AbstractEngineConfiguration setTableDataManager(TableDataManager tableDataManager) {
this.tableDataManager = tableDataManager;
return this;
}
public List<EngineDeployer> getDeployers() {
return deployers;
}
public AbstractEngineConfiguration setDeployers(List<EngineDeployer> deployers) {
this.deployers = deployers;
return this;
}
public List<EngineDeployer> getCustomPreDeployers() {
return customPreDeployers;
}
public AbstractEngineConfiguration setCustomPreDeployers(List<EngineDeployer> customPreDeployers) {
this.customPreDeployers = customPreDeployers;
return this;
}
public List<EngineDeployer> getCustomPostDeployers() {
return customPostDeployers;
}
public AbstractEngineConfiguration setCustomPostDeployers(List<EngineDeployer> customPostDeployers) {
this.customPostDeployers = customPostDeployers;
return this;
}
public boolean isEnableConfiguratorServiceLoader() {
return enableConfiguratorServiceLoader;
}
public AbstractEngineConfiguration setEnableConfiguratorServiceLoader(boolean enableConfiguratorServiceLoader) {
this.enableConfiguratorServiceLoader = enableConfiguratorServiceLoader;
return this;
}
public List<EngineConfigurator> getConfigurators() {
return configurators;
}
public AbstractEngineConfiguration addConfigurator(EngineConfigurator configurator) {
if (configurators == null) {
configurators = new ArrayList<>();
}
configurators.add(configurator);
return this;
}
/**
* @返回所有{@link EngineConfigurator}实例。将仅包含引擎初始化后的值.
* 否则,请使用{@link#getConfigurator()}或{@link#addConfigurator(EngineConfigurator)}方法.
*/
public List<EngineConfigurator> getAllConfigurators() {
return allConfigurators;
}
public AbstractEngineConfiguration setConfigurators(List<EngineConfigurator> configurators) {
this.configurators = configurators;
return this;
}
public EngineConfigurator getIdmEngineConfigurator() {
return idmEngineConfigurator;
}
public AbstractEngineConfiguration setIdmEngineConfigurator(EngineConfigurator idmEngineConfigurator) {
this.idmEngineConfigurator = idmEngineConfigurator;
return this;
}
public EngineConfigurator getEventRegistryConfigurator() {
return eventRegistryConfigurator;
}
public AbstractEngineConfiguration setEventRegistryConfigurator(EngineConfigurator eventRegistryConfigurator) {
this.eventRegistryConfigurator = eventRegistryConfigurator;
return this;
}
public AbstractEngineConfiguration setForceCloseMybatisConnectionPool(boolean forceCloseMybatisConnectionPool) {
this.forceCloseMybatisConnectionPool = forceCloseMybatisConnectionPool;
return this;
}
public boolean isForceCloseMybatisConnectionPool() {
return forceCloseMybatisConnectionPool;
}
}