1 package org.hibernate.engine; 3 4 import java.util.Set ; 5 6 import org.hibernate.persister.entity.Loadable; 7 import org.hibernate.persister.entity.PropertyMapping; 8 import org.hibernate.util.StringHelper; 9 10 13 public class SubselectFetch { 14 private final Set resultingEntityKeys; 15 private final String queryString; 16 private final String alias; 17 private final Loadable loadable; 18 private final QueryParameters queryParameters; 19 20 public SubselectFetch( 21 final String alias, 23 final Loadable loadable, 24 final QueryParameters queryParameters, 25 final Set resultingEntityKeys 26 ) { 27 this.resultingEntityKeys = resultingEntityKeys; 28 this.queryParameters = queryParameters; 29 this.loadable = loadable; 30 this.alias = alias; 31 32 final String 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 49 public Set getResult() { 50 return resultingEntityKeys; 51 } 52 53 public String toSubselectString(String ukname) { 54 55 String [] joinColumns = ukname==null ? 56 StringHelper.qualify( alias, loadable.getIdentifierColumnNames() ) : 57 ( (PropertyMapping) loadable ).toColumns(alias, ukname); 58 59 return new StringBuffer () 60 .append("select ") 61 .append( StringHelper.join(", ", joinColumns) ) 62 .append(queryString) 63 .toString(); 64 } 65 66 public String toString() { 67 return "SubselectFetch(" + queryString + ')'; 68 } 69 70 } 71 | Popular Tags |