01: // $Id: CollectionSubqueryFactory.java 9046 2006-01-13 03:10:57Z steveebersole $
02: package org.hibernate.hql;
03:
04: import org.hibernate.engine.JoinSequence;
05: import org.hibernate.sql.JoinFragment;
06: import org.hibernate.MappingException;
07: import org.hibernate.QueryException;
08: import org.hibernate.util.StringHelper;
09:
10: import java.util.Map;
11:
12: /**
13: * Provides the SQL for collection subqueries.
14: * <br>
15: * Moved here from PathExpressionParser to make it re-useable.
16: *
17: * @author josh
18: */
19: public final class CollectionSubqueryFactory {
20:
21: //TODO: refactor to .sql package
22:
23: private CollectionSubqueryFactory() {
24: }
25:
26: public static String createCollectionSubquery(
27: JoinSequence joinSequence, Map enabledFilters,
28: String[] columns) {
29: try {
30: JoinFragment join = joinSequence.toJoinFragment(
31: enabledFilters, true);
32: return new StringBuffer("select ").append(
33: StringHelper.join(", ", columns)).append(" from ")
34: .append(join.toFromFragmentString().substring(2))// remove initial ", "
35: .append(" where ").append(
36: join.toWhereFragmentString().substring(5))// remove initial " and "
37: .toString();
38: } catch (MappingException me) {
39: throw new QueryException(me);
40: }
41: }
42: }
|