FileDocCategorySizeDatePackage
ParameterTranslationsImpl.javaAPI DocHibernate 3.2.54821Wed Oct 18 22:25:42 BST 2006org.hibernate.hql.ast

ParameterTranslationsImpl

public class ParameterTranslationsImpl extends Object implements org.hibernate.hql.ParameterTranslations
Defines the information available for parameters encountered during query translation through the antlr-based parser.
author
Steve Ebersole

Fields Summary
private final Map
namedParameters
private final ParameterInfo[]
ordinalParameters
Constructors Summary
public ParameterTranslationsImpl(List parameterSpecifications)
Constructs a parameter metadata object given a list of parameter specifications.

Note: the order in the incoming list denotes the parameter's psudeo-position within the resulting sql statement.

param
parameterSpecifications


		class NamedParamTempHolder {
			String name;
			Type type;
			List positions = new ArrayList();
		}

		int size = parameterSpecifications.size();
		List ordinalParameterList = new ArrayList();
		Map namedParameterMap = new HashMap();
		for ( int i = 0; i < size; i++ ) {
			final ParameterSpecification spec = ( ParameterSpecification ) parameterSpecifications.get( i );
			if ( PositionalParameterSpecification.class.isAssignableFrom( spec.getClass() ) ) {
				PositionalParameterSpecification ordinalSpec = ( PositionalParameterSpecification ) spec;
				ordinalParameterList.add( new ParameterInfo( i, ordinalSpec.getExpectedType() ) );
			}
			else if ( NamedParameterSpecification.class.isAssignableFrom( spec.getClass() ) ) {
				NamedParameterSpecification namedSpec = ( NamedParameterSpecification ) spec;
				NamedParamTempHolder paramHolder = ( NamedParamTempHolder ) namedParameterMap.get( namedSpec.getName() );
				if ( paramHolder == null ) {
					paramHolder = new NamedParamTempHolder();
					paramHolder.name = namedSpec.getName();
					paramHolder.type = namedSpec.getExpectedType();
					namedParameterMap.put( namedSpec.getName(), paramHolder );
				}
				paramHolder.positions.add( new Integer( i ) );
			}
			else {
				// don't care about other param types here, just those explicitly user-defined...
			}
		}

		ordinalParameters = ( ParameterInfo[] ) ordinalParameterList.toArray( new ParameterInfo[ordinalParameterList.size()] );

		if ( namedParameterMap.isEmpty() ) {
			namedParameters = java.util.Collections.EMPTY_MAP;
		}
		else {
			Map namedParametersBacking = new HashMap( namedParameterMap.size() );
			Iterator itr = namedParameterMap.values().iterator();
			while( itr.hasNext() ) {
				final NamedParamTempHolder holder = ( NamedParamTempHolder ) itr.next();
				namedParametersBacking.put(
						holder.name,
				        new ParameterInfo( ArrayHelper.toIntArray( holder.positions ), holder.type )
				);
			}
			namedParameters = java.util.Collections.unmodifiableMap( namedParametersBacking );
		}
	
Methods Summary
public org.hibernate.type.TypegetNamedParameterExpectedType(java.lang.String name)

		return getNamedParameterInfo( name ).getExpectedType();
	
public org.hibernate.hql.ast.ParameterTranslationsImpl$ParameterInfogetNamedParameterInfo(java.lang.String name)

		return ( ParameterInfo ) namedParameters.get( name );
	
public java.util.SetgetNamedParameterNames()

		return namedParameters.keySet();
	
public int[]getNamedParameterSqlLocations(java.lang.String name)

		return getNamedParameterInfo( name ).getSqlLocations();
	
public intgetOrdinalParameterCount()

		return ordinalParameters.length;
	
public org.hibernate.type.TypegetOrdinalParameterExpectedType(int ordinalPosition)

		return getOrdinalParameterInfo( ordinalPosition ).getExpectedType();
	
public org.hibernate.hql.ast.ParameterTranslationsImpl$ParameterInfogetOrdinalParameterInfo(int ordinalPosition)

		// remember that ordinal parameters numbers are 1-based!!!
		return ordinalParameters[ordinalPosition - 1];
	
public intgetOrdinalParameterSqlLocation(int ordinalPosition)

		return getOrdinalParameterInfo( ordinalPosition ).getSqlLocations()[0];
	
public booleansupportsOrdinalParameterMetadata()

		return true;