java.lang.Object
org.miaixz.bus.pager.parsing.DefaultCountSqlParser
- All Implemented Interfaces:
CountSqlParser
Default implementation of
CountSqlParser that provides a more intelligent way to generate count query SQL. It
attempts to optimize the count query by removing unnecessary ORDER BY clauses and simplifying the SELECT statement.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected static final net.sf.jsqlparser.expression.AliasFields inherited from interface org.miaixz.bus.pager.parsing.CountSqlParser
AGGREGATE_FUNCTIONS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetSimpleCountSql(String sql) Retrieves a simple COUNT SQL, suitable for unparseable or complex scenarios.getSimpleCountSql(String sql, String name) Retrieves a simple COUNT SQL with a specified COUNT column name.getSmartCountSql(String sql, String countColumn) Retrieves an intelligent COUNT SQL, automatically detecting whether to keep the ORDER BY clause.booleanisSimpleCount(net.sf.jsqlparser.statement.select.PlainSelect select) Determines if a simple COUNT query can be used.protected booleanChecks if the ORDER BY clause should be kept.protected booleanChecks if the ORDER BY clause of subqueries should be kept.booleanorderByHashParameters(List<net.sf.jsqlparser.statement.select.OrderByElement> orderByElements) Determines if the ORDER BY clause contains parameters (?).voidprocessFromItem(net.sf.jsqlparser.statement.select.FromItem fromItem) Processes subqueries in the FROM clause.voidprocessPlainSelect(net.sf.jsqlparser.statement.select.PlainSelect plainSelect) Processes the body of a PlainSelect type.voidprocessSelect(net.sf.jsqlparser.statement.select.Select select) Processes the SELECT body to remove unnecessary ORDER BY clauses.voidprocessWithItemsList(List<net.sf.jsqlparser.statement.select.WithItem<?>> withItemsList) Processes the WITH clause to remove unnecessary ORDER BY clauses.net.sf.jsqlparser.statement.select.SelectsqlToCount(net.sf.jsqlparser.statement.select.Select select, String name) Converts a SQL statement to a count query.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.pager.parsing.CountSqlParser
getSmartCountSql
-
Field Details
-
KEEP_ORDERBY
- See Also:
-
TABLE_ALIAS
protected static final net.sf.jsqlparser.expression.Alias TABLE_ALIAS
-
-
Constructor Details
-
DefaultCountSqlParser
public DefaultCountSqlParser()
-
-
Method Details
-
getSmartCountSql
Retrieves an intelligent COUNT SQL, automatically detecting whether to keep the ORDER BY clause. This method optimizes string handling and parsing logic to reduce performance overhead.- Specified by:
getSmartCountSqlin interfaceCountSqlParser- Parameters:
sql- the original SQL querycountColumn- the COUNT column name, defaults to "0"- Returns:
- the optimized COUNT SQL
-
getSimpleCountSql
Retrieves a simple COUNT SQL, suitable for unparseable or complex scenarios.- Parameters:
sql- the original query SQL- Returns:
- a simple COUNT SQL
-
getSimpleCountSql
Retrieves a simple COUNT SQL with a specified COUNT column name. This method optimizes StringBuilder capacity estimation to reduce resizing.- Parameters:
sql- the original query SQLname- the COUNT column name- Returns:
- a simple COUNT SQL
-
sqlToCount
public net.sf.jsqlparser.statement.select.Select sqlToCount(net.sf.jsqlparser.statement.select.Select select, String name) Converts a SQL statement to a count query.- Parameters:
select- the original query SQLname- the name of the count column- Returns:
- the resulting count query SQL
-
isSimpleCount
public boolean isSimpleCount(net.sf.jsqlparser.statement.select.PlainSelect select) Determines if a simple COUNT query can be used. This method avoids using the deprecated Parenthesis class, using ParenthesedExpressionList or generic Expression instead.- Parameters:
select- the query- Returns:
- true if it is a simple COUNT, false otherwise
-
processSelect
public void processSelect(net.sf.jsqlparser.statement.select.Select select) Processes the SELECT body to remove unnecessary ORDER BY clauses. This method optimizes recursive processing logic to reduce redundant calls.- Parameters:
select- the query information
-
processPlainSelect
public void processPlainSelect(net.sf.jsqlparser.statement.select.PlainSelect plainSelect) Processes the body of a PlainSelect type. This method optimizes JOIN and FROM item processing logic.- Parameters:
plainSelect- the query
-
processWithItemsList
public void processWithItemsList(List<net.sf.jsqlparser.statement.select.WithItem<?>> withItemsList) Processes the WITH clause to remove unnecessary ORDER BY clauses.- Uses List<WithItem<?>> to adapt to JSqlParser 5.1's generic API.
- Checks for keepSubSelectOrderBy and empty lists early to reduce unnecessary loops.
- Uses a for-each loop to reduce iterator creation.
- Checks for non-null select early to reduce invalid recursion.
- Parameters:
withItemsList- the list of WITH clauses
-
processFromItem
public void processFromItem(net.sf.jsqlparser.statement.select.FromItem fromItem) Processes subqueries in the FROM clause. This method optimizes type checking and recursive logic.- Parameters:
fromItem- the FROM clause item
-
keepOrderBy
protected boolean keepOrderBy()Checks if the ORDER BY clause should be kept. This method uses the configuration fromPageMethod.- Returns:
- true if ORDER BY should be kept, false otherwise
-
keepSubSelectOrderBy
protected boolean keepSubSelectOrderBy()Checks if the ORDER BY clause of subqueries should be kept.- Returns:
- true if subquery ORDER BY should be kept, false otherwise
-
orderByHashParameters
public boolean orderByHashParameters(List<net.sf.jsqlparser.statement.select.OrderByElement> orderByElements) Determines if the ORDER BY clause contains parameters (?). This method optimizes null checks and loop efficiency.- Parameters:
orderByElements- the list of ORDER BY elements- Returns:
- true if it contains parameters, false otherwise
-