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 VarArgsSQLFunction implements SQLFunction { 17 18 private final String begin; 19 private final String sep; 20 private final String end; 21 private final Type type; 22 23 public VarArgsSQLFunction(Type type, String begin, String sep, String end) { 24 this.begin = begin; 25 this.sep = sep; 26 this.end = end; 27 this.type = type; 28 } 29 30 public VarArgsSQLFunction(String begin, String sep, String end) { 31 this.begin = begin; 32 this.sep = sep; 33 this.end = end; 34 this.type = null; 35 } 36 37 public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { 38 return type==null ? columnType : type; 39 } 40 41 public boolean hasArguments() { 42 return true; 43 } 44 45 public boolean hasParenthesesIfNoArguments() { 46 return true; 47 } 48 49 public String render(List args, SessionFactoryImplementor factory) throws QueryException { 50 StringBuffer buf = new StringBuffer ().append(begin); 51 for ( int i=0; i<args.size(); i++ ) { 52 buf.append( args.get(i) ); 53 if (i<args.size()-1) buf.append(sep); 54 } 55 return buf.append(end).toString(); 56 } 57 58 } 59 | Popular Tags |