Java Code Examples for org.mybatis.generator.api.dom.java.TopLevelClass#addStaticImports()
The following examples show how to use
org.mybatis.generator.api.dom.java.TopLevelClass#addStaticImports() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderDeleteByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.DELETE_FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getDeleteByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine(String.format("DELETE_FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (context.getPlugins().providerDeleteByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 2
Source File: ProviderCountByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getCountByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine("SELECT(\"count(*)\");"); //$NON-NLS-1$ method.addBodyLine(String.format("FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (context.getPlugins().providerCountByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 3
Source File: ProviderApplyWhereMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.WHERE"); //$NON-NLS-1$ importedTypes.add(new FullyQualifiedJavaType( "java.util.List")); //$NON-NLS-1$ FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); importedTypes.add(new FullyQualifiedJavaType( String.format("%s.Criteria", fqjt.getFullyQualifiedName()))); //$NON-NLS-1$ importedTypes.add(new FullyQualifiedJavaType( String.format("%s.Criterion", fqjt.getFullyQualifiedName()))); //$NON-NLS-1$ Method method = new Method("applyWhere"); //$NON-NLS-1$ method.setVisibility(JavaVisibility.PROTECTED); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "includeExamplePhrase")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); for (String methodLine : methodLines) { method.addBodyLine(methodLine); } if (context.getPlugins().providerApplyWhereMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 4
Source File: ProviderDeleteByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.DELETE_FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getDeleteByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine(String.format("DELETE_FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ method.addBodyLine(String.format("sql.DELETE_FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(sql, example, false);"); //$NON-NLS-1$ method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (context.getPlugins().providerDeleteByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 5
Source File: ProviderUpdateByExampleSelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); 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"); //$NON-NLS-1$ importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$ Method method = new Method(introspectedTable.getUpdateByExampleSelectiveStatementId()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$ "parameter")); //$NON-NLS-1$ FullyQualifiedJavaType record = introspectedTable.getRules().calculateAllFieldsClass(); importedTypes.add(record); method.addBodyLine(String.format("%s record = (%s) parameter.get(\"record\");", //$NON-NLS-1$ record.getShortName(), record.getShortName())); FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$ example.getShortName(), example.getShortName())); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine(""); //$NON-NLS-1$ method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine(String.format("UPDATE(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); //$NON-NLS-1$ for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$ getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); //$NON-NLS-1$ method.addBodyLine(String.format("SET(\"%s = %s\");", //$NON-NLS-1$ escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine("}"); //$NON-NLS-1$ } method.addBodyLine(""); //$NON-NLS-1$ } method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (context.getPlugins().providerUpdateByExampleSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 6
Source File: ProviderInsertSelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES"); //$NON-NLS-1$ FullyQualifiedJavaType fqjt = introspectedTable.getRules() .calculateAllFieldsClass(); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getInsertSelectiveStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "record")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine(String.format("INSERT_INTO(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()))); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { if (introspectedColumn.isIdentity()) { // cannot set values on identity fields continue; } method.addBodyLine(""); //$NON-NLS-1$ if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$ getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } method.addBodyLine(String.format("VALUES(\"%s\", \"%s\");", //$NON-NLS-1$ escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn))); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine("}"); //$NON-NLS-1$ } } method.addBodyLine(""); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 7
Source File: ProviderSelectByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT_DISTINCT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.ORDER_BY"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method(getMethodName()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("BEGIN();"); //$NON-NLS-1$ boolean distinctCheck = true; for (IntrospectedColumn introspectedColumn : getColumns()) { if (distinctCheck) { method.addBodyLine("if (example != null && example.isDistinct()) {"); //$NON-NLS-1$ method.addBodyLine(String.format("SELECT_DISTINCT(\"%s\");", //$NON-NLS-1$ escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("} else {"); //$NON-NLS-1$ method.addBodyLine(String.format("SELECT(\"%s\");", //$NON-NLS-1$ escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("}"); //$NON-NLS-1$ } else { method.addBodyLine(String.format("SELECT(\"%s\");", //$NON-NLS-1$ escapeStringForJava(getSelectListPhrase(introspectedColumn)))); } distinctCheck = false; } method.addBodyLine(String.format("FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ method.addBodyLine(""); //$NON-NLS-1$ method.addBodyLine("if (example != null && example.getOrderByClause() != null) {"); //$NON-NLS-1$ method.addBodyLine("ORDER_BY(example.getOrderByClause());"); //$NON-NLS-1$ method.addBodyLine("}"); //$NON-NLS-1$ method.addBodyLine(""); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 8
Source File: ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); 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"); //$NON-NLS-1$ importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$ Method method = new Method(getMethodName()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$ "parameter")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine(String.format("UPDATE(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); //$NON-NLS-1$ for (IntrospectedColumn introspectedColumn : getColumns()) { StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); //$NON-NLS-1$ method.addBodyLine(String.format("SET(\"%s = %s\");", //$NON-NLS-1$ escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); } method.addBodyLine(""); //$NON-NLS-1$ FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$ example.getShortName(), example.getShortName())); method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 9
Source File: ProviderUpdateByExampleSelectiveMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { 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"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$ Method method = new Method(introspectedTable.getUpdateByExampleSelectiveStatementId()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$ "parameter")); //$NON-NLS-1$ FullyQualifiedJavaType record = introspectedTable.getRules().calculateAllFieldsClass(); importedTypes.add(record); method.addBodyLine(String.format("%s record = (%s) parameter.get(\"record\");", //$NON-NLS-1$ record.getShortName(), record.getShortName())); FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$ example.getShortName(), example.getShortName())); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine(""); //$NON-NLS-1$ if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ } method.addBodyLine(String.format("%sUPDATE(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); //$NON-NLS-1$ for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$ getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); //$NON-NLS-1$ method.addBodyLine(String.format("%sSET(\"%s = %s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine("}"); //$NON-NLS-1$ } method.addBodyLine(""); //$NON-NLS-1$ } if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("applyWhere(sql, example, true);"); //$NON-NLS-1$ method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (context.getPlugins().providerUpdateByExampleSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 10
Source File: ProviderInsertSelectiveMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = introspectedTable.getRules() .calculateAllFieldsClass(); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getInsertSelectiveStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "record")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ } method.addBodyLine(String.format("%sINSERT_INTO(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()))); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { if (introspectedColumn.isIdentity()) { // cannot set values on identity fields continue; } method.addBodyLine(""); //$NON-NLS-1$ if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$ getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } method.addBodyLine(String.format("%sVALUES(\"%s\", \"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn))); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine("}"); //$NON-NLS-1$ } } method.addBodyLine(""); //$NON-NLS-1$ if (useLegacyBuilder) { method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 11
Source File: ProviderCountByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getCountByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); method.addBodyLine("SELECT(\"count(*)\");"); method.addBodyLine(String.format("FROM(\"%s\");", escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); method.addBodyLine("return SQL();"); } else { method.addBodyLine("SQL sql = new SQL();"); method.addBodyLine(String.format("sql.SELECT(\"count(*)\").FROM(\"%s\");", escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(sql, example, false);"); method.addBodyLine("return sql.toString();"); } if (context.getPlugins().providerCountByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 12
Source File: ProviderSelectByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT_DISTINCT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.ORDER_BY"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method(getMethodName()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ } boolean distinctCheck = true; for (IntrospectedColumn introspectedColumn : getColumns()) { if (distinctCheck) { method.addBodyLine("if (example != null && example.isDistinct()) {"); //$NON-NLS-1$ method.addBodyLine(String.format("%sSELECT_DISTINCT(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("} else {"); //$NON-NLS-1$ method.addBodyLine(String.format("%sSELECT(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("}"); //$NON-NLS-1$ } else { method.addBodyLine(String.format("%sSELECT(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); } distinctCheck = false; } method.addBodyLine(String.format("%sFROM(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ } else { method.addBodyLine("applyWhere(sql, example, false);"); //$NON-NLS-1$ } method.addBodyLine(""); //$NON-NLS-1$ method.addBodyLine("if (example != null && example.getOrderByClause() != null) {"); //$NON-NLS-1$ method.addBodyLine(String.format("%sORDER_BY(example.getOrderByClause());", builderPrefix)); //$NON-NLS-1$ method.addBodyLine("}"); //$NON-NLS-1$ method.addBodyLine(""); //$NON-NLS-1$ if (useLegacyBuilder) { method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 13
Source File: ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { 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"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$ Method method = new Method(getMethodName()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$ "parameter")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ } method.addBodyLine(String.format("%sUPDATE(\"%s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); //$NON-NLS-1$ for (IntrospectedColumn introspectedColumn : getColumns()) { StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); //$NON-NLS-1$ method.addBodyLine(String.format("%sSET(\"%s = %s\");", //$NON-NLS-1$ builderPrefix, escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); } method.addBodyLine(""); //$NON-NLS-1$ FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$ example.getShortName(), example.getShortName())); if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("applyWhere(sql, example, true);"); //$NON-NLS-1$ method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 14
Source File: ProviderCountByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<String>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); //$NON-NLS-1$ staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getCountByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); //$NON-NLS-1$ method.addBodyLine("SELECT(\"count(*)\");"); //$NON-NLS-1$ method.addBodyLine(String.format("FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); //$NON-NLS-1$ method.addBodyLine("return SQL();"); //$NON-NLS-1$ } else { method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$ method.addBodyLine(String.format("sql.SELECT(\"count(*)\").FROM(\"%s\");", //$NON-NLS-1$ escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(sql, example, false);"); //$NON-NLS-1$ method.addBodyLine("return sql.toString();"); //$NON-NLS-1$ } if (context.getPlugins().providerCountByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 15
Source File: ProviderUpdateByExampleSelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); Method method = new Method(introspectedTable.getUpdateByExampleSelectiveStatementId()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter( new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), "parameter")); FullyQualifiedJavaType record = introspectedTable.getRules().calculateAllFieldsClass(); importedTypes.add(record); method.addBodyLine(String.format("%s record = (%s) parameter.get(\"record\");", record.getShortName(), record.getShortName())); FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", example.getShortName(), example.getShortName())); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine(""); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); } else { method.addBodyLine("SQL sql = new SQL();"); } method.addBodyLine(String.format("%sUPDATE(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns())) { if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine(String.format("if (record.%s() != null) {", getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); method.addBodyLine(String.format("%sSET(\"%s = %s\");", builderPrefix, escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) { method.addBodyLine("}"); } method.addBodyLine(""); } if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, true);"); method.addBodyLine("return SQL();"); } else { method.addBodyLine("applyWhere(sql, example, true);"); method.addBodyLine("return sql.toString();"); } if (context.getPlugins().providerUpdateByExampleSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 16
Source File: ProviderInsertSelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = introspectedTable.getRules() .calculateAllFieldsClass(); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getInsertSelectiveStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "record")); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); } else { method.addBodyLine("SQL sql = new SQL();"); } method.addBodyLine(String.format("%sINSERT_INTO(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()))); for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) { method.addBodyLine(""); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine(String.format("if (record.%s() != null) {", getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType()))); } method.addBodyLine(String.format("%sVALUES(\"%s\", \"%s\");", builderPrefix, escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn))); if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) { method.addBodyLine("}"); } } method.addBodyLine(""); if (useLegacyBuilder) { method.addBodyLine("return SQL();"); } else { method.addBodyLine("return sql.toString();"); } if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 17
Source File: ProviderDeleteByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.DELETE_FROM"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method( introspectedTable.getDeleteByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); method.addBodyLine(String.format("DELETE_FROM(\"%s\");", escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(example, false);"); method.addBodyLine("return SQL();"); } else { method.addBodyLine("SQL sql = new SQL();"); method.addBodyLine(String.format("sql.DELETE_FROM(\"%s\");", escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine("applyWhere(sql, example, false);"); method.addBodyLine("return sql.toString();"); } if (context.getPlugins().providerDeleteByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 18
Source File: ProviderSelectByExampleWithoutBLOBsMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SELECT_DISTINCT"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.FROM"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.ORDER_BY"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(fqjt); Method method = new Method(getMethodName()); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.addParameter(new Parameter(fqjt, "example")); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); } else { method.addBodyLine("SQL sql = new SQL();"); } boolean distinctCheck = true; for (IntrospectedColumn introspectedColumn : getColumns()) { if (distinctCheck) { method.addBodyLine("if (example != null && example.isDistinct()) {"); method.addBodyLine(String.format("%sSELECT_DISTINCT(\"%s\");", builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("} else {"); method.addBodyLine(String.format("%sSELECT(\"%s\");", builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); method.addBodyLine("}"); } else { method.addBodyLine(String.format("%sSELECT(\"%s\");", builderPrefix, escapeStringForJava(getSelectListPhrase(introspectedColumn)))); } distinctCheck = false; } method.addBodyLine(String.format("%sFROM(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, false);"); } else { method.addBodyLine("applyWhere(sql, example, false);"); } method.addBodyLine(""); method.addBodyLine("if (example != null && example.getOrderByClause() != null) {"); method.addBodyLine(String.format("%sORDER_BY(example.getOrderByClause());", builderPrefix)); method.addBodyLine("}"); method.addBodyLine(""); if (useLegacyBuilder) { method.addBodyLine("return SQL();"); } else { method.addBodyLine("return sql.toString();"); } if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 19
Source File: ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public void addClassElements(TopLevelClass topLevelClass) { Set<String> staticImports = new TreeSet<>(); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); if (useLegacyBuilder) { staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); } else { importedTypes.add(NEW_BUILDER_IMPORT); } importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); Method method = new Method(getMethodName()); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter( new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), "parameter")); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); if (useLegacyBuilder) { method.addBodyLine("BEGIN();"); } else { method.addBodyLine("SQL sql = new SQL();"); } method.addBodyLine(String.format("%sUPDATE(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); method.addBodyLine(""); for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(getColumns())) { StringBuilder sb = new StringBuilder(); sb.append(getParameterClause(introspectedColumn)); sb.insert(2, "record."); method.addBodyLine(String.format("%sSET(\"%s = %s\");", builderPrefix, escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), sb.toString())); } method.addBodyLine(""); FullyQualifiedJavaType example = new FullyQualifiedJavaType(introspectedTable.getExampleType()); importedTypes.add(example); method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", example.getShortName(), example.getShortName())); if (useLegacyBuilder) { method.addBodyLine("applyWhere(example, true);"); method.addBodyLine("return SQL();"); } else { method.addBodyLine("applyWhere(sql, example, true);"); method.addBodyLine("return sql.toString();"); } if (callPlugins(method, topLevelClass)) { topLevelClass.addStaticImports(staticImports); topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }