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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations