Java Code Examples for org.mybatis.generator.api.dom.java.Method#addException()

The following examples show how to use org.mybatis.generator.api.dom.java.Method#addException() . 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: DeleteByExampleMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getDeleteByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 2
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method
            .setName(getDAOMethodNameCalculator()
                    .getUpdateByPrimaryKeyWithoutBLOBsMethodName(
                            introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 3
Source File: GetByKeyBusinessGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String mapperFieldName,FullyQualifiedJavaType keyType){
	List<Method> methodList = new ArrayList<Method>();
	
	// add get by key method
	Method method = new Method();
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(beanType);
       method.setName("get" + beanName + "ByKey"); //$NON-NLS-1$
       method.addParameter(new Parameter(keyType, "key")); //$NON-NLS-1$
       method.addException(new FullyQualifiedJavaType(Exception.class.getName()));
       method.addBodyLine("return this."+ mapperFieldName +".selectByPrimaryKey(key);"); 
       methodList.add(method);
       
       // add new method here
       
       return methodList;
}
 
Example 4
Source File: CountByExampleMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getCountByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 5
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the constructor clone.
 *
 * @param commentGenerator
 *            the comment generator
 * @param type
 *            the type
 * @param introspectedTable
 *            the introspected table
 * @return the constructor clone
 */
public final Method getConstructorClone(CommentGenerator commentGenerator,
        FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
    configure();
    Method answer = new Method();
    answer.setConstructor(true);
    answer.setName(type.getShortName());
    answer.setVisibility(constructorTemplate.getVisibility());
    for (Parameter parm : constructorTemplate.getParameters()) {
        answer.addParameter(parm);
    }

    for (String bodyLine : constructorTemplate.getBodyLines()) {
        answer.addBodyLine(bodyLine);
    }

    for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
        answer.addException(fqjt);
    }

    commentGenerator.addGeneralMethodComment(answer, introspectedTable);

    return answer;
}
 
Example 6
Source File: SelectListBusinessGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String mapperFieldName,FullyQualifiedJavaType paramType){
	List<Method> methodList = new ArrayList<Method>();
	
	// add get by key method
	Method method = new Method();
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(new FullyQualifiedJavaType("java.util.List<"+ beanName +">"));
       method.setName("select" + beanName + "List"); //$NON-NLS-1$
       method.addParameter(new Parameter(paramType, "param")); //$NON-NLS-1$
       method.addException(new FullyQualifiedJavaType(Exception.class.getName()));
       method.addBodyLine("return this."+ mapperFieldName +".selectByExample(param);");
       
       methodList.add(method);
       // add new method here
       
       return methodList;
}
 
Example 7
Source File: DeleteByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getDeleteByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 8
Source File: CountListBusinessGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String mapperFieldName,FullyQualifiedJavaType paramType){
	List<Method> methodList = new ArrayList<Method>();
	
	// add get by key method
	Method method = new Method();
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(FullyQualifiedJavaType.getIntInstance());
       method.setName("count" + beanName + "List"); //$NON-NLS-1$
       method.addParameter(new Parameter(paramType, "param")); //$NON-NLS-1$
       method.addException(new FullyQualifiedJavaType(Exception.class.getName()));
       method.addBodyLine("return this."+ mapperFieldName +".countByExample(param);"); 
       methodList.add(method);
       
       // add new method here
       
       return methodList;
}
 
Example 9
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method
            .setName(getDAOMethodNameCalculator()
                    .getUpdateByPrimaryKeyWithoutBLOBsMethodName(
                            introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 10
Source File: CountByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getCountByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 11
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public final Method getConstructorClone(CommentGenerator commentGenerator,
        FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
    configure();
    Method answer = new Method();
    answer.setConstructor(true);
    answer.setName(type.getShortName());
    answer.setVisibility(constructorTemplate.getVisibility());
    for (Parameter parm : constructorTemplate.getParameters()) {
        answer.addParameter(parm);
    }

    for (String bodyLine : constructorTemplate.getBodyLines()) {
        answer.addBodyLine(bodyLine);
    }

    for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
        answer.addException(fqjt);
    }

    commentGenerator.addGeneralMethodComment(answer, introspectedTable);

    return answer;
}
 
Example 12
Source File: MapperExceptionPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addException(Method method,IntrospectedTable introspectedTable){
	String exceptionClassStr = this.getProperties().getProperty("exceptionClass");
	try {
		method.addException(new FullyQualifiedJavaType(exceptionClassStr));
	} catch (Exception e) {
		method.addException(new FullyQualifiedJavaType(RuntimeException.class.getName()));
	}
}
 
Example 13
Source File: JavaElementTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * clone
 * @param method
 * @return
 */
public static Method clone(Method method) {
    Method dest = new Method(method.getName());
    // 注解
    for (String javaDocLine : method.getJavaDocLines()) {
        dest.addJavaDocLine(javaDocLine);
    }
    dest.setReturnType(method.getReturnType());
    for (Parameter parameter : method.getParameters()) {
        dest.addParameter(JavaElementTools.clone(parameter));
    }
    for (FullyQualifiedJavaType exception : method.getExceptions()) {
        dest.addException(exception);
    }
    for (TypeParameter typeParameter : method.getTypeParameters()) {
        dest.addTypeParameter(typeParameter);
    }
    dest.addBodyLines(method.getBodyLines());
    dest.setConstructor(method.isConstructor());
    dest.setNative(method.isNative());
    dest.setSynchronized(method.isSynchronized());
    dest.setDefault(method.isDefault());
    dest.setFinal(method.isFinal());
    dest.setStatic(method.isStatic());
    dest.setVisibility(method.getVisibility());
    return dest;
}
 
Example 14
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public final List<Method> getMethodClones(
        CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Method> answer = new ArrayList<Method>();
    for (Method oldMethod : methods) {
        Method method = new Method();

        for (String bodyLine : oldMethod.getBodyLines()) {
            method.addBodyLine(bodyLine);
        }

        for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) {
            method.addException(fqjt);
        }

        for (Parameter parm : oldMethod.getParameters()) {
            method.addParameter(parm);
        }

        method.setConstructor(oldMethod.isConstructor());
        method.setFinal(oldMethod.isFinal());
        method.setStatic(oldMethod.isStatic());
        method.setName(oldMethod.getName());
        method.setReturnType(oldMethod.getReturnType());
        method.setVisibility(oldMethod.getVisibility());

        commentGenerator.addGeneralMethodComment(method, introspectedTable);

        answer.add(method);
    }

    return answer;
}
 
Example 15
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator()
            .getInsertSelectiveMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 16
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the method clones.
 *
 * @param commentGenerator
 *            the comment generator
 * @param introspectedTable
 *            the introspected table
 * @return the method clones
 */
public final List<Method> getMethodClones(
        CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Method> answer = new ArrayList<Method>();
    for (Method oldMethod : methods) {
        Method method = new Method();

        for (String bodyLine : oldMethod.getBodyLines()) {
            method.addBodyLine(bodyLine);
        }

        for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) {
            method.addException(fqjt);
        }

        for (Parameter parm : oldMethod.getParameters()) {
            method.addParameter(parm);
        }

        method.setConstructor(oldMethod.isConstructor());
        method.setFinal(oldMethod.isFinal());
        method.setStatic(oldMethod.isStatic());
        method.setName(oldMethod.getName());
        method.setReturnType(oldMethod.getReturnType());
        method.setVisibility(oldMethod.getVisibility());

        commentGenerator.addGeneralMethodComment(method, introspectedTable);

        answer.add(method);
    }

    return answer;
}
 
Example 17
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator()
            .getInsertSelectiveMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 18
Source File: InsertMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }

    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator
            .getInsertMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 19
Source File: InsertMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }

    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator
            .getInsertMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}