01: // $Id: PositionalParameterSpecification.java 8513 2005-11-02 18:47:40Z steveebersole $
02: package org.hibernate.param;
03:
04: import org.hibernate.engine.QueryParameters;
05: import org.hibernate.engine.SessionImplementor;
06: import org.hibernate.type.Type;
07:
08: import java.sql.PreparedStatement;
09: import java.sql.SQLException;
10:
11: /**
12: * Relates to an explicit query positional (or ordinal) parameter.
13: *
14: * @author Steve Ebersole
15: */
16: public class PositionalParameterSpecification extends
17: AbstractExplicitParameterSpecification implements
18: ParameterSpecification {
19:
20: private final int hqlPosition;
21:
22: public PositionalParameterSpecification(int sourceLine,
23: int sourceColumn, int hqlPosition) {
24: super (sourceLine, sourceColumn);
25: this .hqlPosition = hqlPosition;
26: }
27:
28: /**
29: * Bind the appropriate value into the given statement at the specified position.
30: *
31: * @param statement The statement into which the value should be bound.
32: * @param qp The defined values for the current query execution.
33: * @param session The session against which the current execution is occuring.
34: * @param position The position from which to start binding value(s).
35: *
36: * @return The number of sql bind positions "eaten" by this bind operation.
37: */
38: public int bind(PreparedStatement statement, QueryParameters qp,
39: SessionImplementor session, int position)
40: throws SQLException {
41: Type type = qp.getPositionalParameterTypes()[hqlPosition];
42: Object value = qp.getPositionalParameterValues()[hqlPosition];
43:
44: type.nullSafeSet(statement, value, position, session);
45: return type.getColumnSpan(session.getFactory());
46: }
47:
48: public String renderDisplayInfo() {
49: return "ordinal=" + hqlPosition + ", expectedType="
50: + getExpectedType();
51: }
52:
53: public int getHqlPosition() {
54: return hqlPosition;
55: }
56: }
|