All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.impl.SQLQueryImpl Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * 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.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.io.Serializable;

import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.QueryException;
import org.hibernate.SQLQuery;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.MappingException;
import org.hibernate.LockOptions;
import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.NamedSQLQueryDefinition;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.engine.query.sql.NativeSQLQueryJoinReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryScalarReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.StringHelper;

/**
 * Implements SQL query passthrough.
 *
 * 
 * 
 * 
 *   SELECT {person}.NAME AS {person.name}, {person}.AGE AS {person.age}, {person}.SEX AS {person.sex}
 *   FROM PERSON {person} WHERE {person}.NAME LIKE 'Hiber%'
 * 
 * 
* * @author Max Andersen */ public class SQLQueryImpl extends AbstractQueryImpl implements SQLQuery { private final List queryReturns; private Collection querySpaces; private final boolean callable; private boolean autodiscovertypes; /** * Constructs a SQLQueryImpl given a sql query defined in the mappings. * * @param queryDef The representation of the defined . * @param session The session to which this SQLQueryImpl belongs. * @param parameterMetadata Metadata about parameters found in the query. */ SQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata) { super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata ); if ( queryDef.getResultSetRef() != null ) { ResultSetMappingDefinition definition = session.getFactory() .getResultSetMapping( queryDef.getResultSetRef() ); if (definition == null) { throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() ); } this.queryReturns = Arrays.asList( definition.getQueryReturns() ); } else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) { this.queryReturns = Arrays.asList( queryDef.getQueryReturns() ); } else { this.queryReturns = new ArrayList(); } this.querySpaces = queryDef.getQuerySpaces(); this.callable = queryDef.isCallable(); } SQLQueryImpl( final String sql, final List queryReturns, final Collection querySpaces, final FlushMode flushMode, boolean callable, final SessionImplementor session, ParameterMetadata parameterMetadata) { // TODO : absolutely no usages of this constructor form; can it go away? super( sql, flushMode, session, parameterMetadata ); this.queryReturns = queryReturns; this.querySpaces = querySpaces; this.callable = callable; } SQLQueryImpl( final String sql, final String returnAliases[], final Class returnClasses[], final LockMode[] lockModes, final SessionImplementor session, final Collection querySpaces, final FlushMode flushMode, ParameterMetadata parameterMetadata) { // TODO : this constructor form is *only* used from constructor directly below us; can it go away? super( sql, flushMode, session, parameterMetadata ); queryReturns = new ArrayList(returnAliases.length); for ( int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy