For SQL queries in Hibernate, the query results are accepted as new objects. For hql queries

Source: Internet
Author: User

For SQL queries in Hibernate, the query results are accepted as new objects. For hql queries

Zookeeper package com. ucap. netcheck. dao. impl; import java. util. arrayList; import java. util. list; import org. hibernate. query; import org. hibernate. session; import org. hibernate. sessionFactory; import org. springframework. beans. factory. annotation. autowired; import org. springframework. stereotype. repository; import org. springframework. transaction. annotation. transactional; import com. ucap. netcheck. combination. beans. mainP AgeResultCombinationBean; import com. ucap. netcheck. common. page; import com. ucap. netcheck. common. dao. baseDAO; import com. ucap. netcheck. dao. ISingleRejectDao; import com. ucap. netcheck. entity. mainPageScanFail; import com. ucap. netcheck. entity. mainPageScanResult; import com. ucap. netcheck. exception. DAOException;/*** @ Title: CheckMainPageResultDaoImpl. java * @ Package com. ucap. netcheck. dao. impl * @ Description: * @ Uthor * @ date 5:04:34 * @ version V1.0 */@ Repository @ Transactionalpublic class extends BaseDAO implements extends {@ Autowiredprivate SessionFactory sessionFactory; @ SuppressWarnings ("unchecked ") public MainPageScanResult queryMainPageScanResultUnique (Object... params) {try {String SQL = "FROM MainPageScanResult m" + "WHERE m. errorPercent> 5.0 "+" and m. innerUUID =? "+" And m. taskId =? "; Session session = sessionFactory. getCurrentSession (); List list = session. createQuery (SQL ). setParameter (0, (String) params [0]). setParameter (1, (Integer) params [1]). list (); if (! List. isEmpty () {return list. get (0) ;}} catch (Exception e) {e. printStackTrace ();} return null;}/*** queryMainPageScanFailById (this method is used to find the result of failed homepage scan) ** @ Title: queryMainPageScanFailById * @ Description: * @ param pageNo * @ param pageRow * @ param id * @ param @ return sets the file * @ return Page return type * @ throws */public Page queryMainPageScanFailById (int pageNo, int pageRow, Integer id) {try {Listparams = New ArrayList (); String hql = "FROM MainPageScanFail m WHERE m. mainPageScanId =? "; Params. add (id); Page page = this. queryByPage (hql, pageNo, pageRow, params); return page;} catch (Exception e) {throw new DAOException ("querying all pages-> ERROR", e );}} @ SuppressWarnings ("unchecked") public List queryMainPageScanFailListById (Integer id) {try {String hql = "FROM MainPageScanFail m WHERE m. mainPageScanId =: mainPageScanId "; List list = sessionFactory. getCurrentSession (). createQuery (hql ). setParamet Er ("mainPageScanId", id ). list (); return list;} catch (Exception e) {e. printStackTrace ();} return null;}/*** queryMainPageScaneResultStatistics (this method counts the information of this table) ** @ Title: queryMainPageScaneResultStatistics * @ Description: this method counts the information of this table * @ param objs * @ param @ return setting file * @ return Page return type * @ throws */@ SuppressWarnings ("unchecked") public MainPageResultCombinationBean queryMainPageScaneResultS Tatistics (Object... objs) {try {String hql = "SELECT new com. ucap. netcheck. combination. beans. mainPageResultCombinationBean ("+" min (m. taskStartTime), max (m. taskEndTime), count (m. innerUUID), max (m. totalScanNum), max (m. failNum) "+" FROM "+ MainPageScanResult. class. getSimpleName () + "m WHERE m. innerUUID =? "+" AND m. taskId =? "; List list = sessionFactory. getCurrentSession (). createQuery (hql ). setParameter (0, (String) objs [0]). setParameter (1, objs [1]). list (); return (! List. isEmpty ()? (MainPageResultCombinationBean) list. get (0): null);} catch (Exception e) {throw new DAOException ("querying all pages-> ERROR", e );}} @ SuppressWarnings ({"rawtypes", "unchecked"}) @ Overridepublic Page queryMainPageUpdateResultByPage (int pageNo, int pageRow, Object... objs) {try {StringBuilder SQL = new StringBuilder ("SELECT" + "cm. id AS id, "+" cm. TASK_Id AS taskId, "+" cm. innerUUID AS innerUUID, "+" cm. checkshortask Id AS checkpolicaskid, "+" cm. url as url, "+" cm. first_channel AS firstChannel, "+" cm. second_channel AS secondChannel, "+" cm. chanel_name AS chanelName, "+" cm. title as title, "+" cm. IMG_Url AS imgURL, "+" cm. lastModifyTime AS lastModifyTime, "+" cm. SHOW_TIME AS showTime, "+" cm. scanTime AS scanTime, "+" cm. isReject AS isReject "+" FROM cpu_mp AS cm "+" WHERE cm. innerUUID =? "+" AND cm. TASK_ID =? "+" AND cm. isReject = 1 "); Query query = sessionFactory. getCurrentSession (). createSQLQuery (SQL. toString ()). setParameter (0, (String) objs [0]). setParameter (1, (Integer) objs [1]); Page page = new Page (); page. setPageNum (pageNo); page. setNumPerPage (pageRow); page. setAllRows (query. list (). size (); int allPages = page. getAllRows ()/page. getNumPerPage (); if (page. getAllRows () % page. getNumPerPage () = 0) {page. SetAllPages (allPages); // total number of pages} else {page. setAllPages (allPages + 1); // total number of pages} query. setFirstResult (pageNo-1) * pageRow); query. setMaxResults (pageRow); // set List list = query. list (); page. setRecordList (list); return page;} catch (Exception e) {throw new DAOException ("querying all pages-> ERROR", e );}} @ SuppressWarnings ({"unchecked"}) @ Overridepublic List queryMainPageUpdateResultByCondition (Object... objs) {try {Stri NgBuilder SQL = new StringBuilder ("SELECT" + "cm. id AS id, "+" cm. TASK_Id AS taskId, "+" cm. innerUUID AS innerUUID, "+" cm. checkpolicaskid AS checkpolicaskid, "+" cm. url as url, "+" cm. first_channel AS firstChannel, "+" cm. second_channel AS secondChannel, "+" cm. chanel_name AS chanelName, "+" cm. title as title, "+" cm. IMG_Url AS imgURL, "+" cm. lastModifyTime AS lastModifyTime, "+" cm. SHOW_TIME AS showTime, "+ "Cm. scanTime AS scanTime," + "cm. isReject AS isReject" + "FROM cpu_mp AS cm" + "WHERE cm. innerUUID =? "+" AND cm. TASK_ID =? "+" AND cm. isReject = 1 "); Query query = sessionFactory. getCurrentSession (). createSQLQuery (SQL. toString ()). setParameter (0, (String) objs [0]). setParameter (1, (Integer) objs [1]); // set List list = query. list (); return list;} catch (Exception e) {e. printStackTrace ();} return null ;}}

 

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.