use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class UpdateByPrimaryKeyWithoutBLOBsMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
importedTypes.add(parameterType);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getUpdateByPrimaryKeyStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(parameterType, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(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 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);
}
}
Aggregations