private void addUserDefinedMethods(TopLevelClass exampleClass, Interface mapperClass, IntrospectedTable introspectedTable, MyBatisClasses cls) {
        for (Method action : mapperClass.getMethods()) {
            if (!userDefinedMethods.matcher(action.getName()).matches()) continue;
            StringBuilder args = new StringBuilder();
            List<Parameter> params = new ArrayList<Parameter>();
            boolean example = false;
            if (action.getParameters() != null)
                for (Parameter param : action.getParameters()) {
                    String name;
                    if (Objects.equals(param.getType(), exampleClass.getType())) {
                        example = true;
                        name = "this";
                    } else {
                        name = param.getName();
                        params.add(new Parameter(param.getType(), name));
                    }
                    if (args.length() > 0)
                        args.append(", ");
                    args.append(name);
                }
            if (!example) {
                //System.err.println("Invalid user-defined mapper method: "+action.getName());
                continue;
            }

            exampleClass.addMethod(method(
                PUBLIC, INT, action.getName(), _(sqlSession, "sql"), params.toArray(new Parameter[params.size()]), __(
                    "return sql.getMapper(" + cls.names.mapper + ".class)."+action.getName()+"("+args+");"
            )));
            exampleClass.addMethod(method(
                PUBLIC, INT, action.getName(), _(cls.types.mapper, "mapper"), params.toArray(new Parameter[params.size()]), __(
                    "return mapper."+action.getName()+"("+args+");"
            )));
        }
    }
 private void addGetRecordMethods(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, MyBatisClasses cls, String base, String withBLOBs, String expression) {
     String returnType = cls.names.base;
     topLevelClass.addImportedType(cls.imports.base);
     String listType = "java.util.List<"+returnType+">";
     if (!base.startsWith(SKIP) && introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), base, _(sqlSession, "sql"), __(
                 listType + " list = sql.getMapper(" + cls.names.mapper + ".class).selectByExample(this);",
                 "return "+expression.replace("@result", returnType)+";"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), base, _(cls.types.mapper, "mapper"), __(
                 listType + " list = mapper.selectByExample(this);",
                 "return "+expression.replace("@result", returnType)+";"
         )));
     }
     if (introspectedTable.hasBLOBColumns() && !withBLOBs.startsWith(SKIP) && introspectedTable.getRules().generateSelectByExampleWithBLOBs()) {
         if (cls.exists.blob) {
             returnType = cls.names.blob;
             topLevelClass.addImportedType(cls.imports.blob);
         }
         listType = "java.util.List<"+returnType+">";
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), withBLOBs, _(sqlSession, "sql"), __(
                 listType + " list = sql.getMapper(" + cls.names.mapper + ".class).selectByExampleWithBLOBs(this);",
                 "return "+expression.replace("@result", returnType)+";"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), withBLOBs, _(cls.types.mapper, "mapper"), __(
                 listType + " list = mapper.selectByExampleWithBLOBs(this);",
                 "return "+expression.replace("@result", returnType)+";"
         )));
     }
 }
 private void addUpdateMethods(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, MyBatisClasses cls, String base, String withBLOBs, boolean selective) {
     String record = cls.names.base;
     topLevelClass.addImportedType(cls.imports.base);
     String mapperMethod = selective ? "updateByExampleSelective" : "updateByExample";
     Rules r = introspectedTable.getRules();
     if (!base.startsWith(SKIP) && ( selective ? r.generateUpdateByExampleSelective() : r.generateUpdateByExampleWithoutBLOBs() )) {
         if (selective && r.generateRecordWithBLOBsClass()) {
             record = cls.names.blob;
             topLevelClass.addImportedType(cls.imports.blob);
         }
         topLevelClass.addMethod(method(
             PUBLIC, INT, base, _(sqlSession, "sql"), _(new FullyQualifiedJavaType(record), "record"), __(
                 "return sql.getMapper(" + cls.names.mapper + ".class)."+mapperMethod+"(record, this);"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, INT, base, _(cls.types.mapper, "mapper"), _(new FullyQualifiedJavaType(record), "record"), __(
                 "return mapper."+mapperMethod+"(record, this);"
         )));
     }
     if (introspectedTable.hasBLOBColumns() && !withBLOBs.startsWith(SKIP) && !selective && r.generateUpdateByExampleWithBLOBs()) {
         if (r.generateRecordWithBLOBsClass()) {
             record = cls.names.blob;
             topLevelClass.addImportedType(cls.imports.blob);
         }
         mapperMethod = selective ? "updateByExampleSelectiveWithBLOBs" /* not supported */ : "updateByExampleWithBLOBs";
         topLevelClass.addMethod(method(
             PUBLIC, INT, withBLOBs, _(sqlSession, "sql"), _(new FullyQualifiedJavaType(record), "record"), __(
                 "return sql.getMapper(" + cls.names.mapper + ".class)."+mapperMethod+"(record, this);"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, INT, withBLOBs, _(cls.types.mapper, "mapper"), _(new FullyQualifiedJavaType(record), "record"), __(
                 "return mapper."+mapperMethod+"(record, this);"
         )));
     }
 }
 private void addListMethods(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, MyBatisClasses cls) {
     String returnType = "java.util.List<"+cls.names.base+">";
     topLevelClass.addImportedType(cls.imports.base);
     if (!listMethod.startsWith(SKIP) && introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), listMethod, _(sqlSession, "sql"), __(
                 "return sql.getMapper(" + cls.names.mapper + ".class).selectByExample(this);"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), listMethod, _(cls.types.mapper, "mapper"), __(
                 "return mapper.selectByExample(this);"
         )));
     }
     if (introspectedTable.hasBLOBColumns() && !listWithBLOBsMethod.startsWith(SKIP) && introspectedTable.getRules().generateSelectByExampleWithBLOBs()) {
         if (cls.exists.blob) {
             returnType = "java.util.List<" + cls.names.blob + ">";
             topLevelClass.addImportedType(cls.imports.blob);
         }
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), listWithBLOBsMethod, _(sqlSession, "sql"), __(
                 "return sql.getMapper("+cls.names.mapper+".class).selectByExampleWithBLOBs(this);"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, new FullyQualifiedJavaType(returnType), listWithBLOBsMethod, _(cls.types.mapper, "mapper"), __(
                 "return mapper.selectByExampleWithBLOBs(this);"
         )));
     }
 }
 private void addCountMethods(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, MyBatisClasses cls) {
     if (!countMethod.startsWith(SKIP) && introspectedTable.getRules().generateCountByExample()) {
         topLevelClass.addMethod(method(
             PUBLIC, INT, countMethod, _(sqlSession, "sql"), __(
                 "return sql.getMapper(" + cls.names.mapper + ".class).countByExample(this);"
         )));
         topLevelClass.addMethod(method(
             PUBLIC, INT, countMethod, _(cls.types.mapper, "mapper"), __(
                 "return mapper.countByExample(this);"
         )));
     }
 }