01: // $Id: NamedParameterSpecification.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.engine.TypedValue;
07:
08: import java.sql.PreparedStatement;
09: import java.sql.SQLException;
10:
11: /**
12: * Relates to an explicit query named-parameter.
13: *
14: * @author Steve Ebersole
15: */
16: public class NamedParameterSpecification extends
17: AbstractExplicitParameterSpecification implements
18: ParameterSpecification {
19:
20: private final String name;
21:
22: public NamedParameterSpecification(int sourceLine,
23: int sourceColumn, String name) {
24: super (sourceLine, sourceColumn);
25: this .name = name;
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: TypedValue typedValue = (TypedValue) qp.getNamedParameters()
42: .get(name);
43: typedValue.getType().nullSafeSet(statement,
44: typedValue.getValue(), position, session);
45: return typedValue.getType().getColumnSpan(session.getFactory());
46: }
47:
48: public String renderDisplayInfo() {
49: return "name=" + name + ", expectedType=" + getExpectedType();
50: }
51:
52: public String getName() {
53: return name;
54: }
55: }
|