Java Code Examples for org.mybatis.generator.api.dom.java.Method#setConstructor()
The following examples show how to use
org.mybatis.generator.api.dom.java.Method#setConstructor() .
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: PrimaryKeyGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
private void addParameterizedConstructor(TopLevelClass topLevelClass) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); method.setName(topLevelClass.getType().getShortName()); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example 2
Source File: PrimaryKeyGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private void addParameterizedConstructor(TopLevelClass topLevelClass) { Method method = new Method(topLevelClass.getType().getShortName()); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example 3
Source File: DynamicSqlSupportClassGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName()); InnerClass innerClass = new InnerClass(fqjt.getShortName()); innerClass.setVisibility(JavaVisibility.PUBLIC); innerClass.setStatic(true); innerClass.setFinal(true); innerClass.setSuperClass(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlTable")); Method method = new Method(fqjt.getShortName()); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); method.addBodyLine("super(\"" + escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()) + "\");"); innerClass.addMethod(method); commentGenerator.addClassAnnotation(innerClass, introspectedTable, topLevelClass.getImportedTypes()); return innerClass; }
Example 4
Source File: AbstractDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example 5
Source File: AbstractDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
/** * Gets the constructor clone. * * @param commentGenerator * the comment generator * @param type * the type * @param introspectedTable * the introspected table * @return the constructor clone */ public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example 6
Source File: PrimaryKeyGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private void addParameterizedConstructor(TopLevelClass topLevelClass) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); method.setName(topLevelClass.getType().getShortName()); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example 7
Source File: AbstractJavaGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
protected void addDefaultConstructor(TopLevelClass topLevelClass) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); method.setName(topLevelClass.getType().getShortName()); method.addBodyLine("super();"); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 8
Source File: GenericSIDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addBodyLine("super();"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 9
Source File: AbstractDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public final List<Method> getMethodClones( CommentGenerator commentGenerator, IntrospectedTable introspectedTable) { configure(); List<Method> answer = new ArrayList<Method>(); for (Method oldMethod : methods) { Method method = new Method(); for (String bodyLine : oldMethod.getBodyLines()) { method.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) { method.addException(fqjt); } for (Parameter parm : oldMethod.getParameters()) { method.addParameter(parm); } method.setConstructor(oldMethod.isConstructor()); method.setFinal(oldMethod.isFinal()); method.setStatic(oldMethod.isStatic()); method.setName(oldMethod.getName()); method.setReturnType(oldMethod.getReturnType()); method.setVisibility(oldMethod.getVisibility()); commentGenerator.addGeneralMethodComment(method, introspectedTable); answer.add(method); } return answer; }
Example 10
Source File: SpringDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addBodyLine("super();"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 11
Source File: IbatisDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$ method.addBodyLine("super(daoManager);"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 12
Source File: GenericCIDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method constructor = new Method(); constructor.setConstructor(true); constructor.setVisibility(JavaVisibility.PUBLIC); constructor .addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$ constructor.addBodyLine("super();"); //$NON-NLS-1$ constructor.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$ setConstructorTemplate(constructor); }
Example 13
Source File: AbstractJavaGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
protected void addDefaultConstructor(TopLevelClass topLevelClass) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); method.setName(topLevelClass.getType().getShortName()); method.addBodyLine("super();"); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 14
Source File: GenericSIDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addBodyLine("super();"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 15
Source File: AbstractDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Gets the method clones. * * @param commentGenerator * the comment generator * @param introspectedTable * the introspected table * @return the method clones */ public final List<Method> getMethodClones( CommentGenerator commentGenerator, IntrospectedTable introspectedTable) { configure(); List<Method> answer = new ArrayList<Method>(); for (Method oldMethod : methods) { Method method = new Method(); for (String bodyLine : oldMethod.getBodyLines()) { method.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) { method.addException(fqjt); } for (Parameter parm : oldMethod.getParameters()) { method.addParameter(parm); } method.setConstructor(oldMethod.isConstructor()); method.setFinal(oldMethod.isFinal()); method.setStatic(oldMethod.isStatic()); method.setName(oldMethod.getName()); method.setReturnType(oldMethod.getReturnType()); method.setVisibility(oldMethod.getVisibility()); commentGenerator.addGeneralMethodComment(method, introspectedTable); answer.add(method); } return answer; }
Example 16
Source File: SpringDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addBodyLine("super();"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 17
Source File: IbatisDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$ method.addBodyLine("super(daoManager);"); //$NON-NLS-1$ setConstructorTemplate(method); }
Example 18
Source File: GenericCIDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override protected void configureConstructorTemplate() { Method constructor = new Method(); constructor.setConstructor(true); constructor.setVisibility(JavaVisibility.PUBLIC); constructor .addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$ constructor.addBodyLine("super();"); //$NON-NLS-1$ constructor.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$ setConstructorTemplate(constructor); }
Example 19
Source File: JavaElementTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * clone * @param method * @return */ public static Method clone(Method method) { Method dest = new Method(method.getName()); // 注解 for (String javaDocLine : method.getJavaDocLines()) { dest.addJavaDocLine(javaDocLine); } dest.setReturnType(method.getReturnType()); for (Parameter parameter : method.getParameters()) { dest.addParameter(JavaElementTools.clone(parameter)); } for (FullyQualifiedJavaType exception : method.getExceptions()) { dest.addException(exception); } for (TypeParameter typeParameter : method.getTypeParameters()) { dest.addTypeParameter(typeParameter); } dest.addBodyLines(method.getBodyLines()); dest.setConstructor(method.isConstructor()); dest.setNative(method.isNative()); dest.setSynchronized(method.isSynchronized()); dest.setDefault(method.isDefault()); dest.setFinal(method.isFinal()); dest.setStatic(method.isStatic()); dest.setVisibility(method.getVisibility()); return dest; }
Example 20
Source File: HySwaggerMapperPlugin.java From jvue-admin with MIT License | 4 votes |
private void addFieldEnum(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (this.modelFieldEnum) { String enumName = "FieldEnum"; String javaFieldName = "javaFieldName"; String dbFieldName = "dbFieldName"; InnerEnum enum1 = new InnerEnum(new FullyQualifiedJavaType(enumName)); enum1.setVisibility(JavaVisibility.PUBLIC); StringBuilder enumConstant = new StringBuilder(); List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns(); int index = 0; for (IntrospectedColumn column : allColumns) { String dbName = column.getActualColumnName(); String javaName = column.getJavaProperty(); enumConstant.append(dbName.toUpperCase()).append("(\"").append(javaName).append("\",\"").append(dbName).append("\")"); if (++index < allColumns.size()) { enumConstant.append(",\n\t\t"); } } enum1.addEnumConstant(enumConstant.toString()); //java字段 Field field = new Field(); field.setVisibility(JavaVisibility.PRIVATE); field.setStatic(false); field.setType(new FullyQualifiedJavaType("String")); field.setName(javaFieldName); enum1.addField(field); //db字段 Field field1 = new Field(); field1.setVisibility(JavaVisibility.PRIVATE); field1.setStatic(false); field1.setType(new FullyQualifiedJavaType("String")); field1.setName(dbFieldName); enum1.addField(field1); //构造器 Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.DEFAULT); method.setStatic(false); method.setName(enumName); method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), javaFieldName)); method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), dbFieldName)); method.addBodyLine("this."+javaFieldName+" = "+javaFieldName+";"); method.addBodyLine("this."+dbFieldName+" = "+dbFieldName+";"); enum1.addMethod(method); //方法 Method getMethod = new Method(); getMethod.setConstructor(false); getMethod.setVisibility(JavaVisibility.PUBLIC); getMethod.setStatic(false); getMethod.setName(javaFieldName); getMethod.addBodyLine("return "+javaFieldName+";"); getMethod.setReturnType(new FullyQualifiedJavaType("String")); enum1.addMethod(getMethod); Method getMethod1 = new Method(); getMethod1.setConstructor(false); getMethod1.setVisibility(JavaVisibility.PUBLIC); getMethod1.setStatic(false); getMethod1.setName(dbFieldName); getMethod1.addBodyLine("return "+dbFieldName+";"); getMethod1.setReturnType(new FullyQualifiedJavaType("String")); enum1.addMethod(getMethod1); topLevelClass.addInnerEnum(enum1); } }