All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.jweb.mybatis.generator.plugins.PagePlugin Maven / Gradle / Ivy

There is a newer version: 1.0.13
Show newest version
package net.sourceforge.jweb.mybatis.generator.plugins;

import java.util.List;
import java.util.Properties;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.plugins.RowBoundsPlugin;

/**
 * PagePlugin is replacement of org.mybatis.generator.plugins.RowBoundsPlugin.
 * change selectByExampleWithRowBounds' parameter RowBounds to Page. becuase my
 * design of mybatis interceptor for paging used Page which extends RowBounds
 * holding paging information.
 * 
 * Usage:
 * 
 * 
 * <plugin type="net.sourceforge.jweb.mybatis.generator.plugins.PagePlugin">
 * <property name="useRowBounds" value="true/false"/><--true to use old org.mybatis.generator.plugins.RowBoundsPlugin -->
 * </plugin>
 * 
* *
 * <table ...>
 * <!-- your mapper file, you can use any tag name as root -->
 * <--true to use old org.mybatis.generator.plugins.RowBoundsPlugin in one table level -->
 * <property name="PagePluginUseRowBounds" value="true/false"/>
 * </table>
 * 
* * @author [email protected] * */ public class PagePlugin extends RowBoundsPlugin { private FullyQualifiedJavaType pageBound; private boolean useOldRowBounds = false; public boolean validate(List warnings) { System.out.println("\tPage plugin usage*******************************************"); System.out.print("\tnet.sourceforge.jweb.mybatis.generator.plugins.PagePlugin"); System.out.println(" is replacement of org.mybatis.generator.plugins.RowBoundsPlugin"); System.out.println("\tPagePlugin changes client methods "); System.out.println( "\tList selectByExampleWithBLOBsWithRowbounds(DomainExample example, RowBounds rowBounds);"); System.out.println("\tList selectByExampleWithRowbounds(DomainExample example, RowBounds rowBounds);"); System.out.println("\tto"); System.out.println( "\tList selectByExampleWithBLOBsWithRowbounds(DomainExample example, Page rowBounds);"); System.out.println("\tList selectByExampleWithRowbounds(DomainExample example, Page rowBounds);"); System.out.println("\tPage class is in below maven artifact"); System.out.println("\t "); System.out.println("\t "); System.out.println("\t com.github.alexmao86"); System.out.println("\t jweb-common"); System.out.println("\t ???"); System.out.println("\t "); Properties properties = this.getProperties(); if (properties != null) { String value = properties.getProperty("useRowBounds"); useOldRowBounds = "true".equalsIgnoreCase(value); } return super.validate(warnings); } public PagePlugin() { super(); this.pageBound = new FullyQualifiedJavaType("net.sourceforge.orm.mybatis.Page"); } @Override public boolean clientSelectByExampleWithBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { Properties properties = introspectedTable.getTableConfiguration().getProperties(); boolean useOldRowBoundsTableLevel = "true".equalsIgnoreCase(properties.getProperty("PagePluginUseRowBounds")); if (useOldRowBounds || useOldRowBoundsTableLevel) { return super.clientSelectByExampleWithBLOBsMethodGenerated(method, interfaze, introspectedTable); } else { if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) { copyAndAddMethod(method, interfaze, introspectedTable); } } return true; } @Override public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { Properties properties = introspectedTable.getTableConfiguration().getProperties(); boolean useOldRowBoundsTableLevel = "true".equalsIgnoreCase(properties.getProperty("PagePluginUseRowBounds")); if (useOldRowBounds || useOldRowBoundsTableLevel) { return super.clientSelectByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable); } else { if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) { copyAndAddMethod(method, interfaze, introspectedTable); } } return true; } private void copyAndAddMethod(Method method, Interface interfaze, final IntrospectedTable introspectedTable) { final String domainFullName = introspectedTable.getBaseRecordType(); final FullyQualifiedJavaType domainType = new FullyQualifiedJavaType(domainFullName); final Method newMethod = new Method(method); newMethod.setName(method.getName() + "WithRowbounds"); FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(this.pageBound.getFullyQualifiedName()); parameterType.addTypeArgument(domainType); newMethod.addParameter(new Parameter(parameterType, "rowBounds")); interfaze.addMethod(newMethod); interfaze.addImportedType(this.pageBound); interfaze.addImportedType(domainType); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy