Message Selectors

Message selectors are strings that conform to the standard ANSI SQL-92 syntax (found at http://www.ansi.org) after the WHERE

The interface javax.jms.QueueSession


public QueueReceiver createReceiver(Queue queue, String selector) throws JMSException, InvalidDestinationException, InvalidSelectorException


The interface javax.jms.QueueSession


public TopicSubscriber createSubscriber(Topic topic, String selector, boolean noLocal) throws JMSException, InvalidDestinationException, InvalidSelectorException


Example Selectors

This section explains a few examples for JMS message selectors. For a more in depth look at message selectors please refer to Appendix B.

A message consumer with the message selector below will be delivered only those messages having a string property named manager with the value as Vialli:



manager = 'Vialli'



A message consumer with the message selector below will be delivered only those messages having a string property named gender with the value as M AND a numeric property named salary



gender = 'M' AND salary > 100



A message consumer with the message selector below will be delivered only those messages having a string property named gender with the value as M OR a numeric property named salary



gender = 'M' OR salary > 100



A message consumer with the message selector below will be delivered only those messages having a string property named name with the value as either all or Dick:



name in ('all', 'Dick')



A message consumer with the message selector below will be delivered only those messages having a string property named name with values not starting with the letter J:



name NOT LIKE 'J%'



A message consumer with the message selector below will be delivered only those messages having the JMSType header set to the string XYZ:



JMSType = 'XYZ'



 


 


=========== http://www.novell.com/documentation/extend5/Docs/help/Composer/books/JMSAppendixB.html


APPENDIX B

Message Selector Syntax

A message selector is a String containing an expression that, if it evaluates to TRUE, will result in messages being selected, or if FALSE results in messages being neglected. The syntax of the JMS selector expression is based on a subset of SQL92. The order of evaluation of a message selector is from left to right within precedence level; but parentheses can be used to alter the evaluation order. For consistency, predefined selector literals and operator names are shown in upper case below (but are nevertheless case-insensitive).

A selector can contain tokens, operators, and expressions conforming to the rules outlined hereunder.



 

Message Selectors sql 92_sed

Literals

A string literal is enclosed in single quotes. If a string literal is to contain an included single quote, it can be represented by a doubled single quote: for example, 'its' and 'it''s'. As with Java String literals, the Unicode character encoding is presumed.

An exact numeric literal is a numeric value without a decimal point, such as 59, -257, +82, etc. Numbers in the range of Java long are supported. Exact numeric literals use the Java integer literal syntax.

An approximate numeric literal is a numeric value in scientific notation, such as 7E4, -27.9E2 or a numeric value with a decimal such as 7., -95.7, +16.2; numbers in the range of Java double are supported. Approximate literals use the Java floating point literal syntax.

A boolean literal can have a value of TRUE or FALSE.



 

Message Selectors sql 92_sed

Identifiers

Identifiers can be either header field references or property references. An identifier is a character sequence that begins with a Java-identifier start character and is followed by characters that are Java-identifier part characters. An identifier start character is any character for which the method Character.isJavaIdentifierStart() returns true. This includes underscore and $. An identifier part character is any character for which the method Character.isJavaIdentifierPart() returns true.

Identifiers cannot be NULL, TRUE,nor FALSE.

Identifiers cannot be NOT, AND, OR, BETWEEN, LIKE, IN, nor IS.

Identifiers are case-sensitive.

Message header field references are restricted to JMSDeliveryMode, JMSPriority, JMSMessageID, JMSTimestamp, JMSCorrelationID, and JMSType.

JMSMessageID, JMSCorrelationID, and JMSType values may be null and if so are treated as a NULL value.

Any name beginning with 'JMSX' is a JMS-defined property name.

Any name beginning with 'JMS_' is a provider-specific property name.

Any name that does not begin with 'JMS' is an application-specific property name. If a non-existent property is referenced, its value is NULL. If it does exist, its value is the corresponding property value.

Whitespace



 

Message Selectors sql 92_sed

Expressions

A selector is a conditional expression. Any selector that evaluates to true matches; a selector that evaluates to false

Arithmetic expressions are composed of arithmetic operators, identifiers with numeric values, numeric literals and/or other arithmetic expressions.

Conditional

Standard bracketing () for ordering expression evaluation is supported.

Logical operators in precedence order: NOT, AND, OR

Comparison operators: =, >, >=, <, <=, <> (not equal)

Only like type values can be compared. One exception is that it is valid to compare exact numeric values and approximate numeric values. (The necessary type conversion is conducted according to the rules of Java numeric promotion.) If the comparison of non-like type values is attempted, the selector is always false.

String and Boolean comparisons are restricted to = (equal) and <> (not equal). Two strings are equal if and only if they contain the same sequence of characters.

Arithmetic operators in precedence order:

+, - unary

*, / multiplication and division

+, - addition and subtraction



NOTE:   Arithmetic operations must use Java numeric promotion.






 

Message Selectors sql 92_sed

Comparisons

· arithmetic-expr1 [NOT] BETWEEN arithmetic-expr2 and arithmetic-expr3

Example:

age BETWEEN 15 and 19 is equivalent to age >= 15 AND age <= 19

age NOT BETWEEN 15 and 19 is equivalent to age < 15 OR age > 19


· identifier [NOT] IN (string-literal1, string-literal2,...), where identifieris a String or NULL value.

Example: Country IN (' UK', 'US', 'France')

is true for 'UK' and false for 'Peru'. It is equivalent to the expression:

(Country = ' UK') OR (Country = ' US') OR (Country = ' France')


Example: Country NOT IN (' UK', 'US', 'France')

is false for 'UK' and true for 'Peru'. It is equivalent to the expression:

NOT ((Country = ' UK') OR (Country = ' US') OR (Country = ' France'))


If identifier in an IN or NOT IN operation is NULL, the value of the operation is unknown.


· identifier [NOT] LIKE pattern-value [ESCAPE escape-character], where identifier has a String value; pattern-value is a string literal where '_' (underscore) stands for any single character; '%' stands for any sequence of characters (including the empty sequence); and all other characters stand for themselves. The optional escape-character is a single-character string literal whose character is used to escape the special meaning of the '_' and '%' in pattern-value.


phone LIKE '12%3' is true for '123' or '12993' and false for '1234'

phone NOT LIKE '12%3' is false for '123' and '12993' and true for '1234'

word LIKE 'l_se' is true for 'lose' and false for 'loose'

underscored LIKE '\_%' ESCAPE '\' is true for '_foo' and false for 'bar'


If identifier in a LIKE or NOT LIKE operation is NULL, the value of the operation is unknown.


· identifier IS NULL tests for a null header field value, or a missing property value.

· identifier IS NOT NULL tests for the existence of a non null header field value or property value.


The following message selector selects messages with a message type of car and color of red and weight greater than 3500 lbs:

"JMSType = 'car' AND color = 'red' AND weight > 3500"



 

Message Selectors sql 92_sed

Null Values

As noted above, header fields and property values may be NULL. The evaluation of selector expressions containing NULL values is defined by SQL 92 NULL semantics. I.e., SQL treats a NULL value as unknown. Comparison or arithmetic with an unknown value always yields an unknown value. The IS NULL and IS NOT NULL operators convert an unknown header or property value intoTRUE or FALSE values.



 

Message Selectors sql 92_sed

Special Considerations

When used in a message selector, JMSDeliveryMode will have the value 'PERSISTENT' or 'NON_PERSISTENT'.

Date and time values should use the standard Java long millis value. When including a date or time literal in a message selector, it should be an integer literal for a millis value. The standard way to produce millis values is to use java.util.Calendar. Although SQL supports fixed decimal comparison and arithmetic, JMS message selectors do not. (This is the reason for restricting exact numeric literals to non-decimals.)

SQL comments are not