KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: MckoiCaseFragment.java,v 1.1 2004/06/03 16:30:12 steveebersole Exp $
2
package org.hibernate.sql;
3
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 /**
8  * A Mckoi IF function.
9  * <br>
10  * <code>if(..., ..., ...) as ...</code>
11  * <br>
12  * @author Gavin King
13  */

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