com.edustructures.sifworks.tools.queries
Class QueryFormatter

java.lang.Object
  extended by com.edustructures.sifworks.tools.queries.QueryFormatter
Direct Known Subclasses:
SQLQueryFormatter

public abstract class QueryFormatter
extends java.lang.Object

The abstract base class for query formatters, which format SIF_Query queries in another form such as an SQL WHERE clause. The way in which a query is formatted is determined by the subclass implementation. A subclass must implement these methods:

Version:
ADK 1.0

Constructor Summary
QueryFormatter()
          Constructs a QueryFormatter
 
Method Summary
 java.lang.String format(Query query, java.util.Map table)
          Builds a query string given a dictionary of field definitions and a Query instance.
 java.lang.String format(Query query, java.util.Map table, boolean explicit)
           
abstract  java.lang.String getCloseBrace()
          Return the text that should be inserted for a closing brace
abstract  java.lang.String getOpenBrace()
          Return the text that should be inserted for an opening brace
abstract  java.lang.String getOperator(ComparisonOperators op)
          Return the text that should be inserted for the particular comparison operator, such as "Equals"
abstract  java.lang.String getOperator(GroupOperators op)
          Return the text that should be inserted for the particular grouping operator, such as "AND"
abstract  java.lang.String renderField(ElementDef field, java.lang.Object def)
          Return the text for a field name
abstract  java.lang.String renderValue(java.lang.String value, java.lang.Object def)
          Return the text for a field value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryFormatter

public QueryFormatter()
Constructs a QueryFormatter

Method Detail

format

public java.lang.String format(Query query,
                               java.util.Map table)
                        throws QueryFormatterException
Builds a query string given a dictionary of field definitions and a Query instance. This method evaluates the conditions of that Query to produce a textual query string in the format determined by the implementation.

The dictionary should contain application-defined field values that map to ElementDef key elements. Whenever a SIF element or attribute is found in the Query, the corresponding application-defined field is used in its place.

A special convention allows agents to define an in-line translation table for replacing SIF element/attribute values with values defined in the table. If a field is expressed in the form "field-name{value1=cons1;value2=cons2;..}", the comma-delimited list of values within the curly braces is applied to the value of the SIF_Value element in the SIF_Query, such that "value1" is represented as "cons1". For example, the acceptable values for LibraryPatronStatus/@SifRefIdType attribute are "StudentPersonal" and "StaffPersonal". If in your application you represent these values as numeric types - say, 1 and 2, respectively - you could create the following in-line translation table to instruct the QueryFormatter to substitute "StudentPersonal" with "1" and "StaffPersonal" with "2": "CircRecord.PatronType{StudentPersonal=1;StaffPersonal=2}"

Parameters:
query - An ADK Query object, usually obtained during the processing of a SIF_Request by a Publisher message handler
table - A dictionary that maps SIFDTD ElementDef constants to application-defined field values
Throws:
QueryFormatterException

format

public java.lang.String format(Query query,
                               java.util.Map table,
                               boolean explicit)
                        throws QueryFormatterException
Throws:
QueryFormatterException

getOpenBrace

public abstract java.lang.String getOpenBrace()
Return the text that should be inserted for an opening brace


getCloseBrace

public abstract java.lang.String getCloseBrace()
Return the text that should be inserted for a closing brace


getOperator

public abstract java.lang.String getOperator(ComparisonOperators op)
Return the text that should be inserted for the particular comparison operator, such as "Equals"


getOperator

public abstract java.lang.String getOperator(GroupOperators op)
Return the text that should be inserted for the particular grouping operator, such as "AND"


renderField

public abstract java.lang.String renderField(ElementDef field,
                                             java.lang.Object def)
                                      throws QueryFormatterException
Return the text for a field name

Parameters:
field - The field name
def - The corresponding field definition from the Map passed to the format method
Returns:
The implementation returns the field name in whatever form is appropriate to the implementation, using the supplied def Object if necessary to obtain additional field information.
Throws:
QueryFormatterException

renderValue

public abstract java.lang.String renderValue(java.lang.String value,
                                             java.lang.Object def)
                                      throws QueryFormatterException
Return the text for a field value

Parameters:
field - The field value
def - The corresponding field definition from the Map passed to the format method
Returns:
The implementation returns the field value in whatever form is appropriate to the implementation, using the supplied def Object if necessary to obtain additional field information
Throws:
QueryFormatterException


Copyright © 2001-2007 Edustructures LLC. All Rights Reserved. SIFWorks® and ADK® are registered trademarks of Edustructures LLC. SIF™ and Schools Interoperability Framework are trademarks of the Schools Interoperability Framework Association.