Search in sources :

Example 1 with KotlinProperty

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

the class KotlinDynamicSqlSupportClassGenerator method handleColumn.

private void handleColumn(KotlinFile kotlinFile, KotlinType outerObject, KotlinType innerClass, String tableFieldName, IntrospectedColumn column) {
    FullyQualifiedKotlinType kt = JavaToKotlinTypeConverter.convert(column.getFullyQualifiedJavaType());
    kotlinFile.addImports(kt.getImportList());
    String fieldName = column.getJavaProperty();
    // outer object
    if (fieldName.equals(tableFieldName)) {
        // name collision, skip the shortcut field
        warnings.add(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "Warning.29", fieldName, getSupportObjectImport()));
    } else {
        KotlinProperty prop = KotlinProperty.newVal(fieldName).withInitializationString(tableFieldName + "." + fieldName).build();
        outerObject.addNamedItem(prop);
    }
    // inner class
    KotlinProperty property = KotlinProperty.newVal(fieldName).withInitializationString(calculateInnerInitializationString(column, kt)).build();
    innerClass.addNamedItem(property);
}
Also used : KotlinProperty(org.mybatis.generator.api.dom.kotlin.KotlinProperty) FullyQualifiedKotlinType(org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)

Example 2 with KotlinProperty

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

Aggregations

FullyQualifiedKotlinType (org.mybatis.generator.api.dom.kotlin.FullyQualifiedKotlinType)2 KotlinProperty (org.mybatis.generator.api.dom.kotlin.KotlinProperty)2 CommentGenerator (org.mybatis.generator.api.CommentGenerator)1 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)1 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)1 KotlinFile (org.mybatis.generator.api.dom.kotlin.KotlinFile)1 KotlinType (org.mybatis.generator.api.dom.kotlin.KotlinType)1