KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: VarArgsSQLFunction.java,v 1.4 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  * Support for slightly more general templating than <tt>StandardSQLFunction</tt>,
13  * with an unlimited number of arguments.
14  * @author Gavin King
15  */

16 public class VarArgsSQLFunction implements SQLFunction {
17
18     private final String JavaDoc begin;
19     private final String JavaDoc sep;
20     private final String JavaDoc end;
21     private final Type type;
22     
23     public VarArgsSQLFunction(Type type, String JavaDoc begin, String JavaDoc sep, String JavaDoc end) {
24         this.begin = begin;
25         this.sep = sep;
26         this.end = end;
27         this.type = type;
28     }
29
30     public VarArgsSQLFunction(String JavaDoc begin, String JavaDoc sep, String JavaDoc 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 JavaDoc render(List JavaDoc args, SessionFactoryImplementor factory) throws QueryException {
50         StringBuffer JavaDoc buf = new StringBuffer JavaDoc().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