本文整理汇总了Java中org.apache.ibatis.parsing.PropertyParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyParser.parse方法的具体用法?Java PropertyParser.parse怎么用?Java PropertyParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.parsing.PropertyParser
的用法示例。
在下文中一共展示了PropertyParser.parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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();
}
}
示例5: 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);
}
示例6: 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);
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: 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;
}
}
示例10: 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) {
if (source.getNodeName().equals("include")) {
// new full context for included SQL - contains inherited context and new variables from current include node
Properties fullContext;
String refid = getStringAttribute(source, "refid");
// replace variables in include refid value
refid = PropertyParser.parse(refid, variablesContext);
Node toInclude = findSqlFragment(refid);
Properties newVariablesContext = getVariablesContext(source, variablesContext);
if (!newVariablesContext.isEmpty()) {
// merge contexts
fullContext = new Properties();
fullContext.putAll(variablesContext);
fullContext.putAll(newVariablesContext);
} else {
// no new context - use inherited fully
fullContext = variablesContext;
}
applyIncludes(toInclude, fullContext);
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) {
NodeList children = source.getChildNodes();
for (int i=0; i<children.getLength(); i++) {
applyIncludes(children.item(i), variablesContext);
}
} else if (source.getNodeType() == Node.ATTRIBUTE_NODE && !variablesContext.isEmpty()) {
// replace variables in all attribute values
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
} else if (source.getNodeType() == Node.TEXT_NODE && !variablesContext.isEmpty()) {
// replace variables ins all text nodes
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
}
}
示例11: replacePlaceholder
import org.apache.ibatis.parsing.PropertyParser; //导入方法依赖的package包/类
private String replacePlaceholder(String sql) {
return PropertyParser.parse(sql, configuration.getVariables());
}