Java Code Examples for org.mybatis.generator.api.dom.java.TopLevelClass

The following examples show how to use org.mybatis.generator.api.dom.java.TopLevelClass. These examples are extracted from open source projects. 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
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    
    StringBuilder sb = new StringBuilder();
    for (IntrospectedColumn introspectedColumn : introspectedTable
            .getPrimaryKeyColumns()) {
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(),
                introspectedColumn.getJavaProperty()));
        sb.setLength(0);
        sb.append("this."); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(" = "); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    
    topLevelClass.addMethod(method);
}
 
Example 2
/**
 * 测试配置了模板参数转换
 */
@Test
public void testGenerateWithOutComment() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator-without-comment.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    // java中的注释
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFileName().equals("Tb.java")) {
            TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit();
            // addJavaFileComment
            Assert.assertEquals(topLevelClass.getFileCommentLines().size(), 0);
            // addFieldComment
            Field id = topLevelClass.getFields().get(0);
            Assert.assertEquals(id.getJavaDocLines().size(), 0);
            // addGeneralMethodComment
            Method cons = topLevelClass.getMethods().get(0);
            Assert.assertEquals(cons.getJavaDocLines().size(), 0);
            // addSetterComment
            Method setter = topLevelClass.getMethods().get(5);
            Assert.assertEquals(setter.getJavaDocLines().size(), 0);
        }
    }
}
 
Example 3
public boolean modelGetterMethodGenerated(Method method,
        TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
        IntrospectedTable introspectedTable,
        Plugin.ModelClassType modelClassType) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable, modelClassType)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 4
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    method
            .addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);"); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();

    sb.append("int rows = "); //$NON-NLS-1$

    sb.append(daoTemplate.getUpdateMethod(introspectedTable
            .getIbatis2SqlMapNamespace(), introspectedTable
            .getUpdateByExampleSelectiveStatementId(), "parms")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    method.addBodyLine("return rows;"); //$NON-NLS-1$

    if (context.getPlugins()
            .clientUpdateByExampleSelectiveMethodGenerated(method,
                    topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
Example 5
@Override
public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
    String classAnnotation = "@ApiModel(value=\"" + topLevelClass.getType()  + "\")";
    if(!topLevelClass.getAnnotations().contains(classAnnotation)) {
        topLevelClass.addAnnotation(classAnnotation);
    }

    String apiModelAnnotationPackage =  properties.getProperty("apiModelAnnotationPackage");
    String apiModelPropertyAnnotationPackage = properties.getProperty("apiModelPropertyAnnotationPackage");
    if(null == apiModelAnnotationPackage) apiModelAnnotationPackage = "io.swagger.annotations.ApiModel";
    if(null == apiModelPropertyAnnotationPackage) apiModelPropertyAnnotationPackage = "io.swagger.annotations.ApiModelProperty";

    topLevelClass.addImportedType(apiModelAnnotationPackage);
    topLevelClass.addImportedType(apiModelPropertyAnnotationPackage);

    field.addAnnotation("@ApiModelProperty(value=\"" + introspectedColumn.getJavaProperty() + introspectedColumn.getRemarks() + "\")");
    return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
}
 
Example 6
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    if (generateForJava5) {
        method.addSuppressTypeWarningsAnnotation();
    }

    StringBuilder sb = new StringBuilder();
    sb.append(method.getReturnType().getShortName());
    sb.append(" list = "); //$NON-NLS-1$
    sb.append(daoTemplate.getQueryForListMethod(introspectedTable
            .getIbatis2SqlMapNamespace(), introspectedTable
            .getSelectByExampleWithBLOBsStatementId(), "example")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return list;"); //$NON-NLS-1$

    if (context.getPlugins()
            .clientSelectByExampleWithBLOBsMethodGenerated(method,
                    topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
Example 7
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    // generate the implementation method
    StringBuilder sb = new StringBuilder();

    sb.append("Integer count = (Integer)  "); //$NON-NLS-1$
    sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable
            .getIbatis2SqlMapNamespace(), introspectedTable
            .getCountByExampleStatementId(), "example")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    if (generateForJava5) {
        method.addBodyLine("return count;"); //$NON-NLS-1$
    } else {
        method.addBodyLine("return count.intValue();"); //$NON-NLS-1$
    }

    if (context.getPlugins().clientCountByExampleMethodGenerated(method,
            topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
Example 8
protected boolean addUpdateByExampleWithBLOBsMethod(
        TopLevelClass topLevelClass) {
    boolean rc = false;
    if (introspectedTable.getRules().generateUpdateByExampleWithBLOBs()) {
        AbstractJavaProviderMethodGenerator methodGenerator =
                new ProviderUpdateByExampleWithBLOBsMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
        rc = true;
    }

    return rc;
}
 
Example 9
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean providerSelectByExampleWithBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	boolean rc = true;

	for (Plugin plugin : plugins) {
		if (!plugin.providerSelectByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) {
			rc = false;
			break;
		}
	}

	return rc;
}
 
Example 10
public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass tlc,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.modelRecordWithBLOBsClassGenerated(tlc,
                introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 11
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean providerUpdateByExampleSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	boolean rc = true;

	for (Plugin plugin : plugins) {
		if (!plugin.providerUpdateByExampleSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) {
			rc = false;
			break;
		}
	}

	return rc;
}
 
Example 12
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

    // import接口
    topLevelClass.addImportedType(example);
    topLevelClass.addSuperInterface(new FullyQualifiedJavaType(
            example
    ));
    return true;
}
 
Example 13
/**
 * Intercepts "record with blob" class generation
 *
 * @param topLevelClass     the generated record with BLOBs class
 * @param introspectedTable The class containing information about the table as
 *                          introspected from the database
 * @return always true
 */
@Override
public boolean modelRecordWithBLOBsClassGenerated(
        TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable
) {
    addAnnotations(topLevelClass);
    return true;
}
 
Example 14
public boolean providerUpdateByExampleWithBLOBsMethodGenerated(
        Method method, TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.providerUpdateByExampleWithBLOBsMethodGenerated(method,
                topLevelClass, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 15
private TopLevelClass buildBasicClass() {
	TopLevelClass topLevelClass = new TopLevelClass(calculateClassName());
	topLevelClass.setVisibility(JavaVisibility.PUBLIC);
	topLevelClass.setFinal(true);
	topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlColumn")); //$NON-NLS-1$
	topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlTable")); //$NON-NLS-1$
	topLevelClass.addImportedType(new FullyQualifiedJavaType("java.sql.JDBCType")); //$NON-NLS-1$
	return topLevelClass;
}
 
Example 16
public boolean modelPrimaryKeyClassGenerated(TopLevelClass tlc,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.modelPrimaryKeyClassGenerated(tlc, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 17
protected void addUpdateByPrimaryKeySelectiveMethod(
        TopLevelClass topLevelClass) {
    if (introspectedTable.getRules().generateUpdateByPrimaryKeySelective()) {
        AbstractJavaProviderMethodGenerator methodGenerator = new ProviderUpdateByPrimaryKeySelectiveMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
    }
}
 
Example 18
@Override
public boolean modelRecordWithBLOBsClassGenerated(
        TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    generateEquals(topLevelClass, introspectedTable.getAllColumns(),
            introspectedTable);
    generateHashCode(topLevelClass, introspectedTable.getAllColumns(),
            introspectedTable);

    return true;
}
 
Example 19
public boolean providerSelectByExampleWithBLOBsMethodGenerated(
        Method method, TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.providerSelectByExampleWithBLOBsMethodGenerated(method,
                topLevelClass, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 20
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, Plugin.ModelClassType modelClassType) {
	boolean rc = true;

	for (Plugin plugin : plugins) {
		if (!plugin.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType)) {
			rc = false;
			break;
		}
	}

	return rc;
}
 
Example 21
Source Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass tlc,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.modelBaseRecordClassGenerated(tlc, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example 22
Source Project: mybatis-generator-plus   Source File: DAOGenerator.java    License: Apache License 2.0 5 votes vote down vote up
protected void addSelectByExampleWithoutBLOBsMethod(
        TopLevelClass topLevelClass, Interface interfaze) {
    if (introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
        AbstractDAOElementGenerator methodGenerator = new SelectByExampleWithoutBLOBsMethodGenerator(
                generateForJava5);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass,
                interfaze);
    }
}
 
Example 23
Source Project: mybatis-generator-plus   Source File: DAOGenerator.java    License: Apache License 2.0 5 votes vote down vote up
protected void initializeAndExecuteGenerator(
        AbstractDAOElementGenerator methodGenerator,
        TopLevelClass topLevelClass, Interface interfaze) {
    methodGenerator.setDAOTemplate(daoTemplate);
    methodGenerator.setContext(context);
    methodGenerator.setIntrospectedTable(introspectedTable);
    methodGenerator.setProgressCallback(progressCallback);
    methodGenerator.setWarnings(warnings);
    methodGenerator.addImplementationElements(topLevelClass);
    methodGenerator.addInterfaceElements(interfaze);
}
 
Example 24
protected boolean addSelectByExampleWithoutBLOBsMethod(
        TopLevelClass topLevelClass) {
    boolean rc = false;
    if (introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
        AbstractJavaProviderMethodGenerator methodGenerator = new ProviderSelectByExampleWithoutBLOBsMethodGenerator();
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
        rc = true;
    }

    return rc;
}
 
Example 25
protected void initializeAndExecuteGenerator(
        AbstractJavaProviderMethodGenerator methodGenerator,
        TopLevelClass topLevelClass) {
    methodGenerator.setContext(context);
    methodGenerator.setIntrospectedTable(introspectedTable);
    methodGenerator.setProgressCallback(progressCallback);
    methodGenerator.setWarnings(warnings);
    methodGenerator.addClassElements(topLevelClass);
}
 
Example 26
protected void addUpdateByPrimaryKeySelectiveMethod(
        TopLevelClass topLevelClass) {
    if (introspectedTable.getRules().generateUpdateByPrimaryKeySelective()) {
        AbstractJavaProviderMethodGenerator methodGenerator =
                new ProviderUpdateByPrimaryKeySelectiveMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
    }
}
 
Example 27
Source Project: jvue-admin   Source File: HySwaggerMapperPlugin.java    License: MIT License 5 votes vote down vote up
@Override
public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass,
		IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
	if (setterMethodChainEnabled) {
		method.setReturnType(new FullyQualifiedJavaType(topLevelClass.getType().getShortName()));
		method.addBodyLine("return this;");
	}
	return true;
}
 
Example 28
Source Project: mybatis-generator-core-fix   Source File: DAOGenerator.java    License: Apache License 2.0 5 votes vote down vote up
protected void initializeAndExecuteGenerator(
        AbstractDAOElementGenerator methodGenerator,
        TopLevelClass topLevelClass, Interface interfaze) {
    methodGenerator.setDAOTemplate(daoTemplate);
    methodGenerator.setContext(context);
    methodGenerator.setIntrospectedTable(introspectedTable);
    methodGenerator.setProgressCallback(progressCallback);
    methodGenerator.setWarnings(warnings);
    methodGenerator.addImplementationElements(topLevelClass);
    methodGenerator.addInterfaceElements(interfaze);
}
 
Example 29
protected boolean addUpdateByExampleWithBLOBsMethod(
        TopLevelClass topLevelClass) {
    boolean rc = false;
    if (introspectedTable.getRules().generateUpdateByExampleWithBLOBs()) {
        AbstractJavaProviderMethodGenerator methodGenerator = new ProviderUpdateByExampleWithBLOBsMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
        rc = true;
    }

    return rc;
}
 
Example 30
Source Project: feiqu-opensource   Source File: SerializablePlugin.java    License: Apache License 2.0 4 votes vote down vote up
public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    this.makeSerializable(topLevelClass, introspectedTable);
    return true;
}