General generic generichibernatedao

Source: Internet
Author: User

/**
*
* @ Author lny
*/
Public interface genericdao <t extends serializable, PK extends serializable>
{
// -------------------- Basic Search, add, modify, and delete operations --------------------

// Obtain the object based on the primary key. If no corresponding entity exists, null is returned.
Public t get (Pk ID );

// Obtain and lock an object based on the primary key. If no corresponding entity exists, null is returned.
Public t getwithlock (Pk ID, lockmode lock );

// Obtain the object based on the primary key. If no corresponding entity exists, an exception is thrown.
Public t load (Pk ID );

// Obtain and lock an object based on the primary key. If no corresponding entity exists, an exception is thrown.
Public t loadwithlock (Pk ID, lockmode lock );

// Obtain all objects.
Public list <t> loadall ();

// Loadallwithlock ()?

// Update an object
Public void Update (T entity );

// Update and lock the object
Public void updatewithlock (T entity, lockmode lock );

// Store the object to the database
Public void save (T entity );

// Savewithlock ()

// Add or update an object
Public void saveorupdate (T entity );

// Add or update all objects in the Set
Public void saveorupdateall (collection <t> entities );

// Delete the specified object
Public void Delete (T entity );

// Lock and delete the specified object
Public void deletewithlock (T entity, lockmode lock );

// Delete the specified object based on the primary key
Public void deletebykey (Pk ID );

// Lock the primary key and delete the specified object
Public void deletebykeywithlock (Pk ID, lockmode lock );

// Delete all objects in the Set
Public void deleteall (collection <t> entities );

// -------------------- Hsql ----------------------------------------------

// Use the hsql statement to add, update, and delete objects directly.
Public int bulkupdate (string querystring );

// Use the hsql statement with parameters to add, update, and delete objects
Public int bulkupdate (string querystring, object [] values );

// Use an hsql statement to retrieve data
Public list find (string querystring );

// Use a hsql statement with parameters to retrieve data
Public list find (string querystring, object [] values );

// Use the hsql statement with the name parameter to retrieve data
Public list findbynamedparam (string querystring, string [] paramnames, object [] values );

Eg: * string hql = "select count (*) from Member where email =: email and ID! =: ID ";
* List list = This. Support. gethibernatetemplate (). findbynamedparam (hql, new string [] {"email", "ID "},
* New object [] {"sdf@sfd.com", null });

// Use the named hsql statement to retrieve data
Public list findbynamedquery (string queryname );

// Use a named hsql statement with parameters to retrieve data
Public list findbynamedquery (string queryname, object [] values );

// Use the hsql statement with the name parameter to retrieve data
Public list findbynamedqueryandnamedparam (string queryname, string [] paramnames, object [] values );

// Use an hsql statement to retrieve data and return iterator
Public iterator iterate (string querystring );

// Use the hsql statement with parameters to retrieve data and return iterator
Public iterator iterate (string querystring, object [] values );

// Disable iterator returned by Retrieval
Public void closeiterator (iterator it );

// ---------------------------------- Criteria ------------------------------

// Create a standard Object unrelated to the session
Public detachedcriteria createdetachedcriteria ();

// Create a retrieval standard Object bound to the session
Public criteria createcriteria ();

// Use the specified search criteria to retrieve data
Public list findbycriteria (detachedcriteria criteria );

// Use the specified retrieval standard to retrieve data and return some records
Public list findbycriteria (detachedcriteria criteria, int firstresult, int maxresults );

// Retrieve data using the specified object and attribute (except for the primary key and the object value)
Public list <t> findequalbyentity (T entity, string [] propertynames );

// Use the specified object and attribute (non-primary key) to retrieve data that meets the like String object Value
Public list <t> findlikebyentity (T entity, string [] propertynames );

// Use the specified retrieval standard to retrieve data and return records within the specified range
Public integer getrowcount (detachedcriteria criteria );

// Use the specified retrieval standard to retrieve data and return the specified statistical value
Public object getstatvalue (detachedcriteria criteria, string propertyname, string statname );

// ---------------------------------- Others --------------------------------

// Lock the specified object
Public void lock (T entity, lockmode );

// Force initialize the specified object
Public void initialize (Object proxy );

// Force immediately update the buffered data to the database (otherwise, the data is updated only when the transaction is committed)
Public void flush ();

}

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.