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


Java PropertyParser.parse方法代码示例

本文整理汇总了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);
    }
  }
}
 
开发者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: 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

示例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);
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:13,代码来源:XMLIncludeTransformer.java

示例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;
}
 
开发者ID:mybatis,项目名称:migrations,代码行数:12,代码来源:MigrationReader.java

示例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);
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:11,代码来源:XMLIncludeTransformer.java

示例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;
  }
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:33,代码来源:XMLIncludeTransformer.java

示例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));
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:47,代码来源:XMLIncludeTransformer.java

示例11: replacePlaceholder

import org.apache.ibatis.parsing.PropertyParser; //导入方法依赖的package包/类
private String replacePlaceholder(String sql) {
  return PropertyParser.parse(sql, configuration.getVariables());
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:4,代码来源:ProviderSqlSource.java


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