alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (Projection.java)

This example Hibernate source code file (Projection.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

criteria, criteriaquery, criteriaquery, hibernateexception, hibernateexception, io, projection, serializable, string, string, type, type

The Hibernate Projection.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Middleware LLC.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 *
 */
package org.hibernate.criterion;
import java.io.Serializable;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.type.Type;

/**
 * An object-oriented representation of a query result set projection  in a {@link Criteria} query.
 * Built-in projection types are provided  by the {@link Projections} factory class.  This interface might be
 * implemented by application classes that define custom projections.
 *
 * @author Gavin King
 * @author Steve Ebersole
 * @see Projections
 * @see Criteria
 */
public interface Projection extends Serializable {

	/**
	 * Render the SQL fragment to be used in the <tt>SELECT clause.
	 *
	 * @param criteria The local criteria to which this project is attached (for resolution).
	 * @param position The number of columns rendered in the <tt>SELECT clause before this projection.  Generally
	 * speaking this is useful to ensure uniqueness of the individual columns aliases.
	 * @param criteriaQuery The overall criteria query instance.
	 * @return The SQL fragment to plug into the <tt>SELECT
	 * @throws HibernateException Indicates a problem performing the rendering
	 */
	public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
			throws HibernateException;

	/**
	 * Render the SQL fragment to be used in the <tt>GROUP BY clause
	 *
	 * @param criteria The local criteria to which this project is attached (for resolution).
	 * @param criteriaQuery The overall criteria query instance.
	 * @return The SQL fragment to plug into the <tt>GROUP BY
	 * @throws HibernateException Indicates a problem performing the rendering
	 */
	public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
			throws HibernateException;

	/**
	 * Types returned by the rendered SQL {@link #toSqlString fragment}.  In other words what are the types
	 * that would represent the values this projection asked to be pulled into the result set?
	 *
	 * @param criteria The local criteria to which this project is attached (for resolution).
	 * @param criteriaQuery The overall criteria query instance.
	 * @return The return types.
	 * @throws HibernateException Indicates a problem resolving the types
	 */
	public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
			throws HibernateException;

	/**
	 * Get the return types for a particular user-visible alias.
	 * <p/>
	 * Differs from {@link #getTypes(org.hibernate.Criteria, CriteriaQuery)} in that here we are only interested in
	 * the types related to the given criteria-level alias.
	 *
	 * @param alias The criteria-level alias for which to find types.
	 * @param criteria The local criteria to which this project is attached (for resolution).
	 * @param criteriaQuery The overall criteria query instance.
	 * @return The return types; expected to return null if this projection does not understand this alias.
	 * @throws HibernateException Indicates a problem resolving the types
	 */
	public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery)
			throws HibernateException;


	/**
	 * Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
	 * <tt>SELECT clause ({@link #toSqlString}.  Hibernate always uses column aliases to extract data from the
	 * JDBC {@link java.sql.ResultSet}, so it is important that these be implemented correctly in order for
	 * Hibernate to be able to extract these val;ues correctly.
	 *
	 * @param position Just as in {@link #toSqlString}, represents the number of <b>columns rendered
	 * prior to this projection.
	 * @return The columns aliases.
	 */
	public String[] getColumnAliases(int position);

	/**
	 * Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
	 * <tt>SELECT clause ({@link #toSqlString} for a particular criteria-level alias.
	 *
	 * @param alias The criteria-level alias
	 * @param position Just as in {@link #toSqlString}, represents the number of <b>columns rendered
	 * prior to this projection.
	 * @return The columns aliases pertaining to a particular criteria-level alias; expected to return null if
	 * this projection does not understand this alias.
	 */
	public String[] getColumnAliases(String alias, int position);

	/**
	 * Get the criteria-level aliases for this projection (ie. the ones that will be passed to the
	 * {@link org.hibernate.transform.ResultTransformer})
	 *
	 * @return The aliases
	 */
	public String[] getAliases();

	/**
	 * Is this projection fragment (<tt>SELECT clause) also part of the GROUP BY
	 *
	 * @return True if the projection is also part of the <tt>GROUP BY; false otherwise.
	 */
	public boolean isGrouped();

}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Projection.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.