KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > param > NamedParameterSpecification


1 // $Id: NamedParameterSpecification.java,v 1.1 2005/07/12 19:56:56 steveebersole Exp $
2
package org.hibernate.param;
3
4 import org.hibernate.engine.QueryParameters;
5 import org.hibernate.engine.SessionImplementor;
6 import org.hibernate.engine.TypedValue;
7
8 import java.sql.PreparedStatement JavaDoc;
9 import java.sql.SQLException JavaDoc;
10
11 /**
12  * Relates to an HQL named-parameter.
13  *
14  * @author Steve Ebersole
15  */

16 public class NamedParameterSpecification implements ParameterSpecification {
17
18     private final String JavaDoc name;
19
20     public NamedParameterSpecification(String JavaDoc name) {
21         this.name = name;
22     }
23
24     /**
25      * Bind the appropriate value into the given statement at the specified position.
26      *
27      * @param statement The statement into which the value should be bound.
28      * @param qp The defined values for the current query execution.
29      * @param session The session against which the current execution is occuring.
30      * @param position The position from which to start binding value(s).
31      *
32      * @return The number of sql bind positions "eaten" by this bind operation.
33      */

34     public int bind(PreparedStatement JavaDoc statement, QueryParameters qp, SessionImplementor session, int position)
35             throws SQLException JavaDoc {
36         TypedValue typedValue = ( TypedValue ) qp.getNamedParameters().get( name );
37         typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
38         return typedValue.getType().getColumnSpan( session.getFactory() );
39     }
40 }
41
Popular Tags