KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: DerbyCaseFragment.java,v 1.2 2004/09/29 12:29:05 pgmjsd Exp $
2
package org.hibernate.sql;
3
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 /**
8  * @author Simon Johnston
9  * @see org.hibernate.dialect.DerbyDialect
10  */

11 public class DerbyCaseFragment extends CaseFragment {
12
13     /**
14      * From http://www.jroller.com/comments/kenlars99/Weblog/cloudscape_soon_to_be_derby
15      * <p/>
16      * The problem we had, was when Hibernate does a select with a case statement, for joined subclasses.
17      * This seems to be because there was no else at the end of the case statement (other dbs seem to not mind).
18      */

19     public String JavaDoc toFragmentString() {
20         StringBuffer JavaDoc buf = new StringBuffer JavaDoc( cases.size() * 15 + 10 );
21         buf.append( "case" ); //$NON-NLS-1
22
Iterator JavaDoc iter = cases.entrySet().iterator();
23         while ( iter.hasNext() ) {
24             Map.Entry JavaDoc me = ( Map.Entry JavaDoc ) iter.next();
25             buf.append( " when " )//$NON-NLS-1
26
.append( me.getKey() )
27                     .append( " is not null then " )//$NON-NLS-1
28
.append( me.getValue() );
29         }
30         // null is not considered the same type as Integer.
31
buf.append( " else -1" ); //$NON-NLS-1
32
buf.append( " end" ); //$NON-NLS-1
33
if ( returnColumnName != null ) {
34             buf.append( " as " )//$NON-NLS-1
35
.append( returnColumnName );
36         }
37         return buf.toString();
38     }
39 }
40
Popular Tags