KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > dialect > function > NoArgSQLFunction


1 //$Id: NoArgSQLFunction.java,v 1.3 2005/04/29 15:32:30 oneovthafew Exp $
2
package org.hibernate.dialect.function;
3
4 import java.util.List JavaDoc;
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 /**
13  * A function which takes no arguments
14  * @author Michi
15  */

16 public class NoArgSQLFunction implements SQLFunction {
17     private Type returnType;
18     private boolean hasParenthesesIfNoArguments;
19     private String JavaDoc name;
20
21     public NoArgSQLFunction(String JavaDoc name, Type returnType) {
22         this(name, returnType, true);
23     }
24
25     public NoArgSQLFunction(String JavaDoc 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 JavaDoc render(List JavaDoc 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