Search in sources :

Example 1 with AbstractHelperDialect

use of com.github.pagehelper.dialect.AbstractHelperDialect in project Mybatis-PageHelper by pagehelper.

the class PageHelper method afterAll.

@Override
public void afterAll() {
    //这个方法即使不分页也会被执行,所以要判断 null
    AbstractHelperDialect delegate = autoDialect.getDelegate();
    if (delegate != null) {
        delegate.afterAll();
        autoDialect.clearDelegate();
    }
    clearPage();
}
Also used : AbstractHelperDialect(com.github.pagehelper.dialect.AbstractHelperDialect)

Example 2 with AbstractHelperDialect

use of com.github.pagehelper.dialect.AbstractHelperDialect in project Mybatis-PageHelper by pagehelper.

the class PageAutoDialect method initDialect.

/**
     * 初始化 helper
     *
     * @param dialectClass
     * @param properties
     */
private AbstractHelperDialect initDialect(String dialectClass, Properties properties) {
    AbstractHelperDialect dialect;
    if (StringUtil.isEmpty(dialectClass)) {
        throw new PageException("使用 PageHelper 分页插件时,必须设置 helper 属性");
    }
    try {
        Class sqlDialectClass = resloveDialectClass(dialectClass);
        if (AbstractHelperDialect.class.isAssignableFrom(sqlDialectClass)) {
            dialect = (AbstractHelperDialect) sqlDialectClass.newInstance();
        } else {
            throw new PageException("使用 PageHelper 时,方言必须是实现 " + AbstractHelperDialect.class.getCanonicalName() + " 接口的实现类!");
        }
    } catch (Exception e) {
        throw new PageException("初始化 helper [" + dialectClass + "]时出错:" + e.getMessage(), e);
    }
    dialect.setProperties(properties);
    return dialect;
}
Also used : PageException(com.github.pagehelper.PageException) AbstractHelperDialect(com.github.pagehelper.dialect.AbstractHelperDialect) SQLException(java.sql.SQLException) PageException(com.github.pagehelper.PageException)

Example 3 with AbstractHelperDialect

use of com.github.pagehelper.dialect.AbstractHelperDialect in project Mybatis-PageHelper by pagehelper.

the class PageAutoDialect method getDialect.

/**
     * 根据 jdbcUrl 获取数据库方言
     *
     * @param ms
     * @return
     */
private AbstractHelperDialect getDialect(MappedStatement ms) {
    //改为对dataSource做缓存
    DataSource dataSource = ms.getConfiguration().getEnvironment().getDataSource();
    String url = getUrl(dataSource);
    if (urlDialectMap.containsKey(url)) {
        return urlDialectMap.get(url);
    }
    try {
        lock.lock();
        if (urlDialectMap.containsKey(url)) {
            return urlDialectMap.get(url);
        }
        if (StringUtil.isEmpty(url)) {
            throw new PageException("无法自动获取jdbcUrl,请在分页插件中配置dialect参数!");
        }
        String dialectStr = fromJdbcUrl(url);
        if (dialectStr == null) {
            throw new PageException("无法自动获取数据库类型,请通过 helperDialect 参数指定!");
        }
        AbstractHelperDialect dialect = initDialect(dialectStr, properties);
        urlDialectMap.put(url, dialect);
        return dialect;
    } finally {
        lock.unlock();
    }
}
Also used : PageException(com.github.pagehelper.PageException) AbstractHelperDialect(com.github.pagehelper.dialect.AbstractHelperDialect) DataSource(javax.sql.DataSource)

Aggregations

AbstractHelperDialect (com.github.pagehelper.dialect.AbstractHelperDialect)3 PageException (com.github.pagehelper.PageException)2 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1