org.mybatis.generator.api.dom.java.JavaVisibility Java Examples

The following examples show how to use org.mybatis.generator.api.dom.java.JavaVisibility. 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: JavaBeansUtil.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the java beans getter.
 *
 * @param introspectedColumn
 *            the introspected column
 * @param context
 *            the context
 * @param introspectedTable
 *            the introspected table
 * @return the java beans getter
 */
public static Method getJavaBeansGetter(IntrospectedColumn introspectedColumn,
        Context context,
        IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example #2
Source File: DeleteByExampleMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getDeleteByExampleStatementId());
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins().clientDeleteByExampleMethodGenerated(
            method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #3
Source File: CountByExampleMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());

    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>();
    importedTypes.add(fqjt);

    Method method = new Method(introspectedTable.getCountByExampleStatementId());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setAbstract(true);
    method.setReturnType(new FullyQualifiedJavaType("long"));
    method.addParameter(new Parameter(fqjt, "example"));
    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(method);
    
    if (context.getPlugins().clientCountByExampleMethodGenerated(method,
            interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #4
Source File: SerializablePlugin.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example #6
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();

    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(introspectedTable.getInsertSelectiveStatementId());

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins().clientInsertSelectiveMethodGenerated(
            method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #7
Source File: CustomSerializablePlugin.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getUpdateByPrimaryKeyStatementId());
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins()
            .clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method,
                    interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #9
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method
            .setName(getDAOMethodNameCalculator()
                    .getUpdateByPrimaryKeyWithoutBLOBsMethodName(
                            introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example #10
Source File: GetByKeyBusinessGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String mapperFieldName,FullyQualifiedJavaType keyType){
	List<Method> methodList = new ArrayList<Method>();
	
	// add get by key method
	Method method = new Method();
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(beanType);
       method.setName("get" + beanName + "ByKey"); //$NON-NLS-1$
       method.addParameter(new Parameter(keyType, "key")); //$NON-NLS-1$
       method.addException(new FullyQualifiedJavaType(Exception.class.getName()));
       method.addBodyLine("return this."+ mapperFieldName +".selectByPrimaryKey(key);"); 
       methodList.add(method);
       
       // add new method here
       
       return methodList;
}
 
Example #11
Source File: DeleteByExampleMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method(introspectedTable.getDeleteByExampleStatementId());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setAbstract(true);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.addParameter(new Parameter(type, "example"));

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(method);
    
    if (context.getPlugins().clientDeleteByExampleMethodGenerated(
            method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #12
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) {
	FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sqlTableClassName);
	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")); //$NON-NLS-1$

	Method method = new Method(fqjt.getShortName());
	method.setVisibility(JavaVisibility.PUBLIC);
	method.setConstructor(true);
	method.addBodyLine("super(\"" //$NON-NLS-1$
			+ escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()) + "\");"); //$NON-NLS-1$
	innerClass.addMethod(method);

	commentGenerator.addClassAnnotation(innerClass, introspectedTable, topLevelClass.getImportedTypes());

	return innerClass;
}
 
Example #13
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private Field calculateTableDefinition(TopLevelClass topLevelClass) {
    FullyQualifiedJavaType fqjt =
            new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    String fieldName =
            JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    Field field = new Field(fieldName, fqjt);
    commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
    field.setVisibility(JavaVisibility.PUBLIC);
    field.setStatic(true);
    field.setFinal(true);
    
    StringBuilder initializationString = new StringBuilder();
    initializationString.append(String.format("new %s()",
            escapeStringForJava(introspectedTable.getFullyQualifiedTable().getDomainObjectName())));
    field.setInitializationString(initializationString.toString());
    return field;
}
 
Example #14
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: CaseInsensitiveLikePlugin.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private Method toMethod(IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and");
    sb.append("LikeInsensitive");
    Method method = new Method(sb.toString());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(introspectedColumn
            .getFullyQualifiedJavaType(), "value"));

    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

    sb.setLength(0);
    sb.append("addCriterion(\"upper(");
    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(") like\", value.toUpperCase(), \"");
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");");
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;");
    return method;
}
 
Example #16
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example #17
Source File: ExampleGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example #18
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example #19
Source File: CountListBusinessGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String mapperFieldName,FullyQualifiedJavaType paramType){
	List<Method> methodList = new ArrayList<Method>();
	
	// add get by key method
	Method method = new Method();
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(FullyQualifiedJavaType.getIntInstance());
       method.setName("count" + beanName + "List"); //$NON-NLS-1$
       method.addParameter(new Parameter(paramType, "param")); //$NON-NLS-1$
       method.addException(new FullyQualifiedJavaType(Exception.class.getName()));
       method.addBodyLine("return this."+ mapperFieldName +".countByExample(param);"); 
       methodList.add(method);
       
       // add new method here
       
       return methodList;
}
 
Example #20
Source File: JavaBeansUtil.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the java beans setter.
 *
 * @param introspectedColumn
 *            the introspected column
 * @param context
 *            the context
 * @param introspectedTable
 *            the introspected table
 * @return the java beans setter
 */
public static Method getJavaBeansSetter(IntrospectedColumn introspectedColumn,
        Context context,
        IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    if (isTrimStringsEnabled(context) && introspectedColumn.isStringColumn()) {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(" == null ? null : "); //$NON-NLS-1$
        sb.append(property);
        sb.append(".trim();"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example #21
Source File: PluginUtil.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 	添加属性域
 * 
 * @param annotation
 * @param classType
 * @param fieldName
 * @return
 */
public static Field getField (String annotation,FullyQualifiedJavaType classType, String fieldName){
	Field field = new Field();
	field.setVisibility(JavaVisibility.PRIVATE);
	field.addAnnotation(annotation);
	field.setType(classType);
	field.setName(fieldName);
       return field;
}
 
Example #22
Source File: InsertControllerGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String businessFieldName){
	List<Method> methodList = new ArrayList<Method>();
	
	String beanFieldName = StringUtils.uncapitalize(beanName);
	
	Method method = new Method();
	method.addAnnotation("@RequestMapping(value = \"insert.do\")");
	method.setVisibility(JavaVisibility.PUBLIC);
	method.setReturnType(new FullyQualifiedJavaType(String.class.getName()));
	method.setName("insert");
	Parameter param = new Parameter(beanType, beanFieldName);
	param.addAnnotation("@ModelAttribute(\"" + beanFieldName + "\") ");
	Parameter paramModelMap = new Parameter(new FullyQualifiedJavaType(ModelMap.class.getName()), "map");
	method.addParameter(param); 
	method.addParameter(paramModelMap); 
	// 方法body
	method.addBodyLine("try {");
	method.addBodyLine("// 数据校验");
	method.addBodyLine("");
	method.addBodyLine("if(this." + businessFieldName + ".insertSelective(" + beanFieldName + ") == 1){");
	method.addBodyLine("map.put(\"message\",\"插入成功。\");");
	method.addBodyLine("}else{");
	method.addBodyLine("map.put(\"message\",\"插入失败。\");");
	method.addBodyLine("}");
	method.addBodyLine("} catch (Exception e) {");
	method.addBodyLine("logger.error(\"插入异常\" + e.getMessage());");
	method.addBodyLine("map.put(\"message\",\"插入异常\" + e.getMessage());");
	method.addBodyLine("}");
	method.addBodyLine(ControllerPluginUtil.RETURN);
	
	methodList.add(method);
       
       return methodList;
}
 
Example #23
Source File: GenericCIDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    field.setName("sqlMapClient"); //$NON-NLS-1$
    addField(field);
}
 
Example #24
Source File: GenericSIDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureConstructorTemplate() {
    Method method = new Method();
    method.setConstructor(true);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addBodyLine("super();"); //$NON-NLS-1$
    setConstructorTemplate(method);
}
 
Example #25
Source File: UpdateByExampleSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable
            .getUpdateByExampleSelectiveStatementId());

    FullyQualifiedJavaType parameterType =
        introspectedTable.getRules().calculateAllFieldsClass();
    method.addParameter(new Parameter(parameterType,
            "record", "@Param(\"record\")")); //$NON-NLS-1$ //$NON-NLS-2$
    importedTypes.add(parameterType);

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    method.addParameter(new Parameter(exampleType,
            "example", "@Param(\"example\")")); //$NON-NLS-1$ //$NON-NLS-2$
    importedTypes.add(exampleType);

    importedTypes.add(new FullyQualifiedJavaType(
            "org.apache.ibatis.annotations.Param")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins()
            .clientUpdateByExampleSelectiveMethodGenerated(method, interfaze,
                    introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example #26
Source File: UpdateByExampleSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = getMethodShell(importedTypes);

        if (context.getPlugins()
                .clientUpdateByExampleSelectiveMethodGenerated(method,
                        interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}
 
Example #27
Source File: UpdateByExampleWithoutBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = getMethodShell(importedTypes);

        if (context.getPlugins()
                .clientUpdateByExampleWithoutBLOBsMethodGenerated(method,
                        interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}
 
Example #28
Source File: WrapObjectPluginTest.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddWrappedObjectFieldToModelBaseRecordClass() throws Exception {
	// Given
	given(introspectedTable.getFullyQualifiedTableNameAtRuntime()).willReturn(TABLE_NAME);

	// When
	boolean ok = plugin.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);

	// Then
	assertThat(ok).isTrue();

	ArgumentCaptor<Field> fieldCaptor = ArgumentCaptor.forClass(Field.class);
	ArgumentCaptor<FullyQualifiedJavaType> typeCaptor = ArgumentCaptor.forClass(FullyQualifiedJavaType.class);

	verify(topLevelClass).addField(fieldCaptor.capture());
	verify(topLevelClass).addImportedType(typeCaptor.capture());

	Field field = fieldCaptor.getValue();
	FullyQualifiedJavaType type = typeCaptor.getValue();

	assertThat(field).isNotNull();
	assertThat(type).isNotNull();

	assertThat(field.getName()).isEqualTo(OBJECT_FIELD_NAME);
	assertThat(field.getType()).isEqualTo(type);
	assertThat(field.getType().getFullyQualifiedName()).isEqualTo(OBJECT_CLASS);
	assertThat(field.getVisibility()).isEqualTo(JavaVisibility.PROTECTED);
	assertThat(field.getInitializationString()).isNotNull();
	assertThat(field.getJavaDocLines()).contains(" * @mbggenerated");
}
 
Example #29
Source File: ProviderDeleteByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: SelectByExampleWithBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = getMethodShell(importedTypes);

        if (context.getPlugins()
                .clientSelectByExampleWithBLOBsMethodGenerated(method,
                        interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}