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