Java Code Examples for org.mybatis.generator.api.IntrospectedTable#isConstructorBased()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#isConstructorBased() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AliasResultMapWithoutBLOBsElementGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * addElements: 在当前的parentElement元素中添加别名ReulstMap列元素. <br/>
 *
 * @author Hongbin Yuan			父元素,新的elements将作为子元素添加到该元素
 * @param parentElement
 * @param introspectedTable		当前表的信息
 * @since JDK 1.6
 */
public void addElements(XmlElement parentElement,IntrospectedTable introspectedTable) {
	XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
	
	introspectedTable.getContext().getCommentGenerator().addComment(answer);
	
	answer.addAttribute(new Attribute("id", resultMapId));
	String returnType = null;
	if (isSimple) {
		returnType = introspectedTable.getBaseRecordType();
	} else {
		if (introspectedTable.getRules().generateBaseRecordClass()) {
			returnType = introspectedTable.getBaseRecordType();
		} else {
			returnType = introspectedTable.getPrimaryKeyType();
		}
	}
	answer.addAttribute(new Attribute("type", //$NON-NLS-1$
			returnType));

	if (introspectedTable.isConstructorBased()) {
		addResultMapConstructorElements(answer,introspectedTable);
	} else {
		addResultMapElements(answer,introspectedTable);
	}
	
	parentElement.addElement(answer);
}
 
Example 2
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 生成selectOneByExampleSelective
 * @param introspectedTable
 * @return
 */
private XmlElement generateSelectSelectiveElement(String id, IntrospectedTable introspectedTable, boolean selectOne, boolean byExample) {
    XmlElement selectSelectiveEle = new XmlElement("select");
    commentGenerator.addComment(selectSelectiveEle);

    selectSelectiveEle.addAttribute(new Attribute("id", id));
    // issues#16
    if (introspectedTable.isConstructorBased()) {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", ID_FOR_PROPERTY_BASED_RESULT_MAP));
    } else if (introspectedTable.hasBLOBColumns()) {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
    } else {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
    }
    selectSelectiveEle.addAttribute(new Attribute("parameterType", "map"));

    if (byExample) {
        selectSelectiveEle.addElement(new TextElement("select"));

        if (!selectOne) {
            // issues#20
            XmlElement ifDistinctElement = new XmlElement("if");
            ifDistinctElement.addAttribute(new Attribute("test", "example != null and example.distinct"));
            ifDistinctElement.addElement(new TextElement("distinct"));
            selectSelectiveEle.addElement(ifDistinctElement);
        }

        //issue#102
        if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
            selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByExampleQueryId() + "' as QUERYID,"));
        }
    } else {
        selectSelectiveEle.addElement(new TextElement("select"));
        if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
            selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByPrimaryKeyQueryId() + "' as QUERYID,"));
        }
    }

    selectSelectiveEle.addElement(this.generateSelectiveElement(introspectedTable));
    selectSelectiveEle.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));

    if (byExample) {
        XmlElement ifElement = new XmlElement("if");
        ifElement.addAttribute(new Attribute("test", "example != null"));

        XmlElement includeElement = new XmlElement("include");
        includeElement.addAttribute(new Attribute("refid", introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
        ifElement.addElement(includeElement);

        selectSelectiveEle.addElement(ifElement);

        XmlElement ifElement1 = new XmlElement("if");
        ifElement1.addAttribute(new Attribute("test", "example != null and example.orderByClause != null"));
        ifElement1.addElement(new TextElement("order by ${example.orderByClause}"));
        selectSelectiveEle.addElement(ifElement1);
    } else {
        boolean and = false;
        StringBuffer sb = new StringBuffer();
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            sb.setLength(0);
            if (and) {
                sb.append("  and ");
            } else {
                sb.append("where ");
                and = true;
            }

            sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
            sb.append(" = ");
            sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, introspectedTable.getRules().generatePrimaryKeyClass() ? "record." : null));
            selectSelectiveEle.addElement(new TextElement(sb.toString()));
        }
    }

    if (selectOne) {
        // 只查询一条
        selectSelectiveEle.addElement(new TextElement("limit 1"));
    }

    return selectSelectiveEle;
}