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

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getExampleType() . 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: MapperExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 获取实体类

    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());

    // 获取Example类
    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    // import接口

    for (String mapper : mappers) {
        interfaze.addImportedType(new FullyQualifiedJavaType(mapper));
        interfaze.addSuperInterface(
                new FullyQualifiedJavaType(
                        mapper + "<" + entityType.getShortName() + "," + exampleType.getShortName() + ">"));
    }
    // import实体类

    interfaze.addImportedType(entityType);
    return true;

}
 
Example 2
Source File: OptimisticLockerPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 替换Example 方法
 * @param introspectedTable
 * @param method
 * @param interfaze
 * @param methodName
 * @return
 */
private Method replaceDeleteExampleMethod(IntrospectedTable introspectedTable, Method method, Interface interfaze, String methodName) {
    Method withVersionMethod = new Method(method);

    // 替换方法名
    withVersionMethod.setName(methodName);
    FormatTools.replaceGeneralMethodComment(commentGenerator, withVersionMethod, introspectedTable);

    Parameter versionParam = new Parameter(this.versionColumn.getFullyQualifiedJavaType(), "version", "@Param(\"version\")");
    Parameter exampleParam = new Parameter(new FullyQualifiedJavaType(introspectedTable.getExampleType()), "example", "@Param(\"example\")");

    withVersionMethod.getParameters().clear();
    withVersionMethod.addParameter(versionParam);
    withVersionMethod.addParameter(exampleParam);

    return withVersionMethod;
}
 
Example 3
Source File: SelectiveEnhancedPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * updateByExampleSelective
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param method
 * @param interfaze
 * @param introspectedTable
 * @return
 */
@Override
public boolean clientUpdateByExampleSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
    method.getParameters().clear();

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

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    method.addParameter(new Parameter(exampleType, "example", "@Param(\"example\")"));

    // 找出全字段对应的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.clientUpdateByExampleSelectiveMethodGenerated(method, interfaze, introspectedTable);
}
 
Example 4
Source File: SelectByBigOffsetMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public void addMethod(Interface interfaze,IntrospectedTable introspectedTable) {
    Method method = new Method();
    // 1.设置方法可见性
    method.setVisibility(JavaVisibility.PUBLIC);
    // 2.设置返回值类型
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    FullyQualifiedJavaType paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    returnType.addTypeArgument(paramListType);
    method.setReturnType(returnType);
    // 3.设置方法名
    method.setName(METHOD_NAME);
    // 4.设置方法入参
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    method.addParameter(new Parameter(type, "example"));
    interfaze.addMethod(method);
}
 
Example 5
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
private void addPageTemplate(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("pageByExample");

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    FullyQualifiedJavaType baseQueryType = new FullyQualifiedJavaType("com.diligrp.shop.constant.BaseQuery");
    FullyQualifiedJavaType pageTmplType = new FullyQualifiedJavaType("com.diligrp.shop.constant.PageTemplate");

    String recordType = introspectedTable.getBaseRecordType();

    method.setReturnType(pageTmplType);

    method.addParameter(new Parameter(exampleType, "example"));
    method.addParameter(new Parameter(baseQueryType, "baseQuery"));

    StringBuffer code = new StringBuffer(32);
    code.append("int count = this.countByExample(example);\n");
    code.append("List<" + recordType + "> list = this.selectByExample(example);\n");
    code.append("com.diligrp.shop.constant.PageTemplate<" + recordType + "> pageTemplate = com.diligrp.shop.constant.PageTemplate.build();\n ");
    code.append("pageTemplate.setTotalSize(count);\n");
    code.append("pageTemplate.setList(list);\n");
    code.append("if(baseQuery != null){");
    code.append("pageTemplate.setCurrPage(baseQuery.getCurrent());\n");
    code.append("pageTemplate.setPageSize(baseQuery.getSize());\n");
    code.append("}");
    code.append("return pageTemplate;");

    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
 
Example 6
Source File: RenameExampleClassPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(IntrospectedTable introspectedTable) {
    String oldType = introspectedTable.getExampleType();
    Matcher matcher = pattern.matcher(oldType);
    oldType = matcher.replaceAll(replaceString);

    introspectedTable.setExampleType(oldType);
}
 
Example 7
Source File: ExampleTargetPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化阶段
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 *
 * @param introspectedTable
 */
@Override
public void initialized(IntrospectedTable introspectedTable) {
    super.initialized(introspectedTable);
    String exampleType = introspectedTable.getExampleType();
    // 修改包名
    Context context = getContext();
    JavaModelGeneratorConfiguration configuration = context.getJavaModelGeneratorConfiguration();
    String targetPackage = configuration.getTargetPackage();
    String newExampleType = exampleType.replace(targetPackage, this.targetPackage);

    introspectedTable.setExampleType(newExampleType);

    logger.debug("itfsw(Example 目标包修改插件):修改"+introspectedTable.getExampleType()+"的包到"+this.targetPackage);
}
 
Example 8
Source File: IntrospectedTableTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 设置DomainObjectName和MapperName
 * @param introspectedTable
 * @param context
 * @param domainObjectName
 */
public static void setDomainObjectName(IntrospectedTable introspectedTable, Context context, String domainObjectName) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    // 配置信息(没啥用)
    introspectedTable.getTableConfiguration().setDomainObjectName(domainObjectName);

    // FullyQualifiedTable修正
    Field domainObjectNameField = FullyQualifiedTable.class.getDeclaredField("domainObjectName");
    domainObjectNameField.setAccessible(true);
    domainObjectNameField.set(introspectedTable.getFullyQualifiedTable(), domainObjectName);

    // 重新修正introspectedTable属性信息
    Method calculateJavaClientAttributes = IntrospectedTable.class.getDeclaredMethod("calculateJavaClientAttributes");
    calculateJavaClientAttributes.setAccessible(true);
    calculateJavaClientAttributes.invoke(introspectedTable);

    Method calculateModelAttributes = IntrospectedTable.class.getDeclaredMethod("calculateModelAttributes");
    calculateModelAttributes.setAccessible(true);
    calculateModelAttributes.invoke(introspectedTable);

    Method calculateXmlAttributes = IntrospectedTable.class.getDeclaredMethod("calculateXmlAttributes");
    calculateXmlAttributes.setAccessible(true);
    calculateXmlAttributes.invoke(introspectedTable);

    // 注意!! 如果配置了ExampleTargetPlugin插件,要修正Example 位置
    PluginConfiguration configuration = PluginTools.getPluginConfiguration(context, ExampleTargetPlugin.class);
    if (configuration != null && configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE) != null) {
        String exampleType = introspectedTable.getExampleType();
        // 修改包名
        JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = context.getJavaModelGeneratorConfiguration();
        String targetPackage = javaModelGeneratorConfiguration.getTargetPackage();
        String newExampleType = exampleType.replace(targetPackage, configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE));

        introspectedTable.setExampleType(newExampleType);
    }
}
 
Example 9
Source File: RenameExampleClassPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(IntrospectedTable introspectedTable) {
    String oldType = introspectedTable.getExampleType();
    Matcher matcher = pattern.matcher(oldType);
    oldType = matcher.replaceAll(replaceString);

    introspectedTable.setExampleType(oldType);
}
 
Example 10
Source File: RenameExampleClassPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(IntrospectedTable introspectedTable) {
    String oldType = introspectedTable.getExampleType();
    Matcher matcher = pattern.matcher(oldType);
    oldType = matcher.replaceAll(replaceString);

    introspectedTable.setExampleType(oldType);
}
 
Example 11
Source File: RenameExampleClassAndMethodsPlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(IntrospectedTable introspectedTable) {
	String oldType = introspectedTable.getExampleType();
	Matcher matcher = classMethodPattern.matcher(oldType);
	oldType = matcher.replaceAll(classMethodReplaceString);

	introspectedTable.setExampleType(oldType);
}