Search in sources :

Example 1 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class BaseColumnListElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("sql");
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "id", introspectedTable.getBaseColumnListId()));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    Iterator<IntrospectedColumn> iter = introspectedTable.getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter.next()));
        if (iter.hasNext()) {
            //$NON-NLS-1$
            sb.append(", ");
        }
        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }
    if (sb.length() > 0) {
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapBaseColumnListElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TextElement(org.mybatis.generator.api.dom.xml.TextElement) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 2 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class SelectByPrimaryKeyMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
    method.setReturnType(returnType);
    importedTypes.add(returnType);
    method.setName(getDAOMethodNameCalculator().getSelectByPrimaryKeyMethodName(introspectedTable));
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
        importedTypes.add(type);
        //$NON-NLS-1$
        method.addParameter(new Parameter(type, "_key"));
    } else {
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(type);
            method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
        }
    }
    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    return method;
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 3 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class DeleteByPrimaryKeyMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getDeleteByPrimaryKeyMethodName(introspectedTable));
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
        importedTypes.add(type);
        //$NON-NLS-1$
        method.addParameter(new Parameter(type, "_key"));
    } else {
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(type);
            method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
        }
    }
    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    return method;
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 4 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class DeleteByPrimaryKeyMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    StringBuilder sb = new StringBuilder();
    if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
        // no primary key class, but primary key is enabled. Primary
        // key columns must be in the base class.
        FullyQualifiedJavaType keyType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        topLevelClass.addImportedType(keyType);
        sb.setLength(0);
        sb.append(keyType.getShortName());
        //$NON-NLS-1$
        sb.append(" _key = new ");
        sb.append(keyType.getShortName());
        //$NON-NLS-1$
        sb.append("();");
        method.addBodyLine(sb.toString());
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            sb.setLength(0);
            //$NON-NLS-1$
            sb.append("_key.");
            sb.append(getSetterMethodName(introspectedColumn.getJavaProperty()));
            sb.append('(');
            sb.append(introspectedColumn.getJavaProperty());
            //$NON-NLS-1$
            sb.append(");");
            method.addBodyLine(sb.toString());
        }
    }
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("int rows = ");
    sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getDeleteByPrimaryKeyStatementId(), //$NON-NLS-1$
    "_key"));
    method.addBodyLine(sb.toString());
    //$NON-NLS-1$
    method.addBodyLine("return rows;");
    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Example 5 with IntrospectedColumn

use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.

the class BaseRecordGenerator method addParameterizedConstructor.

private void addParameterizedConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    List<IntrospectedColumn> constructorColumns = includeBLOBColumns() ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns();
    for (IntrospectedColumn introspectedColumn : constructorColumns) {
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
        topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
    }
    StringBuilder sb = new StringBuilder();
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        boolean comma = false;
        //$NON-NLS-1$
        sb.append("super(");
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            if (comma) {
                //$NON-NLS-1$
                sb.append(", ");
            } else {
                comma = true;
            }
            sb.append(introspectedColumn.getJavaProperty());
        }
        //$NON-NLS-1$
        sb.append(");");
        method.addBodyLine(sb.toString());
    }
    List<IntrospectedColumn> introspectedColumns = getColumnsInThisClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append("this.");
        sb.append(introspectedColumn.getJavaProperty());
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    topLevelClass.addMethod(method);
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Aggregations

IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)107 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)36 Method (org.mybatis.generator.api.dom.java.Method)33 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)32 Attribute (org.mybatis.generator.api.dom.xml.Attribute)28 ArrayList (java.util.ArrayList)26 Parameter (org.mybatis.generator.api.dom.java.Parameter)24 TextElement (org.mybatis.generator.api.dom.xml.TextElement)24 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)14 Field (org.mybatis.generator.api.dom.java.Field)11 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)10 CommentGenerator (org.mybatis.generator.api.CommentGenerator)9 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)9 Plugin (org.mybatis.generator.api.Plugin)8 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)8 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 HashSet (java.util.HashSet)6 List (java.util.List)6 HashMap (java.util.HashMap)5 KotlinFunction (org.mybatis.generator.api.dom.kotlin.KotlinFunction)5