~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/param/PositionalParameterSpecification.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Id: PositionalParameterSpecification.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.type.Type;
 
7
 
 
8
import java.sql.PreparedStatement;
 
9
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 AbstractExplicitParameterSpecification implements ParameterSpecification {
 
17
 
 
18
        private final int hqlPosition;
 
19
 
 
20
        public PositionalParameterSpecification(int sourceLine, int sourceColumn, int hqlPosition) {
 
21
                super( sourceLine, sourceColumn );
 
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 statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException {
 
36
                Type type = qp.getPositionalParameterTypes()[hqlPosition];
 
37
                Object value = qp.getPositionalParameterValues()[hqlPosition];
 
38
 
 
39
                type.nullSafeSet( statement, value, position, session );
 
40
                return type.getColumnSpan( session.getFactory() );
 
41
        }
 
42
 
 
43
        public String renderDisplayInfo() {
 
44
                return "ordinal=" + hqlPosition + ", expectedType=" + getExpectedType();
 
45
        }
 
46
 
 
47
        public int getHqlPosition() {
 
48
                return hqlPosition;
 
49
        }
 
50
}