/** * 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.builder;
public String getCurrentNamespace(){ return currentNamespace; }
publicvoidsetCurrentNamespace(String currentNamespace){ if (currentNamespace == null) { thrownew BuilderException("The mapper element requires a namespace attribute to be specified."); }
if (this.currentNamespace != null && !this.currentNamespace.equals(currentNamespace)) { thrownew BuilderException("Wrong namespace. Expected '" + this.currentNamespace + "' but found '" + currentNamespace + "'."); }
this.currentNamespace = currentNamespace; }
// 获取当前mapper 中的 namespace.methodName public String applyCurrentNamespace(String base, boolean isReference){ if (base == null) { returnnull; } if (isReference) { // is it qualified with any namespace yet? if (base.contains(".")) { return base; } } else { // is it qualified with this namespace yet? if (base.startsWith(currentNamespace + ".")) { return base; } if (base.contains(".")) { thrownew BuilderException("Dots are not allowed in element names, please remove it from " + base); } } return currentNamespace + "." + base; }
// 替换当前保存的 缓存信息; 如果替换失败,将抛出异常 public Cache useCacheRef(String namespace){ if (namespace == null) { thrownew BuilderException("cache-ref element requires a namespace attribute."); } try { // 默认缓存信息无法解析 unresolvedCacheRef = true; // 获取 namespace 对应的缓存 Cache cache = configuration.getCache(namespace); // 如果没有获取缓存则抛出异常 if (cache == null) { thrownew IncompleteElementException("No cache for namespace '" + namespace + "' could be found."); } currentCache = cache; unresolvedCacheRef = false; return cache; } catch (IllegalArgumentException e) { thrownew IncompleteElementException("No cache for namespace '" + namespace + "' could be found.", e); } }