|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.tools.queries.QueryFormatter
com.edustructures.sifworks.tools.queries.SQLQueryFormatter
public class SQLQueryFormatter
An implementation of a QueryFormatter that formats SIF_Query conditions as a
string suitable for inclusion in an SQL WHERE clause.
When preparing a dictionary to be passed to the SQLQueryFormatter.format
method, the caller must map SIFDTD ElementDef constants to instances
of the SQLField class. The constructor to that class requires two
parameters: the application-defined name of the field, and a type code constant
from the java.sql.Types class. The type code is used to properly
render the field value according to its data type (e.g. strings are quoted with
a single quote, numeric fields are rendered as-is, etc.)
For example,
Map m = new HashMap();
The above example might result in a string such as "( Students.US_Citizen_Bool = 0 )"
or "( Students.Foreign_ID = '898' ) OR ( Students.Last_Name = 'Cortez' AND First_Name = 'Robert' )"
m.put( SIFDTD.STUDENTPERSONAL_REFID,
new SQLField( "Students.Foreign_ID", java.sql.Types.VARCHAR ) );
m.put( SIFDTD.NAME_LASTNAME,
new SQLField( "Students.Last_Name", java.sql.Types.VARCHAR ) );
m.put( SIFDTD.NAME_FIRSTNAME,
new SQLField( "First_Name", java.sql.Types.VARCHAR ) );
m.put( SIFDTD.DEMOGRAPHICS_CITIZENSHIPSTATUS,
new SQLField( "Students.US_Citizen_Bool{04=1;=0}", java.sql.Types.NUMERIC ) );
| Constructor Summary | |
|---|---|
SQLQueryFormatter()
Constructs a SQLQueryFormatter |
|
| Method Summary | |
|---|---|
void |
addField(ElementDef def,
QueryField field)
Adds a QueryField to use for rendering an SQL Where clause using the format(Query) method. |
void |
addField(ElementDef def,
SQLField field)
Adds an SQLField to use for rendering an SQL Where clause using the format(Query) method. |
void |
addField(java.lang.String xPath,
QueryField field)
Adds a QueryField to use for rendering an SQL Where clause using the format(Query) method. |
void |
addField(java.lang.String xPath,
SQLField field)
Adds an SQLField to use for rendering an SQL Where clause using the format(Query) method. |
void |
addFields(MappingsContext context)
Adds SQLFields to represent each field rule in the specified MappingsContext. |
java.lang.String |
format(Query query)
Builds a query string given a dictionary of field definitions and a Query instance. |
java.lang.String |
format(Query query,
boolean explicit)
|
java.lang.String |
getCloseBrace()
Return the text that should be inserted for a closing brace |
java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>> |
getFields()
Returns all of the SQLFields that have been mapped for this instance |
java.lang.String |
getOpenBrace()
Return the text that should be inserted for an opening brace |
java.lang.String |
getOperator(ComparisonOperators op)
Return the text that should be inserted for the particular comparison operator, such as "Equals" |
java.lang.String |
getOperator(GroupOperators op)
Return the text that should be inserted for the particular grouping operator, such as "AND" |
java.lang.String |
renderField(ElementDef field,
java.lang.Object def)
Return the text for a field name |
java.lang.String |
renderValue(java.lang.String value,
java.lang.Object def)
Return the text for a field value |
| Methods inherited from class com.edustructures.sifworks.tools.queries.QueryFormatter |
|---|
format, format |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SQLQueryFormatter()
| Method Detail |
|---|
public void addField(ElementDef def,
SQLField field)
format(Query) method.
def - The ElementDef that is represented by the fieldfield - The SQL representation of the field
public void addField(java.lang.String xPath,
SQLField field)
format(Query) method.
def - The XPath representing the SIF Element being mappedfield - The SQL representation of the field
public void addField(ElementDef def,
QueryField field)
format(Query) method.
def - The ElementDef that is represented by the fieldfield - The SQL representation of the field
public void addField(java.lang.String xPath,
QueryField field)
format(Query) method.
def - The xPath representing the SIF Element being mappedfield - The SQL representation of the fieldpublic void addFields(MappingsContext context)
context - The MappingsContext containing FieldMappingspublic java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>> getFields()
public java.lang.String format(Query query)
throws QueryFormatterException
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}"
query - An ADK Query object, usually obtained during the processing
of a SIF_Request by a Publisher message handler
QueryFormatterException
public java.lang.String format(Query query,
boolean explicit)
throws QueryFormatterException
QueryFormatterExceptionpublic java.lang.String getOpenBrace()
getOpenBrace in class QueryFormatterpublic java.lang.String getCloseBrace()
getCloseBrace in class QueryFormatterpublic java.lang.String getOperator(ComparisonOperators op)
getOperator in class QueryFormatterpublic java.lang.String getOperator(GroupOperators op)
getOperator in class QueryFormatter
public java.lang.String renderField(ElementDef field,
java.lang.Object def)
throws QueryFormatterException
renderField in class QueryFormatterfield - The fielddef - The corresponding field definition from the Map passed to
the format method
QueryFormatterException
public java.lang.String renderValue(java.lang.String value,
java.lang.Object def)
throws QueryFormatterException
renderValue in class QueryFormatterfield - The field valuedef - The corresponding field definition from the Map passed to
the format method
QueryFormatterException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||