Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageAutoDialect#getDialect NPE #414

Closed
ly641921791 opened this issue Jul 26, 2019 · 1 comment
Closed

PageAutoDialect#getDialect NPE #414

ly641921791 opened this issue Jul 26, 2019 · 1 comment

Comments

@ly641921791
Copy link

  • [√] 我已在 issues 搜索类似问题,并且不存在相同的问题.

功能建议

具体建议在代码块注释中

   private AbstractHelperDialect getDialect(MappedStatement ms) {
        //改为对dataSource做缓存
        DataSource dataSource = ms.getConfiguration().getEnvironment().getDataSource();
        /* 
             当使用TDDL时,获得的url是null,而urlDialectMap是ConcurrentHashMap类型
             这种情况下,下面紧跟的urlDialectMap.containsKey(url)会导致NPE
             因此,个人感觉应该把后面的if (StringUtil.isEmpty(url)) 校验放提前
        */
        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();
        }
    }
@abel533
Copy link
Collaborator

abel533 commented Oct 6, 2021

最新版本会增加接口允许自己实现动态获取dialect。

@abel533 abel533 closed this as completed Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants