use of org.mybatis.generator.api.dom.kotlin.KotlinFunction in project generator by mybatis.
the class InsertMultipleMethodGenerator method generateMethodAndImports.
@Override
public KotlinFunctionAndImports generateMethodAndImports() {
if (!Utils.generateMultipleRowInsert(introspectedTable)) {
return null;
}
// Kotlin type inference gets lost if we don't name the helper method something different from the
// regular mapper method
String functionImport;
String functionShortName;
if (Utils.canRetrieveMultiRowGeneratedKeys(introspectedTable)) {
functionImport = // $NON-NLS-1$
"org.mybatis.dynamic.sql.util.kotlin.mybatis3.insertMultipleWithGeneratedKeys";
// $NON-NLS-1$
functionShortName = "insertMultipleWithGeneratedKeys";
} else {
// $NON-NLS-1$
functionImport = "org.mybatis.dynamic.sql.util.kotlin.mybatis3.insertMultiple";
// $NON-NLS-1$
functionShortName = "insertMultiple";
}
KotlinFunctionAndImports functionAndImports = KotlinFunctionAndImports.withFunction(// $NON-NLS-1$
KotlinFunction.newOneLineFunction(mapperName + ".insertMultiple").withArgument(// $NON-NLS-1$
KotlinArg.newArg("records").withDataType(// $NON-NLS-1$
"Collection<" + recordType.getShortNameWithTypeArguments() + // $NON-NLS-1$
">").build()).build()).withImport(functionImport).withImports(recordType.getImportList()).build();
addFunctionComment(functionAndImports);
KotlinFunction function = functionAndImports.getFunction();
function.addCodeLine(// $NON-NLS-1$
functionShortName + "(this::insertMultiple" + ", records, " + // $NON-NLS-1$
tableFieldName + // $NON-NLS-1$
") {");
List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
for (IntrospectedColumn column : columns) {
AbstractKotlinFunctionGenerator.FieldNameAndImport fieldNameAndImport = AbstractKotlinFunctionGenerator.calculateFieldNameAndImport(tableFieldName, supportObjectImport, column);
functionAndImports.getImports().add(fieldNameAndImport.importString());
function.addCodeLine(// $NON-NLS-1$
" map(" + fieldNameAndImport.fieldName() + ") toProperty \"" + // $NON-NLS-1$
column.getJavaProperty() + // $NON-NLS-1$
"\"");
}
// $NON-NLS-1$
function.addCodeLine("}");
return functionAndImports;
}
use of org.mybatis.generator.api.dom.kotlin.KotlinFunction in project generator by mybatis.
the class UpdateAllColumnsMethodGenerator method generateMethodAndImports.
@Override
public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunctionAndImports functionAndImports = KotlinFunctionAndImports.withFunction(// $NON-NLS-1$
KotlinFunction.newOneLineFunction("KotlinUpdateBuilder.updateAllColumns").withArgument(// $NON-NLS-1$
KotlinArg.newArg("row").withDataType(recordType.getShortNameWithTypeArguments()).build()).build()).withImport(// $NON-NLS-1$
"org.mybatis.dynamic.sql.util.kotlin.KotlinUpdateBuilder").withImports(recordType.getImportList()).build();
addFunctionComment(functionAndImports);
KotlinFunction function = functionAndImports.getFunction();
// $NON-NLS-1$
function.addCodeLine("apply {");
List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
KotlinFunctionParts functionParts = fragmentGenerator.getSetEqualLines(columns);
acceptParts(functionAndImports, functionParts);
// $NON-NLS-1$
function.addCodeLine("}");
return functionAndImports;
}
use of org.mybatis.generator.api.dom.kotlin.KotlinFunction in project generator by mybatis.
the class InsertMethodGenerator method generateMethodAndImports.
@Override
public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunctionAndImports functionAndImports = KotlinFunctionAndImports.withFunction(// $NON-NLS-1$
KotlinFunction.newOneLineFunction(mapperName + ".insert").withArgument(// $NON-NLS-1$
KotlinArg.newArg("row").withDataType(recordType.getShortNameWithTypeArguments()).build()).build()).withImport(// $NON-NLS-1$
"org.mybatis.dynamic.sql.util.kotlin.mybatis3.insert").withImports(recordType.getImportList()).build();
addFunctionComment(functionAndImports);
KotlinFunction function = functionAndImports.getFunction();
function.addCodeLine(// $NON-NLS-1$
"insert(this::insert, row, " + tableFieldName + // $NON-NLS-1$
") {");
List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
for (IntrospectedColumn column : columns) {
AbstractKotlinFunctionGenerator.FieldNameAndImport fieldNameAndImport = AbstractKotlinFunctionGenerator.calculateFieldNameAndImport(tableFieldName, supportObjectImport, column);
functionAndImports.getImports().add(fieldNameAndImport.importString());
function.addCodeLine(// $NON-NLS-1$
" map(" + fieldNameAndImport.fieldName() + ") toProperty \"" + // $NON-NLS-1$
column.getJavaProperty() + // $NON-NLS-1$
"\"");
}
// $NON-NLS-1$
function.addCodeLine("}");
return functionAndImports;
}
use of org.mybatis.generator.api.dom.kotlin.KotlinFunction in project generator by mybatis.
the class InsertSelectiveMethodGenerator method generateMethodAndImports.
@Override
public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunctionAndImports functionAndImports = KotlinFunctionAndImports.withFunction(// $NON-NLS-1$
KotlinFunction.newOneLineFunction(mapperName + ".insertSelective").withArgument(// $NON-NLS-1$
KotlinArg.newArg("row").withDataType(recordType.getShortNameWithTypeArguments()).build()).build()).withImport(// $NON-NLS-1$
"org.mybatis.dynamic.sql.util.kotlin.mybatis3.insert").withImports(recordType.getImportList()).build();
addFunctionComment(functionAndImports);
KotlinFunction function = functionAndImports.getFunction();
function.addCodeLine(// $NON-NLS-1$
"insert(this::insert, row, " + tableFieldName + // $NON-NLS-1$
") {");
List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
for (IntrospectedColumn column : columns) {
AbstractKotlinFunctionGenerator.FieldNameAndImport fieldNameAndImport = AbstractKotlinFunctionGenerator.calculateFieldNameAndImport(tableFieldName, supportObjectImport, column);
functionAndImports.getImports().add(fieldNameAndImport.importString());
if (column.isSequenceColumn()) {
function.addCodeLine(// $NON-NLS-1$
" map(" + fieldNameAndImport.fieldName() + ").toProperty(\"" + // $NON-NLS-1$
column.getJavaProperty() + // $NON-NLS-1$
"\")");
} else {
function.addCodeLine(// $NON-NLS-1$
" map(" + fieldNameAndImport.fieldName() + ").toPropertyWhenPresent(\"" + // $NON-NLS-1$
column.getJavaProperty() + // $NON-NLS-1$
"\", row::" + column.getJavaProperty() + // $NON-NLS-1$
")");
}
}
// $NON-NLS-1$
function.addCodeLine("}");
return functionAndImports;
}
use of org.mybatis.generator.api.dom.kotlin.KotlinFunction in project generator by mybatis.
the class UpdateSelectiveColumnsMethodGenerator method generateMethodAndImports.
@Override
public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunctionAndImports functionAndImports = KotlinFunctionAndImports.withFunction(// $NON-NLS-1$
KotlinFunction.newOneLineFunction("KotlinUpdateBuilder.updateSelectiveColumns").withArgument(// $NON-NLS-1$
KotlinArg.newArg("row").withDataType(recordType.getShortNameWithTypeArguments()).build()).build()).withImport(// $NON-NLS-1$
"org.mybatis.dynamic.sql.util.kotlin.KotlinUpdateBuilder").withImports(recordType.getImportList()).build();
addFunctionComment(functionAndImports);
KotlinFunction function = functionAndImports.getFunction();
// $NON-NLS-1$
function.addCodeLine("apply {");
List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
KotlinFunctionParts functionParts = fragmentGenerator.getSetEqualWhenPresentLines(columns);
acceptParts(functionAndImports, functionParts);
// $NON-NLS-1$
function.addCodeLine("}");
return functionAndImports;
}
Aggregations