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

The following examples show how to use org.mybatis.generator.api.dom.java.FullyQualifiedJavaType. 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: CountByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: WrapObjectPluginTest.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReplaceSetterToCallWrappedProperty() throws Exception {
	Parameter parameter = new Parameter(FullyQualifiedJavaType.getStringInstance(), "name");
	List<Parameter> parameters = new ArrayList<>();
	parameters.add(parameter);

	// Given
	given(introspectedTable.getFullyQualifiedTableNameAtRuntime()).willReturn(TABLE_NAME);
	given(method.getName()).willReturn("setName");
	given(method.getParameters()).willReturn(parameters);
	plugin.getSettersToWrap().add("setName");

	// When
	boolean ok = plugin.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, null);

	// Then
	assertThat(ok).isTrue();
	assertThat(methodLines).hasSize(1);
	verify(method).getBodyLines();
	verify(method).addBodyLine(anyString());
}
 
Example #3
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 #4
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: SelectiveEnhancedPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * insertSelective 方法生成
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param method
 * @param interfaze
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientInsertSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
    method.getParameters().clear();

    FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();
    method.addParameter(new Parameter(parameterType, "record", "@Param(\"record\")"));

    // 找出全字段对应的Model
    FullyQualifiedJavaType fullFieldModel = introspectedTable.getRules().calculateAllFieldsClass();
    // column枚举
    FullyQualifiedJavaType selectiveType = new FullyQualifiedJavaType(fullFieldModel.getShortName() + "." + ModelColumnPlugin.ENUM_NAME);
    method.addParameter(new Parameter(selectiveType, "selective", "@Param(\"selective\")", true));

    FormatTools.replaceGeneralMethodComment(commentGenerator, method, introspectedTable);

    return super.clientInsertSelectiveMethodGenerated(method, interfaze, introspectedTable);
}
 
Example #6
Source File: RenameExampleClassAndMethodsPluginTest.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreMethodParametersThatDontMatch() throws Exception {
	FullyQualifiedJavaType type = new FullyQualifiedJavaType("type");

	Parameter parameter = new Parameter(type, "someName", "annotation");
	List<Parameter> parameters = new ArrayList<>();
	parameters.add(parameter);

	// Given
	given(method.getName()).willReturn(String.format("Some%1$sWith%1$sInName", CLASS_SEARCH));
	given(method.getParameters()).willReturn(parameters);

	// When
	boolean ok = plugin.renameMethod(method);

	// Then
	assertThat(ok).isTrue();
	assertThat(parameters).hasSize(1);

	Parameter newParameter = parameters.get(0);
	assertThat(newParameter).isSameAs(parameter);
}
 
Example #7
Source File: InsertSelectiveMethodGenerator.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>();
    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 #8
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 #9
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 #10
Source File: UpdateByPrimaryKeySelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@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
            .getUpdateByPrimaryKeySelectiveStatementId(), "record")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    method.addBodyLine("return rows;"); //$NON-NLS-1$

    if (context.getPlugins()
            .clientUpdateByPrimaryKeySelectiveMethodGenerated(method,
                    topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
Example #11
Source File: OutputUtilities.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * returns a unique set of "import xxx;" Strings for the set of types.
 *
 * @param importedTypes
 *            the imported types
 * @return the sets the
 */
public static Set<String> calculateImports(
        Set<FullyQualifiedJavaType> importedTypes) {
    StringBuilder sb = new StringBuilder();
    Set<String> importStrings = new TreeSet<String>();
    for (FullyQualifiedJavaType fqjt : importedTypes) {
        for (String importString : fqjt.getImportList()) {
            sb.setLength(0);
            sb.append("import "); //$NON-NLS-1$
            sb.append(importString);
            sb.append(';');
            importStrings.add(sb.toString());
        }
    }

    return importStrings;
}
 
Example #12
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 #13
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator()
            .getInsertSelectiveMethodName(introspectedTable));

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

    importedTypes.add(parameterType);
    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 #14
Source File: AbstractJavaMapperMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
protected String getResultAnnotation(Interface interfaze, IntrospectedColumn introspectedColumn,
        boolean idColumn, boolean constructorBased) {
    StringBuilder sb = new StringBuilder();
    if (constructorBased) {
        interfaze.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
        sb.append("@Arg(column=\"");
        sb.append(getRenamedColumnNameForResultMap(introspectedColumn));
        sb.append("\", javaType=");
        sb.append(introspectedColumn.getFullyQualifiedJavaType().getShortName());
        sb.append(".class");
    } else {
        sb.append("@Result(column=\"");
        sb.append(getRenamedColumnNameForResultMap(introspectedColumn));
        sb.append("\", property=\"");
        sb.append(introspectedColumn.getJavaProperty());
        sb.append('\"');
    }

    if (stringHasValue(introspectedColumn.getTypeHandler())) {
        FullyQualifiedJavaType fqjt =
                new FullyQualifiedJavaType(introspectedColumn.getTypeHandler());
        interfaze.addImportedType(fqjt);
        sb.append(", typeHandler=");
        sb.append(fqjt.getShortName());
        sb.append(".class");
    }

    sb.append(", jdbcType=JdbcType.");
    sb.append(introspectedColumn.getJdbcTypeName());
    if (idColumn) {
        sb.append(", id=true");
    }
    sb.append(')');

    return sb.toString();
}
 
Example #15
Source File: FullyQualifiedJavaTypeTest.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleType2() {
    FullyQualifiedJavaType fqjt =
        new FullyQualifiedJavaType("com.foo.bar"); //$NON-NLS-1$
    assertTrue(fqjt.isExplicitlyImported());
    assertEquals("bar", fqjt.getShortName()); //$NON-NLS-1$
    assertEquals("com.foo.bar", fqjt.getFullyQualifiedName()); //$NON-NLS-1$
    assertEquals("com.foo", fqjt.getPackageName()); //$NON-NLS-1$
    assertEquals(1, fqjt.getImportList().size());
    assertEquals("com.foo.bar", fqjt.getImportList().get(0));
}
 
Example #16
Source File: JavaTypeResolverDefaultImpl.java    From scaffold-cloud with MIT License 5 votes vote down vote up
public FullyQualifiedJavaType calculateJavaType(
            IntrospectedColumn introspectedColumn) {
//        System.out.println(introspectedColumn.getActualColumnName()+"___"+introspectedColumn.getLength());
        FullyQualifiedJavaType answer = null;
        JdbcTypeInformation jdbcTypeInformation = typeMap
                .get(introspectedColumn.getJdbcType());

        if (jdbcTypeInformation != null) {
            answer = jdbcTypeInformation.getFullyQualifiedJavaType();
            answer = overrideDefaultType(introspectedColumn, answer);
        }

        return answer;
    }
 
Example #17
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
@Override
public void addJavaFileComment(CompilationUnit compilationUnit) {
    super.addJavaFileComment(compilationUnit);
    //只在model中添加swagger注解类的导入
    if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){
        compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME));
    }
}
 
Example #18
Source File: AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
    interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append("@UpdateProvider(type="); //$NON-NLS-1$
    sb.append(fqjt.getShortName());
    sb.append(".class, method=\""); //$NON-NLS-1$
    sb.append(introspectedTable.getUpdateByExampleWithBLOBsStatementId());
    sb.append("\")"); //$NON-NLS-1$
    
    method.addAnnotation(sb.toString());
}
 
Example #19
Source File: JavaTypeResolverDefaultImpl.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column,
        FullyQualifiedJavaType defaultType) {
    FullyQualifiedJavaType answer = defaultType;

    switch (column.getJdbcType()) {
    case Types.BIT:
        answer = calculateBitReplacement(column, defaultType);
        break;
    case Types.DATE:
        answer = calculateDateType(column, defaultType);
        break;
    case Types.DECIMAL:
    case Types.NUMERIC:
        answer = calculateBigDecimalReplacement(column, defaultType);
        break;
    case Types.TIME:
        answer = calculateTimeType(column, defaultType);
        break;
    case Types.TIMESTAMP:
        answer = calculateTimestampType(column, defaultType);
        break;
    default:
        break;
    }

    return answer;
}
 
Example #20
Source File: AnnotatedSelectByPrimaryKeyMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private void addAnnotationImports(Interface interfaze) {
    interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.type.JdbcType"));

    if (introspectedTable.isConstructorBased()) {
        interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Arg"));
        interfaze.addImportedType(
                new FullyQualifiedJavaType("org.apache.ibatis.annotations.ConstructorArgs"));
    } else {
        interfaze.addImportedType(
                new FullyQualifiedJavaType("org.apache.ibatis.annotations.Result"));
        interfaze.addImportedType(
                new FullyQualifiedJavaType("org.apache.ibatis.annotations.Results"));
    }
}
 
Example #21
Source File: CreateGenericInterfacePluginTest.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddClientUpdateByExampleWithoutBLOBsMethod() {
	// Given
	CreateGenericInterfacePlugin plugin = spy(this.plugin);

	// When
	boolean ok1 = plugin.clientUpdateByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable);
	boolean ok2 = plugin.clientUpdateByExampleWithoutBLOBsMethodGenerated(method, topLevelClass, introspectedTable);

	// Then
	then(ok1).isTrue();
	then(ok2).isTrue();
	verify(plugin, times(2)).addGenericMethod(eq(method), any(FullyQualifiedJavaType.class), Matchers.<FullyQualifiedJavaType>anyVararg());
}
 
Example #22
Source File: UpdateByExampleSelectiveMethodGenerator.java    From mybatis-generator-core-fix 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 #23
Source File: AbstractJavaMapperMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
protected String getResultAnnotation(Interface interfaze, IntrospectedColumn introspectedColumn,
        boolean idColumn, boolean constructorBased) {
    StringBuilder sb = new StringBuilder();
    if (constructorBased) {
        interfaze.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
        sb.append("@Arg(column=\""); //$NON-NLS-1$
        sb.append(getRenamedColumnNameForResultMap(introspectedColumn));
        sb.append("\", javaType="); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType().getShortName());
        sb.append(".class"); //$NON-NLS-1$
    } else {
        sb.append("@Result(column=\""); //$NON-NLS-1$
        sb.append(getRenamedColumnNameForResultMap(introspectedColumn));
        sb.append("\", property=\""); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append('\"');
    }
    
    if (stringHasValue(introspectedColumn.getTypeHandler())) {
        FullyQualifiedJavaType fqjt =
            new FullyQualifiedJavaType(introspectedColumn.getTypeHandler());
        interfaze.addImportedType(fqjt);
        sb.append(", typeHandler="); //$NON-NLS-1$
        sb.append(fqjt.getShortName());
        sb.append(".class"); //$NON-NLS-1$
    }
    
    sb.append(", jdbcType=JdbcType."); //$NON-NLS-1$
    sb.append(introspectedColumn.getJdbcTypeName());
    if (idColumn) {
        sb.append(", id=true"); //$NON-NLS-1$
    }
    sb.append(')');

    return sb.toString();
}
 
Example #24
Source File: CustomPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * 修改Example类,添加分页支持
 *
 * @param topLevelClass
 * @param introspectedTable
 */
private void addPage(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	CommentGenerator commentGenerator = context.getCommentGenerator();
	//.add offset Field
	Field offsetField = new Field();
	offsetField.setVisibility(JavaVisibility.PROTECTED);
	offsetField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	offsetField.setName("offset");
	commentGenerator.addFieldComment(offsetField, introspectedTable);
	topLevelClass.addField(offsetField);

	//.add limit Field
	Field limitField = new Field();
	limitField.setVisibility(JavaVisibility.PROTECTED);
	limitField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	limitField.setName("limit");
	commentGenerator.addFieldComment(limitField, introspectedTable);
	topLevelClass.addField(limitField);

	//.add end Field
	Field endField = new Field();
	endField.setVisibility(JavaVisibility.PROTECTED);
	endField.setType(new FullyQualifiedJavaType("java.lang.Long"));
	endField.setName("end");
	commentGenerator.addFieldComment(endField, introspectedTable);
	topLevelClass.addField(endField);

	//.add setPagination method
	Method method = new Method();
	method.setVisibility(JavaVisibility.PUBLIC);
	method.setName("setPagination");
	method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "offset"));
	method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "limit"));
	method.addBodyLine("this.offset = offset;");
	method.addBodyLine("this.limit = limit;");
	method.addBodyLine("this.end = offset + limit;");
	commentGenerator.addGeneralMethodComment(method, introspectedTable);
	topLevelClass.addMethod(method);
}
 
Example #25
Source File: AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
    interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append("@UpdateProvider(type="); //$NON-NLS-1$
    sb.append(fqjt.getShortName());
    sb.append(".class, method=\""); //$NON-NLS-1$
    sb.append(introspectedTable.getUpdateByExampleStatementId());
    sb.append("\")"); //$NON-NLS-1$
    
    method.addAnnotation(sb.toString());
}
 
Example #26
Source File: FullyQualifiedJavaTypeTest.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Test
public void testUppercasePackage2() {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType("org.foo.Bar.Inner.Inner");
    assertTrue(fqjt.isExplicitlyImported());
    assertEquals("Inner", fqjt.getShortName()); //$NON-NLS-1$
    assertEquals("org.foo.Bar.Inner.Inner", fqjt.getFullyQualifiedName()); //$NON-NLS-1$
    assertEquals("org.foo.Bar.Inner", fqjt.getPackageName()); //$NON-NLS-1$
    assertEquals(1, fqjt.getImportList().size());
    assertEquals("org.foo.Bar.Inner.Inner", fqjt.getImportList().get(0));
}
 
Example #27
Source File: DefaultCommentGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
        Set<FullyQualifiedJavaType> imports) {
    imports.add(new FullyQualifiedJavaType("javax.annotation.Generated"));
    String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
    field.addAnnotation(getGeneratedAnnotation(comment));
}
 
Example #28
Source File: SelectByExampleWithoutBLOBsMethodGenerator.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()
                .clientSelectByExampleWithoutBLOBsMethodGenerated(method,
                        interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }
}
 
Example #29
Source File: DefaultCommentGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
        Set<FullyQualifiedJavaType> imports) {
    imports.add(new FullyQualifiedJavaType("javax.annotation.Generated"));
    String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
    method.addAnnotation(getGeneratedAnnotation(comment));
}
 
Example #30
Source File: SimpleJavaClientGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString("Progress.17", introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getMyBatis3JavaMapperType());
    Interface interfaze = new Interface(type);
    interfaze.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(interfaze);

    String rootInterface = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    if (!stringHasValue(rootInterface)) {
        rootInterface = context.getJavaClientGeneratorConfiguration().getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    }

    if (stringHasValue(rootInterface)) {
        FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(rootInterface);
        interfaze.addSuperInterface(fqjt);
        interfaze.addImportedType(fqjt);
    }

    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addSelectAllMethod(interfaze);
    addUpdateByPrimaryKeyMethod(interfaze);

    List<CompilationUnit> answer = new ArrayList<>();
    if (context.getPlugins().clientGenerated(interfaze, introspectedTable)) {
        answer.add(interfaze);
    }

    List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits();
    if (extraCompilationUnits != null) {
        answer.addAll(extraCompilationUnits);
    }

    return answer;
}