/** * Copyright 2009-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.ibatis.session;
protected Properties variables = new Properties(); protected ReflectorFactory reflectorFactory = new DefaultReflectorFactory(); protected ObjectFactory objectFactory = new DefaultObjectFactory(); protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory();
protectedboolean lazyLoadingEnabled = false; protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL
protected String databaseId; /** * Configuration factory class. * Used to create Configuration for loading deserialized unread properties. * * @see <a href='https://code.google.com/p/mybatis/issues/detail?id=300'>Issue 300 (google code)</a> */ protected Class<?> configurationFactory;
protectedfinal MapperRegistry mapperRegistry = new MapperRegistry(this); protectedfinal InterceptorChain interceptorChain = new InterceptorChain(); protectedfinal TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry(); protectedfinal TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry(); protectedfinal LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry();
protectedfinal Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection"); protectedfinal Map<String, Cache> caches = new StrictMap<Cache>("Caches collection"); protectedfinal Map<String, ResultMap> resultMaps = new StrictMap<ResultMap>("Result Maps collection"); protectedfinal Map<String, ParameterMap> parameterMaps = new StrictMap<ParameterMap>("Parameter Maps collection"); protectedfinal Map<String, KeyGenerator> keyGenerators = new StrictMap<KeyGenerator>("Key Generators collection");
protectedfinal Set<String> loadedResources = new HashSet<String>(); protectedfinal Map<String, XNode> sqlFragments = new StrictMap<XNode>("XML fragments parsed from previous mappers");
protectedfinal Collection<XMLStatementBuilder> incompleteStatements = new LinkedList<XMLStatementBuilder>(); protectedfinal Collection<CacheRefResolver> incompleteCacheRefs = new LinkedList<CacheRefResolver>(); protectedfinal Collection<ResultMapResolver> incompleteResultMaps = new LinkedList<ResultMapResolver>(); // Configuration 中待解析的 Method protectedfinal Collection<MethodResolver> incompleteMethods = new LinkedList<MethodResolver>();
/* * 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. */ protectedfinal Map<String, String> cacheRefMap = new HashMap<String, String>();
/* * Parses all the unprocessed statement nodes in the cache. It is recommended * to call this method once all the mappers are added as it provides fail-fast * statement validation. */ protectedvoidbuildAllStatements(){ if (!incompleteResultMaps.isEmpty()) { synchronized (incompleteResultMaps) { // This always throws a BuilderException. incompleteResultMaps.iterator().next().resolve(); } } if (!incompleteCacheRefs.isEmpty()) { synchronized (incompleteCacheRefs) { // This always throws a BuilderException. incompleteCacheRefs.iterator().next().resolveCacheRef(); } } if (!incompleteStatements.isEmpty()) { synchronized (incompleteStatements) { // This always throws a BuilderException. incompleteStatements.iterator().next().parseStatementNode(); } } if (!incompleteMethods.isEmpty()) { synchronized (incompleteMethods) { // This always throws a BuilderException. incompleteMethods.iterator().next().resolve(); } } }
/* * Extracts namespace from fully qualified statement id. * * @param statementId * @return namespace or null when id does not contain period. */ protected String extractNamespace(String statementId){ int lastPeriod = statementId.lastIndexOf('.'); return lastPeriod > 0 ? statementId.substring(0, lastPeriod) : null; }
// Slow but a one time cost. A better solution is welcome. protectedvoidcheckGloballyForDiscriminatedNestedResultMaps(ResultMap rm){ if (rm.hasNestedResultMaps()) { for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) { Object value = entry.getValue(); if (value instanceof ResultMap) { ResultMap entryResultMap = (ResultMap) value; if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) { Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap().values(); if (discriminatedResultMapNames.contains(rm.getId())) { entryResultMap.forceNestedResultMaps(); } } } } } }
// Slow but a one time cost. A better solution is welcome. protectedvoidcheckLocallyForDiscriminatedNestedResultMaps(ResultMap rm){ if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) { for (Map.Entry<String, String> entry : rm.getDiscriminator().getDiscriminatorMap().entrySet()) { String discriminatedResultMapName = entry.getValue(); if (hasResultMap(discriminatedResultMapName)) { ResultMap discriminatedResultMap = resultMaps.get(discriminatedResultMapName); if (discriminatedResultMap.hasNestedResultMaps()) { rm.forceNestedResultMaps(); break; } } } } }
@SuppressWarnings("unchecked") public V put(String key, V value){ if (containsKey(key)) { thrownew IllegalArgumentException(name + " already contains value for " + key); } if (key.contains(".")) { final String shortKey = getShortName(key); if (super.get(shortKey) == null) { super.put(shortKey, value); } else { super.put(shortKey, (V) new Ambiguity(shortKey)); } } returnsuper.put(key, value); }
public V get(Object key){ V value = super.get(key); if (value == null) { thrownew IllegalArgumentException(name + " does not contain value for " + key); } if (value instanceof Ambiguity) { thrownew IllegalArgumentException(((Ambiguity) value).getSubject() + " is ambiguous in " + name + " (try using the full name including the namespace, or rename one of the entries)"); } return value; }