org.mmbase.storage.search.implementation.database
Interface SqlHandler

Package class diagram package SqlHandler
All Known Implementing Classes:
BasicSqlHandler, ChainedSqlHandler, EtxSqlHandler, FunctionSqlHandler, HSqlSqlHandler, InformixSqlHandler, MSSqlSqlHandler, MySqlSqlHandler, PostgreSqlSqlHandler

public interface SqlHandler

Interface for handler classes that are used to create SQL string representations of SearchQuery objects.

A number of SqlHandler objects can create a chain of handlers, following the Chain Of Responsibility design pattern.

In short:

Each handler in the chain adds functionality to its successor(s), in a way similar to subclassing. The chained design enables a chain of handlers to be configured and created at runtime.

In addition to the methods defined in the interface, the concrete SqlHandler class for the last element in the chain is required to have a constructor with this signature:

public <constructor>(Map disallowedValues) { .. }
where disallowedValues is a map that maps disallowed table/fieldnames to allowed alternatives.

The concrete SqlHandler class for the other, chained, elements in the chain are required to have a constructor with this signature:

public <constructor>(SqlHandler successor) { .. }
where successor is the successor in the chain of responsibility.

Since:
MMBase-1.7
Version:
$Id: SqlHandler.java 40539 2010-01-12 16:15:57Z michiel $
Author:
Rob van Maris

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)
          Deprecated. use StorageManagerFactory.getStorageIdentifier()
 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.
 

Method Detail

toSql

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

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

void appendQueryBodyToSql(StringBuilder sb,
                          SearchQuery query,
                          SqlHandler firstInChain)
                          throws SearchQueryException
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.

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

void appendConstraintToSql(StringBuilder sb,
                           Constraint constraint,
                           SearchQuery query,
                           boolean inverse,
                           boolean inComposite)
                           throws SearchQueryException
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.

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

int getSupportLevel(int feature,
                    SearchQuery query)
                    throws SearchQueryException
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.

Throws:
SearchQueryException

getSupportLevel

int getSupportLevel(Constraint constraint,
                    SearchQuery query)
                    throws SearchQueryException
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.

Throws:
SearchQueryException

getAllowedValue

String getAllowedValue(String value)
Deprecated. use StorageManagerFactory.getStorageIdentifier()

Maps string to value that is allowed as table or field name.

Parameters:
value - The string value.
Returns:
The mapped value.


MMBase2 Core 2.0-SNAPSHOT - 2013-05-29T22:08