FileDocCategorySizeDatePackage
ParameterBinder.javaAPI DocHibernate 3.2.53725Wed Jul 06 12:13:16 BST 2005org.hibernate.engine

ParameterBinder

public class ParameterBinder extends Object
Centralizes the commonality regarding binding of parameter values into PreparedStatements as this logic is used in many places.

Ideally would like to move to the parameter handling as it is done in the hql.ast package.

author
Steve Ebersole

Fields Summary
private static final Log
log
Constructors Summary
private ParameterBinder()


	    
		   
	

	  
	
Methods Summary
public static intbindNamedParameters(java.sql.PreparedStatement ps, QueryParameters queryParameters, int start, org.hibernate.engine.ParameterBinder$NamedParameterSource source, SessionImplementor session)

		return bindNamedParameters( ps, queryParameters.getNamedParameters(), start, source, session );
	
public static intbindNamedParameters(java.sql.PreparedStatement ps, java.util.Map namedParams, int start, org.hibernate.engine.ParameterBinder$NamedParameterSource source, SessionImplementor session)

		if ( namedParams != null ) {
			// assumes that types are all of span 1
			Iterator iter = namedParams.entrySet().iterator();
			int result = 0;
			while ( iter.hasNext() ) {
				Map.Entry e = ( Map.Entry ) iter.next();
				String name = ( String ) e.getKey();
				TypedValue typedval = ( TypedValue ) e.getValue();
				int[] locations = source.getNamedParameterLocations( name );
				for ( int i = 0; i < locations.length; i++ ) {
					if ( log.isDebugEnabled() ) {
						log.debug( "bindNamedParameters() " +
								typedval.getValue() + " -> " + name +
								" [" + ( locations[i] + start ) + "]" );
					}
					typedval.getType().nullSafeSet( ps, typedval.getValue(), locations[i] + start, session );
				}
				result += locations.length;
			}
			return result;
		}
		else {
			return 0;
		}
	
public static intbindPositionalParameters(java.sql.PreparedStatement st, QueryParameters queryParameters, int start, SessionImplementor session)

		return bindPositionalParameters(
		        st,
		        queryParameters.getPositionalParameterValues(),
		        queryParameters.getPositionalParameterTypes(),
		        start,
		        session
		);
	
public static intbindPositionalParameters(java.sql.PreparedStatement st, java.lang.Object[] values, org.hibernate.type.Type[] types, int start, SessionImplementor session)

		int span = 0;
		for ( int i = 0; i < values.length; i++ ) {
			types[i].nullSafeSet( st, values[i], start + span, session );
			span += types[i].getColumnSpan( session.getFactory() );
		}
		return span;
	
public static intbindQueryParameters(java.sql.PreparedStatement st, QueryParameters queryParameters, int start, org.hibernate.engine.ParameterBinder$NamedParameterSource source, SessionImplementor session)

		int col = start;
		col += bindPositionalParameters( st, queryParameters, col, session );
		col += bindNamedParameters( st, queryParameters, col, source, session );
		return col;