Package org.kawanfw.sql.api.server
Class StatementNormalizer
java.lang.Object
org.kawanfw.sql.api.server.StatementNormalizer
public class StatementNormalizer extends Object
Allows to "normalize" the text of a SQL statement. This will remove all
spaces, tabs or line feeds in excess. This allows to make sure that two SQL
statements that will give identical results but have a different text
representations are in fact equals.
For example the two following statements:
Note that in this version the normalization is straightforward and applied only on text format, and not on parameters (?) replacement for
This means that the two statements:
will not change after applying normalization and thus still be considered different when comparing with
For example the two following statements:
"SELECT * from my_table where my_colum = ?"
"SELECT * from my_table where my_colum = ?"
will be normalized to the same String with extra spaces removed:
"SELECT * from my_table where my_colum = ?"
Note that text between single quotes won't be modified:
SELECT * from customer where name = 'John Doe'
will be normalized to:SELECT * from customer where name = 'John Doe' Note that in this version the normalization is straightforward and applied only on text format, and not on parameters (?) replacement for
PreparedStatement. This means that the two statements:
select * from my_table where my_column = ? and select * from my_table where my_column = 9 will not change after applying normalization and thus still be considered different when comparing with
String.equals(Object).
- Since:
- 11.0
- Author:
- Nicolas de Pomereu
-
Constructor Summary
Constructors Constructor Description StatementNormalizer() -
Method Summary
Modifier and Type Method Description static StringgetNormalized(String sql)Returns the normalized text of the SQL statement.
-
Constructor Details
-
StatementNormalizer
public StatementNormalizer()
-
-
Method Details
-
getNormalized
Returns the normalized text of the SQL statement.- Parameters:
sql- the SQL statement to normalize- Returns:
- the normalized text of the SQL statement.
-