use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class ProviderUpdateByExampleWithoutBLOBsMethodGenerator method addClassElements.
@Override
public void addClassElements(TopLevelClass topLevelClass) {
Set<String> staticImports = new TreeSet<String>();
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
if (useLegacyBuilder) {
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL");
} else {
importedTypes.add(NEW_BUILDER_IMPORT);
}
//$NON-NLS-1$
importedTypes.add(new FullyQualifiedJavaType("java.util.Map"));
Method method = new Method(getMethodName());
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
method.setVisibility(JavaVisibility.PUBLIC);
method.addParameter(new //$NON-NLS-1$
Parameter(//$NON-NLS-1$
new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$
"parameter"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("BEGIN();");
} else {
//$NON-NLS-1$
method.addBodyLine("SQL sql = new SQL();");
}
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sUPDATE(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())));
//$NON-NLS-1$
method.addBodyLine("");
for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(getColumns())) {
StringBuilder sb = new StringBuilder();
sb.append(getParameterClause(introspectedColumn));
//$NON-NLS-1$
sb.insert(2, "record.");
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sSET(\"%s = %s\");", builderPrefix, escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString()));
}
//$NON-NLS-1$
method.addBodyLine("");
FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType());
importedTypes.add(example);
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%s example = (%s) parameter.get(\"example\");", example.getShortName(), example.getShortName()));
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("applyWhere(example, true);");
//$NON-NLS-1$
method.addBodyLine("return SQL();");
} else {
//$NON-NLS-1$
method.addBodyLine("applyWhere(sql, example, true);");
//$NON-NLS-1$
method.addBodyLine("return sql.toString();");
}
if (callPlugins(method, topLevelClass)) {
topLevelClass.addStaticImports(staticImports);
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class UpdateByPrimaryKeySelectiveMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType parameterType;
if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
} else {
parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
}
importedTypes.add(parameterType);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(parameterType, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientUpdateByPrimaryKeySelectiveMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class UpdateByPrimaryKeyWithBLOBsMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType parameterType;
if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
} else {
parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
}
importedTypes.add(parameterType);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(parameterType, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Method 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.Method 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);
}
}
Aggregations