Java Code Examples for org.mybatis.generator.api.dom.java.Interface#addSuperInterface()

The following examples show how to use org.mybatis.generator.api.dom.java.Interface#addSuperInterface() . 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: MapperExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 获取实体类

    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());

    // 获取Example类
    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    // import接口

    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(
                new FullyQualifiedJavaType(
                        mapper + "<" + entityType.getShortName() + "," + exampleType.getShortName() + ">"));
    }
    // import实体类

    interfaze.addImportedType(entityType);
    return true;

}
 
Example 2
Source File: CustomSettingsPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 配置生成的Mapper接口
 * @param i
 * @param table
 * @author Frodez
 * @date 2018-12-13
 */
private void configImportAndJavaDoc(Interface i, IntrospectedTable table) {
	// 获取实体类
	FullyQualifiedJavaType entity = new FullyQualifiedJavaType(table.getBaseRecordType());
	// import接口
	i.addImportedType(new FullyQualifiedJavaType(MAPPER_NAME));
	i.addSuperInterface(new FullyQualifiedJavaType(MAPPER_NAME + "<" + entity.getShortName() + ">"));
	// import实体类
	i.addImportedType(entity);
	// import Spring Repository注解
	i.addImportedType(new FullyQualifiedJavaType("org.springframework.stereotype.Repository"));
	i.addAnnotation("@Repository");
	i.addJavaDocLine("/**");
	i.addJavaDocLine(" * @description " + (table.getRemarks() == null ? "" : table.getRemarks()));
	i.addJavaDocLine(" * @table " + table.getFullyQualifiedTable());
	i.addJavaDocLine(" * @date " + LocalDate.now().toString());
	i.addJavaDocLine(" */");
}
 
Example 3
Source File: CrudSupportPlugin.java    From azeroth with Apache License 2.0 6 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //主键
    FullyQualifiedJavaType idType = null;
    List<IntrospectedColumn> columns = introspectedTable.getPrimaryKeyColumns();
    for (IntrospectedColumn col : columns) {
        idType = javaTypeResolver.calculateJavaType(col);
        break;
    }
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(
                new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + "," + idType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 4
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 5
Source File: MyPgMapperPlugin.java    From jvue-admin with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 6
Source File: MapperPlugin.java    From tk-mybatis with MIT License 5 votes vote down vote up
/**
 * 生成的Mapper接口
 *
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    //获取实体类
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    //import接口
    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(new FullyQualifiedJavaType(mapper + "<" + entityType.getShortName() + ">"));
    }
    //import实体类
    interfaze.addImportedType(entityType);
    return true;
}
 
Example 7
Source File: CreateGenericInterfacePlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	FullyQualifiedJavaType type = new FullyQualifiedJavaType(interfaceName);
	type.addTypeArgument(models.get(introspectedTable));
	type.addTypeArgument(examples.get(introspectedTable));
	type.addTypeArgument(ids.get(introspectedTable));

	interfaze.addSuperInterface(type);

	return true;
}
 
Example 8
Source File: JavaMapperGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 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);
    }

    addCountByExampleMethod(interfaze);
    addDeleteByExampleMethod(interfaze);
    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addInsertSelectiveMethod(interfaze);
    addInsertBatchMethod(interfaze);
    addSelectByExampleWithBLOBsMethod(interfaze);
    addSelectByExampleWithoutBLOBsMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addUpdateByExampleSelectiveMethod(interfaze);
    addUpdateByExampleWithBLOBsMethod(interfaze);
    addUpdateByExampleWithoutBLOBsMethod(interfaze);
    addUpdateByPrimaryKeySelectiveMethod(interfaze);
    addUpdateByPrimaryKeyWithBLOBsMethod(interfaze);
    addUpdateByPrimaryKeyWithoutBLOBsMethod(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 9
Source File: JavaMapperGenerator.java    From mybatis-generator-core-fix 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);
    }
    
    addCountByExampleMethod(interfaze);
    addDeleteByExampleMethod(interfaze);
    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addInsertSelectiveMethod(interfaze);
    addSelectByExampleWithBLOBsMethod(interfaze);
    addSelectByExampleWithoutBLOBsMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addUpdateByExampleSelectiveMethod(interfaze);
    addUpdateByExampleWithBLOBsMethod(interfaze);
    addUpdateByExampleWithoutBLOBsMethod(interfaze);
    addUpdateByPrimaryKeySelectiveMethod(interfaze);
    addUpdateByPrimaryKeyWithBLOBsMethod(interfaze);
    addUpdateByPrimaryKeyWithoutBLOBsMethod(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 10
Source File: SimpleJavaClientGenerator.java    From mybatis-generator-core-fix 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 11
Source File: JavaMapperGenerator.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);
    }
    
    addCountByExampleMethod(interfaze);
    addDeleteByExampleMethod(interfaze);
    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addInsertSelectiveMethod(interfaze);
    addSelectByExampleWithBLOBsMethod(interfaze);
    addSelectByExampleWithoutBLOBsMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addUpdateByExampleSelectiveMethod(interfaze);
    addUpdateByExampleWithBLOBsMethod(interfaze);
    addUpdateByExampleWithoutBLOBsMethod(interfaze);
    addUpdateByPrimaryKeySelectiveMethod(interfaze);
    addUpdateByPrimaryKeyWithBLOBsMethod(interfaze);
    addUpdateByPrimaryKeyWithoutBLOBsMethod(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 12
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 13
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;
}