KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: PositionalParameterSpecification.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.type.Type;
7 import org.hibernate.param.ParameterSpecification;
8
9 import java.sql.PreparedStatement JavaDoc;
10 import java.sql.SQLException JavaDoc;
11
12 /**
13  * Relates to an HQL positional parameter.
14  *
15  * @author Steve Ebersole
16  */

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

35     public int bind(PreparedStatement JavaDoc statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException JavaDoc {
36         Type type = qp.getPositionalParameterTypes()[hqlPosition];
37         Object JavaDoc value = qp.getPositionalParameterValues()[hqlPosition];
38
39         type.nullSafeSet( statement, value, position, session );
40         return type.getColumnSpan( session.getFactory() );
41     }
42 }
43
Popular Tags