org.objectweb.cjdbc.common.sql.filters
Class MacrosHandler

java.lang.Object
  extended byorg.objectweb.cjdbc.common.sql.filters.MacrosHandler
All Implemented Interfaces:
XmlComponent

public class MacrosHandler
extends java.lang.Object
implements XmlComponent

This class defines a MacrosHandler

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  long clockResolution
           
private  int currentDate
           
private  int currentTime
           
private  int currentTimestamp
           
static int DATE_DATE
          Value if date macro should be replaced by an java.sql.Date value
static int DATE_OFF
          Value if a date macro should not be replaced
static int DATE_TIME
          Value if date macro should be replaced by an java.sql.Time value
static int DATE_TIMESTAMP
          Value if date macro should be replaced by an java.sql.Timestamp value
private static java.lang.String MACRO_CURRENT_DATE
          String for current_date macro
private static java.lang.String MACRO_CURRENT_TIME
          String for current_times macro
private static java.lang.String MACRO_CURRENT_TIMESTAMP
          String for current_timestamp macro
private static java.lang.String MACRO_NOW
          String for now() macro
private static java.lang.String MACRO_RAND
          String for rand() macro
private static java.lang.String MACRO_TIMEODFAY
          String for timeofday() macro
private  boolean needsDateProcessing
           
private  boolean needsProcessing
           
private  int now
           
static int RAND_DOUBLE
          Value if rand() macro should be replaced by an double value
static int RAND_FLOAT
          Value if rand() macro should be replaced by an float value (default)
static int RAND_INT
          Value if rand() macro should be replaced by an integer value
static int RAND_LONG
          Value if rand() macro should be replaced by an long value
static int RAND_OFF
          Value if rand() macro should not be replaced
private  java.util.Random randGenerator
           
private  int replaceRand
           
private  int timeOfDay
           
static int UNKNOWN_INT_VALUE
          Used when level is unknown
static java.lang.String UNKNOWN_STRING_VALUE
          Used when level is unknown
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
MacrosHandler(int replaceRand, long clockResolution, int now, int currentDate, int currentTime, int timeOfDay, int currentTimestamp)
          Creates a new MacrosHandler object
 
Method Summary
static int getIntDateLevel(java.lang.String dateLevel)
          Convert the date level from string (xml value) to integer
static int getIntRandLevel(java.lang.String randLevel)
          Convert the rand level from string (xml value) to integer
private  java.lang.Integer[] getQuoteIndexes(java.lang.String sql)
          Retrieve all the indexes of quotes in the string
static java.lang.String getStringDateLevel(int dateLevel)
          Convert the date level from int (java code) to string (xml value)
static java.lang.String getStringRandLevel(int randLevel)
          Convert the rand level from int (java code) to string (xml value)
 java.lang.String getXml()
          Return this MacrosHandler to the corresponding xml form
 java.lang.String macroDate(java.lang.String originalSql, java.lang.String macroPattern, int replacementPolicy, long currentClock, java.lang.Integer[] idxs)
          Processes a date related macro using the given timestamp.
 java.lang.String macroRand(java.lang.String originalSql, java.lang.Integer[] idxs)
          Replaces rand() with a randomized value.
 java.lang.String processMacros(java.lang.String sql)
          Processes all macros in the given request and returns a new String with the processed macros.
private  boolean shouldReplaceMacro(int idx, java.lang.Integer[] list)
          Should we replace a macro situated at index idx, knowing that the quotes are at indexes list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_INT_VALUE

public static final int UNKNOWN_INT_VALUE
Used when level is unknown

See Also:
Constant Field Values

UNKNOWN_STRING_VALUE

public static final java.lang.String UNKNOWN_STRING_VALUE
Used when level is unknown

See Also:
Constant Field Values

MACRO_RAND

private static final java.lang.String MACRO_RAND
String for rand() macro

See Also:
Constant Field Values

RAND_OFF

public static final int RAND_OFF
Value if rand() macro should not be replaced

See Also:
Constant Field Values

RAND_INT

public static final int RAND_INT
Value if rand() macro should be replaced by an integer value

See Also:
Constant Field Values

RAND_LONG

public static final int RAND_LONG
Value if rand() macro should be replaced by an long value

See Also:
Constant Field Values

RAND_FLOAT

public static final int RAND_FLOAT
Value if rand() macro should be replaced by an float value (default)

See Also:
Constant Field Values

RAND_DOUBLE

public static final int RAND_DOUBLE
Value if rand() macro should be replaced by an double value

See Also:
Constant Field Values

randGenerator

private final java.util.Random randGenerator

replaceRand

private int replaceRand

MACRO_NOW

private static final java.lang.String MACRO_NOW
String for now() macro

See Also:
Constant Field Values

MACRO_CURRENT_DATE

private static final java.lang.String MACRO_CURRENT_DATE
String for current_date macro

See Also:
Constant Field Values

MACRO_CURRENT_TIME

private static final java.lang.String MACRO_CURRENT_TIME
String for current_times macro

See Also:
Constant Field Values

MACRO_TIMEODFAY

private static final java.lang.String MACRO_TIMEODFAY
String for timeofday() macro

See Also:
Constant Field Values

MACRO_CURRENT_TIMESTAMP

private static final java.lang.String MACRO_CURRENT_TIMESTAMP
String for current_timestamp macro

See Also:
Constant Field Values

DATE_OFF

public static final int DATE_OFF
Value if a date macro should not be replaced

See Also:
Constant Field Values

DATE_DATE

public static final int DATE_DATE
Value if date macro should be replaced by an java.sql.Date value

See Also:
Constant Field Values

DATE_TIME

public static final int DATE_TIME
Value if date macro should be replaced by an java.sql.Time value

See Also:
Constant Field Values

DATE_TIMESTAMP

public static final int DATE_TIMESTAMP
Value if date macro should be replaced by an java.sql.Timestamp value

See Also:
Constant Field Values

clockResolution

private long clockResolution

now

private int now

currentDate

private int currentDate

currentTime

private int currentTime

timeOfDay

private int timeOfDay

currentTimestamp

private int currentTimestamp

needsProcessing

private boolean needsProcessing

needsDateProcessing

private boolean needsDateProcessing
Constructor Detail

MacrosHandler

public MacrosHandler(int replaceRand,
                     long clockResolution,
                     int now,
                     int currentDate,
                     int currentTime,
                     int timeOfDay,
                     int currentTimestamp)
Creates a new MacrosHandler object

Parameters:
replaceRand - replacement of rand() macro
clockResolution - clock resolution for date macros
now - replacement of now()
currentDate - replacement of current_date
currentTime - replacement of current_time
timeOfDay - replacement of timeofday()
currentTimestamp - replacement of current_timestamp
Method Detail

getIntRandLevel

public static final int getIntRandLevel(java.lang.String randLevel)
Convert the rand level from string (xml value) to integer

Parameters:
randLevel - the rand level
Returns:
an int corresponding to the string description

getXml

public java.lang.String getXml()
Return this MacrosHandler to the corresponding xml form

Specified by:
getXml in interface XmlComponent
Returns:
the XML representation of this element

getStringRandLevel

public static final java.lang.String getStringRandLevel(int randLevel)
Convert the rand level from int (java code) to string (xml value)

Parameters:
randLevel - the rand level
Returns:
a string description corresponding to that level

getIntDateLevel

public static final int getIntDateLevel(java.lang.String dateLevel)
Convert the date level from string (xml value) to integer

Parameters:
dateLevel - the date level
Returns:
an int corresponding to the string description

getStringDateLevel

public static final java.lang.String getStringDateLevel(int dateLevel)
Convert the date level from int (java code) to string (xml value)

Parameters:
dateLevel - the date level
Returns:
a string description corresponding to that level

macroDate

public java.lang.String macroDate(java.lang.String originalSql,
                                  java.lang.String macroPattern,
                                  int replacementPolicy,
                                  long currentClock,
                                  java.lang.Integer[] idxs)
Processes a date related macro using the given timestamp.

Parameters:
originalSql - original SQL request
macroPattern - macro text to look for
replacementPolicy - DATE_DATE, DATE_TIME or DATE_TIMESTAMP
currentClock - current time in ms
idxs - quote indexes
Returns:
new SQL statement

macroRand

public java.lang.String macroRand(java.lang.String originalSql,
                                  java.lang.Integer[] idxs)
Replaces rand() with a randomized value.

Parameters:
originalSql - original SQL request
idxs - quote indexes
Returns:
new SQL statement

processMacros

public final java.lang.String processMacros(java.lang.String sql)
Processes all macros in the given request and returns a new String with the processed macros. If no macro has to be processed, the original String is returned.

Parameters:
sql - SQL statement to process
Returns:
processed statement

getQuoteIndexes

private java.lang.Integer[] getQuoteIndexes(java.lang.String sql)
Retrieve all the indexes of quotes in the string

Parameters:
sql - the original query
Returns:
an array of integer corresponding to the quote indexes

shouldReplaceMacro

private boolean shouldReplaceMacro(int idx,
                                   java.lang.Integer[] list)
Should we replace a macro situated at index idx, knowing that the quotes are at indexes list

Parameters:
idx - the index of the macro
list - the indexes of quotes
Returns:
true if we should change the macro, false if the macro is within a string


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.