Search in sources :

Example 1 with KotlinFile

use of org.mybatis.generator.api.dom.kotlin.KotlinFile in project generator by mybatis.

the class KotlinMapperAndExtensionsGenerator method getKotlinFiles.

@Override
public List<KotlinFile> getKotlinFiles() {
    progressCallback.startTask(getString(// $NON-NLS-1$
    "Progress.17", introspectedTable.getFullyQualifiedTable().toString()));
    preCalculate();
    KotlinFile mapperFile = createMapperInterfaceFile();
    KotlinType mapper = createMapperInterface(mapperFile);
    if (hasGeneratedKeys) {
        addBasicInsertMethod(mapperFile, mapper);
        addBasicInsertMultipleMethod(mapperFile, mapper);
    }
    boolean reuseResultMap = addBasicSelectManyMethod(mapperFile, mapper);
    addBasicSelectOneMethod(mapperFile, mapper, reuseResultMap);
    String mapperName = mapper.getName();
    addGeneralCountMethod(mapperFile, mapper, mapperName);
    addGeneralDeleteMethod(mapperFile, mapper, mapperName);
    addDeleteByPrimaryKeyMethod(mapperFile, mapperName);
    addInsertOneMethod(mapperFile, mapper, mapperName);
    addInsertMultipleMethod(mapperFile, mapper, mapperName);
    addInsertMultipleVarargMethod(mapperFile, mapperName);
    addInsertSelectiveMethod(mapperFile, mapper, mapperName);
    addColumnListProperty(mapperFile);
    addGeneralSelectMethod(mapperFile, mapperName);
    addSelectDistinctMethod(mapperFile, mapperName);
    addSelectByPrimaryKeyMethod(mapperFile, mapperName);
    addGeneralUpdateMethod(mapperFile, mapper, mapperName);
    addUpdateAllMethod(mapperFile);
    addUpdateSelectiveMethod(mapperFile);
    addUpdateByPrimaryKeyMethod(mapperFile, mapperName);
    addUpdateByPrimaryKeySelectiveMethod(mapperFile, mapperName);
    KotlinFile supportFile = supportClassGenerator.getKotlinFile();
    List<KotlinFile> answer = new ArrayList<>();
    if (context.getPlugins().dynamicSqlSupportGenerated(supportFile, supportClassGenerator.getOuterObject(), supportClassGenerator.getInnerClass(), introspectedTable)) {
        answer.add(supportFile);
    }
    if (context.getPlugins().mapperGenerated(mapperFile, mapper, introspectedTable)) {
        answer.add(mapperFile);
    }
    return answer;
}
Also used : KotlinType(org.mybatis.generator.api.dom.kotlin.KotlinType) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType) KotlinFile(org.mybatis.generator.api.dom.kotlin.KotlinFile) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString)

Example 2 with KotlinFile

use of org.mybatis.generator.api.dom.kotlin.KotlinFile in project generator by mybatis.

the class IntrospectedTableMyBatis3Impl method getGeneratedKotlinFiles.

@Override
public List<GeneratedKotlinFile> getGeneratedKotlinFiles() {
    List<GeneratedKotlinFile> answer = new ArrayList<>();
    for (AbstractKotlinGenerator kotlinGenerator : kotlinGenerators) {
        List<KotlinFile> kotlinFiles = kotlinGenerator.getKotlinFiles();
        for (KotlinFile kotlinFile : kotlinFiles) {
            GeneratedKotlinFile gjf = new GeneratedKotlinFile(kotlinFile, kotlinGenerator.getProject(), context.getProperty(PropertyRegistry.CONTEXT_KOTLIN_FILE_ENCODING), context.getKotlinFormatter());
            answer.add(gjf);
        }
    }
    return answer;
}
Also used : AbstractKotlinGenerator(org.mybatis.generator.codegen.AbstractKotlinGenerator) GeneratedKotlinFile(org.mybatis.generator.api.GeneratedKotlinFile) ArrayList(java.util.ArrayList) GeneratedKotlinFile(org.mybatis.generator.api.GeneratedKotlinFile) KotlinFile(org.mybatis.generator.api.dom.kotlin.KotlinFile)

Example 3 with KotlinFile

use of org.mybatis.generator.api.dom.kotlin.KotlinFile in project generator by mybatis.

the class KotlinDataClassGenerator method getKotlinFiles.

@Override
public List<KotlinFile> getKotlinFiles() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    // $NON-NLS-1$
    progressCallback.startTask(getString("Progress.8", table.toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();
    FullyQualifiedKotlinType type = new FullyQualifiedKotlinType(introspectedTable.getKotlinRecordType());
    KotlinFile kf = new KotlinFile(type.getShortNameWithoutTypeArguments());
    kf.setPackage(type.getPackageName());
    KotlinType dataClass = KotlinType.newClass(type.getShortNameWithoutTypeArguments()).withModifier(KotlinModifier.DATA).build();
    kf.addNamedItem(dataClass);
    commentGenerator.addFileComment(kf);
    commentGenerator.addModelClassComment(dataClass, introspectedTable);
    List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        FullyQualifiedKotlinType kotlinType = JavaToKotlinTypeConverter.convert(introspectedColumn.getFullyQualifiedJavaType());
        KotlinProperty kp = KotlinProperty.newVar(introspectedColumn.getJavaProperty()).withDataType(// $NON-NLS-1$
        kotlinType.getShortNameWithTypeArguments() + "?").withInitializationString(// $NON-NLS-1$
        "null").build();
        dataClass.addConstructorProperty(kp);
        kf.addImports(kotlinType.getImportList());
    }
    if (context.getPlugins().kotlinDataClassGenerated(kf, dataClass, introspectedTable)) {
        return listOf(kf);
    } else {
        return Collections.emptyList();
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) CommentGenerator(org.mybatis.generator.api.CommentGenerator) KotlinProperty(org.mybatis.generator.api.dom.kotlin.KotlinProperty) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType) KotlinType(org.mybatis.generator.api.dom.kotlin.KotlinType) KotlinFile(org.mybatis.generator.api.dom.kotlin.KotlinFile) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)

Example 4 with KotlinFile

use of org.mybatis.generator.api.dom.kotlin.KotlinFile in project generator by mybatis.

the class KotlinMapperAndExtensionsGenerator method createMapperInterfaceFile.

protected KotlinFile createMapperInterfaceFile() {
    FullyQualifiedKotlinType type = new FullyQualifiedKotlinType(introspectedTable.getMyBatis3JavaMapperType());
    KotlinFile kf = new KotlinFile(type.getShortNameWithoutTypeArguments());
    kf.setPackage(type.getPackageName());
    return kf;
}
Also used : KotlinFile(org.mybatis.generator.api.dom.kotlin.KotlinFile) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)

Example 5 with KotlinFile

use of org.mybatis.generator.api.dom.kotlin.KotlinFile in project generator by mybatis.

the class KotlinDynamicSqlSupportClassGenerator method buildBasicFile.

private KotlinFile buildBasicFile(FullyQualifiedJavaType type) {
    KotlinFile kf = new KotlinFile(type.getShortNameWithoutTypeArguments());
    kf.setPackage(type.getPackageName());
    context.getCommentGenerator().addFileComment(kf);
    return kf;
}
Also used : KotlinFile(org.mybatis.generator.api.dom.kotlin.KotlinFile)

Aggregations

KotlinFile (org.mybatis.generator.api.dom.kotlin.KotlinFile)5 FullyQualifiedKotlinType (org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)3 ArrayList (java.util.ArrayList)2 KotlinType (org.mybatis.generator.api.dom.kotlin.KotlinType)2 CommentGenerator (org.mybatis.generator.api.CommentGenerator)1 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)1 GeneratedKotlinFile (org.mybatis.generator.api.GeneratedKotlinFile)1 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)1 KotlinProperty (org.mybatis.generator.api.dom.kotlin.KotlinProperty)1 AbstractKotlinGenerator (org.mybatis.generator.codegen.AbstractKotlinGenerator)1 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)1