Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Mybatis source code analysis [05.Configuration]

Shulou Source: shulou.com Published: 2022-06-02 19:09:56 10月02日 Update

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

Tags: Caches executors registrants types aliases objects that is factories plug-ins nodes statements branches functions processors more patterns environments results behaviors wrappers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker NVidia Xiaomi MariaDB