Search in sources :

Example 56 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.

the class DefaultCommentGenerator method addSetterComment.

/* (non-Javadoc)
     * @see org.mybatis.generator.api.CommentGenerator#addSetterComment(org.mybatis.generator.api.dom.java.Method, org.mybatis.generator.api.IntrospectedTable, org.mybatis.generator.api.IntrospectedColumn)
     */
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    if (suppressAllComments) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    method.addJavaDocLine("/**");
    method.addJavaDocLine(//$NON-NLS-1$
    " * This method was generated by MyBatis Generator.");
    //$NON-NLS-1$
    sb.append(" * This method sets the value of the database column ");
    sb.append(introspectedTable.getFullyQualifiedTable());
    sb.append('.');
    sb.append(introspectedColumn.getActualColumnName());
    method.addJavaDocLine(sb.toString());
    //$NON-NLS-1$
    method.addJavaDocLine(" *");
    Parameter parm = method.getParameters().get(0);
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append(" * @param ");
    sb.append(parm.getName());
    //$NON-NLS-1$
    sb.append(" the value for ");
    sb.append(introspectedTable.getFullyQualifiedTable());
    sb.append('.');
    sb.append(introspectedColumn.getActualColumnName());
    method.addJavaDocLine(sb.toString());
    addJavadocTag(method, false);
    //$NON-NLS-1$
    method.addJavaDocLine(" */");
}
Also used : Parameter(org.mybatis.generator.api.dom.java.Parameter)

Example 57 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.

the class CaseInsensitiveLikePlugin method modelExampleClassGenerated.

@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    InnerClass criteria = null;
    // first, find the Criteria inner class
    for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
        if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) {
            //$NON-NLS-1$
            criteria = innerClass;
            break;
        }
    }
    if (criteria == null) {
        // can't find the inner class for some reason, bail out.
        return true;
    }
    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
        if (!introspectedColumn.isJdbcCharacterColumn() || !introspectedColumn.isStringColumn()) {
            continue;
        }
        Method method = new Method();
        method.setVisibility(JavaVisibility.PUBLIC);
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), //$NON-NLS-1$
        "value"));
        StringBuilder sb = new StringBuilder();
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        //$NON-NLS-1$
        sb.insert(0, "and");
        //$NON-NLS-1$
        sb.append("LikeInsensitive");
        method.setName(sb.toString());
        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append("addCriterion(\"upper(");
        sb.append(Ibatis2FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(") like\", value.toUpperCase(), \"");
        sb.append(introspectedColumn.getJavaProperty());
        //$NON-NLS-1$
        sb.append("\");");
        method.addBodyLine(sb.toString());
        //$NON-NLS-1$
        method.addBodyLine("return (Criteria) this;");
        criteria.addMethod(method);
    }
    return true;
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) InnerClass(org.mybatis.generator.api.dom.java.InnerClass) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 58 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.

the class EqualsHashCodePlugin method generateEquals.

/**
     * Generates an <tt>equals</tt> method that does a comparison of all fields.
     * <p>
     * The generated <tt>equals</tt> method will be correct unless:
     * <ul>
     * <li>Other fields have been added to the generated classes</li>
     * <li>A <tt>rootClass</tt> is specified that holds state</li>
     * </ul>
     * 
     * @param topLevelClass
     *            the class to which the method will be added
     * @param introspectedColumns
     *            column definitions of this class and any superclass of this
     *            class
     * @param introspectedTable
     *            the table corresponding to this class
     */
protected void generateEquals(TopLevelClass topLevelClass, List<IntrospectedColumn> introspectedColumns, IntrospectedTable introspectedTable) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    //$NON-NLS-1$
    method.setName("equals");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
    "that"));
    if (introspectedTable.isJava5Targeted()) {
        //$NON-NLS-1$
        method.addAnnotation("@Override");
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    //$NON-NLS-1$
    method.addBodyLine("if (this == that) {");
    //$NON-NLS-1$
    method.addBodyLine("return true;");
    //$NON-NLS-1$
    method.addBodyLine("}");
    //$NON-NLS-1$
    method.addBodyLine("if (that == null) {");
    //$NON-NLS-1$
    method.addBodyLine("return false;");
    //$NON-NLS-1$
    method.addBodyLine("}");
    //$NON-NLS-1$
    method.addBodyLine("if (getClass() != that.getClass()) {");
    //$NON-NLS-1$
    method.addBodyLine("return false;");
    //$NON-NLS-1$
    method.addBodyLine("}");
    StringBuilder sb = new StringBuilder();
    sb.append(topLevelClass.getType().getShortName());
    //$NON-NLS-1$
    sb.append(" other = (");
    sb.append(topLevelClass.getType().getShortName());
    //$NON-NLS-1$
    sb.append(") that;");
    method.addBodyLine(sb.toString());
    if (useEqualsHashCodeFromRoot && topLevelClass.getSuperClass() != null) {
        //$NON-NLS-1$
        method.addBodyLine("if (!super.equals(other)) {");
        //$NON-NLS-1$
        method.addBodyLine("return false;");
        //$NON-NLS-1$
        method.addBodyLine("}");
    }
    boolean first = true;
    Iterator<IntrospectedColumn> iter = introspectedColumns.iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();
        sb.setLength(0);
        if (first) {
            //$NON-NLS-1$
            sb.append("return (");
            first = false;
        } else {
            OutputUtilities.javaIndent(sb, 1);
            //$NON-NLS-1$
            sb.append("&& (");
        }
        String getterMethod = getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType());
        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
            //$NON-NLS-1$
            sb.append("this.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("() == ");
            //$NON-NLS-1$
            sb.append("other.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("())");
        } else if (introspectedColumn.getFullyQualifiedJavaType().isArray()) {
            //$NON-NLS-1$
            topLevelClass.addImportedType("java.util.Arrays");
            //$NON-NLS-1$
            sb.append("Arrays.equals(this.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("(), ");
            //$NON-NLS-1$
            sb.append("other.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("()))");
        } else {
            //$NON-NLS-1$
            sb.append("this.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("() == null ? other.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("() == null : this.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("().equals(other.");
            sb.append(getterMethod);
            //$NON-NLS-1$
            sb.append("()))");
        }
        if (!iter.hasNext()) {
            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)

Example 59 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.

the class RowBoundsPlugin method copyAndAddMethod.

/**
     * Use the method copy constructor to create a new method, then
     * add the rowBounds parameter.
     * 
     * @param fullyQualifiedTable
     * @param method
     */
private void copyAndAddMethod(Method method, Interface interfaze) {
    Method newMethod = new Method(method);
    //$NON-NLS-1$
    newMethod.setName(method.getName() + "WithRowbounds");
    //$NON-NLS-1$
    newMethod.addParameter(new Parameter(rowBounds, "rowBounds"));
    interfaze.addMethod(newMethod);
    interfaze.addImportedType(rowBounds);
}
Also used : Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 60 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.

the class JavaBeansUtil method getJavaBeansSetter.

/**
     * Gets the java beans setter.
     *
     * @param introspectedColumn
     *            the introspected column
     * @param context
     *            the context
     * @param introspectedTable
     *            the introspected table
     * @return the java beans setter
     */
public static Method getJavaBeansSetter(IntrospectedColumn introspectedColumn, Context context, IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method, introspectedTable, introspectedColumn);
    StringBuilder sb = new StringBuilder();
    if (introspectedColumn.isStringColumn() && isTrimStringsEnabled(introspectedColumn)) {
        //$NON-NLS-1$
        sb.append("this.");
        sb.append(property);
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(property);
        //$NON-NLS-1$
        sb.append(" == null ? null : ");
        sb.append(property);
        //$NON-NLS-1$
        sb.append(".trim();");
        method.addBodyLine(sb.toString());
    } else {
        //$NON-NLS-1$
        sb.append("this.");
        sb.append(property);
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    return method;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Aggregations

Parameter (org.mybatis.generator.api.dom.java.Parameter)68 Method (org.mybatis.generator.api.dom.java.Method)66 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)55 TreeSet (java.util.TreeSet)20 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)17 Field (org.mybatis.generator.api.dom.java.Field)11 ArrayList (java.util.ArrayList)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)5 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)5 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)4 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)3 CommentGenerator (org.mybatis.generator.api.CommentGenerator)2 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)2 Interface (org.mybatis.generator.api.dom.java.Interface)2 DAOMethodNameCalculator (org.mybatis.generator.api.DAOMethodNameCalculator)1 Rules (org.mybatis.generator.internal.rules.Rules)1