1 package org.hibernate.dialect.function; 3 4 import java.util.List ; 5 6 import org.hibernate.QueryException; 7 import org.hibernate.engine.Mapping; 8 import org.hibernate.engine.SessionFactoryImplementor; 9 import org.hibernate.type.Type; 10 11 16 public class NvlFunction implements SQLFunction { 17 18 public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { 19 return columnType; 20 } 21 22 public boolean hasArguments() { 23 return true; 24 } 25 26 public boolean hasParenthesesIfNoArguments() { 27 return true; 28 } 29 30 public String render(List args, SessionFactoryImplementor factory) throws QueryException { 31 int lastIndex = args.size()-1; 32 Object last = args.remove(lastIndex); 33 if ( lastIndex==0 ) return last.toString(); 34 Object secondLast = args.get(lastIndex-1); 35 String nvl = "nvl(" + secondLast + ", " + last + ")"; 36 args.set(lastIndex-1, nvl); 37 return render(args, factory); 38 } 39 40 41 42 } 43 | Popular Tags |