本文整理汇总了Java中org.apache.ibatis.parsing.PropertyParser类的典型用法代码示例。如果您正苦于以下问题:Java PropertyParser类的具体用法?Java PropertyParser怎么用?Java PropertyParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyParser类属于org.apache.ibatis.parsing包,在下文中一共展示了PropertyParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createSqlSource
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
// issue #3
if (script.startsWith("<script>")) {
XPathParser parser = new XPathParser(script, false, configuration.getVariables(), new XMLMapperEntityResolver());
return createSqlSource(configuration, parser.evalNode("/script"), parameterType);
} else {
// issue #127
script = PropertyParser.parse(script, configuration.getVariables());
TextSqlNode textSqlNode = new TextSqlNode(script);
if (textSqlNode.isDynamic()) {
return new DynamicSqlSource(configuration, textSqlNode);
} else {
return new RawSqlSource(configuration, script, parameterType);
}
}
}
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:XMLLanguageDriver.java
示例2: getVariablesContext
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
/**
* Read placholders and their values from include node definition.
* @param node Include node instance
* @param inheritedVariablesContext Current context used for replace variables in new variables values
* @return variables context from include instance (no inherited values)
*/
private Properties getVariablesContext(Node node, Properties inheritedVariablesContext) {
Properties variablesContext = new Properties();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
String name = getStringAttribute(n, "name");
String value = getStringAttribute(n, "value");
// Replace variables inside
value = PropertyParser.parse(value, inheritedVariablesContext);
// Push new value
Object originalValue = variablesContext.put(name, value);
if (originalValue != null) {
throw new BuilderException("Variable " + name + " defined twice in the same include definition");
}
}
}
return variablesContext;
}
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:26,代码来源:XMLIncludeTransformer.java
示例3: createSqlSource
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
// issue #3
if (script.startsWith("<script>")) {
XPathParser parser = new XPathParser(script, false, configuration.getVariables(), new XMLMapperEntityResolver());
return createSqlSource(configuration, parser.evalNode("/script"), parameterType);
} else {
// issue #127
script = PropertyParser.parse(script, configuration.getVariables());
TextSqlNode textSqlNode = new TextSqlNode(script);
//一种是动态,一种是原始
if (textSqlNode.isDynamic()) {
return new DynamicSqlSource(configuration, textSqlNode);
} else {
return new RawSqlSource(configuration, script, parameterType);
}
}
}
开发者ID:shurun19851206,项目名称:mybaties,代码行数:19,代码来源:XMLLanguageDriver.java
示例4: copyTemplate
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
protected static void copyTemplate(Reader templateReader, File toFile, Properties variables) throws IOException {
LineNumberReader reader = new LineNumberReader(templateReader);
try {
PrintWriter writer = new PrintWriter(new FileWriter(toFile));
try {
String line;
while ((line = reader.readLine()) != null) {
line = PropertyParser.parse(line, variables);
writer.println(line);
}
} finally {
writer.close();
}
} finally {
reader.close();
}
}
开发者ID:mybatis,项目名称:migrations,代码行数:18,代码来源:BaseCommand.java
示例5: applyDefaultValueOnXmlConfiguration
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyDefaultValueOnXmlConfiguration() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.NULL);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults");
Assertions.assertThat(configuration.getDatabaseId()).isEqualTo("hsql");
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("default");
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:19,代码来源:ConfigurationTest.java
示例6: applyPropertyValueOnXmlConfiguration
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyPropertyValueOnXmlConfiguration() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty("settings.jdbcTypeForNull", JdbcType.CHAR.name());
props.setProperty("db.name", "global_variables_defaults_custom");
props.setProperty("productName.hsql", "Hsql");
props.setProperty("objectFactory.name", "custom");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.CHAR);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults_custom");
Assertions.assertThat(configuration.getDatabaseId()).isNull();
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("custom");
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:23,代码来源:ConfigurationTest.java
示例7: applyDefaultValueOnAnnotationMapper
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyDefaultValueOnAnnotationMapper() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(AnnotationMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(AnnotationMapper.class.getName()));
Assertions.assertThat(cache.getName()).isEqualTo("default");
SqlSession sqlSession = factory.openSession();
try {
AnnotationMapper mapper = sqlSession.getMapper(AnnotationMapper.class);
Assertions.assertThat(mapper.ping()).isEqualTo("Hello");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:26,代码来源:AnnotationMapperTest.java
示例8: convertToProperties
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
private Properties convertToProperties(Property[] properties) {
if (properties.length == 0) {
return null;
}
Properties props = new Properties();
for (Property property : properties) {
props.setProperty(property.name(), PropertyParser.parse(property.value(), configuration.getVariables()));
}
return props;
}
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:11,代码来源:MybatisMapperAnnotationBuilder.java
示例9: test4
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void test4() {
Properties properties = new Properties();
properties.put("today", "now");
properties.put("m", "l");
String content = "today is ${today}, ${m)";
String result = PropertyParser.parse(content, properties);
System.out.println(result);
}
开发者ID:justice-code,项目名称:QiuQiu,代码行数:10,代码来源:OgnlTest.java
示例10: findSqlFragment
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
private Node findSqlFragment(String refid) {
refid = PropertyParser.parse(refid, configuration.getVariables());
refid = builderAssistant.applyCurrentNamespace(refid, true);
try {
//去之前存到内存map的SQL片段中寻找
XNode nodeToInclude = configuration.getSqlFragments().get(refid);
//clone一下,以防改写?
return nodeToInclude.getNode().cloneNode(true);
} catch (IllegalArgumentException e) {
throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
}
}
开发者ID:shurun19851206,项目名称:mybaties,代码行数:13,代码来源:XMLIncludeTransformer.java
示例11: replaceVariables
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
private void replaceVariables() {
if (variableStatus == VariableStatus.FOUND_POSSIBLE_VARIABLE) {
String lineBufferStr = lineBuffer.toString();
String processed = PropertyParser.parse(lineBufferStr, variables);
if (!lineBufferStr.equals(processed)) {
lineBuffer.setLength(0);
lineBuffer.append(processed);
}
}
variableStatus = VariableStatus.NOTHING;
}
开发者ID:mybatis,项目名称:migrations,代码行数:12,代码来源:MigrationReader.java
示例12: convertToProperties
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
private Properties convertToProperties(Property[] properties) {
if (properties.length == 0) {
return null;
}
Properties props = new Properties();
for (Property property : properties) {
props.setProperty(property.name(),
PropertyParser.parse(property.value(), configuration.getVariables()));
}
return props;
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:12,代码来源:MapperAnnotationBuilder.java
示例13: applyIncludes
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
/**
* Recursively apply includes through all SQL fragments.
* @param source Include node in DOM tree
* @param variablesContext Current context for static variables with values
*/
private void applyIncludes(Node source, final Properties variablesContext, boolean included) {
if (source.getNodeName().equals("include")) {
Node toInclude = findSqlFragment(getStringAttribute(source, "refid"), variablesContext);
Properties toIncludeContext = getVariablesContext(source, variablesContext);
applyIncludes(toInclude, toIncludeContext, true);
if (toInclude.getOwnerDocument() != source.getOwnerDocument()) {
toInclude = source.getOwnerDocument().importNode(toInclude, true);
}
source.getParentNode().replaceChild(toInclude, source);
while (toInclude.hasChildNodes()) {
toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude);
}
toInclude.getParentNode().removeChild(toInclude);
} else if (source.getNodeType() == Node.ELEMENT_NODE) {
if (included && !variablesContext.isEmpty()) {
// replace variables in attribute values
NamedNodeMap attributes = source.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node attr = attributes.item(i);
attr.setNodeValue(PropertyParser.parse(attr.getNodeValue(), variablesContext));
}
}
NodeList children = source.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
applyIncludes(children.item(i), variablesContext, included);
}
} else if (included && source.getNodeType() == Node.TEXT_NODE
&& !variablesContext.isEmpty()) {
// replace variables in text node
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:38,代码来源:XMLIncludeTransformer.java
示例14: findSqlFragment
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
private Node findSqlFragment(String refid, Properties variables) {
refid = PropertyParser.parse(refid, variables);
refid = builderAssistant.applyCurrentNamespace(refid, true);
try {
XNode nodeToInclude = configuration.getSqlFragments().get(refid);
return nodeToInclude.getNode().cloneNode(true);
} catch (IllegalArgumentException e) {
throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:11,代码来源:XMLIncludeTransformer.java
示例15: getVariablesContext
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
/**
* Read placeholders and their values from include node definition.
* @param node Include node instance
* @param inheritedVariablesContext Current context used for replace variables in new variables values
* @return variables context from include instance (no inherited values)
*/
private Properties getVariablesContext(Node node, Properties inheritedVariablesContext) {
Map<String, String> declaredProperties = null;
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
String name = getStringAttribute(n, "name");
// Replace variables inside
String value = PropertyParser.parse(getStringAttribute(n, "value"), inheritedVariablesContext);
if (declaredProperties == null) {
declaredProperties = new HashMap<String, String>();
}
if (declaredProperties.put(name, value) != null) {
throw new BuilderException("Variable " + name + " defined twice in the same include definition");
}
}
}
if (declaredProperties == null) {
return inheritedVariablesContext;
} else {
Properties newProperties = new Properties();
newProperties.putAll(inheritedVariablesContext);
newProperties.putAll(declaredProperties);
return newProperties;
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:33,代码来源:XMLIncludeTransformer.java
示例16: applyDefaultValueWhenCustomizeDefaultValueSeparator
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyDefaultValueWhenCustomizeDefaultValueSeparator() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty(PropertyParser.KEY_DEFAULT_VALUE_SEPARATOR, "?:");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config-custom-separator.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(CustomDefaultValueSeparatorMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(CustomDefaultValueSeparatorMapper.class.getName()));
Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.NULL);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults");
Assertions.assertThat(configuration.getDatabaseId()).isEqualTo("hsql");
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("default");
Assertions.assertThat(cache.getName()).isEqualTo("default");
SqlSession sqlSession = factory.openSession();
try {
CustomDefaultValueSeparatorMapper mapper = sqlSession.getMapper(CustomDefaultValueSeparatorMapper.class);
Assertions.assertThat(mapper.selectValue(null)).isEqualTo("default");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:32,代码来源:CustomizationTest.java
示例17: applyPropertyValueWhenCustomizeDefaultValueSeparator
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyPropertyValueWhenCustomizeDefaultValueSeparator() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty(PropertyParser.KEY_DEFAULT_VALUE_SEPARATOR, "?:");
props.setProperty("settings:jdbcTypeForNull", JdbcType.CHAR.name());
props.setProperty("db:name", "global_variables_defaults_custom");
props.setProperty("productName:hsql", "Hsql");
props.setProperty("objectFactory:name", "customObjectFactory");
props.setProperty("cache:name", "customCache");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config-custom-separator.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(CustomDefaultValueSeparatorMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(CustomDefaultValueSeparatorMapper.class.getName()));
Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.CHAR);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults_custom");
Assertions.assertThat(configuration.getDatabaseId()).isNull();
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("customObjectFactory");
Assertions.assertThat(cache.getName()).isEqualTo("customCache");
SqlSession sqlSession = factory.openSession();
try {
CustomDefaultValueSeparatorMapper mapper = sqlSession.getMapper(CustomDefaultValueSeparatorMapper.class);
Assertions.assertThat(mapper.selectValue("3333")).isEqualTo("3333");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:37,代码来源:CustomizationTest.java
示例18: applyPropertyValueOnAnnotationMapper
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyPropertyValueOnAnnotationMapper() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty("ping.sql", "SELECT 'Hi' FROM INFORMATION_SCHEMA.SYSTEM_USERS");
props.setProperty("cache.name", "custom");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(AnnotationMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(AnnotationMapper.class.getName()));
Assertions.assertThat(cache.getName()).isEqualTo("custom");
SqlSession sqlSession = factory.openSession();
try {
AnnotationMapper mapper = sqlSession.getMapper(AnnotationMapper.class);
Assertions.assertThat(mapper.ping()).isEqualTo("Hi");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:28,代码来源:AnnotationMapperTest.java
示例19: applyDefaultValueOnXmlMapper
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyDefaultValueOnXmlMapper() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(XmlMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(XmlMapper.class.getName()));
Assertions.assertThat(cache.getName()).isEqualTo("default");
SqlSession sqlSession = factory.openSession();
try {
XmlMapper mapper = sqlSession.getMapper(XmlMapper.class);
Assertions.assertThat(mapper.ping()).isEqualTo("Hello");
Assertions.assertThat(mapper.selectOne()).isEqualTo("1");
Assertions.assertThat(mapper.selectFromVariable()).isEqualTo("9999");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:28,代码来源:XmlMapperTest.java
示例20: applyPropertyValueOnXmlMapper
import org.apache.ibatis.parsing.PropertyParser; //导入依赖的package包/类
@Test
public void applyPropertyValueOnXmlMapper() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty("ping.sql", "SELECT 'Hi' FROM INFORMATION_SCHEMA.SYSTEM_USERS");
props.setProperty("cache.name", "custom");
props.setProperty("select.columns", "'5555'");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(XmlMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(XmlMapper.class.getName()));
Assertions.assertThat(cache.getName()).isEqualTo("custom");
SqlSession sqlSession = factory.openSession();
try {
XmlMapper mapper = sqlSession.getMapper(XmlMapper.class);
Assertions.assertThat(mapper.ping()).isEqualTo("Hi");
Assertions.assertThat(mapper.selectOne()).isEqualTo("1");
Assertions.assertThat(mapper.selectFromVariable()).isEqualTo("5555");
} finally {
sqlSession.close();
}
}
开发者ID:mybatis,项目名称:mybatis-3,代码行数:31,代码来源:XmlMapperTest.java
注:本文中的org.apache.ibatis.parsing.PropertyParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论