Java Code Examples for org.mybatis.generator.api.dom.java.FullyQualifiedJavaType#addTypeArgument()

The following examples show how to use org.mybatis.generator.api.dom.java.FullyQualifiedJavaType#addTypeArgument() . 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: FullyQualifiedJavaTypeTest.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericType3() {
    FullyQualifiedJavaType listOfStrings = new FullyQualifiedJavaType("java.util.List"); //$NON-NLS-1$
    listOfStrings.addTypeArgument(new FullyQualifiedJavaType("java.lang.String")); //$NON-NLS-1$

    FullyQualifiedJavaType fqjt =
        new FullyQualifiedJavaType("java.util.Map"); //$NON-NLS-1$
    fqjt.addTypeArgument(new FullyQualifiedJavaType("java.lang.String")); //$NON-NLS-1$
    fqjt.addTypeArgument(listOfStrings);

    assertTrue(fqjt.isExplicitlyImported());
    assertEquals("Map<String, List<String>>", fqjt.getShortName()); //$NON-NLS-1$
    assertEquals("java.util.Map<java.lang.String, java.util.List<java.lang.String>>", fqjt.getFullyQualifiedName()); //$NON-NLS-1$
    assertEquals("java.util", fqjt.getPackageName()); //$NON-NLS-1$
    assertEquals(2, fqjt.getImportList().size());
    assertEquals("java.util.Map", fqjt.getFullyQualifiedNameWithoutTypeParameters()); //$NON-NLS-1$
}
 
Example 2
Source File: CreateGenericInterfacePlugin.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
private void init() {
	genericModelList = FullyQualifiedJavaType.getNewListInstance();
	genericModelList.addTypeArgument(genericModel);

	longPrimitive = new FullyQualifiedJavaType("long");

	FullyQualifiedJavaType className = new FullyQualifiedJavaType(interfaceName);
	className.addTypeArgument(genericModel);
	className.addTypeArgument(genericExample);
	className.addTypeArgument(genericId);

	genericInterface = new Interface(className);
	genericInterface.setVisibility(JavaVisibility.PUBLIC);

	methodsAdded = new HashSet<>();

	models = new HashMap<>();
	examples = new HashMap<>();
	ids = new HashMap<>();
}
 
Example 3
Source File: CreateGenericInterfacePlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	FullyQualifiedJavaType type = new FullyQualifiedJavaType(interfaceName);
	type.addTypeArgument(models.get(introspectedTable));
	type.addTypeArgument(examples.get(introspectedTable));
	type.addTypeArgument(ids.get(introspectedTable));

	interfaze.addSuperInterface(type);

	return true;
}
 
Example 4
Source File: BasicInsertMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public MethodAndImports generateMethodAndImports() {
    if (!introspectedTable.getRules().generateInsert()
            && !introspectedTable.getRules().generateInsertSelective()) {
        return null;
    }

    Set<FullyQualifiedJavaType> imports = new HashSet<>();
    
    FullyQualifiedJavaType adapter =
            new FullyQualifiedJavaType("org.mybatis.dynamic.sql.util.SqlProviderAdapter");
    FullyQualifiedJavaType annotation =
            new FullyQualifiedJavaType("org.apache.ibatis.annotations.InsertProvider");
    
    imports.add(new FullyQualifiedJavaType(
            "org.mybatis.dynamic.sql.insert.render.InsertStatementProvider"));
    imports.add(adapter);
    imports.add(annotation);
    
    FullyQualifiedJavaType parameterType =
            new FullyQualifiedJavaType(
                    "org.mybatis.dynamic.sql.insert.render.InsertStatementProvider");
    imports.add(recordType);
    parameterType.addTypeArgument(recordType);
    
    Method method = new Method("insert");
    method.setAbstract(true);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.addParameter(new Parameter(parameterType, "insertStatement"));
    context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports);
    method.addAnnotation("@InsertProvider(type=SqlProviderAdapter.class, method=\"insert\")");

    MethodAndImports.Builder builder = MethodAndImports.withMethod(method)
            .withImports(imports);
  
    GeneratedKey gk = introspectedTable.getGeneratedKey();
    if (gk != null) {
        MethodParts methodParts = fragmentGenerator.getGeneratedKeyAnnotation(gk);
        acceptParts(builder, method, methodParts);
    }

    return builder.build();
}
 
Example 5
Source File: BasicSelectManyMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public MethodAndImports generateMethodAndImports() {
    if (!introspectedTable.getRules().generateSelectByExampleWithBLOBs()
            && !introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
        return null;
    }
    
    Set<FullyQualifiedJavaType> imports = new HashSet<>();
    
    FullyQualifiedJavaType parameterType =
            new FullyQualifiedJavaType(
                    "org.mybatis.dynamic.sql.select.render.SelectStatementProvider");
    FullyQualifiedJavaType adapter =
            new FullyQualifiedJavaType("org.mybatis.dynamic.sql.util.SqlProviderAdapter");
    FullyQualifiedJavaType annotation =
            new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectProvider");
    
    imports.add(parameterType);
    imports.add(adapter);
    imports.add(annotation);
    
    imports.add(FullyQualifiedJavaType.getNewListInstance());
    
    imports.add(recordType);
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    returnType.addTypeArgument(recordType);
    Method method = new Method("selectMany");
    method.setAbstract(true);
    method.setReturnType(returnType);
    method.addParameter(new Parameter(parameterType, "selectStatement"));
    context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports);
    method.addAnnotation("@SelectProvider(type=SqlProviderAdapter.class, method=\"select\")");

    MethodAndImports.Builder builder = MethodAndImports.withMethod(method)
            .withImports(imports);

    MethodParts methodParts;
    if (introspectedTable.isConstructorBased()) {
        methodParts = fragmentGenerator.getAnnotatedConstructorArgs();
    } else {
        methodParts = fragmentGenerator.getAnnotatedResults();
    }
    acceptParts(builder, method, methodParts);
    
    return builder.build();
}
 
Example 6
Source File: ExampleGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param introspectedColumn
 * @param inMethod
 *            if true generates an "in" method, else generates a "not in"
 *            method
 * @return a generated method for the in or not in method
 */
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn,
        boolean inMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = FullyQualifiedJavaType
            .getNewListInstance();
    if (generateForJava5) {
        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
            type.addTypeArgument(introspectedColumn
                    .getFullyQualifiedJavaType().getPrimitiveTypeWrapper());
        } else {
            type.addTypeArgument(introspectedColumn
                    .getFullyQualifiedJavaType());
        }
    }

    method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (inMethod) {
        sb.append("In"); //$NON-NLS-1$
    } else {
        sb.append("NotIn"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (inMethod) {
        sb.append(" in"); //$NON-NLS-1$
    } else {
        sb.append(" not in"); //$NON-NLS-1$
    }
    sb.append("\", values, \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 7
Source File: ExampleGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param introspectedColumn
 * @param inMethod
 *            if true generates an "in" method, else generates a "not in"
 *            method
 * @return a generated method for the in or not in method
 */
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn,
        boolean inMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = FullyQualifiedJavaType
            .getNewListInstance();
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
        type.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper());
    } else {
        type
                .addTypeArgument(introspectedColumn
                        .getFullyQualifiedJavaType());
    }

    method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (inMethod) {
        sb.append("In"); //$NON-NLS-1$
    } else {
        sb.append("NotIn"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (inMethod) {
        sb.append(" in"); //$NON-NLS-1$
    } else {
        sb.append(" not in"); //$NON-NLS-1$
    }
    sb.append("\", values, \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 8
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param introspectedColumn
 * @param inMethod
 *            if true generates an "in" method, else generates a "not in"
 *            method
 * @return a generated method for the in or not in method
 */
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn,
        boolean inMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = FullyQualifiedJavaType
            .getNewListInstance();
    if (generateForJava5) {
        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
            type.addTypeArgument(introspectedColumn
                    .getFullyQualifiedJavaType().getPrimitiveTypeWrapper());
        } else {
            type.addTypeArgument(introspectedColumn
                    .getFullyQualifiedJavaType());
        }
    }

    method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (inMethod) {
        sb.append("In"); //$NON-NLS-1$
    } else {
        sb.append("NotIn"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (inMethod) {
        sb.append(" in"); //$NON-NLS-1$
    } else {
        sb.append(" not in"); //$NON-NLS-1$
    }
    sb.append("\", values, \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 9
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param introspectedColumn
 * @param inMethod
 *            if true generates an "in" method, else generates a "not in"
 *            method
 * @return a generated method for the in or not in method
 */
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn,
        boolean inMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = FullyQualifiedJavaType
            .getNewListInstance();
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
        type.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper());
    } else {
        type
                .addTypeArgument(introspectedColumn
                        .getFullyQualifiedJavaType());
    }

    method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (inMethod) {
        sb.append("In"); //$NON-NLS-1$
    } else {
        sb.append("NotIn"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (inMethod) {
        sb.append(" in"); //$NON-NLS-1$
    } else {
        sb.append(" not in"); //$NON-NLS-1$
    }
    sb.append("\", values, \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}