public MybatisXMLConfigBuilder(Reader reader, String environment, Properties props) { this(new XPathParser(reader, true, props, new XMLMapperEntityResolver()), environment, props); }
public Configuration parseMybatisConfiguration(Configuration configuration, XMLConfigBuilder parser) { return parseCustomMybatisXMLMappers(parser.parse()); }
public Configuration parseCustomMybatisXMLMappers(Configuration configuration) { if (getCustomMybatisXMLMappers() != null) // see XMLConfigBuilder.mapperElement() for (String resource : getCustomMybatisXMLMappers()) { XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments()); mapperParser.parse(); } return configuration; }
Set loadedResourcesSet = ((Set) loadedResourcesField.get(configuration)); XPathParser xPathParser = new XPathParser(resource.getInputStream(), true, configuration.getVariables(), new XMLMapperEntityResolver()); XNode context = xPathParser.evalNode("/mapper"); String namespace = context.getStringAttribute("namespace"); cleanKeyGenerators(context.evalNodes("insert|update"), namespace); cleanSqlElement(context.evalNodes("/mapper/sql"), namespace); XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(), sqlSessionFactory.getConfiguration(), resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments()); xmlMapperBuilder.parse(); logger.debug("refresh: '" + resource + "', success!"); } catch (IOException e) {
private SqlSessionFactory buildSqlSessionFactory() throws IOException { SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder(); Configuration baseConfiguration = new XMLConfigBuilder(configLocation.getInputStream()).parse(); String ibatisConfigXmlLocation = databaseStrategy.getIbatisConfigXmlLocation(); if (isNotBlank(ibatisConfigXmlLocation)) { XMLConfigBuilder builder = new XMLConfigBuilder(new ClassPathResource(ibatisConfigXmlLocation).getInputStream()); // hacky way to "inject" a previous configuration Field configurationField = ReflectionUtils.findField(XMLConfigBuilder.class, "configuration"); ReflectionUtils.makeAccessible(configurationField); ReflectionUtils.setField(configurationField, builder, baseConfiguration); baseConfiguration = builder.parse(); } baseConfiguration.setEnvironment(new Environment(getClass().getSimpleName(), new SpringManagedTransactionFactory(), this.dataSource)); return factoryBuilder.build(baseConfiguration); }
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) { XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties); Configuration configuration = parser.getConfiguration(); if(databaseType != null) { configuration.setDatabaseId(databaseType); } configuration.setEnvironment(environment); initMybatisTypeHandlers(configuration); initCustomMybatisMappers(configuration); configuration = parseMybatisConfiguration(configuration, parser); return configuration; }
private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) { for (XNode context : list) { final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId); try { statementParser.parseStatementNode(); } catch (IncompleteElementException e) { configuration.addIncompleteStatement(statementParser); } } }
private void resultMapElements(List<XNode> list) throws Exception { for (XNode resultMapNode : list) { try { resultMapElement(resultMapNode); } catch (IncompleteElementException e) { // ignore, it will be retried } } }
private void sqlElement(List<XNode> list) throws Exception { if (configuration.getDatabaseId() != null) { sqlElement(list, configuration.getDatabaseId()); } sqlElement(list, null); }
private void parseSelectKeyNodes(String parentId, List<XNode> list, Class<?> parameterTypeClass, LanguageDriver langDriver, String skRequiredDatabaseId) { for (XNode nodeToHandle : list) { String id = parentId + SelectKeyGenerator.SELECT_KEY_SUFFIX; String databaseId = nodeToHandle.getStringAttribute("databaseId"); if (databaseIdMatchesCurrent(id, databaseId, skRequiredDatabaseId)) { parseSelectKeyNode(id, nodeToHandle, parameterTypeClass, langDriver, databaseId); } } }
private void buildStatementFromContext(List<XNode> list) { if (configuration.getDatabaseId() != null) { buildStatementFromContext(list, configuration.getDatabaseId()); } buildStatementFromContext(list, null); }
private LanguageDriver getLanguageDriver(String lang) { Class<?> langClass = null; if (lang != null) { langClass = resolveClass(lang); } return builderAssistant.getLanguageDriver(langClass); }
private void loadXmlResource() { // Spring may not know the real resource name so we check a flag // to prevent loading again a resource twice // this flag is set at XMLMapperBuilder#bindMapperForNamespace if (!configuration.isResourceLoaded("namespace:" + type.getName())) { String xmlResource = type.getName().replace('.', '/') + ".xml"; // #1347 InputStream inputStream = type.getResourceAsStream("/" + xmlResource); if (inputStream == null) { // Search XML mapper that is not in the module but in the classpath. try { inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource); } catch (IOException e2) { // ignore, resource is not required } } if (inputStream != null) { XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName()); xmlParser.parse(); } } }
public MybatisXMLConfigBuilder(InputStream inputStream, String environment, Properties props) { this(new XPathParser(inputStream, true, props, new XMLMapperEntityResolver()), environment, props); }
private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) { for (XNode context : list) { final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId); try { statementParser.parseStatementNode(); } catch (IncompleteElementException e) { configuration.addIncompleteStatement(statementParser); } } }
private void resultMapElements(List<XNode> list) throws Exception { for (XNode resultMapNode : list) { try { resultMapElement(resultMapNode); } catch (IncompleteElementException e) { // ignore, it will be retried } } }
private void sqlElement(List<XNode> list) { if (configuration.getDatabaseId() != null) { sqlElement(list, configuration.getDatabaseId()); } sqlElement(list, null); }
private void mapperElement(XNode parent) throws Exception { /* * 定义集合 用来分类放置mybatis的Mapper与XML 按顺序依次遍历 */ if (parent != null) { //指定在classpath中的mapper文件 Set<String> resources = new HashSet<>(); //指向一个mapper接口 Set<Class<?>> mapperClasses = new HashSet<>(); setResource(parent, resources, mapperClasses); // 依次遍历 首先 resource 然后 mapper for (String resource : resources) { ErrorContext.instance().resource(resource); InputStream inputStream = Resources.getResourceAsStream(resource); //TODO XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments()); mapperParser.parse(); } for (Class<?> mapper : mapperClasses) { //TODO configuration.addMapper(mapper); } } }
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(), configuration, mapperLocation.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); } catch (Exception e) { throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);