Save This Page
Home » hibernate-distribution-3.3.1.GA-dist » org.hibernate » param » [javadoc | source]
    1   /*
    2    * Hibernate, Relational Persistence for Idiomatic Java
    3    *
    4    * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
    5    * indicated by the @author tags or express copyright attribution
    6    * statements applied by the authors.  All third-party contributions are
    7    * distributed under license by Red Hat Middleware LLC.
    8    *
    9    * This copyrighted material is made available to anyone wishing to use, modify,
   10    * copy, or redistribute it subject to the terms and conditions of the GNU
   11    * Lesser General Public License, as published by the Free Software Foundation.
   12    *
   13    * This program is distributed in the hope that it will be useful,
   14    * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15    * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   16    * for more details.
   17    *
   18    * You should have received a copy of the GNU Lesser General Public License
   19    * along with this distribution; if not, write to:
   20    * Free Software Foundation, Inc.
   21    * 51 Franklin Street, Fifth Floor
   22    * Boston, MA  02110-1301  USA
   23    *
   24    */
   25   package org.hibernate.param;
   26   
   27   import org.hibernate.engine.QueryParameters;
   28   import org.hibernate.engine.SessionImplementor;
   29   import org.hibernate.type.Type;
   30   
   31   import java.sql.PreparedStatement;
   32   import java.sql.SQLException;
   33   
   34   /**
   35    * Relates to an explicit query positional (or ordinal) parameter.
   36    *
   37    * @author Steve Ebersole
   38    */
   39   public class PositionalParameterSpecification extends AbstractExplicitParameterSpecification implements ParameterSpecification {
   40   
   41   	private final int hqlPosition;
   42   
   43   	public PositionalParameterSpecification(int sourceLine, int sourceColumn, int hqlPosition) {
   44   		super( sourceLine, sourceColumn );
   45   		this.hqlPosition = hqlPosition;
   46   	}
   47   
   48   	/**
   49   	 * Bind the appropriate value into the given statement at the specified position.
   50   	 *
   51   	 * @param statement The statement into which the value should be bound.
   52   	 * @param qp The defined values for the current query execution.
   53   	 * @param session The session against which the current execution is occuring.
   54   	 * @param position The position from which to start binding value(s).
   55   	 *
   56   	 * @return The number of sql bind positions "eaten" by this bind operation.
   57   	 */
   58   	public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException {
   59   		Type type = qp.getPositionalParameterTypes()[hqlPosition];
   60   		Object value = qp.getPositionalParameterValues()[hqlPosition];
   61   
   62   		type.nullSafeSet( statement, value, position, session );
   63   		return type.getColumnSpan( session.getFactory() );
   64   	}
   65   
   66   	public String renderDisplayInfo() {
   67   		return "ordinal=" + hqlPosition + ", expectedType=" + getExpectedType();
   68   	}
   69   
   70   	public int getHqlPosition() {
   71   		return hqlPosition;
   72   	}
   73   }

Save This Page
Home » hibernate-distribution-3.3.1.GA-dist » org.hibernate » param » [javadoc | source]