KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > engine > SubselectFetch


1 //$Id: SubselectFetch.java,v 1.6 2005/05/11 14:33:12 oneovthafew Exp $
2
package org.hibernate.engine;
3
4 import java.util.Set JavaDoc;
5
6 import org.hibernate.persister.entity.Loadable;
7 import org.hibernate.persister.entity.PropertyMapping;
8 import org.hibernate.util.StringHelper;
9
10 /**
11  * @author Gavin King
12  */

13 public class SubselectFetch {
14     private final Set JavaDoc resultingEntityKeys;
15     private final String JavaDoc queryString;
16     private final String JavaDoc alias;
17     private final Loadable loadable;
18     private final QueryParameters queryParameters;
19     
20     public SubselectFetch(
21         //final String queryString,
22
final String JavaDoc alias,
23         final Loadable loadable,
24         final QueryParameters queryParameters,
25         final Set JavaDoc resultingEntityKeys
26     ) {
27         this.resultingEntityKeys = resultingEntityKeys;
28         this.queryParameters = queryParameters;
29         this.loadable = loadable;
30         this.alias = alias;
31         
32         //TODO: ugly here:
33
final String JavaDoc queryString = queryParameters.getFilteredSQL();
34         int fromIndex = queryString.indexOf(" from ");
35         int orderByIndex = queryString.lastIndexOf("order by");
36         this.queryString = orderByIndex>0 ?
37             queryString.substring(fromIndex, orderByIndex) :
38             queryString.substring(fromIndex);
39             
40 }
41
42     public QueryParameters getQueryParameters() {
43         return queryParameters;
44     }
45     
46     /**
47      * Get the Set of EntityKeys
48      */

49     public Set JavaDoc getResult() {
50         return resultingEntityKeys;
51     }
52     
53     public String JavaDoc toSubselectString(String JavaDoc ukname) {
54         
55         String JavaDoc[] joinColumns = ukname==null ?
56             StringHelper.qualify( alias, loadable.getIdentifierColumnNames() ) :
57             ( (PropertyMapping) loadable ).toColumns(alias, ukname);
58         
59         return new StringBuffer JavaDoc()
60             .append("select ")
61             .append( StringHelper.join(", ", joinColumns) )
62             .append(queryString)
63             .toString();
64     }
65     
66     public String JavaDoc toString() {
67         return "SubselectFetch(" + queryString + ')';
68     }
69
70 }
71
Popular Tags