Open Source Repository

Home /hibernate/hibernate-3.2.4.ga | Repository Home



org/hibernate/dialect/function/ConvertFunction.java
//$Id: CastFunction.java 7368 2005-07-04 02:54:27Z oneovthafew $
package org.hibernate.dialect.function;

import java.util.List;

import org.hibernate.QueryException;
import org.hibernate.Hibernate;
import org.hibernate.engine.Mapping;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.Type;

/**
 * A Caché defintion of a convert function.
 *
 @author Jonathan Levinson
 */
public class ConvertFunction implements SQLFunction {

  public Type getReturnType(Type columnType, Mapping mappingthrows QueryException {
    return Hibernate.STRING;
  }

  public boolean hasArguments() {
    return true;
  }

  public boolean hasParenthesesIfNoArguments() {
    return true;
  }

  public String render(List args, SessionFactoryImplementor factorythrows QueryException {
    if args.size() != && args.size() != ) {
      throw new QueryException"convert() requires two or three arguments" );
    }
    String type = String args.get);

    if args.size() == ) {
      return "{fn convert(" + args.get" , " + type + ")}";
    }
    else {
      return "convert(" + args.get" , " + type + "," + args.get")";
    }
  }

}