KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > CollectionSubqueryFactory


1 // $Id: CollectionSubqueryFactory.java,v 1.3 2005/02/23 02:31:40 oneovthafew Exp $
2
package org.hibernate.hql;
3
4 import org.hibernate.engine.JoinSequence;
5 import org.hibernate.sql.JoinFragment;
6 import org.hibernate.MappingException;
7 import org.hibernate.QueryException;
8 import org.hibernate.util.StringHelper;
9
10 import java.util.Map JavaDoc;
11
12 /**
13  * Provides the SQL for collection subqueries.
14  * <br>
15  * Moved here from PathExpressionParser to make it re-useable.
16  * @author josh Dec 23, 2004 7:12:55 AM
17  */

18 public final class CollectionSubqueryFactory {
19
20     private CollectionSubqueryFactory() {
21     }
22
23     public static String JavaDoc createCollectionSubquery(JoinSequence joinSequence, Map JavaDoc enabledFilters, String JavaDoc[] columns) {
24         //TODO: refactor to .sql package
25
JoinFragment join;
26         try {
27             join = joinSequence.toJoinFragment( enabledFilters, true );
28         }
29         catch ( MappingException me ) {
30             throw new QueryException( me );
31         }
32         return new StringBuffer JavaDoc( "select " )
33                 .append( StringHelper.join( ", ", columns ) )
34                 .append( " from " )
35                 /*.append(collectionTable)
36                 .append(' ')
37                 .append(collectionName)*/

38                 .append( join.toFromFragmentString().substring( 2 ) )// remove initial ", "
39
.append( " where " )
40                 .append( join.toWhereFragmentString().substring( 5 ) )// remove initial " and "
41
.toString();
42     }
43 }
44
Popular Tags