Java Code Examples for org.mybatis.generator.api.dom.java.TopLevelClass#addImportedType()
The following examples show how to use
org.mybatis.generator.api.dom.java.TopLevelClass#addImportedType() .
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: MyPgMapperPlugin.java From jvue-admin with MIT License | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if(forceAnnotation){ topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 2
Source File: CrudSupportPlugin.java From azeroth with Apache License 2.0 | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 3
Source File: GeneratorSwagger2Doc.java From mybatis-generator-plugins with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { String classAnnotation = "@ApiModel(value=\"" + topLevelClass.getType() + "\")"; if(!topLevelClass.getAnnotations().contains(classAnnotation)) { topLevelClass.addAnnotation(classAnnotation); } String apiModelAnnotationPackage = properties.getProperty("apiModelAnnotationPackage"); String apiModelPropertyAnnotationPackage = properties.getProperty("apiModelPropertyAnnotationPackage"); if(null == apiModelAnnotationPackage) apiModelAnnotationPackage = "io.swagger.annotations.ApiModel"; if(null == apiModelPropertyAnnotationPackage) apiModelPropertyAnnotationPackage = "io.swagger.annotations.ApiModelProperty"; topLevelClass.addImportedType(apiModelAnnotationPackage); topLevelClass.addImportedType(apiModelPropertyAnnotationPackage); field.addAnnotation("@ApiModelProperty(value=\"" + introspectedColumn.getJavaProperty() + introspectedColumn.getRemarks() + "\")"); return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType); }
Example 4
Source File: HySwaggerMapperPlugin.java From jvue-admin with MIT License | 6 votes |
private void columnTypeAnnotation(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (this.columnTypeEnabled) { String columnType = "tk.mybatis.mapper.annotation.ColumnType"; String jdbcType = "org.apache.ibatis.type.JdbcType"; topLevelClass.addImportedType(columnType); topLevelClass.addImportedType(jdbcType); List<Field> fields = topLevelClass.getFields(); for (Field field : fields) { List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns(); for (IntrospectedColumn introspectedColumn : allColumns) if (field.getName().equals(introspectedColumn.getJavaProperty())) { String jdbcTypeName = introspectedColumn.getJdbcTypeName(); if(StringUtil.isEmpty(jdbcTypeName)){ continue; }else{ jdbcTypeName="JdbcType."+jdbcTypeName; } field.addAnnotation("@ColumnType(jdbcType=" + jdbcTypeName + ")"); } } } }
Example 5
Source File: CrudSupportPlugin.java From jeesuite-libs with Apache License 2.0 | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 6
Source File: SerializablePlugin.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (addGWTInterface) { topLevelClass.addImportedType(gwtSerializable); topLevelClass.addSuperInterface(gwtSerializable); } if (!suppressJavaInterface) { topLevelClass.addImportedType(serializable); topLevelClass.addSuperInterface(serializable); Field field = new Field(); field.setFinal(true); field.setInitializationString("1L"); //$NON-NLS-1$ field.setName("serialVersionUID"); //$NON-NLS-1$ field.setStatic(true); field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$ field.setVisibility(JavaVisibility.PRIVATE); context.getCommentGenerator().addFieldComment(field, introspectedTable); topLevelClass.addField(field); } }
Example 7
Source File: WrapObjectPlugin.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Override public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (tableMatches(introspectedTable)) { FullyQualifiedJavaType type = new FullyQualifiedJavaType(objectClass.getName()); Field field = new Field(objectFieldName, type); field.setVisibility(JavaVisibility.PROTECTED); field.setInitializationString(String.format("new %s()", objectClass.getSimpleName())); field.addJavaDocLine("/**"); field.addJavaDocLine(" * This field was generated by MyBatis Generator."); field.addJavaDocLine(" * This field corresponds to the wrapped object."); field.addJavaDocLine(" *"); field.addJavaDocLine(" * @mbggenerated"); field.addJavaDocLine(" */"); topLevelClass.addField(field); topLevelClass.addImportedType(type); } return true; }
Example 8
Source File: CustomSerializablePlugin.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (addGWTInterface) { topLevelClass.addImportedType(gwtSerializable); topLevelClass.addSuperInterface(gwtSerializable); } if (!suppressJavaInterface) { topLevelClass.addImportedType(serializable); topLevelClass.addSuperInterface(serializable); Field field = new Field(); field.setFinal(true); field.setInitializationString("1L"); //$NON-NLS-1$ field.setName("serialVersionUID"); //$NON-NLS-1$ field.setStatic(true); field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$ field.setVisibility(JavaVisibility.PRIVATE); context.getCommentGenerator().addFieldComment(field, introspectedTable); topLevelClass.addField(field); } }
Example 9
Source File: DynamicSqlSupportClassGenerator.java From mybatis-generator-plugins with Apache License 2.0 | 5 votes |
private TopLevelClass buildBasicClass() { TopLevelClass topLevelClass = new TopLevelClass(calculateClassName()); topLevelClass.setVisibility(JavaVisibility.PUBLIC); topLevelClass.setFinal(true); topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlColumn")); //$NON-NLS-1$ topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlTable")); //$NON-NLS-1$ topLevelClass.addImportedType(new FullyQualifiedJavaType("java.sql.JDBCType")); //$NON-NLS-1$ return topLevelClass; }
Example 10
Source File: ExampleExtendsPlugin.java From S-mall-ssm with GNU General Public License v3.0 | 5 votes |
@Override public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { // import接口 topLevelClass.addImportedType(example); topLevelClass.addSuperInterface(new FullyQualifiedJavaType( example )); return true; }
Example 11
Source File: DAOGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
protected TopLevelClass getTopLevelClassShell() { FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType( introspectedTable.getDAOInterfaceType()); FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType( introspectedTable.getDAOImplementationType()); CommentGenerator commentGenerator = context.getCommentGenerator(); TopLevelClass answer = new TopLevelClass(implementationType); answer.setVisibility(JavaVisibility.PUBLIC); answer.setSuperClass(daoTemplate.getSuperClass()); answer.addImportedType(daoTemplate.getSuperClass()); answer.addSuperInterface(interfaceType); answer.addImportedType(interfaceType); for (FullyQualifiedJavaType fqjt : daoTemplate .getImplementationImports()) { answer.addImportedType(fqjt); } commentGenerator.addJavaFileComment(answer); // add constructor from the template answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable)); // add any fields from the template for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) { answer.addField(field); } // add any methods from the template for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) { answer.addMethod(method); } return answer; }
Example 12
Source File: DynamicSqlModelGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString("Progress.8", table.toString())); Plugin plugins = context.getPlugins(); CommentGenerator commentGenerator = context.getCommentGenerator(); FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); TopLevelClass topLevelClass = new TopLevelClass(type); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); FullyQualifiedJavaType superClass = getSuperClass(); if (superClass != null) { topLevelClass.setSuperClass(superClass); topLevelClass.addImportedType(superClass); } commentGenerator.addModelClassComment(topLevelClass, introspectedTable); List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns(); if (introspectedTable.isConstructorBased()) { addParameterizedConstructor(topLevelClass); if (!introspectedTable.isImmutable()) { addDefaultConstructorWithGeneratedAnnotatoin(topLevelClass); } } String rootClass = getRootClass(); for (IntrospectedColumn introspectedColumn : introspectedColumns) { if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) { continue; } Field field = getJavaBeansFieldWithGeneratedAnnotation(introspectedColumn, context, introspectedTable, topLevelClass); if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addField(field); topLevelClass.addImportedType(field.getType()); } Method method = getJavaBeansGetterWithGeneratedAnnotation(introspectedColumn, context, introspectedTable, topLevelClass); if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } if (!introspectedTable.isImmutable()) { method = getJavaBeansSetterWithGeneratedAnnotation(introspectedColumn, context, introspectedTable, topLevelClass); if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } } } List<CompilationUnit> answer = new ArrayList<>(); if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example 13
Source File: PrimaryKeyGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString( "Progress.7", table.toString())); //$NON-NLS-1$ Plugin plugins = context.getPlugins(); CommentGenerator commentGenerator = context.getCommentGenerator(); TopLevelClass topLevelClass = new TopLevelClass(introspectedTable .getPrimaryKeyType()); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); String rootClass = getRootClass(); if (rootClass != null) { topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass)); topLevelClass.addImportedType(topLevelClass.getSuperClass()); } if (introspectedTable.isConstructorBased()) { addParameterizedConstructor(topLevelClass); if (!introspectedTable.isImmutable()) { addDefaultConstructor(topLevelClass); } } commentGenerator.addModelClassComment(topLevelClass, introspectedTable); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { if (RootClassInfo.getInstance(rootClass, warnings) .containsProperty(introspectedColumn)) { continue; } Field field = getJavaBeansField(introspectedColumn, context, introspectedTable); if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) { topLevelClass.addField(field); topLevelClass.addImportedType(field.getType()); } Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable); if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) { topLevelClass.addMethod(method); } if (!introspectedTable.isImmutable()) { method = getJavaBeansSetter(introspectedColumn, context, introspectedTable); if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) { topLevelClass.addMethod(method); } } } List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (context.getPlugins().modelPrimaryKeyClassGenerated( topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example 14
Source File: DeleteByPrimaryKeyMethodGenerator.java From mybatis-generator-plus 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 15
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 16
Source File: BaseRecordGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString( "Progress.8", table.toString())); //$NON-NLS-1$ Plugin plugins = context.getPlugins(); CommentGenerator commentGenerator = context.getCommentGenerator(); TopLevelClass topLevelClass = new TopLevelClass(introspectedTable .getBaseRecordType()); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); FullyQualifiedJavaType superClass = getSuperClass(); if (superClass != null) { topLevelClass.setSuperClass(superClass); topLevelClass.addImportedType(superClass); } List<IntrospectedColumn> introspectedColumns; if (includePrimaryKeyColumns()) { if (includeBLOBColumns()) { introspectedColumns = introspectedTable.getAllColumns(); } else { introspectedColumns = introspectedTable.getNonBLOBColumns(); } } else { if (includeBLOBColumns()) { introspectedColumns = introspectedTable .getNonPrimaryKeyColumns(); } else { introspectedColumns = introspectedTable.getBaseColumns(); } } String rootClass = getRootClass(); for (IntrospectedColumn introspectedColumn : introspectedColumns) { if (RootClassInfo.getInstance(rootClass, warnings) .containsProperty(introspectedColumn)) { continue; } Field field = getJavaBeansField(introspectedColumn, context, introspectedTable); if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addField(field); topLevelClass.addImportedType(field.getType()); } Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable); if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } method = getJavaBeansSetter(introspectedColumn, context, introspectedTable); if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } } List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (context.getPlugins().modelBaseRecordClassGenerated( topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example 17
Source File: SelectByPrimaryKeyMethodGenerator.java From mybatis-generator-plus 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 18
Source File: SimpleModelGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString("Progress.8", table.toString())); //$NON-NLS-1$ Plugin plugins = context.getPlugins(); CommentGenerator commentGenerator = context.getCommentGenerator(); FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); TopLevelClass topLevelClass = new TopLevelClass(type); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); FullyQualifiedJavaType superClass = getSuperClass(); if (superClass != null) { topLevelClass.setSuperClass(superClass); topLevelClass.addImportedType(superClass); } List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns(); if (introspectedTable.isConstructorBased()) { addParameterizedConstructor(topLevelClass); if (!introspectedTable.isImmutable()) { addDefaultConstructor(topLevelClass); } } String rootClass = getRootClass(); for (IntrospectedColumn introspectedColumn : introspectedColumns) { if (RootClassInfo.getInstance(rootClass, warnings) .containsProperty(introspectedColumn)) { continue; } Field field = getJavaBeansField(introspectedColumn); if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addField(field); topLevelClass.addImportedType(field.getType()); } Method method = getJavaBeansGetter(introspectedColumn); if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } if (!introspectedTable.isImmutable()) { method = getJavaBeansSetter(introspectedColumn); if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) { topLevelClass.addMethod(method); } } } List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example 19
Source File: RecordWithBLOBsGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); progressCallback.startTask(getString( "Progress.9", table.toString())); //$NON-NLS-1$ Plugin plugins = context.getPlugins(); CommentGenerator commentGenerator = context.getCommentGenerator(); TopLevelClass topLevelClass = new TopLevelClass(introspectedTable .getRecordWithBLOBsType()); topLevelClass.setVisibility(JavaVisibility.PUBLIC); commentGenerator.addJavaFileComment(topLevelClass); if (introspectedTable.getRules().generateBaseRecordClass()) { topLevelClass.setSuperClass(introspectedTable.getBaseRecordType()); } else { topLevelClass.setSuperClass(introspectedTable.getPrimaryKeyType()); } String rootClass = getRootClass(); for (IntrospectedColumn introspectedColumn : introspectedTable .getBLOBColumns()) { if (RootClassInfo.getInstance(rootClass, warnings) .containsProperty(introspectedColumn)) { continue; } Field field = getJavaBeansField(introspectedColumn); if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) { topLevelClass.addField(field); topLevelClass.addImportedType(field.getType()); } Method method = getJavaBeansGetter(introspectedColumn); if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) { topLevelClass.addMethod(method); } method = getJavaBeansSetter(introspectedColumn); if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) { topLevelClass.addMethod(method); } } List<CompilationUnit> answer = new ArrayList<CompilationUnit>(); if (context.getPlugins().modelRecordWithBLOBsClassGenerated( topLevelClass, introspectedTable)) { answer.add(topLevelClass); } return answer; }
Example 20
Source File: QueryDslPlugin.java From dolphin with Apache License 2.0 | 4 votes |
public void addQueryEntityAnnotation(TopLevelClass topLevelClass) { topLevelClass.addAnnotation(QUERY_ENTITY_ANNOTATION); topLevelClass.addImportedType(QUERY_ENTITY_ANNOTATION_TYPE); }