Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mybatis source code analysis [05.Configuration]

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Mybatis configuration class

public class Configuration { //Environment protected Environment environment; //-------Node------ protected boolean safeRowBoundsEnabled = false; protected boolean safeResultHandlerEnabled = true; protected boolean mapUnderscoreToCamelCase = false; protected boolean aggressiveLazyLoading = true; protected boolean multipleResultSetEnabled = true; protected boolean useGeneratedKeys = false; protected boolean useColumnLabel = true; //cache enabled by default protected boolean cacheEnabled = true; protected boolean callSettersOnNulls = false; protected String logPrefix; protected Class configurationFactory; protected final InterceptorChain interceptorChain = new InterceptorChain(); //type handler registry protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry();//type alias registry protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry(); protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry(); //mapped statements exist in Map protected final Map mapedStatements = new Strictly Map ("Mapped Statements collection"); //cache, protected final Map caches = new Strict Map exists in Map ("Caches collection"); //result map, exists in Map protected final Map resultMaps = new Strictly Map ("Result Maps collection"); protected final Map parameterMaps = new StrictMap ("Parameter Maps collection"); protected final Map keyGenerators = new StrictMap ("Key Generators collection"); protected final Set loadedResources = new HashSet(); protected final Map sqlFragments = new StrictMap ("XML fragments parsed from previous mappers"); //incomplete SQL statements protected final Collection completeStatements = new LinkedList(); protected final Collection completeCacheRefs = new LinkedList(); protected final Collection incompleteResultMaps = new LinkedList(); protected final Collection incompleteMethods = new LinkedList(); /* * A map holds cache-ref relationship. The key is the namespace that * references a cache bound to another namespace and the value is the * namespace which the actual cache is bound to. */ protected final Map cacheRefMap = new HashMap(); public Configuration(Environment environment) { this(); this.environment = environment; } public Configuration() { //Register more type aliases typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class); typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class); typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class); typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class); typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class); typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class); typeAliasRegistry.registerAlias("FIFO", FifoCache.class); typeAliasRegistry.registerAlias("LRU", LruCache.class); typeAliasRegistry.registerAlias("SOFT", SoftCache.class); typeAliasRegistry.registerAlias("WEAK", WeakCache.class); typeAliasRegistry.registerAlias("DB_VENDOR", VendorDatabaseIdProvider.class); typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class); typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class); typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class); typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class); typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class); typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class); typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class); typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class); typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class); typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class); typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class); languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class); languageRegistry.register(RawLanguageDriver.class); }}

The Configuration class has the ability to generate actuators

//generate executor public Executor newExecutor(Transaction transaction, ExecutorType executorType) { executorType = executorType == null ? defaultExecutorType : executorType; executorType = executorType == null ? ExecutorType.SIMPLE : executorType; Executor executor; //Then there are three simple branches, resulting in three types of executors BatchExecutive/ReuseExecutive/SimpleExecutive if (ExecutorType.BATCH == executorType) { executor = new BatchExecutor(this, transaction); } else if (ExecutorType.REUSE == executorType) { executor = new ReuseExecutor(this, transaction); } else { executor = new SimpleExecutor(this, transaction); } //If caching is required, generate another CachingExecutor(default is cached), decorator mode, so default is to return CachingExecutor if (cacheEnabled) { executor = new CachingExecutor(executor); } //call plug-ins here, plug-ins can change the behavior of the Executor executor = (Executor) interceptorChain.pluginAll(executor); return executor; }

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report