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 12 16 public class NoArgSQLFunction implements SQLFunction { 17 private Type returnType; 18 private boolean hasParenthesesIfNoArguments; 19 private String name; 20 21 public NoArgSQLFunction(String name, Type returnType) { 22 this(name, returnType, true); 23 } 24 25 public NoArgSQLFunction(String name, Type returnType, boolean hasParenthesesIfNoArguments) { 26 this.returnType = returnType; 27 this.hasParenthesesIfNoArguments = hasParenthesesIfNoArguments; 28 this.name = name; 29 } 30 31 public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { 32 return returnType; 33 } 34 35 public boolean hasArguments() { 36 return false; 37 } 38 39 public boolean hasParenthesesIfNoArguments() { 40 return hasParenthesesIfNoArguments; 41 } 42 43 public String render(List args, SessionFactoryImplementor factory) throws QueryException { 44 if ( args.size()>0 ) { 45 throw new QueryException("function takes no arguments: " + name); 46 } 47 return hasParenthesesIfNoArguments ? name + "()" : name; 48 } 49 } 50 | Popular Tags |