nativePageSql

This commit is contained in:
redkale
2024-06-06 17:00:35 +08:00
parent 2e8c183c3a
commit 43012a5399

View File

@@ -80,7 +80,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
((CompletableFuture<Sheet>) querySheetDBAsync(i, false, false, false, null, null, (FilterNode) null))
.thenApply(e -> e == null ? new ArrayList() : e.list(true));
protected final IntFunction<String> signFunc = index -> prepareParamSign(index);
protected final IntFunction<String> signFunc = this::prepareParamSign;
// Flipper.sort转换成以ORDER BY开头SQL的缓存
protected final Map<String, String> sortOrderbySqls = new ConcurrentHashMap<>();
@@ -161,23 +161,21 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
protected <T> PageCountSql createPageCountSql(
EntityInfo<T> info,
final boolean readCache,
boolean readCache,
boolean needTotal,
final boolean distinct,
boolean distinct,
SelectColumn selects,
String[] tables,
Flipper flipper,
FilterNode node) {
final Map<Class, String> 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(this, info, joinTabalis);
final String joinAndWhere =
(join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
final String joinAndWhere = (join == null ? "" : join) + (Utility.isEmpty(where) ? "" : (" WHERE " + where));
String pageSql = null;
String countSql = null;
boolean containsLimit = false;
{ // 组装pageSql、countSql
// 组装pageSql、countSql
String listSubSql;
StringBuilder union = new StringBuilder();
if (tables.length == 1) {
@@ -204,8 +202,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
if ("oracle".equals(dbtype)) {
int start = flipper.getOffset();
int end = flipper.getOffset() + flipper.getLimit();
pageSql = "SELECT * FROM (SELECT T_.*, ROWNUM RN_ FROM (" + pageSql + ") T_) WHERE RN_ BETWEEN "
+ start + " AND " + end;
pageSql = "SELECT * FROM (SELECT T_.*, ROWNUM RN_ FROM (" + pageSql + ") T_) WHERE RN_ BETWEEN " + start
+ " AND " + end;
containsLimit = true;
} else if ("sqlserver".equals(dbtype)) {
int offset = flipper.getOffset();
@@ -231,7 +229,6 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
}
countSql = countSubSql;
}
}
if (readCache && info.isLoggable(logger, Level.FINEST, pageSql)) {
String prefix = needTotal ? " querySheet" : " queryList";
if (countSql != null) {
@@ -240,16 +237,13 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
logger.finest(
info.getType().getSimpleName() + prefix + (needTotal ? " page-sql=" : " list-sql=") + pageSql);
}
PageCountSql rs = new PageCountSql();
rs.pageSql = pageSql;
rs.countSql = countSql;
rs.pageContainsLimit = containsLimit;
return rs;
return new PageCountSql(pageSql, countSql, containsLimit);
}
/**
* 根据Flipper获取ORDER BY的SQL语句不存在Flipper或sort字段返回空字符串
*
* @param info EntityInfo
* @param flipper 翻页对象
* @return String
*/
@@ -3990,12 +3984,18 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
protected static class PageCountSql {
public String pageSql;
public final String pageSql;
@Nullable
public String countSql;
public final String countSql;
public boolean pageContainsLimit;
public final boolean pageContainsLimit;
public PageCountSql(String pageSql, String countSql, boolean pageContainsLimit) {
this.pageSql = pageSql;
this.countSql = countSql;
this.pageContainsLimit = pageContainsLimit;
}
@Override
public String toString() {