java.lang.Object
org.miaixz.bus.mapper.handler.AbstractSqlHandler
org.miaixz.bus.pager.handler.SqlParserHandler
- Direct Known Subclasses:
ConditionHandler,OperationHandler,PaginationHandler
public class SqlParserHandler
extends org.miaixz.bus.mapper.handler.AbstractSqlHandler
Abstract SQL parsing class that provides functionality for parsing and processing SQL statements. This class uses
JSQLParser to handle different types of SQL statements (INSERT, SELECT, UPDATE, DELETE).
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from class org.miaixz.bus.mapper.handler.AbstractSqlHandler
DEFAULT_REFLECTOR_FACTORY, DELEGATE_BOUNDSQL, DELEGATE_BOUNDSQL_SQL, DELEGATE_MAPPEDSTATEMENT, MAPPEDSTATEMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.sf.jsqlparser.statement.StatementParses a single SQL statement string.parserMulti(String sql, Object object) Parses and processes multiple SQL statements.parserSingle(String sql, Object object) Parses and processes a single SQL statement.static net.sf.jsqlparser.statement.StatementsparseStatements(String sql) Parses multiple SQL statement strings.protected voidprocessDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object object) Processes a DELETE statement.protected voidprocessInsert(net.sf.jsqlparser.statement.insert.Insert insert, int index, String sql, Object object) Processes an INSERT statement.protected StringprocessParser(net.sf.jsqlparser.statement.Statement statement, int index, String sql, Object object) Executes the SQL statement parsing and processing.protected voidprocessSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object object) Processes a SELECT statement.protected voidprocessUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object object) Processes an UPDATE statement.protected static voidvalidateSql(String sql) Validates an SQL string to prevent potential injection risks.Methods inherited from class org.miaixz.bus.mapper.handler.AbstractSqlHandler
getMappedStatement, getMappedStatement, getMetaObject, getSqlParserInfo, mapperBoundSql, mapperStatementHandler, realTarget, setAdditionalParameter
-
Constructor Details
-
SqlParserHandler
public SqlParserHandler()
-
-
Method Details
-
parse
public static net.sf.jsqlparser.statement.Statement parse(String sql) throws net.sf.jsqlparser.JSQLParserException Parses a single SQL statement string.- Parameters:
sql- the SQL statement string- Returns:
- the parsed
Statementobject - Throws:
net.sf.jsqlparser.JSQLParserException- if parsing fails
-
parseStatements
public static net.sf.jsqlparser.statement.Statements parseStatements(String sql) throws net.sf.jsqlparser.JSQLParserException Parses multiple SQL statement strings.- Parameters:
sql- the SQL statement string containing one or more statements- Returns:
- the parsed
Statementsobject - Throws:
net.sf.jsqlparser.JSQLParserException- if parsing fails
-
parserSingle
Parses and processes a single SQL statement.- Parameters:
sql- the SQL statement stringobject- an additional object for processing- Returns:
- the processed SQL statement string
- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if parsing fails
-
parserMulti
Parses and processes multiple SQL statements.- Parameters:
sql- the SQL statement string containing one or more statementsobject- an additional object for processing- Returns:
- the processed SQL statements, separated by semicolons
- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if parsing fails
-
processParser
protected String processParser(net.sf.jsqlparser.statement.Statement statement, int index, String sql, Object object) Executes the SQL statement parsing and processing.- Parameters:
statement- the JSQLParser parsed statement objectindex- the index of the statement (for multiple statements)sql- the original SQL statementobject- an additional object for processing- Returns:
- the processed SQL statement string
-
processInsert
protected void processInsert(net.sf.jsqlparser.statement.insert.Insert insert, int index, String sql, Object object) Processes an INSERT statement. This method should be overridden by subclasses to provide specific handling.- Parameters:
insert- the INSERT statement objectindex- the index of the statementsql- the original SQL statementobject- an additional object for processing- Throws:
UnsupportedOperationException- by default, as INSERT processing is not supported
-
processDelete
protected void processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object object) Processes a DELETE statement. This method should be overridden by subclasses to provide specific handling.- Parameters:
delete- the DELETE statement objectindex- the index of the statementsql- the original SQL statementobject- an additional object for processing- Throws:
UnsupportedOperationException- by default, as DELETE processing is not supported
-
processUpdate
protected void processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object object) Processes an UPDATE statement. This method should be overridden by subclasses to provide specific handling.- Parameters:
update- the UPDATE statement objectindex- the index of the statementsql- the original SQL statementobject- an additional object for processing- Throws:
UnsupportedOperationException- by default, as UPDATE processing is not supported
-
processSelect
protected void processSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object object) Processes a SELECT statement. This method should be overridden by subclasses to provide specific handling.- Parameters:
select- the SELECT statement objectindex- the index of the statementsql- the original SQL statementobject- an additional object for processing- Throws:
UnsupportedOperationException- by default, as SELECT processing is not supported
-
validateSql
Validates an SQL string to prevent potential injection risks.- Parameters:
sql- the SQL statement string to validate- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if the SQL script validation fails
-