org.sqlproc.engine
Interface SqlFeature

All Known Implementing Classes:
SqlProcessContext

public interface SqlFeature

Optional features, which can be activated in the process of SQL Processor initialization. The internal class SqlContext implements this interface.

The features can be incorporated into queries.properties file in the form of SET_... properties.

For example the SQL Processor supports the special searching feature based on text fragments. Lets have a table PERSON with two columns - ID and NAME.
In queries.properties there's the next definition:

 SET_LIKE_STRING=like
 SET_WILDCARD_CHARACTER=%
 SET_SURROUND_QUERY_LIKE=true
 SET_SURROUND_QUERY_MIN_LEN=2
 
 LIST_LIKE_SQL= \
   select p.ID id, p.NAME name \
   from PERSON p \
   where 1=1 \
   {& id=:id} \
   {& UPPER(name) like :+name} \
   {#1 order by ID} \
   {#2 order by NAME}
 LIST_LIKE_FIELDS=id name
 

The special searching capability is activated with the next statement in queries.properties:

 SET_SURROUND_QUERY_LIKE = true
 
In this case every query with the like keyword is identified and dynamic input parameter, which belongs to this query condition, is handled in a special way. The value for this parameter is surrounded with wildcard character %. This character is defined in queries.properties with the key SET_WILDCARD_CHARACTER. In the runtime to activate this feature, the parameter value has to have the minimal length = 2. This minimal length is defined in queries.properties with the key SET_SURROUND_QUERY_MIN_LEN. In the case of SQL Processor initialization
 SqlPropertiesLoader loader = new SqlPropertiesLoader("queries.properties", this.getClass());
 SqlEngineLoader sqlLoader = new SqlEngineLoader(loader.getProperties());
 SqlEngine sqlEngine = sqlLoader.getSqlEngine("LIKE");
 
there's created an instance of SqlEngine with the name LIKE.

Next there's an instance person of the class Person with the value an for the attribute name. The invocation

 List<Person> list = sqlEngine.query(session, Person.class, person, SqlOrder.getDescOrder(2));
 
produces the next SQL execution
 select p.ID id, p.NAME name from PERSON p where 1=1  AND  UPPER(name) like ?  order by NAME DESC
 
In the result list there are all table rows with name, which contains the text fragment an.

For more info please see the User's tutorial.

Author:
Vladimir Hudec

Field Summary
static java.lang.String DEFAULT_LIKE_STRING
          This is the default value for the key SET_LIKE_STRING.
static java.lang.Integer DEFAULT_SURROUND_QUERY_MIN_LEN
          This is the default value for the key SET_SURROUND_QUERY_MIN_LEN.
static java.lang.String DEFAULT_WILDCARD_CHARACTER
          This is the default value for the key SET_WILDCARD_CHARACTER .
static java.lang.String LIKE_STRING
          SET_LIKE_STRING is the key for the like sql command.
static java.lang.String SURROUND_QUERY_LIKE
          SET_SURROUND_QUERY_LIKE is the key for the special SQL Processor behavior.
static java.lang.String SURROUND_QUERY_MIN_LEN
          SET_SURROUND_QUERY_MIN_LEN is the minimal length of the string input values for the SQL like command to switch on the SQL Processor special behavior described above in the runtime.
static java.lang.String WILDCARD_CHARACTER
          SET_WILDCARD_CHARACTER is the key for the wildcard character for SQL like command in the properties.
 
Method Summary
 java.lang.String getFeature(java.lang.String name)
          Returns the value of the feature as a String.
 java.lang.Integer getFeatureAsInt(java.lang.String name)
          Returns the value of the feature as an Integer.
 boolean isFeature(java.lang.String name)
          Returns the value of the feature as a boolean.
 

Field Detail

WILDCARD_CHARACTER

static final java.lang.String WILDCARD_CHARACTER
SET_WILDCARD_CHARACTER is the key for the wildcard character for SQL like command in the properties.

See Also:
Constant Field Values

DEFAULT_WILDCARD_CHARACTER

static final java.lang.String DEFAULT_WILDCARD_CHARACTER
This is the default value for the key SET_WILDCARD_CHARACTER .

See Also:
Constant Field Values

SURROUND_QUERY_LIKE

static final java.lang.String SURROUND_QUERY_LIKE
SET_SURROUND_QUERY_LIKE is the key for the special SQL Processor behavior. In the case the value of this property is true, the SQL Processor puts wildcard character as a prefix and postfix for all string values in the SQL select commands like. These string values should have to have the minimal length greater or equal to SET_SURROUND_QUERY_MIN_LEN.

See Also:
Constant Field Values

SURROUND_QUERY_MIN_LEN

static final java.lang.String SURROUND_QUERY_MIN_LEN
SET_SURROUND_QUERY_MIN_LEN is the minimal length of the string input values for the SQL like command to switch on the SQL Processor special behavior described above in the runtime.

See Also:
Constant Field Values

DEFAULT_SURROUND_QUERY_MIN_LEN

static final java.lang.Integer DEFAULT_SURROUND_QUERY_MIN_LEN
This is the default value for the key SET_SURROUND_QUERY_MIN_LEN.


LIKE_STRING

static final java.lang.String LIKE_STRING
SET_LIKE_STRING is the key for the like sql command. For example for the Informix database it can be matches.

See Also:
Constant Field Values

DEFAULT_LIKE_STRING

static final java.lang.String DEFAULT_LIKE_STRING
This is the default value for the key SET_LIKE_STRING.

See Also:
Constant Field Values
Method Detail

getFeature

java.lang.String getFeature(java.lang.String name)
Returns the value of the feature as a String.

Parameters:
name - the name of the required feature
Returns:
the value of the feature as a String

isFeature

boolean isFeature(java.lang.String name)
Returns the value of the feature as a boolean.

Parameters:
name - the name of the required feature
Returns:
the value of the feature as a boolean

getFeatureAsInt

java.lang.Integer getFeatureAsInt(java.lang.String name)
Returns the value of the feature as an Integer.

Parameters:
name - the name of the required feature
Returns:
the value of the feature as an Integer


Copyright © 2010. All Rights Reserved.