From 14ae44fcac6fa8180f62b3b1f6e53eec597a711d Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Wed, 15 Aug 2018 16:57:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDataJdbcSource.queryList?= =?UTF-8?q?=E4=BC=9A=E6=9F=A5total=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/source/DataJdbcSource.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/org/redkale/source/DataJdbcSource.java b/src/org/redkale/source/DataJdbcSource.java index 8daaa1197..6a6080294 100644 --- a/src/org/redkale/source/DataJdbcSource.java +++ b/src/org/redkale/source/DataJdbcSource.java @@ -483,7 +483,8 @@ public class DataJdbcSource extends DataSqlSource { final Map joinTabalis = node == null ? null : node.getJoinTabalis(); final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info); final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis); - if ("mysql".equals(this.readPool.getDbtype()) || "postgresql".equals(this.readPool.getDbtype())) { + final String dbtype = this.readPool.getDbtype(); + if ("mysql".equals(dbtype) || "postgresql".equals(dbtype)) { final String listsql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + createSQLOrderby(info, flipper) + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())); if (info.isLoggable(logger, Level.FINEST, listsql)) { @@ -497,13 +498,17 @@ public class DataJdbcSource extends DataSqlSource { set.close(); ps.close(); long total = list.size(); - final String countsql = "SELECT COUNT(*) FROM " + info.getTable(node) + " a" + (join == null ? "" : join) - + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)); - ps = conn.prepareStatement(countsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - set = ps.executeQuery(); - if (set.next()) total = set.getLong(1); - set.close(); - ps.close(); + if (needtotal) { + final String countsql = "SELECT COUNT(*) FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)); + if (info.isLoggable(logger, Level.FINEST, countsql)) { + logger.finest(info.getType().getSimpleName() + " query countsql=" + countsql); + } + ps = conn.prepareStatement(countsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + set = ps.executeQuery(); + if (set.next()) total = set.getLong(1); + set.close(); + ps.close(); + } return CompletableFuture.completedFuture(new Sheet<>(total, list)); } final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)