Search in sources :

Example 16 with CompilationUnit

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

the class DAOGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.14", //$NON-NLS-1$
    table.toString()));
    TopLevelClass topLevelClass = getTopLevelClassShell();
    Interface interfaze = getInterfaceShell();
    addCountByExampleMethod(topLevelClass, interfaze);
    addDeleteByExampleMethod(topLevelClass, interfaze);
    addDeleteByPrimaryKeyMethod(topLevelClass, interfaze);
    addInsertMethod(topLevelClass, interfaze);
    addInsertSelectiveMethod(topLevelClass, interfaze);
    addSelectByExampleWithBLOBsMethod(topLevelClass, interfaze);
    addSelectByExampleWithoutBLOBsMethod(topLevelClass, interfaze);
    addSelectByPrimaryKeyMethod(topLevelClass, interfaze);
    addUpdateByExampleParmsInnerclass(topLevelClass, interfaze);
    addUpdateByExampleSelectiveMethod(topLevelClass, interfaze);
    addUpdateByExampleWithBLOBsMethod(topLevelClass, interfaze);
    addUpdateByExampleWithoutBLOBsMethod(topLevelClass, interfaze);
    addUpdateByPrimaryKeySelectiveMethod(topLevelClass, interfaze);
    addUpdateByPrimaryKeyWithBLOBsMethod(topLevelClass, interfaze);
    addUpdateByPrimaryKeyWithoutBLOBsMethod(topLevelClass, interfaze);
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().clientGenerated(interfaze, topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
        answer.add(interfaze);
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 17 with CompilationUnit

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

the class PrimaryKeyGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
    table.toString()));
    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, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }
        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }
        method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
        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;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) Field(org.mybatis.generator.api.dom.java.Field) JavaBeansUtil.getJavaBeansField(org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField) IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Method(org.mybatis.generator.api.dom.java.Method) Plugin(org.mybatis.generator.api.Plugin)

Example 18 with CompilationUnit

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

the class IntrospectedTableMyBatis3Impl method getGeneratedJavaFiles.

/* (non-Javadoc)
     * @see org.mybatis.generator.api.IntrospectedTable#getGeneratedJavaFiles()
     */
@Override
public List<GeneratedJavaFile> getGeneratedJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (AbstractJavaGenerator javaGenerator : javaModelGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), context.getJavaFormatter());
            answer.add(gjf);
        }
    }
    for (AbstractJavaGenerator javaGenerator : clientGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, context.getJavaClientGeneratorConfiguration().getTargetProject(), context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), context.getJavaFormatter());
            answer.add(gjf);
        }
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) AbstractJavaGenerator(org.mybatis.generator.codegen.AbstractJavaGenerator) ArrayList(java.util.ArrayList) GeneratedJavaFile(org.mybatis.generator.api.GeneratedJavaFile)

Example 19 with CompilationUnit

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

the class BaseRecordGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.8", //$NON-NLS-1$
    table.toString()));
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);
    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }
    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
    List<IntrospectedColumn> introspectedColumns = getColumnsInThisClass();
    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);
        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }
    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
            continue;
        }
        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }
        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }
        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            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;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Method(org.mybatis.generator.api.dom.java.Method) Field(org.mybatis.generator.api.dom.java.Field) JavaBeansUtil.getJavaBeansField(org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField) IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) Plugin(org.mybatis.generator.api.Plugin)

Aggregations

ArrayList (java.util.ArrayList)19 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)19 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)13 CommentGenerator (org.mybatis.generator.api.CommentGenerator)12 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)11 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)10 Field (org.mybatis.generator.api.dom.java.Field)10 Method (org.mybatis.generator.api.dom.java.Method)10 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)9 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)7 Plugin (org.mybatis.generator.api.Plugin)7 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 Interface (org.mybatis.generator.api.dom.java.Interface)5 Parameter (org.mybatis.generator.api.dom.java.Parameter)3 GeneratedJavaFile (org.mybatis.generator.api.GeneratedJavaFile)2 AbstractJavaGenerator (org.mybatis.generator.codegen.AbstractJavaGenerator)2 Rules (org.mybatis.generator.internal.rules.Rules)1