Search in sources :

Example 71 with Method

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

the class SelectByExampleWithBLOBsMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = getMethodShell(importedTypes);
        if (context.getPlugins().clientSelectByExampleWithBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Example 72 with Method

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

the class DAOGenerator method getTopLevelClassShell.

protected TopLevelClass getTopLevelClassShell() {
    FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType(introspectedTable.getDAOInterfaceType());
    FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(introspectedTable.getDAOImplementationType());
    CommentGenerator commentGenerator = context.getCommentGenerator();
    TopLevelClass answer = new TopLevelClass(implementationType);
    answer.setVisibility(JavaVisibility.PUBLIC);
    answer.setSuperClass(daoTemplate.getSuperClass());
    answer.addImportedType(daoTemplate.getSuperClass());
    answer.addSuperInterface(interfaceType);
    answer.addImportedType(interfaceType);
    for (FullyQualifiedJavaType fqjt : daoTemplate.getImplementationImports()) {
        answer.addImportedType(fqjt);
    }
    commentGenerator.addJavaFileComment(answer);
    // add constructor from the template
    answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable));
    // add any fields from the template
    for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) {
        answer.addField(field);
    }
    // add any methods from the template
    for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) {
        answer.addMethod(method);
    }
    return answer;
}
Also used : Field(org.mybatis.generator.api.dom.java.Field) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) Method(org.mybatis.generator.api.dom.java.Method)

Example 73 with Method

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

the class CountByExampleMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = getMethodShell(importedTypes);
        if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Example 74 with Method

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

the class CountByExampleMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    // generate the implementation method
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("Long count = (Long)  ");
    sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getCountByExampleStatementId(), //$NON-NLS-1$
    "example"));
    method.addBodyLine(sb.toString());
    if (generateForJava5) {
        //$NON-NLS-1$
        method.addBodyLine("return count;");
    } else {
        //$NON-NLS-1$
        method.addBodyLine("return count.longValue();");
    }
    if (context.getPlugins().clientCountByExampleMethodGenerated(method, topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
Also used : TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Example 75 with Method

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

the class CountByExampleMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);
    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    //$NON-NLS-1$
    method.setReturnType(new FullyQualifiedJavaType("long"));
    method.setName(getDAOMethodNameCalculator().getCountByExampleMethodName(introspectedTable));
    //$NON-NLS-1$
    method.addParameter(new Parameter(type, "example"));
    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    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

Method (org.mybatis.generator.api.dom.java.Method)121 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)97 Parameter (org.mybatis.generator.api.dom.java.Parameter)66 TreeSet (java.util.TreeSet)51 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)29 Field (org.mybatis.generator.api.dom.java.Field)20 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)17 ArrayList (java.util.ArrayList)14 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)11 CommentGenerator (org.mybatis.generator.api.CommentGenerator)10 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)10 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)9 Plugin (org.mybatis.generator.api.Plugin)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)7 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 Interface (org.mybatis.generator.api.dom.java.Interface)2 PrimitiveTypeWrapper (org.mybatis.generator.api.dom.java.PrimitiveTypeWrapper)2 DAOMethodNameCalculator (org.mybatis.generator.api.DAOMethodNameCalculator)1 Rules (org.mybatis.generator.internal.rules.Rules)1