生活随笔
收集整理的這篇文章主要介紹了
Activiti源码 ProcessEngineConfiguration
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
by yan 20220223
ProcessEngineConfiguration 類圖
public void init() {initConfigurators();configuratorsBeforeInit();initHistoryLevel();initExpressionManager();if (usingRelationalDatabase
) {initDataSource();}initAgendaFactory();initHelpers();initVariableTypes();initBeans();initScriptingEngines();initClock();initBusinessCalendarManager();initCommandContextFactory();initTransactionContextFactory();initCommandExecutors();initServices();initIdGenerator();initBehaviorFactory();initListenerFactory();initBpmnParser();initProcessDefinitionCache();initProcessDefinitionInfoCache();initKnowledgeBaseCache();initJobHandlers();initJobManager();initAsyncExecutor();initTransactionFactory();if (usingRelationalDatabase
) {initSqlSessionFactory();}initSessionFactories();initDataManagers();initEntityManagers();initHistoryManager();initJpa();initDeployers();initDelegateInterceptor();initEventHandlers();initFailedJobCommandFactory();initEventDispatcher();initProcessValidator();initDatabaseEventLogging();configuratorsAfterInit();}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().transactionNotSupported();}}public void initCommandInvoker() {if (commandInvoker
== null
) {if (enableVerboseExecutionTreeLogging
) {commandInvoker
= new DebugCommandInvoker();} else {commandInvoker
= new CommandInvoker();}}}public void initCommandInterceptors() {if (commandInterceptors
== null
) {commandInterceptors
= new ArrayList<CommandInterceptor>();if (customPreCommandInterceptors
!= null
) {commandInterceptors
.addAll(customPreCommandInterceptors
);}commandInterceptors
.addAll(getDefaultCommandInterceptors());if (customPostCommandInterceptors
!= null
) {commandInterceptors
.addAll(customPostCommandInterceptors
);}commandInterceptors
.add(commandInvoker
);}}public Collection
<? extends CommandInterceptor> getDefaultCommandInterceptors() {List
<CommandInterceptor> interceptors
= new ArrayList<CommandInterceptor>();interceptors
.add(new LogInterceptor());CommandInterceptor transactionInterceptor
= createTransactionInterceptor();if (transactionInterceptor
!= null
) {interceptors
.add(transactionInterceptor
);}if (commandContextFactory
!= null
) {interceptors
.add(new CommandContextInterceptor(commandContextFactory
, this));}if (transactionContextFactory
!= null
) {interceptors
.add(new TransactionContextInterceptor(transactionContextFactory
));}return interceptors
;}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 ActivitiException("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 initDataSource() {if (dataSource
== null
) {if (dataSourceJndiName
!= null
) {try {dataSource
= (DataSource
) new InitialContext().lookup(dataSourceJndiName
);} catch (Exception e
) {throw new ActivitiException("couldn't lookup datasource from " + dataSourceJndiName
+ ": " + e
.getMessage(), e
);}} else if (jdbcUrl
!= null
) {if ((jdbcDriver
== null
) || (jdbcUsername
== null
)) {throw new ActivitiException("DataSource or JDBC properties have to be specified in a process engine configuration");}log
.debug("initializing datasource to db: {}", jdbcUrl
);PooledDataSource pooledDataSource
= new PooledDataSource(ReflectUtil
.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 (dataSource
instanceof PooledDataSource) {((PooledDataSource
) dataSource
).forceCloseAll();}}if (databaseType
== null
) {initDatabaseType();}}public void initTransactionFactory() {if (transactionFactory
== null
) {if (transactionsExternallyManaged
) {transactionFactory
= new ManagedTransactionFactory();} 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
);properties
.put("limitBefore" , "");properties
.put("limitAfter" , "");properties
.put("limitBetween" , "");properties
.put("limitOuterJoinBetween" , "");properties
.put("limitBeforeNativeQuery" , "");properties
.put("orderBy" , "order by ${orderByColumns}");properties
.put("blobType" , "BLOB");properties
.put("boolValue" , "TRUE");if (databaseType
!= null
) {properties
.load(getResourceAsStream("org/activiti/db/properties/"+databaseType
+".properties"));}Configuration configuration
= initMybatisConfiguration(environment
, reader
, properties
);sqlSessionFactory
= new DefaultSqlSessionFactory(configuration
);} catch (Exception e
) {throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e
.getMessage(), e
);} finally {IoUtil
.closeSilently(inputStream
);}}}
數(shù)據(jù)源相關(guān)
Mybatis SqlSessionFactoryTransactionFactory、 datasource 構(gòu)建過程:
transactionFactory+dataSource -》Environment+properties -》Configuration-》SqlSessionFactory
Activiti DbSqlSession、DbSqlSessionFactory:
SqlSessionFactory -》DbSqlSessionFactory-》DbSqlSession-》Session
initSqlSessionFactory
以下為Activiti 構(gòu)造 initSqlSessionFactory時,完成Mybatis 的 DefaultSqlSessionFactory的過程。
總結(jié)
以上是生活随笔為你收集整理的Activiti源码 ProcessEngineConfiguration的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。