org.mybatis.generator.api.CommentGenerator Java Examples

The following examples show how to use org.mybatis.generator.api.CommentGenerator. 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: 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 #2
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example #3
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the field clones.
 *
 * @param commentGenerator
 *            the comment generator
 * @param introspectedTable
 *            the introspected table
 * @return the field clones
 */
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example #4
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 #5
Source File: MysqlPaginationPlugin.java    From server-boilerplate with MIT License 6 votes vote down vote up
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(PrimitiveTypeWrapper.getIntegerInstance());
    field.setName(name);
    commentGenerator.addFieldComment(field, introspectedTable);
    topLevelClass.addField(field);
    char c = name.charAt(0);
    String camel = Character.toUpperCase(c) + name.substring(1);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("set" + camel);
    method.addParameter(new Parameter(PrimitiveTypeWrapper.getIntegerInstance(), name));
    method.addBodyLine("this." + name + "=" + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(PrimitiveTypeWrapper.getIntegerInstance());
    method.setName("get" + camel);
    method.addBodyLine("return " + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #6
Source File: FormatTools.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 替换已有注释
 * @param commentGenerator
 * @param element
 */
public static void replaceComment(CommentGenerator commentGenerator, XmlElement element) {
    Iterator<Element> elementIterator = element.getElements().iterator();
    boolean flag = false;
    while (elementIterator.hasNext()) {
        Element ele = elementIterator.next();
        if (ele instanceof TextElement && ((TextElement) ele).getContent().matches(".*<!--.*")) {
            flag = true;
        }

        if (flag) {
            elementIterator.remove();
        }

        if (ele instanceof TextElement && ((TextElement) ele).getContent().matches(".*-->.*")) {
            flag = false;
        }
    }

    XmlElement tmpEle = new XmlElement("tmp");
    commentGenerator.addComment(tmpEle);

    for (int i = tmpEle.getElements().size() - 1; i >= 0; i--) {
        element.addElement(0, tmpEle.getElements().get(i));
    }
}
 
Example #7
Source File: MethodGeneratorTool.java    From hui-mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * 默认的批量新增/更新方法构造器.
 *
 * @param interfaze         the interfaze
 * @param introspectedTable the introspected table
 * @param context           the context
 * @author HuWeihui
 * @since hui_project v1
 */
public static void defaultBatchInsertOrUpdateMethodGen(Integer type ,Interface interfaze,IntrospectedTable introspectedTable, Context context){
    Set<FullyQualifiedJavaType> importedTypes = MethodGeneratorTool.importedBaseTypesGenerator(introspectedTable);

    //List<Entity>
    FullyQualifiedJavaType listParameterType = FullyQualifiedJavaType.getNewListInstance();
    listParameterType.addTypeArgument(introspectedTable.getRules().calculateAllFieldsClass());

    String methodName = BATCH_INSERT;
    //1.batchInsert
    if (type.equals(UPDATE)){
        methodName = BATCH_UPDATE;
    }
    Method insertMethod = MethodGeneratorTool.methodGenerator(methodName,
            JavaVisibility.DEFAULT,
            FullyQualifiedJavaType.getIntInstance(),
            new Parameter(listParameterType, PARAMETER_NAME, "@Param(\"" + PARAMETER_NAME + "\")"));

    CommentGenerator commentGenerator = context.getCommentGenerator();
    commentGenerator.addGeneralMethodComment(insertMethod, introspectedTable);

    interfaze.addImportedTypes(importedTypes);
    interfaze.addMethod(insertMethod);
}
 
Example #8
Source File: Context.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public CommentGenerator getCommentGenerator() {
	if (commentGenerator == null) {
		commentGenerator = ObjectFactory.createCommentGenerator(this);
	}

	return commentGenerator;
}
 
Example #9
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 #10
Source File: DAOGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: SqlProviderGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.18", //$NON-NLS-1$
            introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3SqlProviderType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    boolean addApplyWhereMethod = false;
    addApplyWhereMethod |= addCountByExampleMethod(topLevelClass);
    addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass);
    addInsertSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass);
    addUpdateByPrimaryKeySelectiveMethod(topLevelClass);

    if (addApplyWhereMethod) {
        addApplyWhereMethod(topLevelClass);
    }
    
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    
    if (topLevelClass.getMethods().size() > 0) {
        if (context.getPlugins().providerGenerated(topLevelClass,
            introspectedTable)) {
            answer.add(topLevelClass);
        }
    }

    return answer;
}
 
Example #12
Source File: DAOGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #13
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 #14
Source File: Context.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the comment generator.
 *
 * @return the comment generator
 */
public CommentGenerator getCommentGenerator() {
    if (commentGenerator == null) {
        commentGenerator = ObjectFactory.createCommentGenerator(this);
    }

    return commentGenerator;
}
 
Example #15
Source File: SqlProviderGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.18", //$NON-NLS-1$
            introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3SqlProviderType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    boolean addApplyWhereMethod = false;
    addApplyWhereMethod |= addCountByExampleMethod(topLevelClass);
    addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass);
    addInsertSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass);
    addUpdateByPrimaryKeySelectiveMethod(topLevelClass);

    if (addApplyWhereMethod) {
        addApplyWhereMethod(topLevelClass);
    }
    
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    
    if (topLevelClass.getMethods().size() > 0) {
        if (context.getPlugins().providerGenerated(topLevelClass,
            introspectedTable)) {
            answer.add(topLevelClass);
        }
    }

    return answer;
}
 
Example #16
Source File: OracelPageLimitPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
private void addLimit(TopLevelClass topLevelClass,
                      IntrospectedTable introspectedTable, String name) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getIntInstance());
    field.setName(name);
    field.setInitializationString("-1");
    commentGenerator.addFieldComment(field, introspectedTable);
    topLevelClass.addField(field);
    char c = name.charAt(0);
    String camel = Character.toUpperCase(c) + name.substring(1);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("set" + camel);
    method.addParameter(new Parameter(FullyQualifiedJavaType
            .getIntInstance(), name));
    method.addBodyLine("this." + name + "=" + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName("get" + camel);
    method.addBodyLine("return " + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #17
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
private void addPage(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setPage");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "page"));
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "size"));
    method.addBodyLine("this.limitStart = page * size;this.limitEnd = size;");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #18
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
private void addPageTemplate(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("pageByExample");

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    FullyQualifiedJavaType baseQueryType = new FullyQualifiedJavaType("com.diligrp.shop.constant.BaseQuery");
    FullyQualifiedJavaType pageTmplType = new FullyQualifiedJavaType("com.diligrp.shop.constant.PageTemplate");

    String recordType = introspectedTable.getBaseRecordType();

    method.setReturnType(pageTmplType);

    method.addParameter(new Parameter(exampleType, "example"));
    method.addParameter(new Parameter(baseQueryType, "baseQuery"));

    StringBuffer code = new StringBuffer(32);
    code.append("int count = this.countByExample(example);\n");
    code.append("List<" + recordType + "> list = this.selectByExample(example);\n");
    code.append("com.diligrp.shop.constant.PageTemplate<" + recordType + "> pageTemplate = com.diligrp.shop.constant.PageTemplate.build();\n ");
    code.append("pageTemplate.setTotalSize(count);\n");
    code.append("pageTemplate.setList(list);\n");
    code.append("if(baseQuery != null){");
    code.append("pageTemplate.setCurrPage(baseQuery.getCurrent());\n");
    code.append("pageTemplate.setPageSize(baseQuery.getSize());\n");
    code.append("}");
    code.append("return pageTemplate;");

    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #19
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public static DynamicSqlSupportClassGenerator of(IntrospectedTable introspectedTable,
        CommentGenerator commentGenerator, List<String> warnings) {
    DynamicSqlSupportClassGenerator generator = new DynamicSqlSupportClassGenerator();
    generator.introspectedTable = introspectedTable;
    generator.commentGenerator = commentGenerator;
    generator.warnings = warnings;
    return generator;
}
 
Example #20
Source File: CustomPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * 修改Example类,添加分页支持
 *
 * @param topLevelClass
 * @param introspectedTable
 */
private void addPage(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	CommentGenerator commentGenerator = context.getCommentGenerator();
	//.add offset Field
	Field offsetField = new Field();
	offsetField.setVisibility(JavaVisibility.PROTECTED);
	offsetField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	offsetField.setName("offset");
	commentGenerator.addFieldComment(offsetField, introspectedTable);
	topLevelClass.addField(offsetField);

	//.add limit Field
	Field limitField = new Field();
	limitField.setVisibility(JavaVisibility.PROTECTED);
	limitField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	limitField.setName("limit");
	commentGenerator.addFieldComment(limitField, introspectedTable);
	topLevelClass.addField(limitField);

	//.add end Field
	Field endField = new Field();
	endField.setVisibility(JavaVisibility.PROTECTED);
	endField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	endField.setName("end");
	commentGenerator.addFieldComment(endField, introspectedTable);
	topLevelClass.addField(endField);

	//.add setPagination method
	Method method = new Method();
	method.setVisibility(JavaVisibility.PUBLIC);
	method.setName("setPagination");
	method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "offset"));
	method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "limit"));
	method.addBodyLine("this.offset = offset;");
	method.addBodyLine("this.limit = limit;");
	method.addBodyLine("this.end = offset + limit;");
	commentGenerator.addGeneralMethodComment(method, introspectedTable);
	topLevelClass.addMethod(method);
}
 
Example #21
Source File: SqlProviderGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.18",
            introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3SqlProviderType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    boolean addApplyWhereMethod = false;
    addApplyWhereMethod |= addCountByExampleMethod(topLevelClass);
    addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass);
    addInsertSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass);
    addUpdateByPrimaryKeySelectiveMethod(topLevelClass);

    if (addApplyWhereMethod) {
        addApplyWhereMethod(topLevelClass);
    }

    List<CompilationUnit> answer = new ArrayList<>();
    
    if (!topLevelClass.getMethods().isEmpty()
            && context.getPlugins().providerGenerated(topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }

    return answer;
}
 
Example #22
Source File: SimpleJavaClientGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.17", introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
    Interface interfaze = new Interface(type);
    interfaze.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(interfaze);

    String rootInterface = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    if (!stringHasValue(rootInterface)) {
        rootInterface = context.getJavaClientGeneratorConfiguration().getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    }

    if (stringHasValue(rootInterface)) {
        FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(rootInterface);
        interfaze.addSuperInterface(fqjt);
        interfaze.addImportedType(fqjt);
    }

    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addSelectAllMethod(interfaze);
    addUpdateByPrimaryKeyMethod(interfaze);

    List<CompilationUnit> answer = new ArrayList<>();
    if (context.getPlugins().clientGenerated(interfaze, introspectedTable)) {
        answer.add(interfaze);
    }

    List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits();
    if (extraCompilationUnits != null) {
        answer.addAll(extraCompilationUnits);
    }

    return answer;
}
 
Example #23
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
public static DynamicSqlSupportClassGenerator of(IntrospectedTable introspectedTable, CommentGenerator commentGenerator, String sqlTableClassSuffix,
		boolean addAliasedColumns, boolean addTableAlias, String tableAliasFieldName, Properties properties) {
	DynamicSqlSupportClassGenerator generator = new DynamicSqlSupportClassGenerator();
	generator.introspectedTable = introspectedTable;
	generator.commentGenerator = commentGenerator;
	generator.sqlTableClassName = introspectedTable.getFullyQualifiedTable().getDomainObjectName() + sqlTableClassSuffix;
	generator.addAliasedColumns = addAliasedColumns;
	generator.addTableAlias = addTableAlias;
	generator.tableAliasFieldName = tableAliasFieldName;
	generator.properties = properties;
	return generator;
}
 
Example #24
Source File: MySQLPageLimitPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
private void addLimit(TopLevelClass topLevelClass,
                      IntrospectedTable introspectedTable, String name) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getIntInstance());
    field.setName(name);
    field.setInitializationString("-1");
    commentGenerator.addFieldComment(field, introspectedTable);
    topLevelClass.addField(field);
    char c = name.charAt(0);
    String camel = Character.toUpperCase(c) + name.substring(1);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("set" + camel);
    method.addParameter(new Parameter(FullyQualifiedJavaType
            .getIntInstance(), name));
    method.addBodyLine("this." + name + "=" + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName("get" + camel);
    method.addBodyLine("return " + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #25
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getIntInstance());
    field.setName(name);
    field.setInitializationString("-1");
    commentGenerator.addFieldComment(field, introspectedTable);
    topLevelClass.addField(field);
    char c = name.charAt(0);
    String camel = Character.toUpperCase(c) + name.substring(1);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("set" + camel);
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), name));
    method.addBodyLine("this." + name + "=" + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName("get" + camel);
    method.addBodyLine("return " + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example #26
Source File: Context.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public CommentGenerator getCommentGenerator() {
    if (commentGenerator == null) {
        commentGenerator = ObjectFactory.createCommentGenerator(this);
    }

    return commentGenerator;
}
 
Example #27
Source File: SimpleJavaClientGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.17", //$NON-NLS-1$
            introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
    Interface interfaze = new Interface(type);
    interfaze.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(interfaze);

    String rootInterface = introspectedTable
        .getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    if (!stringHasValue(rootInterface)) {
        rootInterface = context.getJavaClientGeneratorConfiguration()
            .getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    }

    if (stringHasValue(rootInterface)) {
        FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
                rootInterface);
        interfaze.addSuperInterface(fqjt);
        interfaze.addImportedType(fqjt);
    }
    
    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addSelectAllMethod(interfaze);
    addUpdateByPrimaryKeyMethod(interfaze);

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().clientGenerated(interfaze, null,
            introspectedTable)) {
        answer.add(interfaze);
    }
    
    List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits();
    if (extraCompilationUnits != null) {
        answer.addAll(extraCompilationUnits);
    }

    return answer;
}
 
Example #28
Source File: DAOPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * contextGenerateAdditionalJavaFiles:. <br/>
 *
 * @author Hongbin Yuan
 * @param introspectedTable
 * @return
 * @see PluginAdapter#contextGenerateAdditionalJavaFiles(IntrospectedTable)
 */
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
		IntrospectedTable introspectedTable) {
	CommentGenerator commentGenerator = context.getCommentGenerator();

	// 设置文件类型,DAO文件,java 接口文件
	String  javaMapperName = introspectedTable.getMyBatis3JavaMapperType();
	String typeNameProp = this.getProperties().getProperty("typeName");
	if(typeNameProp == null || "".equals(typeNameProp.trim())){
		typeNameProp = typeName;
	}
	javaMapperName = javaMapperName.replaceAll("Mapper$",typeNameProp);
	
       FullyQualifiedJavaType type = new FullyQualifiedJavaType(javaMapperName);
	Interface interfaze = new Interface(type);
       interfaze.setVisibility(JavaVisibility.PUBLIC);
       commentGenerator.addJavaFileComment(interfaze);

       String rootInterface = introspectedTable
           .getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
       if (!stringHasValue(rootInterface)) {
           rootInterface = context.getJavaClientGeneratorConfiguration()
               .getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
       }

       if (stringHasValue(rootInterface)) {
           FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
                   rootInterface);
           interfaze.addSuperInterface(fqjt);
           interfaze.addImportedType(fqjt);
       }
	
       GeneratedJavaFile gjf = new GeneratedJavaFile(interfaze,
		context.getJavaClientGeneratorConfiguration().getTargetProject(),
           context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
           context.getJavaFormatter());
       List<GeneratedJavaFile>  gifList = new ArrayList<GeneratedJavaFile>();
       
       gifList.add(gjf);
       
	return gifList;
}
 
Example #29
Source File: PrimaryKeyGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.7", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable
            .getPrimaryKeyType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    String rootClass = getRootClass();
    if (rootClass != null) {
        topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
        topLevelClass.addImportedType(topLevelClass.getSuperClass());
    }

    for (IntrospectedColumn introspectedColumn : introspectedTable
            .getPrimaryKeyColumns()) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }

        method = getJavaBeansSetter(introspectedColumn);
        if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelPrimaryKeyClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
Example #30
Source File: BaseRecordGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable
            .getBaseRecordType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }

    List<IntrospectedColumn> introspectedColumns;
    if (includePrimaryKeyColumns()) {
        if (includeBLOBColumns()) {
            introspectedColumns = introspectedTable.getAllColumns();
        } else {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        }
    } else {
        if (includeBLOBColumns()) {
            introspectedColumns = introspectedTable
                    .getNonPrimaryKeyColumns();
        } else {
            introspectedColumns = introspectedTable.getBaseColumns();
        }
    }

    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        method = getJavaBeansSetter(introspectedColumn);
        if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}