use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class DeleteByPrimaryKeyMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getDeleteByPrimaryKeyStatementId());
if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "key"));
} else {
// no primary key class - fields are in the base class
// if more than one PK field, then we need to annotate the
// parameters
// for MyBatis
List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
boolean annotate = introspectedColumns.size() > 1;
if (annotate) {
importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
"org.apache.ibatis.annotations.Param"));
}
StringBuilder sb = new StringBuilder();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
if (annotate) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("@Param(\"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\")");
parameter.addAnnotation(sb.toString());
}
method.addParameter(parameter);
}
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class InsertMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = new Method();
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setVisibility(JavaVisibility.PUBLIC);
method.setName(introspectedTable.getInsertStatementId());
FullyQualifiedJavaType parameterType;
if (isSimple) {
parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
} else {
parameterType = introspectedTable.getRules().calculateAllFieldsClass();
}
importedTypes.add(parameterType);
//$NON-NLS-1$
method.addParameter(new Parameter(parameterType, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientInsertMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class SelectByExampleWithoutBLOBsMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
importedTypes.add(type);
importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
FullyQualifiedJavaType listType;
if (introspectedTable.getRules().generateBaseRecordClass()) {
listType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
} else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
listType = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
} else {
//$NON-NLS-1$
throw new RuntimeException(getString("RuntimeError.12"));
}
importedTypes.add(listType);
returnType.addTypeArgument(listType);
method.setReturnType(returnType);
method.setName(introspectedTable.getSelectByExampleStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(type, "example"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(interfaze, method);
if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class SelectByPrimaryKeyMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
method.setReturnType(returnType);
importedTypes.add(returnType);
method.setName(introspectedTable.getSelectByPrimaryKeyStatementId());
if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "key"));
} else {
// no primary key class - fields are in the base class
// if more than one PK field, then we need to annotate the
// parameters
// for MyBatis3
List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
boolean annotate = introspectedColumns.size() > 1;
if (annotate) {
importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
"org.apache.ibatis.annotations.Param"));
}
StringBuilder sb = new StringBuilder();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
if (annotate) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("@Param(\"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\")");
parameter.addAnnotation(sb.toString());
}
method.addParameter(parameter);
}
}
addMapperAnnotations(interfaze, method);
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class TestResourceGenerator method simpleClassWithGeneratedAndCustomItems.
public static String simpleClassWithGeneratedAndCustomItems() {
TopLevelClass tlc = new TopLevelClass(new FullyQualifiedJavaType("org.mybatis.test.SimpleClass"));
tlc.setVisibility(JavaVisibility.PUBLIC);
Field field = new Field("description", FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
commentGenerator.addFieldComment(field);
tlc.addField(field);
Method method = new Method("getDescription");
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
method.addBodyLine("return description;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
method = new Method("setDescription");
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "description"));
method.addBodyLine("this.description = description;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
// no comments on these items - they should survive a merge
FullyQualifiedJavaType bigDecimal = new FullyQualifiedJavaType("java.math.BigDecimal");
tlc.addImportedType(bigDecimal);
field = new Field("amount", bigDecimal);
field.setVisibility(JavaVisibility.PRIVATE);
tlc.addField(field);
method = new Method("getAmount");
method.setReturnType(bigDecimal);
method.addBodyLine("return amount;");
method.setVisibility(JavaVisibility.PUBLIC);
tlc.addMethod(method);
method = new Method("setAmount");
method.addParameter(new Parameter(bigDecimal, "amount"));
method.addBodyLine("this.amount = amount;");
method.setVisibility(JavaVisibility.PUBLIC);
tlc.addMethod(method);
return tlc.getFormattedContent();
}
Aggregations