Message Selectors sql 92

http://romanykultury.info/044.html

 

Message Selectors

Message selectors are strings that conform to the standard ANSI SQL-92 syntax (found at http://www.ansi.org) after the WHERE criterion, and are used by JMS clients for filtering the messages delivered to them. They are evaluated using JMS properties and standard headers and can be specified using both standard and application-specific properties. Message selectors are specified when the message consumer is created. However, because the provider handles the filtering, the client itself is more efficient, and the messaging traffic imposes less bandwidth use.

The interface javax.jms.QueueSession defines a method to create a queue receiver with a specified message selector:

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

The interface javax.jms.QueueSession defines a method to create a queue receiver with a specified message selector:

    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 with a value greater than 100:

    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 with a value greater than 100:

    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'
 Note 

JMS message selectors support all the ANSI SQL-92 compliant combinations. Please refer to an ANSI SQL reference for an exhaustive list.

 
 

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.

 
Top of page

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.

 
Top of page

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 is the same as that defined for Java: space, horizontal tab, form feed and/or line terminator.

 
Top of page

Expressions

A selector is a conditional expression. Any selector that evaluates to true matches; a selector that evaluates to false or unknown does not match.

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

Conditional expressions are composed of comparison operators, logical operators, identifiers with boolean values, boolean literals, and/or other conditional expressions.

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.


 
Top of page

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"

 
Top of page

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.

 
Top of page

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 supported.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值