Java Code Examples for org.mybatis.generator.api.dom.java.TopLevelClass#addImportedTypes()
The following examples show how to use
org.mybatis.generator.api.dom.java.TopLevelClass#addImportedTypes() .
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: SelectByExampleWithBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); if (generateForJava5) { method.addSuppressTypeWarningsAnnotation(); } StringBuilder sb = new StringBuilder(); sb.append(method.getReturnType().getShortName()); sb.append(" list = "); //$NON-NLS-1$ sb.append(daoTemplate.getQueryForListMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getSelectByExampleWithBLOBsStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return list;"); //$NON-NLS-1$ if (context.getPlugins() .clientSelectByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 2
Source File: UpdateByExampleSelectiveMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); method .addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getUpdateMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getUpdateByExampleSelectiveStatementId(), "parms")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins() .clientUpdateByExampleSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 3
Source File: SelectByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); if (generateForJava5) { method.addSuppressTypeWarningsAnnotation(); } StringBuilder sb = new StringBuilder(); sb.append(method.getReturnType().getShortName()); sb.append(" list = "); //$NON-NLS-1$ sb.append(daoTemplate.getQueryForListMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getSelectByExampleStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return list;"); //$NON-NLS-1$ if (context.getPlugins() .clientSelectByExampleWithoutBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 4
Source File: UpdateByExampleWithBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); method .addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getUpdateMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getUpdateByExampleWithBLOBsStatementId(), "parms")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins() .clientUpdateByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 5
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getUpdateMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getUpdateByPrimaryKeyStatementId(), "record")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins() .clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 6
Source File: DeleteByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getDeleteMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getDeleteByExampleStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins().clientDeleteByExampleMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 7
Source File: SelectByExampleWithBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); if (generateForJava5) { method.addSuppressTypeWarningsAnnotation(); } StringBuilder sb = new StringBuilder(); sb.append(method.getReturnType().getShortName()); sb.append(" list = "); //$NON-NLS-1$ sb.append(daoTemplate.getQueryForListMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getSelectByExampleWithBLOBsStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return list;"); //$NON-NLS-1$ if (context.getPlugins() .clientSelectByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 8
Source File: DeleteByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getDeleteMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getDeleteByExampleStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins().clientDeleteByExampleMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 9
Source File: UpdateByExampleWithBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); method .addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getUpdateMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getUpdateByExampleWithBLOBsStatementId(), "parms")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins() .clientUpdateByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 10
Source File: CountByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); // generate the implementation method StringBuilder sb = new StringBuilder(); sb.append("Integer count = (Integer) "); //$NON-NLS-1$ sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getCountByExampleStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); if (generateForJava5) { method.addBodyLine("return count;"); //$NON-NLS-1$ } else { method.addBodyLine("return count.intValue();"); //$NON-NLS-1$ } if (context.getPlugins().clientCountByExampleMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 11
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 12
Source File: DeleteByPrimaryKeyMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); StringBuilder sb = new StringBuilder(); if (!introspectedTable.getRules().generatePrimaryKeyClass()) { // no primary key class, but primary key is enabled. Primary // key columns must be in the base class. FullyQualifiedJavaType keyType = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); topLevelClass.addImportedType(keyType); sb.setLength(0); sb.append(keyType.getShortName()); sb.append(" _key = new "); //$NON-NLS-1$ sb.append(keyType.getShortName()); sb.append("();"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { sb.setLength(0); sb.append("_key."); //$NON-NLS-1$ sb.append(getSetterMethodName(introspectedColumn .getJavaProperty())); sb.append('('); sb.append(introspectedColumn.getJavaProperty()); sb.append(");"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); } } sb.setLength(0); sb.append("int rows = "); //$NON-NLS-1$ sb.append(daoTemplate.getDeleteMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getDeleteByPrimaryKeyStatementId(), "_key")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return rows;"); //$NON-NLS-1$ if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 13
Source File: SelectByPrimaryKeyMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); // generate the implementation method StringBuilder sb = new StringBuilder(); if (!introspectedTable.getRules().generatePrimaryKeyClass()) { // no primary key class, but primary key is enabled. Primary // key columns must be in the base class. FullyQualifiedJavaType keyType = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); topLevelClass.addImportedType(keyType); sb.setLength(0); sb.append(keyType.getShortName()); sb.append(" _key = new "); //$NON-NLS-1$ sb.append(keyType.getShortName()); sb.append("();"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { sb.setLength(0); sb.append("_key."); //$NON-NLS-1$ sb.append(getSetterMethodName(introspectedColumn .getJavaProperty())); sb.append('('); sb.append(introspectedColumn.getJavaProperty()); sb.append(");"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); } } FullyQualifiedJavaType returnType = method.getReturnType(); sb.setLength(0); sb.append(returnType.getShortName()); sb.append(" record = ("); //$NON-NLS-1$ sb.append(returnType.getShortName()); sb.append(") "); //$NON-NLS-1$ sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getSelectByPrimaryKeyStatementId(), "_key")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return record;"); //$NON-NLS-1$ if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 14
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 15
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 16
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 17
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 18
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 19
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 20
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); } }