KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > sql > ANSICaseFragment


1 //$Id: ANSICaseFragment.java,v 1.2 2004/12/02 05:09:49 oneovthafew Exp $
2
package org.hibernate.sql;
3
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 /**
8  An ANSI SQL CASE expression.
9  <br>
10  <code>case when ... then ... end as ...</code>
11  <br>
12  @author Gavin King, Simon Harris
13  */

14 public class ANSICaseFragment extends CaseFragment {
15
16     public String JavaDoc toFragmentString() {
17         
18         StringBuffer JavaDoc buf = new StringBuffer JavaDoc( cases.size() * 15 + 10 )
19             .append("case");
20
21         Iterator JavaDoc iter = cases.entrySet().iterator();
22         while ( iter.hasNext() ) {
23             Map.Entry JavaDoc me = (Map.Entry JavaDoc) iter.next();
24             buf.append(" when ")
25                 .append( me.getKey() )
26                 .append(" is not null then ")
27                 .append( me.getValue() );
28         }
29         
30         buf.append(" end");
31
32         if (returnColumnName!=null) {
33             buf.append(" as ")
34                 .append(returnColumnName);
35         }
36
37         return buf.toString();
38     }
39     
40 }
Popular Tags