Example usage for org.apache.ibatis.parsing XNode getStringAttribute

List of usage examples for org.apache.ibatis.parsing XNode getStringAttribute

Introduction

In this page you can find the example usage for org.apache.ibatis.parsing XNode getStringAttribute.

Prototype

public String getStringAttribute(String name) 

Source Link

Usage

From source file:com.dmm.framework.basedb.apache.ibatis.builder.xml.XMLMapperBuilder.java

License:Apache License

private void sqlElement(List<XNode> list, String requiredDatabaseId) throws Exception {
    for (XNode context : list) {
        String databaseId = context.getStringAttribute("databaseId");
        String id = context.getStringAttribute("id");
        id = builderAssistant.applyCurrentNamespace(id, false);
        if (databaseIdMatchesCurrent(id, databaseId, requiredDatabaseId))
            sqlFragments.put(id, context);
    }/* www . j av  a  2s.c om*/
}

From source file:com.dmm.framework.basedb.apache.ibatis.builder.xml.XMLMapperBuilder.java

License:Apache License

private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) {
    if (requiredDatabaseId != null) {
        if (!requiredDatabaseId.equals(databaseId)) {
            return false;
        }//from   w w  w  . j a  v a  2  s  . c  om
    } else {
        if (databaseId != null) {
            return false;
        }
        // skip this fragment if there is a previous one with a not null
        // databaseId
        if (this.sqlFragments.containsKey(id)) {
            XNode context = this.sqlFragments.get(id);
            if (context.getStringAttribute("databaseId") != null) {
                return false;
            }
        }
    }
    return true;
}

From source file:com.dmm.framework.basedb.apache.ibatis.builder.xml.XMLMapperBuilder.java

License:Apache License

private ResultMapping buildResultMappingFromContext(XNode context, Class<?> resultType,
        ArrayList<ResultFlag> flags) throws Exception {
    String property = context.getStringAttribute("property");
    String column = context.getStringAttribute("column");
    String javaType = context.getStringAttribute("javaType");
    String jdbcType = context.getStringAttribute("jdbcType");
    String nestedSelect = context.getStringAttribute("select");
    String nestedResultMap = context.getStringAttribute("resultMap",
            processNestedResultMappings(context, Collections.<ResultMapping>emptyList()));
    String notNullColumn = context.getStringAttribute("notNullColumn");
    String columnPrefix = context.getStringAttribute("columnPrefix");
    String typeHandler = context.getStringAttribute("typeHandler");
    String resulSet = context.getStringAttribute("resultSet");
    String foreignColumn = context.getStringAttribute("foreignColumn");
    boolean lazy = "lazy".equals(
            context.getStringAttribute("fetchType", configuration.isLazyLoadingEnabled() ? "lazy" : "eager"));
    Class<?> javaTypeClass = resolveClass(javaType);
    @SuppressWarnings("unchecked")
    Class<? extends TypeHandler<?>> typeHandlerClass = (Class<? extends TypeHandler<?>>) resolveClass(
            typeHandler);//from   ww w  .j  ava 2s. c  om
    JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
    return builderAssistant.buildResultMapping(resultType, property, column, javaTypeClass, jdbcTypeEnum,
            nestedSelect, nestedResultMap, notNullColumn, columnPrefix, typeHandlerClass, flags, resulSet,
            foreignColumn, lazy);
}

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;/*  w  ww  .j av  a 2 s. com*/
            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 + "'");
                }/*  w w w . j av  a2 s. c om*/
            }
            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 + "'");
                }//from   www.  j a  v a  2 s . c  o  m
            }
            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.XmlSqlMapConfigParser.java

License:Apache License

@NodeEvent("/sqlMapConfig/properties")
public void sqlMapConfigproperties(XNode context) throws Exception {
    String resource = context.getStringAttribute("resource");
    String url = context.getStringAttribute("url");
    Properties fileVariables;/*from   w w  w . ja v a2s  .c  o  m*/
    if (resource != null) {
        fileVariables = Resources.getResourceAsProperties(resource);
    } else if (url != null) {
        fileVariables = Resources.getUrlAsProperties(url);
    } else {
        throw new RuntimeException("The properties element requires either a resource or a url attribute.");
    }
    // Override file variables with those passed in programmatically
    Properties passedVariables = config.getVariables();
    if (passedVariables != null) {
        fileVariables.putAll(passedVariables);
    }
    config.setVariables(fileVariables);
    parser.setVariables(fileVariables);
}

From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapConfigParser.java

License:Apache License

@NodeEvent("/sqlMapConfig/typeAlias")
public void sqlMapConfigtypeAlias(XNode context) throws Exception {
    String alias = context.getStringAttribute("alias");
    String type = context.getStringAttribute("type");
    config.getTypeAliasRegistry().registerAlias(alias, type);
}

From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapConfigParser.java

License:Apache License

@NodeEvent("/sqlMapConfig/typeHandler")
public void sqlMapConfigtypeHandler(XNode context) throws Exception {
    String jdbcType = context.getStringAttribute("jdbcType");
    String javaType = context.getStringAttribute("javaType");
    String callback = context.getStringAttribute("callback");

    if (javaType != null && callback != null) {
        JdbcType jdbcTypeEnum = JdbcType.valueOf(jdbcType);
        Class javaTypeClass = config.getTypeAliasRegistry().resolveAlias(javaType);
        Class callbackClass = config.getTypeAliasRegistry().resolveAlias(callback);
        Object o = callbackClass.newInstance();
        if (o instanceof TypeHandlerCallback) {
            TypeHandler typeHandler = new TypeHandlerCallbackAdapter((TypeHandlerCallback) o);
            config.getTypeHandlerRegistry().register(javaTypeClass, jdbcTypeEnum, typeHandler);
        }// ww  w.ja  va2s .  c  om
    }
}

From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapConfigParser.java

License:Apache License

@NodeEvent("/sqlMapConfig/transactionManager/end()")
public void sqlMapConfigtransactionManagerend(XNode context) throws Exception {
    String type = context.getStringAttribute("type");
    Class txClass = config.getTypeAliasRegistry().resolveAlias(type);
    boolean commitRequired = context.getBooleanAttribute("commitRequired", false);

    TransactionConfig txConfig = (TransactionConfig) txClass.newInstance();
    txConfig.setDataSource(config.getDataSource());
    txConfig.setProperties(transactionManagerProps);
    txConfig.setForceCommit(commitRequired);
    config.setTransactionManager(new TransactionManager(config, txConfig));
}