Liferay advanced query (1)

Source: Internet
Author: User

Code added to pointexchangelocalserviceimpl. Java

/**

* Query method in point management

*

* @ Param searchterms

* @ Param companyid

* @ Param groupid

* @ Param start

* @ Param end

* @ Return

* @ Throws systemexception

*/




// Query all records in the pointexchange table

@ Suppresswarnings ("unchecked ")

Public list <pointexchange> findpointexchanges (pointsearchterms searchterms, long companyid, int start, int end) throws systemexception {

Dynamicquery = getpointexchangedynamicquery (searchterms, companyid );

Return dynamicquery (dynamicquery, start, end );

}


/**

* Query the total number of users in point management

*

* @ Param searchterms

* @ Param companyid

* @ Param groupid

* @ Return

* @ Throws systemexception

*/

Public int countpointexchange (pointsearchterms searchterms, long companyid) throws systemexception {

Dynamicquery = getpointexchangedynamicquery (searchterms, companyid );

Return (long) dynamicquerycount (dynamicquery). intvalue ();

}


Private dynamicquery getpointexchangedynamicquery (pointsearchterms searchterms, long companyid ){

Dynamicquery = pointexchangepersistence. createdynamicquery ();

Dynamicquery. Add (propertyfactoryutil. forname ("companyid"). eq (companyid ));


If (searchterms. isadvancedsearch () {// determines if it is an advanced Query

// Conditions in the advanced query (by what query)

String realnamelike = searchterms. getrealnamelike ();

Date submitdate = searchterms. getsubmitdate ();

Int confirmstate = searchterms. getconfirmstate ();

Junction junction = NULL;

// And Operation

If (searchterms. isandoperator ()){

Junction = restrictionsfactoryutil. conjunction (); // connection operation, logical and

} Else {

Junction = restrictionsfactoryutil. disjunction (); // logical or operation

}

If (validator. isnotnull (realnamelike )){

String realnamelikesql = daoutil. getlike (realnamelike );

Junction. Add (propertyfactoryutil. forname ("realname"). Like (realnamelikesql); // fuzzy query

}

If (validator. isnotnull (submitdate )){

Calendar Cal = calendar. getinstance ();

Cal. settime (submitdate );

Cal. Add (calendar. date, 1 );

Junction datejunction = restrictionsfactoryutil. conjunction ();

// Greater than or equal to the operator GE, Lt less than the operator, and EQ equal to the operator

Datejunction. Add (propertyfactoryutil. forname ("submitdate"). Ge (submitdate ));

Datejunction. Add (propertyfactoryutil. forname ("submitdate"). LT (Cal. gettime ()));

Junction. Add (datejunction );

}

If (confirmstate! =-1 ){

Junction. Add (propertyfactoryutil. forname ("confirmstate"). eq (confirmstate ));

}

Dynamicquery. Add (junction );

} Else {

String KEYWORDS = searchterms. getkeywords (); // keyword search

String realnamelike = keywords;

If (validator. isnotnull (realnamelike )){

String realnamelikesql = daoutil. getlike (realnamelike );

Dynamicquery. Add (propertyfactoryutil. forname ("realname"). Like (realnamelikesql ));

}

}


Return dynamicquery;

}


This article is from the "hexun.com" blog, please be sure to keep this source http://551735.blog.51cto.com/541735/1529969

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.