druid SQLUnionQueryTableSource没有实现父类SQLTableSourceImpl的clone方法

pokxtpni  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(206)

SQLUnionQueryTableSource没有实现父类SQLTableSourceImpl的clone方法,导致sqlserver在联合子查询中的分页解析出错。

类似如下SQL:

SELECT
    t.* 
FROM (
    SELECT
        logaudit.gmt_logged_ AS gmtLogged,
        u.username_ AS userName,
        logaudit.ip_ AS ip,
        logaudit.action_ AS action,
        logaudit.failed_ AS failed,
        logaudit.module_ AS module,
        logaudit.title_ AS title,
        '' AS clientInfo 
    FROM
        log_audit logaudit
        LEFT JOIN sys_user u ON logaudit.user_id_ = u.id_
    UNION
    SELECT
        login.gmt_logged_ AS gmtLogged,
        login.user_username_ AS userName,
        login.ip_ AS ip,
        '登陆' AS action,
        login.failed_ AS failed,
        '' AS module,
        '' AS title,
        login.client_info_ AS clientInfo 
    FROM
        log_login login 
) AS t 
ORDER BY
    t.gmtLogged DESC

在分页的时候报错如下:

java.lang.UnsupportedOperationException: com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource
	at com.alibaba.druid.sql.ast.statement.SQLTableSourceImpl.clone(SQLTableSourceImpl.java:70)
	at com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock.cloneTo(SQLSelectQueryBlock.java:447)
	at com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock.clone(SQLSelectQueryBlock.java:410)
	at com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock.clone(SQLSelectQueryBlock.java:39)
	at com.alibaba.druid.sql.ast.statement.SQLSelect.clone(SQLSelect.java:203)
	at com.alibaba.druid.sql.PagerUtils.limitSQLServer(PagerUtils.java:288)
	at com.alibaba.druid.sql.PagerUtils.limit(PagerUtils.java:114)
	at com.alibaba.druid.sql.PagerUtils.limit(PagerUtils.java:99)
	at com.alibaba.druid.sql.PagerUtils.limit(PagerUtils.java:95)
	at com.changhongedu.test.jdbc.SQLTest.main(SQLTest.java:90)
vltsax25

vltsax251#

com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource里实现一下这个方法

@Override
    public SQLUnionQueryTableSource clone() {
        SQLUnionQueryTableSource x = new SQLUnionQueryTableSource();
        cloneTo(x);
        return x;
    }

    public void cloneTo(SQLUnionQueryTableSource x) {
        x.alias = alias;
        x.union = union;
    }

相关问题