org.javasimon.jdbc
Class SqlNormalizer

java.lang.Object
  extended by org.javasimon.jdbc.SqlNormalizer

public final class SqlNormalizer
extends Object

SqlNormalizer takes SQL statement and replaces parameters with question marks. It is important to realize, that normalizer IS NOT SQL analyzer. It makes as simple replacement as possible (with my coding skill ;-)) to still truly represent the original statement. Normalized statement is merely used to recognize the original one and also to merge the same statements with various arguments. Its primary purpose is to limit count of distinct per-statement Simons. It doesn't suppose to be perfect or proof to all dialects.

Usage is simple, you create normalizer with SQL statement and than you can ask the object for normalizedSql and type via respective getters.

Author:
Richard "Virgo" Richter

Field Summary
private static Replacer[] FIRST_REPLACERS
           
private static Replacer FUNCTION_REPLACER
           
private  String normalizedSql
           
private static Replacer[] SECOND_REPLACERS
           
private  String sql
           
private  String type
           
private static Replacer TYPE_SELECTOR
           
 
Constructor Summary
SqlNormalizer(List<String> batch)
          Constructor for batch normalization.
SqlNormalizer(String sql)
          Creates SQL normalizer and performs the normalization.
 
Method Summary
private  void applyReplacers(Replacer[] replacers)
           
 String getNormalizedSql()
          Returns the normalized SQL.
 String getSql()
          Returns the original SQL.
 String getType()
          Returns SQL type which is typicaly first word of the SQL (insert, select, etc).
private  void normalize(String sql)
           
 String toString()
          Returns human readable string describing this SQL normalizer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIRST_REPLACERS

private static final Replacer[] FIRST_REPLACERS

SECOND_REPLACERS

private static final Replacer[] SECOND_REPLACERS

FUNCTION_REPLACER

private static final Replacer FUNCTION_REPLACER

TYPE_SELECTOR

private static final Replacer TYPE_SELECTOR

sql

private final String sql

normalizedSql

private String normalizedSql

type

private String type
Constructor Detail

SqlNormalizer

public SqlNormalizer(String sql)
Creates SQL normalizer and performs the normalization.

Parameters:
sql - SQL to normalize

SqlNormalizer

public SqlNormalizer(List<String> batch)
Constructor for batch normalization. Type of the "statement" will be "batch".

Parameters:
batch - list of statements
Method Detail

normalize

private void normalize(String sql)

applyReplacers

private void applyReplacers(Replacer[] replacers)

getSql

public String getSql()
Returns the original SQL.

Returns:
original SQL

getNormalizedSql

public String getNormalizedSql()
Returns the normalized SQL.

Returns:
normalized SQL

getType

public String getType()
Returns SQL type which is typicaly first word of the SQL (insert, select, etc). Returns batch for batches.

Returns:
SQL statement type or "batch"

toString

public String toString()
Returns human readable string describing this SQL normalizer.

Overrides:
toString in class Object
Returns:
original SQL, normalized SQL, SQL type


Copyright © 2011. All Rights Reserved.