List of usage examples for org.apache.ibatis.parsing XNode getNode
public Node getNode()
From source file:com.esofthead.mycollab.core.persistence.VelocityDriverDeclare.java
License:Open Source License
@Override public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterTypeClass) { if (parameterTypeClass == null) { parameterTypeClass = Object.class; }//from w w w .ja v a2s . c o m String templateStr = TOTAL_COUNT_EXPR_MACRO + " " + SELECT_EXPR_MACRO + " " + script.getNode().getTextContent(); return new SQLScriptSource(configuration, templateStr, parameterTypeClass); }
From source file:com.ibatis.common.util.NodeEventWrapper.java
License:Apache License
public void process(XNode context) { try {/*ww w . j a v a 2 s. c o m*/ method.invoke(nodeletTarget, new Object[] { context }); } catch (Exception e) { throw new ParsingException("Error processing node " + context.getNode().getNodeName() + ". Cause: " + e, e); } }
From source file:com.ibatis.sqlmap.engine.builder.DynamicSqlSource.java
License:Apache License
private void parseDynamicTags(XNode node, DynamicParent dynamic, boolean postParseRequired) { NodeList children = node.getNode().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { XNode child = node.newXNode(children.item(i)); String nodeName = child.getNode().getNodeName(); if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) { String data = child.getStringBody(""); SqlText sqlText;/*from w w w . ja v a 2s . co m*/ if (postParseRequired) { sqlText = new SqlText(); sqlText.setPostParseRequired(postParseRequired); sqlText.setText(data); } else { InlineParameterMapParser inlineParameterMapParser = new InlineParameterMapParser(configuration); sqlText = inlineParameterMapParser.parseInlineParameterMap(data); sqlText.setPostParseRequired(postParseRequired); } dynamic.addChild(sqlText); } else if ("include".equals(nodeName)) { String refid = child.getStringAttribute("refid"); XNode includeNode = configParser.getSqlFragment(refid); if (includeNode == null) { String nsrefid = mapParser.applyNamespace(refid); includeNode = configParser.getSqlFragment(nsrefid); if (includeNode == null) { throw new RuntimeException( "Could not find SQL statement to include with refid '" + refid + "'"); } } parseDynamicTags(includeNode, dynamic, postParseRequired); } else { SqlTagHandler handler = SqlTagHandlerFactory.getSqlTagHandler(nodeName); if (handler != null) { SqlTag tag = new SqlTag(); tag.setName(nodeName); tag.setHandler(handler); tag.setPrependAttr(child.getStringAttribute("prepend")); tag.setPropertyAttr(child.getStringAttribute("property")); tag.setRemoveFirstPrepend(child.getStringAttribute("removeFirstPrepend")); tag.setOpenAttr(child.getStringAttribute("open")); tag.setCloseAttr(child.getStringAttribute("close")); tag.setComparePropertyAttr(child.getStringAttribute("compareProperty")); tag.setCompareValueAttr(child.getStringAttribute("compareValue")); tag.setConjunctionAttr(child.getStringAttribute("conjunction")); if (handler instanceof IterateTagHandler && (tag.getPropertyAttr() == null || "".equals(tag.getPropertyAttr()))) { tag.setPropertyAttr("_collection"); } // an iterate ancestor requires a post parse if (dynamic instanceof SqlTag) { SqlTag parentSqlTag = (SqlTag) dynamic; if (parentSqlTag.isPostParseRequired() || tag.getHandler() instanceof IterateTagHandler) { tag.setPostParseRequired(true); } } else if (dynamic instanceof DynamicSql) { if (tag.getHandler() instanceof IterateTagHandler) { tag.setPostParseRequired(true); } } dynamic.addChild(tag); if (child.getNode().hasChildNodes()) { parseDynamicTags(child, tag, tag.isPostParseRequired()); } } } } }
From source file:com.ibatis.sqlmap.engine.builder.SimpleSqlSource.java
License:Apache License
private void parseNodes(XNode node) { StringBuilder sqlBuffer = new StringBuilder(sql); NodeList children = node.getNode().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { XNode child = node.newXNode(children.item(i)); String nodeName = child.getNode().getNodeName(); if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) { String data = child.getStringBody(); InlineParameterMapParser inlineParameterMapParser = new InlineParameterMapParser(configuration); SqlText sqlText = inlineParameterMapParser.parseInlineParameterMap(data); sqlText.setPostParseRequired(false); parameterMappings.addAll(sqlText.getParameterMappings()); sqlBuffer.append(sqlText.getText()); } else if ("include".equals(nodeName)) { String refid = child.getStringAttribute("refid"); XNode includeNode = configParser.getSqlFragment(refid); if (includeNode == null) { String nsrefid = mapParser.applyNamespace(refid); includeNode = configParser.getSqlFragment(nsrefid); if (includeNode == null) { throw new RuntimeException( "Could not find SQL statement to include with refid '" + refid + "'"); }//from ww w . java 2s. co m } parseNodes(includeNode); } } sql = sqlBuffer.toString(); }
From source file:com.ibatis.sqlmap.engine.builder.SqlSourceFactory.java
License:Apache License
private boolean isDynamic(XNode node, boolean isDynamic) { NodeList children = node.getNode().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { XNode child = node.newXNode(children.item(i)); String nodeName = child.getNode().getNodeName(); if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) { } else if ("include".equals(nodeName)) { String refid = child.getStringAttribute("refid"); XNode includeNode = configParser.getSqlFragment(refid); if (includeNode == null) { String nsrefid = mapParser.applyNamespace(refid); includeNode = configParser.getSqlFragment(nsrefid); if (includeNode == null) { throw new RuntimeException( "Could not find SQL statement to include with refid '" + refid + "'"); }//www. j a v a 2 s .com } isDynamic = isDynamic(includeNode, isDynamic); } else { SqlTagHandler handler = SqlTagHandlerFactory.getSqlTagHandler(nodeName); if (handler != null) { isDynamic = true; } } } return isDynamic; }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlStatementParser.java
License:Apache License
public void parseGeneralStatement(XNode context) { // get attributes String id = context.getStringAttribute("id"); String parameterMapName = context.getStringAttribute("parameterMap"); String parameterClassName = context.getStringAttribute("parameterClass"); String resultMapName = context.getStringAttribute("resultMap"); String resultClassName = context.getStringAttribute("resultClass"); String cacheModelName = context.getStringAttribute("cacheModel"); String resultSetType = context.getStringAttribute("resultSetType"); String fetchSize = context.getStringAttribute("fetchSize"); String timeout = context.getStringAttribute("timeout"); // 2.x -- String allowRemapping = context.getStringAttribute("remapResults"); if (context.getStringAttribute("xmlResultName") != null) { throw new UnsupportedOperationException("xmlResultName is not supported by iBATIS 3"); }/*from w w w . jav a 2s . c o m*/ if (mapParser.getConfigParser().isUseStatementNamespaces()) { id = mapParser.applyNamespace(id); } String[] additionalResultMapNames = null; if (resultMapName != null) { additionalResultMapNames = getAllButFirstToken(resultMapName); resultMapName = getFirstToken(resultMapName); resultMapName = mapParser.applyNamespace(resultMapName); for (int i = 0; i < additionalResultMapNames.length; i++) { additionalResultMapNames[i] = mapParser.applyNamespace(additionalResultMapNames[i]); } } String[] additionalResultClassNames = null; if (resultClassName != null) { additionalResultClassNames = getAllButFirstToken(resultClassName); resultClassName = getFirstToken(resultClassName); } Class[] additionalResultClasses = null; if (additionalResultClassNames != null) { additionalResultClasses = new Class[additionalResultClassNames.length]; for (int i = 0; i < additionalResultClassNames.length; i++) { additionalResultClasses[i] = resolveClass(additionalResultClassNames[i]); } } Integer timeoutInt = timeout == null ? null : new Integer(timeout); Integer fetchSizeInt = fetchSize == null ? null : new Integer(fetchSize); // 2.x -- boolean allowRemappingBool = "true".equals(allowRemapping); SqlSource sqlSource = new SqlSourceFactory(mapParser).newSqlSourceIntance(mapParser, context); String nodeName = context.getNode().getNodeName(); SqlCommandType sqlCommandType; try { sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase()); } catch (Exception e) { sqlCommandType = SqlCommandType.UNKNOWN; } MappedStatement.Builder builder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType); builder.useCache(true); if (!"select".equals(context.getNode().getNodeName())) { builder.flushCacheRequired(true); } if (parameterMapName != null) { parameterMapName = mapParser.applyNamespace(parameterMapName); builder.parameterMap(configuration.getParameterMap(parameterMapName)); } else if (parameterClassName != null) { Class parameterClass = resolveClass(parameterClassName); List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>(); if (sqlSource instanceof SimpleSqlSource) { parameterMappings = sqlSource.getBoundSql(null).getParameterMappings(); } ParameterMap.Builder parameterMapBuilder = new ParameterMap.Builder(configuration, id + "-ParameterMap", parameterClass, parameterMappings); builder.parameterMap(parameterMapBuilder.build()); } List<ResultMap> resultMaps = new ArrayList<ResultMap>(); if (resultMapName != null) { resultMaps.add(configuration.getResultMap(resultMapName)); if (additionalResultMapNames != null) { for (String additionalResultMapName : additionalResultMapNames) { resultMaps.add(configuration.getResultMap(additionalResultMapName)); } } } else if (resultClassName != null) { Class resultClass = resolveClass(resultClassName); ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, id + "-ResultMap", resultClass, new ArrayList<ResultMapping>()); resultMaps.add(resultMapBuilder.build()); if (additionalResultClasses != null) { for (Class additionalResultClass : additionalResultClasses) { resultMapBuilder = new ResultMap.Builder(configuration, id + "-ResultMap", additionalResultClass, new ArrayList<ResultMapping>()); resultMaps.add(resultMapBuilder.build()); } } } builder.resultMaps(resultMaps); builder.fetchSize(fetchSizeInt); builder.timeout(timeoutInt); if (cacheModelName != null) { cacheModelName = mapParser.applyNamespace(cacheModelName); Cache cache = configuration.getCache(cacheModelName); builder.cache(cache); } if (resultSetType != null) { builder.resultSetType(ResultSetType.valueOf(resultSetType)); } // allowRemappingBool -- silently ignored findAndParseSelectKey(id, context); configuration.addMappedStatement(builder.build()); }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlStatementParser.java
License:Apache License
private void findAndParseSelectKey(String parentId, XNode context) { try {/* w w w .ja va2 s . c o m*/ boolean runStatementFirst = false; NodeList children = context.getNode().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) { String data = ((CharacterData) child).getData(); if (data.trim().length() > 0) { runStatementFirst = true; } } else if (child.getNodeType() == Node.ELEMENT_NODE && "selectKey".equals(child.getNodeName())) { buildSelectKeyStatement(parentId, context.newXNode(child), runStatementFirst); break; } } } catch (ClassNotFoundException e) { throw new RuntimeException("Error loading result class. Cause: " + e, e); } }
From source file:jetbrick.template.scripting.JetxLanguageDriver.java
License:Apache License
/** * Creates an {@link SqlSource} that will hold the statement read from a mapper xml file. * It is called during startup, when the mapped statement is read from a class or an xml file. * * @param configuration The MyBatis configuration * @param script XNode parsed from a XML file * @param parameterType input parameter type got from a mapper method or specified in the parameterType xml attribute. Can be null. */// ww w . j a v a 2 s . com @Override public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterType) { return createSqlSource(configuration, script.getNode().getTextContent()); }
From source file:org.mybatis.scripting.velocity.Driver.java
License:Apache License
@Override public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterTypeClass) { if (parameterTypeClass == null) { parameterTypeClass = Object.class; }//w w w .j a v a 2s . c o m return new SQLScriptSource(configuration, script.getNode().getTextContent(), parameterTypeClass); }