Hibernate + Spring is listed on DAO!

xiaoxiao2021-03-06  86

Package infoweb.da;

Import java.util.list; import java.util.ITerator;

Import infoweb.pojo.info;

Import net.sf.hibelnate.hibernateException; import net.sf.hibernate.query; import net.sf.hibernate.Session;

Import org.springframework.orm.hibernate.hibernateCallback; import org.springframework.hibernate.support.hibernatedaosupport;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2004 *

Company: * @ Author Duan Hongjie * @version 1.0 * /

Public class infodaoimpl extends hibernatedaosupport implementations iinfodao {/ ** * constructor * / public infodaoIMPL () {super ();}

/ ** * Add record * @Param info info * / public void setInfo (info info) throws exception {gethateTemplate (). Save (info);}

/ ** * Take record via ID * @Param ID string * @return info * / public info getinfobyid (String id) throws exception {info info = (info) gethateTemplate (). Load (info.class, id); return info }

/ ** * Modify Record * @Param Info Info * / Public Void ModifyInfo (Info Info) THROWS Exception {gethibernateTemplate (). Update (Info);

/ ** * Delete Record * @Param Info Info * / Public Void RemoveInfo (Info Info) THROWS Exception {gethateTemplate (). Delete (info);}

/ / / / Below Some of them without audit function / / / / / /

/ ** * Total record total * @Return int * / public int getinfoscount () throws exception {int count = 0; string queryString = "select count (*) from info"; count = ((Integer) gethateTemplate (). Iteerate (querystring) .next ()). INTVALUE (); return count;}

/ ** * takes a set of all records * @return Iterator * / public Iterator getAllInfos () throws Exception {Iterator iterator = null; String queryString = "select info from Info as info order by info.id desc"; List list = getHibernateTemplate ( ) .find (querystring); item = list.iterator (); return itrator;} / ** * Take a record collection * @return itrator * @Param int position, int futureTh * / public iterator getInfos (int position, int length) throws Exception {Iterator iterator = null; String queryString = "select info from info as info order by info.id desc"; Query query = getHibernateTemplate () createQuery (getSession (), queryString);. // set the starting point of the cursor query .SetFirstResult (position); // Set the length of the cursor query.setMaxResults (length); // Record generation List list = query.list (); // put the result of the query to iterator = list.iterator () Return Iterator;}

/ ** * taking a first record * @throws Exception * @return Station * / public Info getFirstInfo () throws Exception {Iterator iterator = null; Info info = null; String queryString = "select info from Info as info order by info .id desc "; query query = gethibernateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator = List.Itemator (); Ite (Iterator.hasNext ()) {info = (info) iterator.next ();} returnifo;}

/ * Get the last record ** * @throws Exception * @return Station * / public Info getLastInfo () throws Exception {Iterator iterator = null; Info info = null; String queryString = "select info from Info as info order by info. ID ASC "; query query = gethibernateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator ( ); Iterator.hasNext ()) {info = (info) iterator.next ();} return;

/ /// / The following partial table must have a specific field to run personal and enterprises / / / / ////

/ ** * Take the total number of requirements, [ISPERSON field in the table] * @return int * @Param Int isperson * /

public int getInfosCountByIsperson (int isPerson) throws Exception {int count = 0; String queryString = "select count (*) from Info as info where info.isperson =" isPerson; count = ((Integer) getHibernateTemplate () iterate (queryString. ) .next ()). INTVALUE (); return count;}

/ ** * Take all the qualified record sets, fuzzy query conditions. [There are ISPERSON fields in the table] * @Return Iterator * @Param int isperson * /

public Iterator getAllInfosByIsperson (int isPerson) throws Exception {Iterator iterator = null; String queryString = "select info from Info as info where info.isperson =" isPerson "order by info.id desc"; List list = getHibernateTemplate (). Find (queryString); // put the result of the query into iterator = list.iterator (); returniteate;}

/ ** * Take a collection of conditions, fuzzy query conditions. [Table must have ISPERSON field] * @Return Iterator * @Param Int isperson, int position, int LENGTH * / PUBLIC ITERATOR GETISBYISPERSON (int isperson, int position, int length) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isperson =" isPerson "order by info.id desc"; // create a query query query = getHibernateTemplate () createQuery. (GetSession (), queryString; // Set the starting point Query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record generation list list = query.list (); // Put the results of the query into iterator = list.iterator (); return itrator;}

/ // / / The following part must have a specific field to properly run the query part ////// / / ** * Take the total number of conditions, the fuzzy query conditions. [There are Title in the table. field] * @return int * @param String text * / public int getInfosCount (String text) throws Exception {int count = 0;. count = ((Integer) getHibernateTemplate () iterate ( "select count (*) from info as info WHERE INFO.TILE LIKE '% " Text "%' "). Next ()). INTVALUE (); Return Count;}

/ ** * Take all the qualified records collection, fuzzy query conditions. [There are title fields in the table] * @Return Iterator * @Param string text * /

public Iterator getAllInfos (String text) throws Exception {Iterator iterator = null; String queryString = "select info from Info as info where info.title like '%" text "%' order by info.id desc"; // Create Query Query = gethiBernateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator (); return Iterator;} / ** * Take a collection of conditions, fuzzy query conditions. [Table must have a title field] * @return itrator * @Param string text, int position, int @ / public iterator getinfos (String text, int Position, intlecth) throws exception {ip. t = null; string queryString = "SELECT INFO from info as info where info.title limited" text "% 'Order by Info.id DESC";

// Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record Generate list list = query.list (); // put the result of the query into iterator = list.iterator (); returniteate;}

/ // / / The following partial table must have a specific field to run registration correlation /// / ///

/ ** * total number of records matches take [Table fields have registername] * @return int * @param String text * / public int getInfosCountByRegisterName (String registerName) throws Exception {int count = 0;. Count = ((Integer) GethibernateTemplate (). Iteerate ("Select Count (*) from info as info where info.registername = '" registername "') .next ()). INTVALUE (); return count;} / ** * By registration obtaining a record name, if a plurality of, taking only the first [table fields have RegisterName] * @param registername String * @return Info * / public Info getInfoByRegisterName (String registerName) throws Exception {Iterator iterator = null.; info info = null; String queryString = "select info from info as info where info.registername = '" registerName "' order by info.id desc";. // create a query query query = getHibernateTemplate () createQuery (getSession ( ), queryString); // Record generation list = query.list (); // put the result of the query to iterator = list.iterator (); if (item.hasNext ()) {info = (info) ) iterator.next (); Return info;

/ ** * get all records set by the registered name [Table fields have RegisterName] * @param registername String * @return Iterator * / public Iterator getAllInfosByRegisterName (String registerName) throws Exception {Iterator iterator = null;. String queryString = " select info from info as info where info.registername = ' " registerName "' order by info.id desc "; // create a query query query = getHibernateTemplate () createQuery (getSession (), queryString);. // record generation List list = query.list (); // put the result of the query into the iterator = list.iterator (); returniteate;} / ** * obtains a list of records through the registration name. [There are registername fields in the table. ] * @param registername String * @return Iterator * / public Iterator getInfosByRegisterName (String registerName, int position, int length) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.registername = '" Registername "'Order by Info.id Desc"; // Create Query Query = GethibernateTemplate (). CREATEQUERY (GetSession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor Query.setMaxResults (length); // Record generation list list = query.list (); // put the result of the query into the iterator = list.iterator (); return itrator;}

/ / / / / The following part table must be used to properly run the tree version block / / / / ////

/ ** * Take the total number of records. [Table must have a Board_ID field] * @return int * @Param string boardid * / public int GetInfoScountbyboard (String BoardID) THROWS Exception {Int count = 0;

Count = (("(" ", item ()) .Next ()). Ite ()). Ite ()). ITVALUE ();}

/ ** * all records acquired through collection area name [Table fields have board_id] * @param BoardId String * @return Iterator * / public Iterator getAllInfosByBoard (String boardId) throws Exception {Iterator iterator = null;. String queryString = " Select info from info as info where info.bookardid = '" boardid "' Order by info.id "; // Create query query query = gethibernateTemplate (). CreateTemplate (). CREATEQERY (GetSession (), queryString; // Record generation List list = query.list (); // put the result of the query to iterator = list.iterator (); returniteate;

/ * ** made by recording area name list. [Table fields have board_id] * @param BoardId String * @return Iterator * / public Iterator getInfosByBoard (String boardId, int position, int length) throws Exception {Iterator iterator = null String queryString = "SELECT INFO from info as info where info.bookardid = '" boardid "' Order by Info.id DESC";

// Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record Generate list list = query.list (); // put the result of the query into the iterator = list.iterator ();

Return Iterator;

}

/ ** * Take the total number of conditions. [Title] Fuzzy query title * @return int * @Param string boardidiD, string text * / public int getInfoscountbyboard (String BoardID, string text) throws Exception { INT count = 0; count = ((Integer) gethibernateTemplate (). Iteerate ("Select Count (*) from info as info where info.BoardId = '" " " " " " " TEXT "% '"). NEXT ()). INTVALUE ();

Return count;

}

/ ** * Get a list of records through the section name. [Table must have a Board_ID field] Fuzzy query title * @Param string boardid, int position, intlene * @return itrator * / public iterator getinfosbyboard (String BoardID, int position, int length, String text) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.boardId = '" boardId "' and info.title like '%" text "%' order "by info.id desc";

// Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record Generate list list = query.list (); // put the result of the query into iterator = list.iterator (); Return Iterator;

}

/ /// / below part with audit function / / ////

/ ** * Take the total number of records * @return int * @Param int isauditing * / public int getInfoscount (int isauditing) throws exception {int count = 0;

Count = (("(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,. All record set * @return Iterator * @param int position, int length, int isAuditing * / public Iterator getAllInfos (int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isauditing = " isauditing " Order by Info.id "; query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Record generation list = query.list (); // Put the query Years Iterator = list.iterator (); return itrator;}

/ ** * takes a set of records * @return Iterator * @param int position, int length, int isAuditing * / public Iterator getInfos (int position, int length, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select Info from info as info where info.isauditing = " isauditing " ORDER BY INFO.ID DESC ";

Query Query = gethateTemplate (). CREATEQUERY (GetSession (), queryString; // Set the starting point query.setfirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (Length); // Record generation List list = Query.List (); // put the result of the query into iterator = list.iterator ();

Return Iterator;

/ /// / The following partial table must have a specific field to run the audit function personal and enterprises / / / / / / ////

/ ** * Take the total number of requirements, [ISPERSON ISAUDITING field] * @return int * @Param Int isperson, int isaudity * /

public int getInfosCountByIsperson (int isPerson, int isAuditing) throws Exception {int count = 0; count = ((Integer) getHibernateTemplate () iterate ( "select count (*) from Info as info where info.isperson =" isPerson ". And info.isauditing = " isauditing) .next ()). INTVALUE ();

Return count;

/ ** * Take all the eligible records, fuzzy query conditions. [There are ISPERSON ISAUDITING fields] * @Return Iterator * @Param int isPerson, int isauditing * /

public Iterator getAllInfosByIsperson (int isPerson, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from Info as info where info.isperson =" isPerson "and info.isauditing =" isAuditing "order by Info.id DESC ";

Query query = gethateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator ();

Return Iterator;

/ ** * Take a collection of conditions, fuzzy query conditions. [There are ISPERSON ISAUDITING fields] * @Return Iterator * @Param Int IsPerson, int position, int length, int isauditing * /

public Iterator getInfosByIsperson (int isPerson, int position, int length, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from Info as info where info.isperson =" isPerson "and info.isauditing =" Isauditing "Order by Info.id";

Query Query = gethateTemplate (). CREATEQUERY (GetSession (), queryString; // Set the starting point query.setfirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (Length); // Record generation List list = Query.list (); // put the result of the query into iterator = list.iterator (); returnite;

}

/ / / / / To have a specific field to run the audit function query part /// / ///// / ** * Take the total number of conditions, the fuzzy query conditions. [There are title fields in the table] * @Return Int * @Param string text, int isauditing * / public int getinfoscount (string text, int isauditing) throws exception {INT count = 0

Count = (("(" ("Select Count (*) from info as info where info.isauditing =" isauditing "and info.title like '%" Text "%'"). Next ()). INTVALUE ();

Return count;

/ ** * Take all the qualified records collection, fuzzy query conditions. [Table must have title field] * @return itrator * @Param string text, int isauditing * /

public Iterator getAllInfos (String text, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from Info as info where info.isauditing =" isAuditing "and info.title like '%" text " % 'Order by Info.id DESC ";

Query query = gethateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator ();

Return Iterator;

/ ** * Take a collection of conditions, fuzzy query conditions. [There are title fields in the table] * @Return Iterator * @Param String text, int position, int length, int isauditing * / public iterator getInfos (String text, int position, int length, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isauditing =" isAuditing "and info.title like '%" text "%' Order by info.id desc "; // Create query query = gethibernateTemplate (). CreateTemplate (). CreateQuery (GetSession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor Query. SetMaxResults (Length); // Record generation list = query.list (); // put the result of the query into iterator = list.iterator ();

Return Iterator;

/ / / / / Must have a specific field to run properly with audit function registration related /// ///

/ * ** taken by the total number recording conditions. [Table fields have registername isauditing] * @return int * @param String text, int isAuditing * / public int getInfosCountByRegisterName (String registerName, int isAuditing) throws Exception {int count = 0 ;

Count = ((Integer) gethibernateTemplate (). Itere Info.is info as info where info.isauditing = " isauditing " and info.registername = '" registername "' ") .next () IntValue ();

Return count;

/ ** * Get a record through the registration name, if there are multiple pieces, only the first one. [Table must have registername isauditing field] * @Param registername string, int isauditing * @return info * / public info getInfobyregistername (String registerName, int isAuditing) throws Exception {Iterator iterator = null; info info = null; String queryString = "select info from info as info where info.isauditing =" isAuditing "and info.registername = '" registerName "' Order by info.id desc

Query query = gethibernateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator (); IF Iterator.hasnext ()) {info = (info) iterator.next ();

Return info;

/ * ** registered names acquired by the set of all records. [Table fields have registername isauditing] * @param registername String, int isAuditing * @return Iterator * / public Iterator getAllInfosByRegisterName (String registerName, int isAuditing) throws Exception {Iterator iterator = NULL;

String queryString = "select info from info as info where info.isauditing =" isauditing "and info.registername = '" registername "' Order by Info.id";

Query query = gethateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator ();

Return Iterator;

/ ** * Get the registered name through the list of records. [Table have registername isauditing field] * @param registername String, int isAuditing * @return Iterator * / public Iterator getInfosByRegisterName (String registerName, int position, int length, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isauditing =" isAuditing "and info.registername = '" registerName "' order by info.id desc"; // Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor Query.setMaxResults (length); // Record generation LIST List = query.list (); // put the result of the query into iterator = list.iterator ();

Return Iterator;

/ / / / / Must have a specific field to run properly with a review function tree version block / / / / ///

/ * ** Total number of records taken [Table fields have board_id isauditing] * @return int * @param String boardId, int isAuditing * / public int getInfosCountByBoard (String boardId, int isAuditing) throws Exception {int count = 0.;

Count = (("(" ", item (" Select Count (*) from info as info where info.isauditing = " isauditing " and info.bookardid = '" BoardID " ") .next () .intvalue ();

Return count;

/ ** * all records acquired through collection area name. [Table fields have board_id isauditing] * @param BoardId String, int isAuditing * @return Iterator * / public Iterator getAllInfosByBoard (String boardId, int isAuditing) throws Exception {Iterator iterator = NULL; STRING QueryString = "SELECT INFO from info as info where info.isauditing =" ISAUDITING "AND INFO.BOARD = '" " " " " " " " "

Query query = gethibernateTemplate (). CREATEQUERY (GetSession (), queryString; // Record generation list = query.list (); // put the query to iterator = list.iterator (); return Iterator }

/ ** * Get a list of records by area name. [Table have board_id isauditing field] * @param BoardId String, int isAuditing * @return Iterator * / public Iterator getInfosByBoard (String boardId, int position, int length, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isauditing =" isAuditing "and info.boardId = '" boardId "' order by info.id desc";

// Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record Generate list list = query.list (); // put the result of the query into the iterator = list.iterator ();

Return Iterator;

}

/ ** * get in line with the conditions the total number of records. [Table have board_id isauditing field, title] fuzzy query title * @return int * @param String boardId, String text, int isAuditing * / public int getInfosCountByBoard (String boardId, String text , int isAuditing) throws Exception {int count = 0; count = ((Integer) getHibernateTemplate () iterate ( "select count (*) from info as info where info.isauditing =" isAuditing "and info.boardId = '. " Boardid " 'and info.title Like'% " Text "% '"). Next ()). INTVALUE ();

Return count;

}

/ ** * Take a list through the section name. [Table you need to have a Board_ID field isauditing] Fuzzy query title * @Param string boardid, int position, int length, int isauditing * @return iterator * / public iterator getinfosbyboard (String BoardID, int position, int length, String text, int isAuditing) throws Exception {Iterator iterator = null; String queryString = "select info from info as info where info.isauditing =" isAuditing "and info.boardId = '" boardId "'and info.title Like'%" Text "% 'Order by Info.id DESC";

// Create query query query = gethibernateTemplate (). CreateQuery (getsession (), queryString; // Set the starting point query.setFirstResult (position) of the cursor; // Set the length of the cursor query.setMaxResults (length); // Record Generate list list = query.list (); // put the result of the query into the iterator = list.iterator ();

Return Iterator;

}

}

转载请注明原文地址:https://www.9cbs.com/read-105945.html

New Post(0)