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

The following examples show how to use org.mybatis.generator.api.dom.java.TopLevelClass. 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: GeneratorSwagger2Doc.java    From mybatis-generator-plugins with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #2
Source File: CountByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: UpdateByExampleSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: CommentPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试配置了模板参数转换
 */
@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 #6
Source File: SelectByExampleWithBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@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
Source File: PrimaryKeyGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: SqlProviderGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
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 File: DAOGenerator.java    From mybatis-generator-core-fix with 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 #10
Source File: PluginAggregator.java    From mybatis-generator-plus with 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 #11
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: HySwaggerMapperPlugin.java    From jvue-admin with 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 #14
Source File: SqlProviderGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
protected void addUpdateByPrimaryKeySelectiveMethod(
        TopLevelClass topLevelClass) {
    if (introspectedTable.getRules().generateUpdateByPrimaryKeySelective()) {
        AbstractJavaProviderMethodGenerator methodGenerator =
                new ProviderUpdateByPrimaryKeySelectiveMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
    }
}
 
Example #15
Source File: SqlProviderGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: PluginAggregator.java    From mybatis-generator-plus with 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 #17
Source File: LombokPlugin.java    From mybatis-generator-lombok-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: ExampleExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

    // import接口
    topLevelClass.addImportedType(example);
    topLevelClass.addSuperInterface(new FullyQualifiedJavaType(
            example
    ));
    return true;
}
 
Example #19
Source File: SqlProviderGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
protected boolean addSelectByExampleWithoutBLOBsMethod(
        TopLevelClass topLevelClass) {
    boolean rc = false;
    if (introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
        AbstractJavaProviderMethodGenerator methodGenerator = new ProviderSelectByExampleWithoutBLOBsMethodGenerator();
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
        rc = true;
    }

    return rc;
}
 
Example #20
Source File: DAOGenerator.java    From mybatis-generator-plus with 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 #21
Source File: DAOGenerator.java    From mybatis-generator-plus with 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 #22
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
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 #23
Source File: PluginAggregator.java    From mapper-generator-javafx with 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 #24
Source File: PluginAggregator.java    From mybatis-generator-plus with 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 #25
Source File: PluginAggregator.java    From mybatis-generator-core-fix with 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 #26
Source File: EqualsHashCodePlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelRecordWithBLOBsClassGenerated(
        TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    generateEquals(topLevelClass, introspectedTable.getAllColumns(),
            introspectedTable);
    generateHashCode(topLevelClass, introspectedTable.getAllColumns(),
            introspectedTable);

    return true;
}
 
Example #27
Source File: SqlProviderGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
protected void addUpdateByPrimaryKeySelectiveMethod(
        TopLevelClass topLevelClass) {
    if (introspectedTable.getRules().generateUpdateByPrimaryKeySelective()) {
        AbstractJavaProviderMethodGenerator methodGenerator = new ProviderUpdateByPrimaryKeySelectiveMethodGenerator(useLegacyBuilder);
        initializeAndExecuteGenerator(methodGenerator, topLevelClass);
    }
}
 
Example #28
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
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 #29
Source File: SqlProviderGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
protected void initializeAndExecuteGenerator(
        AbstractJavaProviderMethodGenerator methodGenerator,
        TopLevelClass topLevelClass) {
    methodGenerator.setContext(context);
    methodGenerator.setIntrospectedTable(introspectedTable);
    methodGenerator.setProgressCallback(progressCallback);
    methodGenerator.setWarnings(warnings);
    methodGenerator.addClassElements(topLevelClass);
}
 
Example #30
Source File: CreateSubPackagePlugin.java    From mybatis-generator-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public boolean clientInsertSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass,
		IntrospectedTable introspectedTable) {
	return renameMethod(method);
}