Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getTargetRuntime()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getTargetRuntime() . 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: CustomSettingsPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 配置序列化
 * @author Frodez
 * @date 2019-01-13
 */
private void makeSerializable(TopLevelClass klass, IntrospectedTable table) {
	klass.addImportedType(new FullyQualifiedJavaType("java.io.Serializable"));
	klass.addSuperInterface(new FullyQualifiedJavaType("java.io.Serializable"));
	Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
	field.setFinal(true);
	field.setInitializationString("1L");
	field.addJavaDocLine("");
	field.setStatic(true);
	field.setVisibility(JavaVisibility.PRIVATE);
	if (table.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
		context.getCommentGenerator().addFieldAnnotation(field, table, klass.getImportedTypes());
	} else {
		context.getCommentGenerator().addFieldComment(field, table);
	}
	klass.getFields().add(0, field);
}
 
Example 2
Source File: MapperAnnotationPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    for (String annotation : this.annotations) {
        if (annotation.equals("@Mapper")) {
            if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) {
                // don't need to do this for MYBATIS3_DSQL as that runtime already adds this annotation
                interfaze.addImportedType(new FullyQualifiedJavaType(ANNOTATION_IMPORTS.get(annotation)));
                interfaze.addAnnotation(annotation);
            }
        } else if (ANNOTATION_IMPORTS.get(annotation) != null) {
            interfaze.addImportedType(new FullyQualifiedJavaType(ANNOTATION_IMPORTS.get(annotation)));
            interfaze.addAnnotation(annotation);
        }
    }

    return true;
}
 
Example 3
Source File: OracleBatchInsertPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) {
        MethodGeneratorTool.defaultBatchInsertOrUpdateMethodGen(MethodGeneratorTool.INSERT, interfaze, introspectedTable, context);
    }
    return super.clientGenerated(interfaze, topLevelClass, introspectedTable);
}
 
Example 4
Source File: RowBoundsPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 5
Source File: RowBoundsPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 6
Source File: RowBoundsPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(
        Method method, Interface interfaze,
        IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    }
    return true;
}
 
Example 7
Source File: RowBoundsPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithBLOBsMethodGenerated(Method method,
        Interface interfaze, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    }
    return true;
}
 
Example 8
Source File: RowBoundsPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 9
Source File: RowBoundsPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 10
Source File: RowBoundsPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(
        Method method, Interface interfaze,
        IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    }
    return true;
}
 
Example 11
Source File: RowBoundsPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithBLOBsMethodGenerated(Method method,
        Interface interfaze, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    }
    return true;
}
 
Example 12
Source File: RowBoundsPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithBLOBsMethodGenerated(Method method,
        Interface interfaze, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    } else if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
        copyAndAddSelectByExampleMethodForDSQL(method, interfaze);
    }
    return true;
}
 
Example 13
Source File: BatchInsertPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * java代码Mapper生成
 * @param interfaze
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientGenerated(Interface interfaze,
                               TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

    if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) {
        addBatchInsertMethod(interfaze, introspectedTable);
    }

    return super.clientGenerated(interfaze, topLevelClass,
            introspectedTable);
}
 
Example 14
Source File: FluentBuilderMethodsPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelSetterMethodGenerated(Method method,
        TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
        IntrospectedTable introspectedTable,
        ModelClassType modelClassType) {
    
    Method fluentMethod = new Method("with" + method.getName().substring(3));
    fluentMethod.setVisibility(JavaVisibility.PUBLIC);
    fluentMethod.setReturnType(topLevelClass.getType());
    fluentMethod.getParameters().addAll(method.getParameters());
     
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
        context.getCommentGenerator().addGeneralMethodAnnotation(fluentMethod,
                introspectedTable, topLevelClass.getImportedTypes());
    } else {
        context.getCommentGenerator().addGeneralMethodComment(fluentMethod,
                introspectedTable);
    }
    
    StringBuilder sb = new StringBuilder()
            .append("this.")
            .append(method.getName())
            .append('(')
            .append(introspectedColumn.getJavaProperty())
            .append(");");
    fluentMethod.addBodyLine(sb.toString());
    fluentMethod.addBodyLine("return this;");

    topLevelClass.addMethod(fluentMethod);

    return super.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn,
            introspectedTable, modelClassType);
}
 
Example 15
Source File: ToStringPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private void generateToString(IntrospectedTable introspectedTable,
        TopLevelClass topLevelClass) {
    Method method = new Method("toString");
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.addAnnotation("@Override");

    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
        context.getCommentGenerator().addGeneralMethodAnnotation(method,
                introspectedTable, topLevelClass.getImportedTypes());
    } else {
        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);
    }

    method.addBodyLine("StringBuilder sb = new StringBuilder();");
    method.addBodyLine("sb.append(getClass().getSimpleName());");
    method.addBodyLine("sb.append(\" [\");");
    method.addBodyLine("sb.append(\"Hash = \").append(hashCode());");
    StringBuilder sb = new StringBuilder();
    for (Field field : topLevelClass.getFields()) {
        String property = field.getName();
        sb.setLength(0);
        sb.append("sb.append(\"").append(", ").append(property) //$NON-NLS-2$
                .append("=\")").append(".append(").append(property) //$NON-NLS-2$
                .append(");");
        method.addBodyLine(sb.toString());
    }

    method.addBodyLine("sb.append(\"]\");");
    if (useToStringFromRoot && topLevelClass.getSuperClass().isPresent()) {
        method.addBodyLine("sb.append(\", from super class \");");
        method.addBodyLine("sb.append(super.toString());");
    }
    method.addBodyLine("return sb.toString();");

    topLevelClass.addMethod(method);
}
 
Example 16
Source File: SerializablePlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    final boolean serializable = Boolean.parseBoolean(introspectedTable.getTableConfigurationProperty("jdkSerializable"));
    if (!serializable) {
        return;
    }

    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }

    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(this.serializable);
        topLevelClass.addSuperInterface(this.serializable);

        Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
        field.setFinal(true);
        field.setInitializationString("1L");
        field.setStatic(true);
        field.setVisibility(JavaVisibility.PRIVATE);

        if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) {
            context.getCommentGenerator().addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
        } else {
            context.getCommentGenerator().addFieldComment(field, introspectedTable);
        }

        topLevelClass.addField(field);
    }
}
 
Example 17
Source File: MapperAnnotationPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) {

    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        // don't need to do this for MYBATIS3_DSQL as that runtime already adds this annotation 
        interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper"));
        interfaze.addAnnotation("@Mapper");
    }
    return true;
}
 
Example 18
Source File: RowBoundsPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 19
Source File: RowBoundsPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(
        XmlElement element, IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndSaveElement(element, introspectedTable.getFullyQualifiedTable());
    }
    return true;
}
 
Example 20
Source File: RowBoundsPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(
        Method method, Interface interfaze,
        IntrospectedTable introspectedTable) {
    if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3) {
        copyAndAddMethod(method, interfaze);
    }
    return true;
}