The Dbutil of Xutil Learning (11)

Source: Internet
Author: User
Tags throwable

I don't see a blog. View Xutil learning Dbutil (10)

Check

(1) FindByID (Class entityType, Object idvalue)
Querying by ID

@SuppressWarnings ("Unchecked") Public<T> TFindByID(class<t> EntityType, Object idvalue) throws Dbexception {if(!tableisexist (EntityType))return NULL; Table table = table.Get( This, EntityType); Selector Selector = Selector. from(EntityType).where(Table.id.getColumnName (),"=", idvalue); String sql = Selector.limit (1). ToString ();LongSeq = CursorUtils.FindCacheSequence.getSeq ();        Findtempcache.setseq (seq); Object obj = Findtempcache.Get(SQL);if(obj! =NULL) {return(T) obj; } cursor cursor = ExecQuery (SQL);if(Cursor! =NULL) {Try{if(Cursor.movetonext ()) {T entity = (t) cursorutils.getentity ( This, cursor, entityType, seq); Findtempcache.put (SQL, entity);returnEntity }            }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }return NULL; }

(2) FindFirst (Selector Selector)
Find the first object that satisfies the selector condition

@SuppressWarnings("Unchecked") Public<T> TFindFirst(Selector Selector)throwsdbexception {if(!tableisexist (Selector.getentitytype ()))return NULL; String sql = Selector.limit (1). ToString ();LongSeq = CursorUtils.FindCacheSequence.getSeq ();        Findtempcache.setseq (seq); Object obj = findtempcache.get (sql);if(obj! =NULL) {return(T) obj; } cursor cursor = ExecQuery (SQL);if(Cursor! =NULL) {Try{if(Cursor.movetonext ()) {T entity = (t) cursorutils.getentity ( This, cursor, selector.getentitytype (), seq); Findtempcache.put (SQL, entity);returnEntity }            }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }return NULL; }

(3) FindFirst (Class entityType)
Find the first object that satisfies the object type

publicfindFirst(Class<T> entityType) throws DbException {        return findFirst(Selector.from(entityType));    }

(4) FindAll (Selector Selector)
Find all objects that meet selector conditions

@SuppressWarnings("Unchecked") Public<T> list<t>FindAll(Selector Selector)throwsdbexception {if(!tableisexist (Selector.getentitytype ()))return NULL; String sql = selector.tostring ();LongSeq = CursorUtils.FindCacheSequence.getSeq ();        Findtempcache.setseq (seq); Object obj = findtempcache.get (sql);if(obj! =NULL) {return(list<t>) obj; } list<t> result =NewArraylist<t> (); cursor cursor = ExecQuery (SQL);if(Cursor! =NULL) {Try{ while(Cursor.movetonext ()) {T entity = (t) cursorutils.getentity ( This, cursor, selector.getentitytype (), seq);                Result.add (entity);            } findtempcache.put (sql, result); }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }returnResult }

(5) FindAll (Class entityType)
Find all objects that satisfy the object type

publicfindAll(Class<T> entityType) throws DbException {        return findAll(Selector.from(entityType));    }

(6) Finddbmodelfirst (Sqlinfo sqlinfo)

public  dbmodel  Finddbmodelfirst  (sqlinfo sqlinfo) throws  dbexception {cursor cursor = EXE Cquery (Sqlinfo); if  (Cursor! = null ) {try  {if  (Cursor.movetonex T ()) {return  cursorutils.getdbmodel (cursor); }} catch  (Throwable e) {throw new  dbexception (e); } finally  {ioutils.closequietly (cursor); }} return  null ; }

(7) Finddbmodelfirst (dbmodelselector selector)

 PublicDbmodelFinddbmodelfirst(Dbmodelselector selector)throwsdbexception {if(!tableisexist (Selector.getentitytype ()))return NULL; cursor cursor = ExecQuery (Selector.limit (1). ToString ());if(Cursor! =NULL) {Try{if(Cursor.movetonext ()) {returnCursorutils.getdbmodel (cursor); }            }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }return NULL; }

(8) Finddbmodelall (Sqlinfo sqlinfo)
The object is encapsulated into Dbmodel by the SQL information to return

  PublicList<dbmodel>Finddbmodelall(Sqlinfo sqlinfo)throwsdbexception {list<dbmodel> dbmodellist =NewArraylist<dbmodel> (); cursor cursor = ExecQuery (sqlinfo);if(Cursor! =NULL) {Try{ while(Cursor.movetonext ())                {Dbmodellist.add (Cursorutils.getdbmodel (cursor)); }            }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }returnDbmodellist; }

(9) Finddbmodelall (dbmodelselector selector)
All objects are encapsulated into Dbmodel returned by selector

  PublicList<dbmodel>Finddbmodelall(Dbmodelselector selector)throwsdbexception {if(!tableisexist (Selector.getentitytype ()))return NULL; List<dbmodel> dbmodellist =NewArraylist<dbmodel> (); cursor cursor = ExecQuery (selector.tostring ());if(Cursor! =NULL) {Try{ while(Cursor.movetonext ())                {Dbmodellist.add (Cursorutils.getdbmodel (cursor)); }            }Catch(Throwable e) {Throw NewDbexception (e); }finally{ioutils.closequietly (cursor); }        }returnDbmodellist; }

The Dbutil of Xutil Learning (11)

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.