// Path: QuickProject-Core/src/main/java/chanedi/dao/dialect/Dialect.java
// public abstract class Dialect {
// 
//     public abstract String addLimitString(String sql, int skipResults, int maxResults);
// 
//     public abstract String addSortString(String sql, List<Sort> sortList);
// 
// }
// 
// Path: QuickProject-Core/src/main/java/chanedi/dao/impl/mybatis/DialectParser.java
// public class DialectParser {
// 
//     public static Dialect parse(Configuration configuration) {
//         DBDialectType databaseType = null;
//         try {
//             databaseType = DBDialectType.valueOf(configuration.getVariables().getProperty("dialect").toUpperCase());
//         } catch (Exception e) {
//             // ignore
//         }
//         if (databaseType == null) {
//             throw new RuntimeException("the value of the dialect property in configuration.xml is not defined : " + configuration.getVariables().getProperty("dialect"));
//         }
//         Dialect dialect = null;
//         switch (databaseType) {
//             case MYSQL:
//                 dialect = new MySql5Dialect();
//                 break;
//             case ORACLE:
//                 dialect = new OracleDialect();
//                 break;
//             case H2:
//                 dialect = new H2Dialect();
//                 break;
//         }
//         return dialect;
//     }
// 
// }


import chanedi.dao.dialect.Dialect;
import chanedi.dao.impl.mybatis.DialectParser;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.RowBounds;
import java.sql.Connection;
import java.util.Properties;
package chanedi.dao.impl.mybatis.interceptor;



/**
 * 支持物理分页。
 * Created by unknown
 * Modify by Chanedi
 */
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class }) })
@Slf4j
public class PageInterceptor implements Interceptor {
	
    @Override
	public Object intercept(Invocation invocation) throws Throwable {
		StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
		BoundSql boundSql = statementHandler.getBoundSql();
		MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
		RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
		if ((rowBounds != null) && (rowBounds != RowBounds.DEFAULT)) {
            Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
// Path: QuickProject-Core/src/main/java/chanedi/dao/dialect/Dialect.java
// public abstract class Dialect {
// 
//     public abstract String addLimitString(String sql, int skipResults, int maxResults);
// 
//     public abstract String addSortString(String sql, List<Sort> sortList);
// 
// }
// 
// Path: QuickProject-Core/src/main/java/chanedi/dao/impl/mybatis/DialectParser.java
// public class DialectParser {
// 
//     public static Dialect parse(Configuration configuration) {
//         DBDialectType databaseType = null;
//         try {
//             databaseType = DBDialectType.valueOf(configuration.getVariables().getProperty("dialect").toUpperCase());
//         } catch (Exception e) {
//             // ignore
//         }
//         if (databaseType == null) {
//             throw new RuntimeException("the value of the dialect property in configuration.xml is not defined : " + configuration.getVariables().getProperty("dialect"));
//         }
//         Dialect dialect = null;
//         switch (databaseType) {
//             case MYSQL:
//                 dialect = new MySql5Dialect();
//                 break;
//             case ORACLE:
//                 dialect = new OracleDialect();
//                 break;
//             case H2:
//                 dialect = new H2Dialect();
//                 break;
//         }
//         return dialect;
//     }
// 
// }


// Path: QuickProject-Core/src/main/java/chanedi/dao/impl/mybatis/interceptor/PageInterceptor.java
import chanedi.dao.dialect.Dialect;
import chanedi.dao.impl.mybatis.DialectParser;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.RowBounds;
import java.sql.Connection;
import java.util.Properties;

package chanedi.dao.impl.mybatis.interceptor;



/**
 * 支持物理分页。
 * Created by unknown
 * Modify by Chanedi
 */
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class }) })
@Slf4j
public class PageInterceptor implements Interceptor {
	
    @Override
	public Object intercept(Invocation invocation) throws Throwable {
		StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
		BoundSql boundSql = statementHandler.getBoundSql();
		MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
		RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
		if ((rowBounds != null) && (rowBounds != RowBounds.DEFAULT)) {
            Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
            Dialect dialect = DialectParser.parse(configuration);