OPENJPA-2571: Criteria Builder query generates extra alias when using multiselect.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1673300 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2015-04-13 22:22:58 +00:00
parent 2fc38594cd
commit 3737fdbd21
6 changed files with 1069 additions and 1 deletions

View File

@ -2894,7 +2894,20 @@ public class SelectImpl
if (this.var != null) {
this.append(this.var);
} else if (this.path == null && this.correlatedVar != null && _sel._dict.isImplicitJoin()) {
this.append(this.correlatedVar);
String str = this.var;
for(Object o : _sel._parent._aliases.keySet()){
if (o instanceof Key) {
Key k = (Key) o;
if (this.correlatedVar.equals(k._path)) {
str = this.correlatedVar;
break;
}
}else if (o.equals(this.correlatedVar)){
str = this.correlatedVar;
break;
}
}
this.append(str);
}
this.var = null;
_outer = false;

View File

@ -0,0 +1,452 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.criteria.multiselect;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="T_DIM_DAY")
public class DimDay {
@Id
@Column(name="DAY_KY")
private Long key;
@Column(name="DAY_DT")
private Date date;
@Column(name = "DAY_FULL_NM")
private String dayFullName;
@Column(name = "QTR_FULL_NM")
private String qtrFullName;
@Column(name = "MNTH_FULL_NM")
private String monthFullName;
@Column(name = "MNTH_SHRT_NM")
private String monthName;
@Column(name = "YR_NBR")
private String year;
@Column(name = "QTR_IN_YR_NBR")
private int quarterInYearNumber;
@Column(name = "YR_CD")
private String yearCode;
@Column(name = "QTR_CD")
private String quarterCode;
@Column(name = "MNTH_CD")
private String monthCode;
@Column(name = "MNTH_IN_YR_NBR")
private Long monthInYearNumber;
@Column(name="CUR_MNTH_IND")
private Long currentMonthInd;
@Column(name="CUR_QTR_IND")
private Long currentQtrInd;
@Column(name="CUR_YR_IND")
private Long currentYearInd;
@Column(name="PREV_MNTH_IND")
private Long prevMonthInd;
@Column(name="PREV_QTR_IND")
private Long prevQtrInd;
@Column(name="PREV_YR_IND")
private Long prevYearInd;
@Column(name="CUR_MNTH_IN_PREV_YR_IND")
private Long currentMonthVsPrevYearInd;
@Column(name="CUR_QTR_IN_PREV_YR_IND")
private Long currentQtrVsPrevYearInd;
@Column(name="WK_IN_YR_NBR")
private Long weekInYear;
@Column(name="WK_IN_YR_FULL_NM")
private String weekInYearFullNm;
@Column(name = "DAY_IN_WK_NBR")
private Long dayInWeek;
@Column(name = "DAY_IN_MNTH_NBR")
private Long dayInMonth;
@Column(name = "DAY_IN_QTR_NBR")
private Long dayInQuarter;
@Column(name = "DAY_IN_YR_NBR")
private Long dayInYear;
@Column(name="EOM_IND")
private Long eomInd;
@Column(name="EOQ_IND")
private Long eoqInd;
@Column(name="EOY_IND")
private Long eoyInd;
@Column(name = "ROLL_13_MNTH_IND")
private Long roll13MonthInd;
@Column(name = "ROLL_4_YRS_IND")
private Long roll4YearsInd;
@Column(name = "ROLL_5_QTRS_IND")
private Long roll5QuartersInd;
@Column(name="MNTH_STRT_DAY_KY")
private Long monthStrtDate;
@Column(name="MNTH_END_DAY_KY")
private Long monthEndDate;
@Column(name="QTR_STRT_DAY_KY")
private Long quarterStrtDate;
@Column(name="QTR_END_DAY_KY")
private Long quarterEndDate;
@Column(name = "YR_STRT_DAY_KY")
private Long yearStrtDate;
@Column(name = "YR_END_DAY_KY")
private Long yearEndDate;
public Long getKey() {
return key;
}
public void setKey(Long key) {
this.key = key;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getDayFullName() {
return dayFullName;
}
public void setDayFullName(String dayFullName) {
this.dayFullName = dayFullName;
}
public String getQtrFullName() {
return qtrFullName;
}
public void setQtrFullName(String qtrFullName) {
this.qtrFullName = qtrFullName;
}
public String getMonthName() {
return monthName;
}
public void setMonthFullName(String monthName) {
this.monthName = monthName;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public Long getCurrentMonthInd() {
return currentMonthInd;
}
public void setCurrentMonthInd(Long currentMonthInd) {
this.currentMonthInd = currentMonthInd;
}
public Long getCurrentQtrInd() {
return currentQtrInd;
}
public void setCurrentQtrInd(Long currentQtrInd) {
this.currentQtrInd = currentQtrInd;
}
public Long getCurrentYearInd() {
return currentYearInd;
}
public void setCurrentYearInd(Long currentYearInd) {
this.currentYearInd = currentYearInd;
}
public Long getPrevQtrInd() {
return prevQtrInd;
}
public void setPrevQtrInd(Long prevQtrInd) {
this.prevQtrInd = prevQtrInd;
}
public Long getPrevYearInd() {
return prevYearInd;
}
public void setPrevYearInd(Long prevYearInd) {
this.prevYearInd = prevYearInd;
}
public Long getCurrentMonthVsPrevYearInd() {
return currentMonthVsPrevYearInd;
}
public void setCurrentMonthVsPrevYearInd(Long currentMonthVsPrevYearInd) {
this.currentMonthVsPrevYearInd = currentMonthVsPrevYearInd;
}
public Long getCurrentQtrVsPrevYearInd() {
return currentQtrVsPrevYearInd;
}
public void setCurrentQtrVsPrevYearInd(Long currentQtrVsPrevYearInd) {
this.currentQtrVsPrevYearInd = currentQtrVsPrevYearInd;
}
public Long getPrevMonthInd() {
return prevMonthInd;
}
public void setPrevMonthInd(Long prevMonthInd) {
this.prevMonthInd = prevMonthInd;
}
public Long getWeekInYear() {
return weekInYear;
}
public void setWeekInYear(Long weekInYear) {
this.weekInYear = weekInYear;
}
public void setMonthName(String monthName) {
this.monthName = monthName;
}
public Long getEomInd() {
return eomInd;
}
public void setEomInd(Long eomInd) {
this.eomInd = eomInd;
}
public String getYearCode() {
return yearCode;
}
public void setYearCode(String yearCode) {
this.yearCode = yearCode;
}
public String getQuarterCode() {
return quarterCode;
}
public void setQuarterCode(String quarterCode) {
this.quarterCode = quarterCode;
}
public String getMonthCode() {
return monthCode;
}
public void setMonthCode(String monthCode) {
this.monthCode = monthCode;
}
public String getMonthFullName() {
return monthFullName;
}
public String getWeekInYearFullNm() {
return weekInYearFullNm;
}
public void setWeekInYearFullNm(String weekInYearFullNm) {
this.weekInYearFullNm = weekInYearFullNm;
}
public Long getMonthInYearNumber() {
return monthInYearNumber;
}
public void setMonthInYearNumber(Long monthInYearNumber) {
this.monthInYearNumber = monthInYearNumber;
}
public int getQuarterInYearNumber() {
return quarterInYearNumber;
}
public void setQuarterInYearNumber(int quarterInYearNumber) {
this.quarterInYearNumber = quarterInYearNumber;
}
public Long getRoll13MonthInd() {
return roll13MonthInd;
}
public void setRoll13MonthInd(Long roll13MonthInd) {
this.roll13MonthInd = roll13MonthInd;
}
public Long getRoll4YearsInd() {
return roll4YearsInd;
}
public void setRoll4YearsInd(Long roll4YearsInd) {
this.roll4YearsInd = roll4YearsInd;
}
public Long getRoll5QuartersInd() {
return roll5QuartersInd;
}
public void setRoll5QuartersInd(Long roll5QuartersInd) {
this.roll5QuartersInd = roll5QuartersInd;
}
public Long getDayInMonth() {
return dayInMonth;
}
public void setDayInMonth(Long dayInMonth) {
this.dayInMonth = dayInMonth;
}
public Long getDayInQuarter() {
return dayInQuarter;
}
public void setDayInQuarter(Long dayInQuarter) {
this.dayInQuarter = dayInQuarter;
}
public Long getDayInYear() {
return dayInYear;
}
public void setDayInYear(Long dayInYear) {
this.dayInYear = dayInYear;
}
public Long getEoqInd() {
return eoqInd;
}
public void setEoqInd(Long eoqInd) {
this.eoqInd = eoqInd;
}
public Long getEoyInd() {
return eoyInd;
}
public void setEoyInd(Long eoyInd) {
this.eoyInd = eoyInd;
}
public Long getMonthStrtDate() {
return monthStrtDate;
}
public void setMonthStrtDate(Long monthStrtDate) {
this.monthStrtDate = monthStrtDate;
}
public Long getMonthEndDate() {
return monthEndDate;
}
public void setMonthEndDate(Long monthEndDate) {
this.monthEndDate = monthEndDate;
}
public Long getQuarterStrtDate() {
return quarterStrtDate;
}
public void setQuarterStrtDate(Long quarterStrtDate) {
this.quarterStrtDate = quarterStrtDate;
}
public Long getQuarterEndDate() {
return quarterEndDate;
}
public void setQuarterEndDate(Long quarterEndDate) {
this.quarterEndDate = quarterEndDate;
}
public Long getYearStrtDate() {
return yearStrtDate;
}
public void setYearStrtDate(Long yearStrtDate) {
this.yearStrtDate = yearStrtDate;
}
public Long getYearEndDate() {
return yearEndDate;
}
public void setYearEndDate(Long yearEndDate) {
this.yearEndDate = yearEndDate;
}
public Long getDayInWeek() {
return dayInWeek;
}
public void setDayInWeek(Long dayInWeek) {
this.dayInWeek = dayInWeek;
}
}

View File

@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.criteria.multiselect;
import java.lang.Integer;
import java.lang.Long;
import java.lang.String;
import java.util.Date;
import javax.persistence.metamodel.SingularAttribute;
@javax.persistence.metamodel.StaticMetamodel
(value=DimDay.class)
@javax.annotation.Generated
(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Mon Feb 23 16:53:34 MST 2015")
public class DimDay_ {
public static volatile SingularAttribute<DimDay,Long> currentMonthInd;
public static volatile SingularAttribute<DimDay,Long> currentMonthVsPrevYearInd;
public static volatile SingularAttribute<DimDay,Long> currentQtrInd;
public static volatile SingularAttribute<DimDay,Long> currentQtrVsPrevYearInd;
public static volatile SingularAttribute<DimDay,Long> currentYearInd;
public static volatile SingularAttribute<DimDay,Date> date;
public static volatile SingularAttribute<DimDay,String> dayFullName;
public static volatile SingularAttribute<DimDay,Long> dayInMonth;
public static volatile SingularAttribute<DimDay,Long> dayInQuarter;
public static volatile SingularAttribute<DimDay,Long> dayInWeek;
public static volatile SingularAttribute<DimDay,Long> dayInYear;
public static volatile SingularAttribute<DimDay,Long> eomInd;
public static volatile SingularAttribute<DimDay,Long> eoqInd;
public static volatile SingularAttribute<DimDay,Long> eoyInd;
public static volatile SingularAttribute<DimDay,Long> key;
public static volatile SingularAttribute<DimDay,String> monthCode;
public static volatile SingularAttribute<DimDay,Long> monthEndDate;
public static volatile SingularAttribute<DimDay,String> monthFullName;
public static volatile SingularAttribute<DimDay,Long> monthInYearNumber;
public static volatile SingularAttribute<DimDay,String> monthName;
public static volatile SingularAttribute<DimDay,Long> monthStrtDate;
public static volatile SingularAttribute<DimDay,Long> prevMonthInd;
public static volatile SingularAttribute<DimDay,Long> prevQtrInd;
public static volatile SingularAttribute<DimDay,Long> prevYearInd;
public static volatile SingularAttribute<DimDay,String> qtrFullName;
public static volatile SingularAttribute<DimDay,String> quarterCode;
public static volatile SingularAttribute<DimDay,Long> quarterEndDate;
public static volatile SingularAttribute<DimDay,Integer> quarterInYearNumber;
public static volatile SingularAttribute<DimDay,Long> quarterStrtDate;
public static volatile SingularAttribute<DimDay,Long> roll13MonthInd;
public static volatile SingularAttribute<DimDay,Long> roll4YearsInd;
public static volatile SingularAttribute<DimDay,Long> roll5QuartersInd;
public static volatile SingularAttribute<DimDay,Long> weekInYear;
public static volatile SingularAttribute<DimDay,String> weekInYearFullNm;
public static volatile SingularAttribute<DimDay,String> year;
public static volatile SingularAttribute<DimDay,String> yearCode;
public static volatile SingularAttribute<DimDay,Long> yearEndDate;
public static volatile SingularAttribute<DimDay,Long> yearStrtDate;
}

View File

@ -0,0 +1,308 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.criteria.multiselect;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "T_FACT_WORK_ASGNMT")
public class FactWorkAssignment {
@Id
@Column(name = "CLNT_OBJ_ID")
private String orgOID;
@Column(name = "rec_eff_strt_dt")
private Date effStartDt;
@Column(name = "rec_eff_end_dt")
private Date effEndDt;
@Column(name = "rec_eff_strt_day_ky")
private Long effectiveStartDate;
@Column(name = "rec_eff_end_day_ky")
private Long effectiveEndDate;
@Column(name = "pers_ky")
private Long personKey;
@Column(name = "pers_obj_id")
private String personObjId;
@Column(name = "prmry_work_asgnmt_ind")
private int primary;
@Column(name = "empl_cnt")
private int employeeCount;
@Column(name = "work_asgnmt_stus_cd")
private String statusCode;
@Column(name="WORK_ASGNMT_STUS_DSC")
private String statusDesc;
@Column(name="WORK_ASGNMT_NBR")
private String workAssgnmntNbr;
@Column(name = "work_loc_ky")
private Long workLocationKey;
@Column(name = "hr_orgn_ky")
private Long hrOrgKey;
@Column(name = "PAYRL_ORGN_KY")
private Long payrollOrgKey;
@Column(name = "job_ky")
private Long jobKey;
@Column(name = "PERS_PRFL_ATTR_KY")
private Long personProfileKey;
@Column(name = "mngr_ky")
private Long managerKey;
@Column(name = "PAY_GRP_KY")
private Long paygroupKey;
@Column(name = "SAL_PLAN_KY")
private Long salPlanKey;
@Column(name = "COMPA_RT")
private Double compaRt;
@Column(name="CLK_NBR")
private String clockNumber;
@Column(name="DATA_CNTL_NBR")
private String dataCntrlNumber;
@Column(name="SEC_CLR_CD")
private String secClrCd;
@Column(name = "CUR_REC_IND")
private boolean currentRecord;
public Long getSalPlanKey() {
return salPlanKey;
}
public void setSalPlanKey(Long salPlanKey) {
this.salPlanKey = salPlanKey;
}
public Long getManagerKey() {
return managerKey;
}
public void setManagerKey(Long managerKey) {
this.managerKey = managerKey;
}
public Long getPersonProfileKey() {
return personProfileKey;
}
public void setPersonProfileKey(Long personProfileKey) {
this.personProfileKey = personProfileKey;
}
public int getPrimary() {
return primary;
}
public void setPrimary(int primary) {
this.primary = primary;
}
public int getEmployeeCount() {
return employeeCount;
}
public void setEmployeeCount(int employeeCount) {
this.employeeCount = employeeCount;
}
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getStatusDesc() {
return statusDesc;
}
public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc;
}
public Long getWorkLocationKey() {
return workLocationKey;
}
public void setWorkLocationKey(Long workLocationKey) {
this.workLocationKey = workLocationKey;
}
public Long getHrOrgKey() {
return hrOrgKey;
}
public void setHrOrgKey(Long hrOrgKey) {
this.hrOrgKey = hrOrgKey;
}
public Long getJobKey() {
return jobKey;
}
public void setJobKey(Long jobKey) {
this.jobKey = jobKey;
}
public Long getPayrollOrgKey() {
return payrollOrgKey;
}
public void setPayrollOrgKey(Long payrollOrgKey) {
this.payrollOrgKey = payrollOrgKey;
}
public Double getCompaRt() {
return compaRt;
}
public void setCompaRt(Double compaRt) {
this.compaRt = compaRt;
}
public Long getPaygroupKey() {
return paygroupKey;
}
public void setPaygroupKey(Long paygroupKey) {
this.paygroupKey = paygroupKey;
}
public String getClockNumber() {
return clockNumber;
}
public void setClockNumber(String clockNumber) {
this.clockNumber = clockNumber;
}
public String getDataCntrlNumber() {
return dataCntrlNumber;
}
public void setDataCntrlNumber(String dataCntrlNumber) {
this.dataCntrlNumber = dataCntrlNumber;
}
public String getSecClrCd() {
return secClrCd;
}
public void setSecClrCd(String secClrCd) {
this.secClrCd = secClrCd;
}
public boolean isCurrentRecord() {
return currentRecord;
}
public void setCurrentRecord(boolean currentRecord) {
this.currentRecord = currentRecord;
}
public String getWorkAssgnmntNbr() {
return workAssgnmntNbr;
}
public void setWorkAssgnmntNbr(String workAssgnmntNbr) {
this.workAssgnmntNbr = workAssgnmntNbr;
}
public String getOrgOID() {
return orgOID;
}
public void setOrgOID(String orgOID) {
this.orgOID = orgOID;
}
public Long getEffectiveStartDate() {
return effectiveStartDate;
}
public void setEffectiveStartDate(Long effectiveStartDate) {
this.effectiveStartDate = effectiveStartDate;
}
public Long getEffectiveEndDate() {
return effectiveEndDate;
}
public void setEffectiveEndDate(Long effectiveEndDate) {
this.effectiveEndDate = effectiveEndDate;
}
public Long getPersonKey() {
return personKey;
}
public void setPersonKey(Long personKey) {
this.personKey = personKey;
}
public String getPersonObjId() {
return personObjId;
}
public void setPersonObjId(String personObjId) {
this.personObjId = personObjId;
}
public Date getEffStartDt() {
return effStartDt;
}
public void setEffStartDt(Date effStartDt) {
this.effStartDt = effStartDt;
}
public Date getEffEndDt() {
return effEndDt;
}
public void setEffEndDt(Date effEndDt) {
this.effEndDt = effEndDt;
}
}

View File

@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.criteria.multiselect;
import java.lang.Boolean;
import java.lang.Double;
import java.lang.Integer;
import java.lang.Long;
import java.lang.String;
import java.util.Date;
import javax.persistence.metamodel.SingularAttribute;
@javax.persistence.metamodel.StaticMetamodel
(value=FactWorkAssignment.class)
@javax.annotation.Generated
(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Mon Feb 23 16:16:50 MST 2015")
public class FactWorkAssignment_ {
public static volatile SingularAttribute<FactWorkAssignment,String> clockNumber;
public static volatile SingularAttribute<FactWorkAssignment,Double> compaRt;
public static volatile SingularAttribute<FactWorkAssignment,Boolean> currentRecord;
public static volatile SingularAttribute<FactWorkAssignment,String> dataCntrlNumber;
public static volatile SingularAttribute<FactWorkAssignment,Date> effEndDt;
public static volatile SingularAttribute<FactWorkAssignment,Date> effStartDt;
public static volatile SingularAttribute<FactWorkAssignment,Long> effectiveEndDate;
public static volatile SingularAttribute<FactWorkAssignment,Long> effectiveStartDate;
public static volatile SingularAttribute<FactWorkAssignment,Integer> employeeCount;
public static volatile SingularAttribute<FactWorkAssignment,Long> hrOrgKey;
public static volatile SingularAttribute<FactWorkAssignment,Long> jobKey;
public static volatile SingularAttribute<FactWorkAssignment,Long> managerKey;
public static volatile SingularAttribute<FactWorkAssignment,String> orgOID;
public static volatile SingularAttribute<FactWorkAssignment,Long> paygroupKey;
public static volatile SingularAttribute<FactWorkAssignment,Long> payrollOrgKey;
public static volatile SingularAttribute<FactWorkAssignment,Long> personKey;
public static volatile SingularAttribute<FactWorkAssignment,String> personObjId;
public static volatile SingularAttribute<FactWorkAssignment,Long> personProfileKey;
public static volatile SingularAttribute<FactWorkAssignment,Integer> primary;
public static volatile SingularAttribute<FactWorkAssignment,Long> salPlanKey;
public static volatile SingularAttribute<FactWorkAssignment,String> secClrCd;
public static volatile SingularAttribute<FactWorkAssignment,String> statusCode;
public static volatile SingularAttribute<FactWorkAssignment,String> statusDesc;
public static volatile SingularAttribute<FactWorkAssignment,String> workAssgnmntNbr;
public static volatile SingularAttribute<FactWorkAssignment,Long> workLocationKey;
}

View File

@ -0,0 +1,166 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.criteria.multiselect;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestCriteriaMultiselectAliasing extends SQLListenerTestCase {
CriteriaQuery<Tuple> critQuery;
String critQueryString;
String doCB = System.getProperty("doCB");
@Override
public void setUp() throws Exception {
// Only run on Oracle....the asserts at this time look for SQL specific to the
// way things are generated for Oracle.
setSupportedDatabases(
org.apache.openjpa.jdbc.sql.OracleDictionary.class);
if (isTestsDisabled()) {
return;
}
super.setUp(DimDay.class, FactWorkAssignment.class
,"openjpa.Log","SQL=TRACE,Tests=TRACE", "openjpa.ConnectionFactoryProperties",
"PrintParameters=true, PrettyPrint=true, PrettyPrintLineLength=72"
);
critQuery = createCriteriaBuilder();
critQueryString = critQuery.toString();
System.out.println("critQueryString = " + critQueryString);
}
public void test (){
if ("true".equals(doCB)){
this.ttestCriteriaQuery();
}
else{
this.ttestGeneratedCriteriaQueryString();
}
}
/**
* This method produce wrong query like (note the extra T_DIM_DAY t3):
* SELECT t0.empl_cnt FROM
* T_FACT_WORK_ASGNMT t0, T_DIM_DAY t1, T_DIM_DAY t3
* WHERE (t0.CLNT_OBJ_ID = ? AND t1.ROLL_13_MNTH_IND = ? AND t0.pers_obj_id IN (
* SELECT t2.pers_obj_id FROM T_FACT_WORK_ASGNMT t2 WHERE (t2.CLNT_OBJ_ID = ? AND
* t3.MNTH_STRT_DAY_KY >= ?)))
* [params=(String) dummy1, (int) 1, (String) dummy1, (long) 20150201]
*
* The correct query should be:
* SELECT t0.empl_cnt FROM
* T_FACT_WORK_ASGNMT t0, T_DIM_DAY t1
* WHERE (t0.CLNT_OBJ_ID = ? AND t1.ROLL_13_MNTH_IND = ? AND t0.pers_obj_id IN (
* SELECT t2.pers_obj_id FROM T_FACT_WORK_ASGNMT t2 WHERE (t2.CLNT_OBJ_ID = ? AND
* t3.MNTH_STRT_DAY_KY >= ?)))
* [params=(String) dummy1, (int) 1, (String) dummy1, (long) 20150201]
*
*/
public void ttestCriteriaQuery() {
EntityManager em = emf.createEntityManager();
resetSQL();
em.createQuery(critQuery).getResultList();
assertNotSQL(".*T_DIM_DAY t3.*");
assertSQL(".*T_DIM_DAY t1.*");
em.close();
}
/**
* If we execute just the string generated by Criteria Builder, we
* do not see an extra alias. We see:
* SELECT t0.empl_cnt FROM T_FACT_WORK_ASGNMT t0, T_DIM_DAY t1
* WHERE (t0.CLNT_OBJ_ID = ? AND t1.ROLL_13_MNTH_IND = ? AND
* t0.pers_obj_id IN (SELECT t2.pers_obj_id FROM
* T_FACT_WORK_ASGNMT t2 WHERE (t2.CLNT_OBJ_ID = ? AND
* t1.MNTH_STRT_DAY_KY = ?)))
*/
public void ttestGeneratedCriteriaQueryString(){
if (!"true".equals(doCB)){
EntityManager em = emf.createEntityManager();
System.out.println("NOT doing CB");
resetSQL();
em.createQuery(critQueryString).getResultList();
assertNotSQL(".*T_DIM_DAY t3.*");
assertSQL(".*T_DIM_DAY t1.*");
em.close();
}
}
public CriteriaQuery<Tuple> createCriteriaBuilder(){
EntityManager em = emf.createEntityManager();
List<Predicate> predicates = new ArrayList<Predicate>();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Root<DimDay> day = cq.from(DimDay.class);
Root<FactWorkAssignment> wa = cq.from(FactWorkAssignment.class);
predicates.add(cb.equal(wa.get(FactWorkAssignment_.orgOID), "dummy1"));
predicates.add(cb.equal(day.get(DimDay_.roll13MonthInd), 1));
Subquery<String> subQuery = cq.subquery(String.class);
Root<FactWorkAssignment> wa1 = subQuery.from(FactWorkAssignment.class);
subQuery.select(wa1.get(FactWorkAssignment_.personObjId));
List<Predicate> subQueryPredicates = new ArrayList<Predicate>();
subQueryPredicates.add(cb.equal(wa1.get(FactWorkAssignment_.orgOID), "dummy1"));
//Removing this seem to "fix" the issue....I think the fact that we use 'day' from
//the 'outer' query has an affect....is it OK to use 'day' from the outer query?? I'm
//assuming so since 'testGeneratedCriteriaQueryString' generates the expected SQL.
// subQueryPredicates.add(cb.greaterThanOrEqualTo(day.get(DimDay_.monthStrtDate), new Long(20150201L)));
subQueryPredicates.add(cb.equal(day.get(DimDay_.monthStrtDate), new Long(20150201L)));
//Doing this places the 'T_DIM_DAY t3' in the 'inner'/sub query. Is this the proper solution?? Or just a
//hacky work around?
//Root<DimDay> day2 = subQuery.from(DimDay.class);
//subQueryPredicates.add(cb.greaterThanOrEqualTo(day2.get(DimDay_.monthStrtDate), new Long(20150201L)));
subQuery.where(subQueryPredicates.toArray(new Predicate[] {}));
Predicate predicate = wa.get(FactWorkAssignment_.personObjId).in(subQuery);
predicates.add(predicate);
List<Selection<?>> selections = new ArrayList<Selection<?>>();
Expression<Integer> expHC = wa.get(FactWorkAssignment_.employeeCount);
selections.add(expHC);
cq.multiselect(selections).where(predicates.toArray(new Predicate[] {}));
return cq;
}
}