org.mmbase.storage.search.implementation.database
Class ChainedSqlHandler

Package class diagram package ChainedSqlHandler
java.lang.Object
  extended by org.mmbase.storage.search.implementation.database.ChainedSqlHandler
All Implemented Interfaces:
SqlHandler
Direct Known Subclasses:
EtxSqlHandler, FunctionSqlHandler

public class ChainedSqlHandler
extends Object
implements SqlHandler

Baseclass for chained sql handlers, these are SqlHandler implementations that wrap SqlHandler objects to create a chain of handlers, following the Chain Of Responsibility design pattern.

This class is provided as a baseclass to for chained handlers. It implements all SqlHandler methods by delegating to its successor, i.e. the next handler in the chain.

Since:
MMBase-1.7
Version:
$Id: ChainedSqlHandler.java 45150 2011-02-10 09:18:12Z michiel $
Author:
Rob van Maris
See Also:
SqlHandler

Constructor Summary
ChainedSqlHandler(SqlHandler successor)
          Creates a new instance of ChainedSqlHandler.
 
Method Summary
 void appendConstraintToSql(StringBuilder sb, Constraint constraint, SearchQuery query, boolean inverse, boolean inComposite)
          Represents Constraint object, that is not a CompositeConstraint, as a constraint in SQL format, appending the result to a stringbuffer.
 void appendQueryBodyToSql(StringBuilder sb, SearchQuery query, SqlHandler firstInChain)
          Represents body of a SearchQuery object as a string in SQL format, using the database configuration.
 String getAllowedValue(String value)
          Maps string to value that is allowed as table or field name.
protected  SqlHandler getSuccessor()
          Accessor to successor in chain of responsibility.
 int getSupportLevel(Constraint constraint, SearchQuery query)
          Gets the level at which a constraint is supported for a query by this handler.
 int getSupportLevel(int feature, SearchQuery query)
          Gets the level at which a feature is supported for a query by this handler.
 String toSql(SearchQuery query, SqlHandler firstInChain)
          Represents a SearchQuery object as a string in SQL format, using the database configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainedSqlHandler

public ChainedSqlHandler(SqlHandler successor)
Creates a new instance of ChainedSqlHandler.

Parameters:
successor - Successor in chain of responsibility.
Method Detail

toSql

public String toSql(SearchQuery query,
                    SqlHandler firstInChain)
             throws SearchQueryException
Description copied from interface: SqlHandler
Represents a SearchQuery object as a string in SQL format, using the database configuration.

Specified by:
toSql in interface SqlHandler
Parameters:
query - The searchquery.
firstInChain - The first element in the chain of handlers. At some point appendQueryBodyToSql() will have to be called on this handler, to generate the body of the query.
Returns:
SQL string representation of the query.
Throws:
SearchQueryException

appendQueryBodyToSql

public void appendQueryBodyToSql(StringBuilder sb,
                                 SearchQuery query,
                                 SqlHandler firstInChain)
                          throws SearchQueryException
Description copied from interface: SqlHandler
Represents body of a SearchQuery object as a string in SQL format, using the database configuration. Appends this to a stringbuffer.
The body of the SQL query string is defined as the substring containing fields, tables, constraints and orders.

Specified by:
appendQueryBodyToSql in interface SqlHandler
Parameters:
sb - The stringbuffer to append to.
query - The searchquery.
firstInChain - The first element in the chain of handlers. At some point appendConstraintToSql() will have to be called on this handler, to generate the constraints in the query.
Throws:
SearchQueryException

appendConstraintToSql

public void appendConstraintToSql(StringBuilder sb,
                                  Constraint constraint,
                                  SearchQuery query,
                                  boolean inverse,
                                  boolean inComposite)
                           throws SearchQueryException
Description copied from interface: SqlHandler
Represents Constraint object, that is not a CompositeConstraint, as a constraint in SQL format, appending the result to a stringbuffer. When it is part of a composite expression, it will be surrounded by parenthesis when needed.

Specified by:
appendConstraintToSql in interface SqlHandler
Parameters:
sb - The stringbuffer to append to.
constraint - The (non-composite) constraint.
query - The searchquery containing the constraint.
inverse - True when the inverse constraint must be represented, false otherwise.
inComposite - True when the constraint is part of a composite expression.
Throws:
SearchQueryException

getSupportLevel

public int getSupportLevel(int feature,
                           SearchQuery query)
                    throws SearchQueryException
Description copied from interface: SqlHandler
Gets the level at which a feature is supported for a query by this handler. This is one of either: Given the choice, the query handler with the highest level of support is prefered.

Specified by:
getSupportLevel in interface SqlHandler
Throws:
SearchQueryException

getSupportLevel

public int getSupportLevel(Constraint constraint,
                           SearchQuery query)
                    throws SearchQueryException
Description copied from interface: SqlHandler
Gets the level at which a constraint is supported for a query by this handler. This is one of either: Given the choice, the query handler with the highest level of support is prefered.

Specified by:
getSupportLevel in interface SqlHandler
Throws:
SearchQueryException

getAllowedValue

public String getAllowedValue(String value)
Description copied from interface: SqlHandler
Maps string to value that is allowed as table or field name.

Specified by:
getAllowedValue in interface SqlHandler
Parameters:
value - The string value.
Returns:
The mapped value.

getSuccessor

protected SqlHandler getSuccessor()
Accessor to successor in chain of responsibility.

Returns:
The successor.


MMBase2 Core 2.0-SNAPSHOT - 2013-03-30T06:36