KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: StandardSQLFunction.java,v 1.4 2005/04/26 18:08:01 oneovthafew Exp $
2
package org.hibernate.dialect.function;
3
4 import java.util.List JavaDoc;
5
6 import org.hibernate.engine.Mapping;
7 import org.hibernate.engine.SessionFactoryImplementor;
8 import org.hibernate.type.Type;
9
10 /**
11  * Provides a standard implementation that supports the majority of the HQL
12  * functions that are translated to SQL. The Dialect and its sub-classes use
13  * this class to provide details required for processing of the associated
14  * function.
15  *
16  * @author David Channon
17  */

18 public class StandardSQLFunction implements SQLFunction {
19     private Type returnType = null;
20     private String JavaDoc name;
21     
22     public StandardSQLFunction(String JavaDoc name) {
23         this.name = name;
24     }
25     
26     public StandardSQLFunction(String JavaDoc 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 JavaDoc render(List JavaDoc args, SessionFactoryImplementor factory) {
44         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc toString() {
55         return name;
56     }
57 }
58
Popular Tags