⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 criteria.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: Criteria.java,v 1.4.2.14 2003/10/27 11:46:57 oneovthafew Exp $
package net.sf.hibernate;

import java.util.List;

import net.sf.hibernate.expression.Criterion;
import net.sf.hibernate.expression.Order;

/**
 * <tt>Criteria</tt> is a simplified API for retrieving entities
 * by composing <tt>Criterion</tt> objects. This is a very
 * convenient approach for functionality like "search" screens
 * where there is a variable number of conditions to be placed
 * upon the result set.<br>
 * <br>
 * The <tt>Session</tt> is a factory for <tt>Criteria</tt>.
 * <tt>Criterion</tt> instances are usually obtained via
 * the factory methods on <tt>Expression</tt>. eg.
 * <pre>
 * List cats = session.createCriteria(Cat.class)
 *     .add( Expression.like("name", "Iz%") )
 *     .add( Expression.gt( "weight", new Float(minWeight) ) )
 *     .addOrder( Order.asc("age") )
 *     .list();
 * </pre>
 * You may navigate associations using <tt>addJoin</tt>.
 * <pre>
 * List cats = session.createCriteria(Cat.class)
 *     .createCriteria("kittens")
 *         .add( Expression.like("name", "Iz%") )
 *     .list();
 * </pre>
 * Hibernate's query language is much more general and should be used 
 * for non-simple cases.<br>
 * <br>
 * <i>This is an experimental API</i>
 * 
 * @see Session#createCriteria(java.lang.Class)
 * @see net.sf.hibernate.expression.Expression
 * @see net.sf.hibernate.expression.Criterion
 * @see net.sf.hibernate.expression.Order
 * @author Gavin King
 */
public interface Criteria {
	
	/**
	 * The alias that refers to the "root" entity of the criteria query.
	 */
	public static final String ROOT_ALIAS = "this";

	/**
	 * Set a limit upon the number of objects to be retrieved.
	 * 
	 * @param maxResults
	 * @return Criteria
	 */
	public Criteria setMaxResults(int maxResults);
	/**
	 * Set the first result to be retrieved.
	 * 
	 * @param firstResult
	 * @return Criteria
	 */
	public Criteria setFirstResult(int firstResult);
	/**
	 * Set a timeout for the underlying JDBC query.
	 * 
	 * @param timeout
	 * @return Criteria
	 */
	public Criteria setTimeout(int timeout);
	/**
	 * Add an <tt>Criterion</tt> to constrain the result to be retrieved.
	 * 
	 * @param criterion
	 * @return Criteria
	 */
	public Criteria add(Criterion criterion);
	
	/**
	 * Add an <tt>Order</tt> to the result set.
	 * 
	 * @param order
	 * @return Criteria
	 */
	public Criteria addOrder(Order order);
	
	/**
	 * Get the results.
	 * 
	 * @return List
	 * @throws HibernateException
	 */
	public List list() throws HibernateException;
	
	/**
	 * Convenience method to return a single instance that matches
	 * the query, or null if the query returns no results.
	 * 
	 * @return the single result or <tt>null</tt>
	 * @throws HibernateException if there is more than one matching result
	 */
	public Object uniqueResult() throws HibernateException;
	
	/**
	 * Specify an association fetching strategy for a
	 * one-to-many, many-to-one or one-to-one association, or
	 * for a collection of values.
	 * 
	 * @param associationPath a dot seperated property path
	 * @param mode the fetch mode
	 * @return the Criteria object for method chaining
	 */
	public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
	/**
	 * Join an association, assigning an alias to the joined entity
	 */
	public Criteria createAlias(String associationPath, String alias) throws HibernateException;
	
	/**
	 * Create a new <tt>Criteria</tt>, "rooted" at the associated entity
	 */
	public Criteria createCriteria(String associationPath) throws HibernateException;
	
	/**
	 * Create a new <tt>Criteria</tt>, "rooted" at the associated entity,
	 * assigning the given alias
	 */
	public Criteria createCriteria(String associationPath, String alias) throws HibernateException;
	
	/**
	 * Get the persistent class that this <tt>Criteria</tt> applies to
	 */
	public Class getCriteriaClass();
	/**
	 * Get the persistent class that the alias refers to
	 */
	public Class getCriteriaClass(String alias);
	
	/**
	 * Return each row of results as a <tt>Map</tt> from alias
	 * to an instance of the aliased entity
	 * @see Criteria#returnRootEntities()
	 */
	public Criteria returnMaps();
	/**
	 * Return each row of results as a single instance of the
	 * "root" entity (this is the default mode)
	 * @see Criteria#returnMaps()
	 */
	public Criteria returnRootEntities();
	
	/**
	 * Set the lock mode of the current entity
	 * @param lockMode the lock mode
	 */
	public Criteria setLockMode(LockMode lockMode);
	/**
	 * Set the lock mode of the aliased entity
	 * @param alias an alias
	 * @param lockMode the lock mode
	 */
	public Criteria setLockMode(String alias, LockMode lockMode);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -