J2EE development framework (3)-query condition Encapsulation

Source: Internet
Author: User

This section describes the query condition interfaces in the framework.

1. the entire structure of the condition Query Class


2. the directory structure of the query conditions under the hqhop-framework-common project:


3. Open searchoperator. java. This class contains all query operators and is an enumeration type:

Public Enum searchoperator {eq ("equal to", "="), NE ("not equal ","! = "), GT (" greater than ","> "), GTE (" greater than or equal to ","> = "), LT (" less than "," <"), LTE ("less than or equal to", "<="), prefixlike ("prefix fuzzy match", "like"), prefixnotlike ("prefix fuzzy mismatch ", "Not like"), suffixlike ("suffix fuzzy match", "like"), suffixnotlike ("suffix fuzzy mismatch", "not like "), like ("fuzzy match", "like"), notlike ("mismatch", "not like"), isnull ("null", "Is null "), isnotnull ("not empty", "is not null"), in ("include", "in"), notin ("do not contain", "not in "), custom ("Custom default", null); private final string Info; private final string symbol; searchoperator (final string info, string symbol) {this.info = Info; this. symbol = symbol;} Public String getinfo () {return Info;} Public String getsymbol () {return symbol;} public static string tostringalloperator () {return arrays. tostring (searchoperator. values ();}/*** whether the operator can be blank ** @ Param operator * @ return */public static Boolean isallowblankvalue (final searchoperator operator) {return operator = searchoperator. isnotnull | Operator = searchoperator. isnull;} public static searchoperator valuebysymbol (string symbol) throws searchexception {symbol = formatsymbol (Symbol); For (searchoperator OPERATOR: values () {If (operator. getsymbol (). equals (Symbol) {return operator;} Throw new searchexception ("searchoperator not method search operator Symbol:" + symbol);} Private Static string formatsymbol (string symbol) {If (utils. isempty (Symbol) {return symbol;} return symbol. trim (). tolowercase (). replace ("","");}}
4. The main implementation of the searchable abstract class is completed in searchrequest, and can be directly queried if there are many codes.

5. query Interface Usage:

1) there is only one single condition (query records with user age = 21)

Searchable searchable = Searchable.newSearchable();searchable.addSearchFilter("age", SearchOperator.eq, 21);
2) use and to connect two query conditions (query records whose user name is 'silentwu' and age is 21)

Searchable searchable = Searchable.newSearchable(); searchable.and(SearchFilterHelper.newCondition("age", SearchOperator.eq, 21), SearchFilterHelper.newCondition("name", SearchOperator.eq, "silentwu"));
3. Use or to connect two query Conditions
Searchable searchable = Searchable.newSearchable(); searchable.or(SearchFilterHelper.newCondition("age", SearchOperator.eq, 21), SearchFilterHelper.newCondition("name", SearchOperator.eq, "silentwu"));




J2EE development framework (3)-query condition Encapsulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.