Source code: org/hibernate/param/NamedParameterSpecification.java
1 // $Id: NamedParameterSpecification.java 8513 2005-11-02 18:47:40Z steveebersole $
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;
9 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 AbstractExplicitParameterSpecification implements ParameterSpecification {
17
18 private final String name;
19
20 public NamedParameterSpecification(int sourceLine, int sourceColumn, String name) {
21 super( sourceLine, sourceColumn );
22 this.name = name;
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 statement, QueryParameters qp, SessionImplementor session, int position)
36 throws SQLException {
37 TypedValue typedValue = ( TypedValue ) qp.getNamedParameters().get( name );
38 typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
39 return typedValue.getType().getColumnSpan( session.getFactory() );
40 }
41
42 public String renderDisplayInfo() {
43 return "name=" + name + ", expectedType=" + getExpectedType();
44 }
45
46 public String getName() {
47 return name;
48 }
49 }