当前位置: 首页>>代码示例>>Java>>正文


Java XMLMapperBuilder.parse方法代码示例

本文整理汇总了Java中org.apache.ibatis.builder.xml.XMLMapperBuilder.parse方法的典型用法代码示例。如果您正苦于以下问题:Java XMLMapperBuilder.parse方法的具体用法?Java XMLMapperBuilder.parse怎么用?Java XMLMapperBuilder.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.builder.xml.XMLMapperBuilder的用法示例。


在下文中一共展示了XMLMapperBuilder.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadXmlResource

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
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";
    InputStream inputStream = null;
    try {
      inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
    } catch (IOException e) {
      // ignore, resource is not required
    }
    if (inputStream != null) {
      XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
      xmlParser.parse();
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:19,代码来源:MapperAnnotationBuilder.java

示例2: mappedStatementWithOptions

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
@Test
public void mappedStatementWithOptions() throws Exception {
  Configuration configuration = new Configuration();
  String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
  builder.parse();

  MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptions");
  assertThat(mappedStatement.getFetchSize(), is(200));
  assertThat(mappedStatement.getTimeout(), is(10));
  assertThat(mappedStatement.getStatementType(), is(StatementType.PREPARED));
  assertThat(mappedStatement.getResultSetType(), is(ResultSetType.SCROLL_SENSITIVE));
  assertThat(mappedStatement.isFlushCacheRequired(), is(false));
  assertThat(mappedStatement.isUseCache(), is(false));

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:XmlMapperBuilderTest.java

示例3: addSqlMappings

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
private static void addSqlMappings(Configuration conf, String mapperFilePath) {
	InputStream is = null;
	try {
		//is = new FileInputStream(mapperFilePath);
		is = Resources.getResourceAsStream(mapperFilePath);
		XMLMapperBuilder xmlParser = new XMLMapperBuilder(is, conf, "mapper.xml", conf.getSqlFragments());
		xmlParser.parse();
	} catch (IOException ex) {
		ex.printStackTrace();
	} finally {
		if(is != null){
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:19,代码来源:MyBatisTest.java

示例4: addSqlMappings

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
private static void addSqlMappings(Configuration conf, String mapperFilePath) {
	InputStream is = null;
	try {
		//is = new FileInputStream(mapperFilePath);
		is = Resources.getResourceAsStream(mapperFilePath);
		XMLMapperBuilder xmlParser = new XMLMapperBuilder(is, conf, mapperFilePath, conf.getSqlFragments());
		xmlParser.parse();
	} catch (IOException ex) {
		ex.printStackTrace();
	} finally {
		if(is != null){
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:19,代码来源:MyBatisTest2.java

示例5: loadXmlResource

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
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";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
        } catch (IOException e) {
            // ignore, resource is not required
        }
        if (inputStream != null) {
            XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
            xmlParser.parse();
        }
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:19,代码来源:MybatisMapperAnnotationBuilder.java

示例6: mapperElement

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:26,代码来源:MybatisXMLConfigBuilder.java

示例7: refresh

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
/**
 * TODO 刷新
 *
 * @param inputStream
 * @param resource
 * @param configuration
 * @throws NestedIOException
 */
public static void refresh(java.io.InputStream inputStream,
						   String resource, Configuration configuration)
		throws NestedIOException {

	try {
		XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(
				inputStream, configuration, resource,
				configuration.getSqlFragments());
		xmlMapperBuilder.parse();
	} catch (Exception e) {
		throw new NestedIOException("Failed to parse mapping resource: '"
				+ resource + "'", e);
	} finally {
		ErrorContext.instance().reset();
	}

}
 
开发者ID:whatlookingfor,项目名称:spring-boot-sample,代码行数:26,代码来源:SqlSessionFactoryBean.java

示例8: initialize

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
/**
 * 使用DataSource初始化SqlSessionFactory
 * @param ds 数据源
 */
public static void initialize(DataSource ds) {
	TransactionFactory transactionFactory = new MybatisTransactionFactory();
	Environment environment = new Environment("snaker", transactionFactory, ds);
	Configuration configuration = new Configuration(environment);
       configuration.getTypeAliasRegistry().registerAliases(SCAN_PACKAGE, Object.class);
       if (log.isInfoEnabled()) {
       	Map<String, Class<?>> typeAliases = configuration.getTypeAliasRegistry().getTypeAliases();
       	for(Entry<String, Class<?>> entry : typeAliases.entrySet()) {
           	log.info("Scanned class:[name=" + entry.getKey() + ",class=" + entry.getValue().getName() + "]");
       	}
       }
	try {
		for(String resource : resources) {
			InputStream in = Resources.getResourceAsStream(resource);
			XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, resource, configuration.getSqlFragments());
			xmlMapperBuilder.parse();
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		ErrorContext.instance().reset();
	}
	sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
开发者ID:snakerflow,项目名称:snakerflow,代码行数:29,代码来源:MybatisHelper.java

示例9: mappedStatementWithOptions

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
@Test
public void mappedStatementWithOptions() throws Exception {
  Configuration configuration = new Configuration();
  String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
  builder.parse();

  MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptions");
  assertThat(mappedStatement.getFetchSize()).isEqualTo(200);
  assertThat(mappedStatement.getTimeout()).isEqualTo(10);
  assertThat(mappedStatement.getStatementType()).isEqualTo(StatementType.PREPARED);
  assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.SCROLL_SENSITIVE);
  assertThat(mappedStatement.isFlushCacheRequired()).isFalse();
  assertThat(mappedStatement.isUseCache()).isFalse();
  inputStream.close();
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:18,代码来源:XmlMapperBuilderTest.java

示例10: refresh

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
/**
 * 刷新mapper
 *
 * @throws Exception
 */
@SuppressWarnings("rawtypes")
private void refresh(Resource resource) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    this.configuration = sqlSessionFactory.getConfiguration();
    boolean isSupper = configuration.getClass().getSuperclass() == Configuration.class;
    try {
        Field loadedResourcesField = isSupper ? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
                : configuration.getClass().getDeclaredField("loadedResources");
        loadedResourcesField.setAccessible(true);
        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");
        Field field = MapperRegistry.class.getDeclaredField("knownMappers");
        field.setAccessible(true);
        Map mapConfig = (Map) field.get(configuration.getMapperRegistry());
        mapConfig.remove(Resources.classForName(namespace));
        loadedResourcesSet.remove(resource.toString());
        configuration.getCacheNames().remove(namespace);
        cleanParameterMap(context.evalNodes("/mapper/parameterMap"), namespace);
        cleanResultMap(context.evalNodes("/mapper/resultMap"), namespace);
        cleanKeyGenerators(context.evalNodes("insert|update"), namespace);
        cleanSqlElement(context.evalNodes("/mapper/sql"), namespace);
        XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(),
                sqlSessionFactory.getConfiguration(), // 注入的sql先不进行处理了
                resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments());
        xmlMapperBuilder.parse();
        logger.debug("refresh: '" + resource + "', success!");
    } catch (IOException e) {
        logger.error("Refresh IOException :" + e.getMessage());
    } finally {
        ErrorContext.instance().reset();
    }
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:40,代码来源:MybatisMapperRefresh.java

示例11: shouldSuccessfullyLoadXMLMapperFile

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
@Test
public void shouldSuccessfullyLoadXMLMapperFile() throws Exception {
  Configuration configuration = new Configuration();
  String resource = "org/apache/ibatis/builder/AuthorMapper.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
  builder.parse();
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:XmlMapperBuilderTest.java

示例12: init

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
void init() throws Exception {
	configuration = new Configuration();
	Map<String, InputStream> sqls = MybatisSqlXmlUtils.openInputs(db);
	Set<Map.Entry<String, InputStream>> entries = sqls.entrySet();
	for (Map.Entry<String, InputStream> entry : entries) {
		InputStream in = entry.getValue();
		XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, entry.getKey(),
				configuration.getSqlFragments());
		xmlMapperBuilder.parse();
		in.close();
	}
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:13,代码来源:SqlSessionFactory.java

示例13: reloadXML

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
public void reloadXML() throws Exception {
	SqlSessionFactory factory = context.getBean(SqlSessionFactory.class);
	Configuration configuration = factory.getConfiguration();
	// 移除加载项
	removeConfig(configuration);
	// 重新扫描加载
	for (String basePackage : basePackages) {
		Resource[] resources = getResource(basePackage, XML_RESOURCE_PATTERN);
		if (resources != null) {
			for (int i = 0; i < resources.length; i++) {
				if (resources[i] == null) {
					continue;
				}
				try {
					XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resources[i].getInputStream(),
							configuration, resources[i].toString(), configuration.getSqlFragments());
					xmlMapperBuilder.parse();
				} catch (Exception e) {
					throw new NestedIOException("Failed to parse mapping resource: '" + resources[i] + "'", e);
				} finally {
					ErrorContext.instance().reset();
				}
			}
		}
	}

}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:28,代码来源:MapperLoader.java

示例14: refresh

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
/**
 * 刷新mapper
 *
 * @throws Exception
 */
@SuppressWarnings("rawtypes")
private void refresh(Resource resource) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    this.configuration = sqlSessionFactory.getConfiguration();
    boolean isSupper = configuration.getClass().getSuperclass() == Configuration.class;
    try {
        Field loadedResourcesField = isSupper ? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
                : configuration.getClass().getDeclaredField("loadedResources");
        loadedResourcesField.setAccessible(true);
        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");
        Field field = MapperRegistry.class.getDeclaredField("knownMappers");
        field.setAccessible(true);
        Map mapConfig = (Map) field.get(configuration.getMapperRegistry());
        mapConfig.remove(Resources.classForName(namespace));
        loadedResourcesSet.remove(resource.toString());
        configuration.getCacheNames().remove(namespace);
        cleanParameterMap(context.evalNodes("/mapper/parameterMap"), namespace);
        cleanResultMap(context.evalNodes("/mapper/resultMap"), 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) {
        logger.error("Refresh IOException :" + e.getMessage());
    } finally {
        ErrorContext.instance().reset();
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:40,代码来源:MybatisMapperRefresh.java

示例15: parseCustomMybatisXMLMappers

import org.apache.ibatis.builder.xml.XMLMapperBuilder; //导入方法依赖的package包/类
protected 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;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:11,代码来源:ProcessEngineConfigurationImpl.java


注:本文中的org.apache.ibatis.builder.xml.XMLMapperBuilder.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。