Search in sources :

Example 1 with KotlinType

use of org.mybatis.generator.api.dom.kotlin.KotlinType 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 KotlinType

use of org.mybatis.generator.api.dom.kotlin.KotlinType 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 3 with KotlinType

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

the class KotlinMapperAndExtensionsGenerator method createMapperInterface.

protected KotlinType createMapperInterface(KotlinFile kotlinFile) {
    FullyQualifiedKotlinType type = new FullyQualifiedKotlinType(introspectedTable.getMyBatis3JavaMapperType());
    KotlinType intf = KotlinType.newInterface(type.getShortNameWithoutTypeArguments()).withAnnotation(// $NON-NLS-1$
    "@Mapper").build();
    // $NON-NLS-1$
    kotlinFile.addImport("org.apache.ibatis.annotations.Mapper");
    kotlinFile.addNamedItem(intf);
    context.getCommentGenerator().addFileComment(kotlinFile);
    return intf;
}
Also used : KotlinType(org.mybatis.generator.api.dom.kotlin.KotlinType) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)

Example 4 with KotlinType

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

the class KotlinDynamicSqlSupportClassGenerator method buildOuterObject.

private KotlinType buildOuterObject(KotlinFile kotlinFile, FullyQualifiedJavaType type) {
    KotlinType outerObject = KotlinType.newObject(type.getShortNameWithoutTypeArguments()).build();
    // $NON-NLS-1$
    kotlinFile.addImport("org.mybatis.dynamic.sql.AliasableSqlTable");
    // $NON-NLS-1$
    kotlinFile.addImport("org.mybatis.dynamic.sql.util.kotlin.elements.column");
    // $NON-NLS-1$
    kotlinFile.addImport("java.sql.JDBCType");
    kotlinFile.addNamedItem(outerObject);
    return outerObject;
}
Also used : FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType) KotlinType(org.mybatis.generator.api.dom.kotlin.KotlinType)

Aggregations

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