1 package org.hibernate.dialect.function; 3 4 import java.util.List ; 5 6 import org.hibernate.engine.Mapping; 7 import org.hibernate.engine.SessionFactoryImplementor; 8 import org.hibernate.type.Type; 9 10 18 public class StandardSQLFunction implements SQLFunction { 19 private Type returnType = null; 20 private String name; 21 22 public StandardSQLFunction(String name) { 23 this.name = name; 24 } 25 26 public StandardSQLFunction(String name, Type typeValue) { 27 returnType = typeValue; 28 this.name = name; 29 } 30 31 public Type getReturnType(Type columnType, Mapping mapping) { 32 return returnType == null ? columnType : returnType; 33 } 34 35 public boolean hasArguments() { 36 return true; 37 } 38 39 public boolean hasParenthesesIfNoArguments() { 40 return true; 41 } 42 43 public String render(List args, SessionFactoryImplementor factory) { 44 StringBuffer buf = new StringBuffer (); 45 buf.append(name) 46 .append('('); 47 for ( int i=0; i<args.size(); i++ ) { 48 buf.append( args.get(i) ); 49 if ( i<args.size()-1 ) buf.append(", "); 50 } 51 return buf.append(')').toString(); 52 } 53 54 public String toString() { 55 return name; 56 } 57 } 58 | Popular Tags |