Search in sources :

Example 1 with Interface

use of org.mybatis.generator.api.dom.java.Interface in project generator by mybatis.

the class TestResourceGenerator method simpleInterfaceWithAllGeneratedItems.

public static String simpleInterfaceWithAllGeneratedItems() {
    Interface itf = new Interface(new FullyQualifiedJavaType("org.mybatis.test.SimpleInterface"));
    itf.setVisibility(JavaVisibility.PUBLIC);
    Method method = new Method("count");
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    commentGenerator.addMethodComment(method);
    itf.addMethod(method);
    method = new Method("add");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "a"));
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "b"));
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    commentGenerator.addMethodComment(method);
    itf.addMethod(method);
    return itf.getFormattedContent();
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 2 with Interface

use of org.mybatis.generator.api.dom.java.Interface in project generator by mybatis.

the class SimpleJavaClientGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString(//$NON-NLS-1$
    "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<CompilationUnit>();
    if (context.getPlugins().clientGenerated(interfaze, null, introspectedTable)) {
        answer.add(interfaze);
    }
    List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits();
    if (extraCompilationUnits != null) {
        answer.addAll(extraCompilationUnits);
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 3 with Interface

use of org.mybatis.generator.api.dom.java.Interface in project generator by mybatis.

the class SupersGenerator method getBaseInterface.

private Interface getBaseInterface() {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".BaseInterface");
    Interface ifc = new Interface(fqjt);
    ifc.setVisibility(JavaVisibility.PUBLIC);
    return ifc;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 4 with Interface

use of org.mybatis.generator.api.dom.java.Interface in project generator by mybatis.

the class SupersGenerator method generate.

@Override
public List<CompilationUnit> generate() {
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    TopLevelClass baseClass = getBaseClass();
    TopLevelClass superClass = getSuperClass();
    baseClass.setSuperClass(superClass.getType());
    Interface baseInterface = getBaseInterface();
    Interface superInterface = getSuperInterface();
    baseInterface.addSuperInterface(superInterface.getType());
    baseClass.addSuperInterface(superInterface.getType());
    answer.add(baseClass);
    answer.add(superClass);
    answer.add(baseInterface);
    answer.add(superInterface);
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 5 with Interface

use of org.mybatis.generator.api.dom.java.Interface in project generator by mybatis.

the class SupersGenerator method getSuperInterface.

private Interface getSuperInterface() {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".sub.SuperInterface");
    Interface ifc = new Interface(fqjt);
    ifc.setVisibility(JavaVisibility.PUBLIC);
    return ifc;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Interface(org.mybatis.generator.api.dom.java.Interface)

Aggregations

Interface (org.mybatis.generator.api.dom.java.Interface)13 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)10 ArrayList (java.util.ArrayList)5 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)5 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)3 Test (org.junit.Test)2 CommentGenerator (org.mybatis.generator.api.CommentGenerator)2 DefaultJavaFormatter (org.mybatis.generator.api.dom.DefaultJavaFormatter)2 Method (org.mybatis.generator.api.dom.java.Method)2 Parameter (org.mybatis.generator.api.dom.java.Parameter)2 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)2 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)1