You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2010/08/13 00:52:37 UTC
svn commit: r985027 - in /openjpa/branches/1.2.x:
openjpa-kernel/src/main/java/org/apache/openjpa/meta/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/
Author: mikedd
Date: Thu Aug 12 22:52:37 2010
New Revision: 985027
URL: http://svn.apache.org/viewvc?rev=985027&view=rev
Log:
OPENJPA-1424: Do not lookup extraFieldData with another mapping's field.
Submitted By: Heath Thomann
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java (with props)
Modified:
openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=985027&r1=985026&r2=985027&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java (original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java Thu Aug 12 22:52:37 2010
@@ -863,7 +863,11 @@ public class ClassMetaData
* @see #getExtraFieldDataLength
*/
public int getExtraFieldDataIndex(int field) {
- return getExtraFieldDataTable()[field];
+ int[] array = getExtraFieldDataTable();
+ if (field < 0 || field >= array.length) {
+ return -1;
+ }
+ return array[field];
}
/**
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.query;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "cases")
+public class Case {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "caseid")
+ private Integer id;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "scheduledayid", nullable = false)
+ private ScheduleDay scheduleDay;
+
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "caze")
+ private List<ScheduledAssignment> scheduledAssignments;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public ScheduleDay getScheduleDay() {
+ return scheduleDay;
+ }
+
+ public void setScheduleDay(ScheduleDay scheduleDay) {
+ this.scheduleDay = scheduleDay;
+ }
+
+ public List<ScheduledAssignment> getScheduledAssignments() {
+ return scheduledAssignments;
+ }
+
+ public void setScheduledAssignments(List<ScheduledAssignment> scheduledAssignments) {
+ this.scheduledAssignments = scheduledAssignments;
+ }
+
+ public void addScheduledAssignment(ScheduledAssignment scheduledAssignment) {
+ scheduledAssignments.add(scheduledAssignment);
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.query;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "lookups")
+public class Lookup {
+
+ @Id
+ @Column(name = "ruleid")
+ private Integer id;
+ @Column(name = "name", nullable = false, length = 100)
+ private String name;
+
+ public Lookup() {
+ }
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.query;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "roles")
+public class Role {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "roleid")
+ private Integer id;
+ @ManyToOne(fetch = FetchType.EAGER, optional = false)
+ @JoinColumn(name = "lookupid", nullable = false)
+ private Lookup lookup;
+
+ public Role() {
+ super();
+ }
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer roleid) {
+ this.id = roleid;
+ }
+
+ public Lookup getLookup() {
+ return lookup;
+ }
+
+ public void setLookup(Lookup lookup) {
+ this.lookup = lookup;
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.query;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name = "scheduledays")
+public class ScheduleDay {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "scheduledayid")
+ private Integer id;
+
+ @Temporal(TemporalType.DATE)
+ @Column(name = "scheduledate", length = 4)
+ private Date date;
+
+ public ScheduleDay() {
+ super();
+ }
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer scheduledayid) {
+ this.id = scheduledayid;
+ }
+
+ public Date getDate() {
+ return this.date;
+ }
+
+ public void setDate(Date scheduledate) {
+ this.date = scheduledate;
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,126 @@
+/*
+ * 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.query;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "scheduledassignments")
+public class ScheduledAssignment {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "scheduledassignmentid")
+ private Integer id;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "autoassignid")
+ private ScheduledAssignment parentScheduledAssignment;
+
+ @ManyToOne(fetch = FetchType.EAGER, optional = false)
+ @JoinColumn(name = "scheduledayid", nullable = false)
+ private ScheduleDay scheduleDay;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "caseid")
+ private Case caze;
+
+ @ManyToOne(fetch = FetchType.EAGER, optional = false)
+ @JoinColumn(name = "roleid", nullable = false)
+ private Role role;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "lookupId")
+ private Lookup brokenRuleLookup;
+
+ @Column(name = "brokencustomruleexplanation")
+ private String brokenCustomRuleExplanation; // somehow, removing this has an effect
+
+ public ScheduledAssignment() {
+ super();
+ }
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public ScheduledAssignment getParentScheduledAssignment() {
+ return this.parentScheduledAssignment;
+ }
+
+ public void setParentScheduledAssignment(ScheduledAssignment scheduledassignments) {
+ this.parentScheduledAssignment = scheduledassignments;
+ }
+
+ public ScheduleDay getScheduleDay() {
+ return this.scheduleDay;
+ }
+
+ public void setScheduleDay(ScheduleDay scheduleDay) {
+ this.scheduleDay = scheduleDay;
+ }
+
+ public Case getCase() {
+ return caze;
+ }
+
+ public void setCase(Case caze) {
+ this.caze = caze;
+ }
+
+ public Role getRole() {
+ return this.role;
+ }
+
+ public void setRole(Role roles) {
+ this.role = roles;
+ }
+
+ public Lookup getBrokenRuleLookup() {
+ return brokenRuleLookup;
+ }
+
+ public void setBrokenRuleLookup(Lookup brokenRuleLookup) {
+ this.brokenRuleLookup = brokenRuleLookup;
+ }
+
+ public Case getCaze() {
+ return caze;
+ }
+
+ public void setCaze(Case caze) {
+ this.caze = caze;
+ }
+
+ public String getBrokenCustomRuleExplanation() {
+ return brokenCustomRuleExplanation;
+ }
+
+ public void setBrokenCustomRuleExplanation(String brokenCustomRuleExplanation) {
+ this.brokenCustomRuleExplanation = brokenCustomRuleExplanation;
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java?rev=985027&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java Thu Aug 12 22:52:37 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.query;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.QueryImpl;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestOutOfBoundsEx extends SingleEMFTestCase {
+ private EntityManager em = null;
+ private Lookup lookup;
+
+ public void setUp() throws Exception {
+ super.setUp(Lookup.class, Case.class, Role.class, ScheduledAssignment.class, ScheduleDay.class,
+ DROP_TABLES);
+ em = emf.createEntityManager();
+ insertLookups();
+ }
+
+ public void testOutOfBounds() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ final Date date = cal.getTime();
+ ScheduleDay sd = insertScheduleDay(date);
+
+ Role role1 = insertJob();
+ insertJob();
+ insertCase(sd);
+ Case kase2 = insertCase(sd);
+ insertScheduledAssignmentInCase(role1, kase2);
+
+ // simulate new web transaction on different em
+ em.close();
+ em = emf.createEntityManager();
+
+ Query query = em.createQuery("select o from Case as o" +
+ " where o.scheduleDay = :sd");
+ query.setParameter("sd", sd);
+ FetchPlan fetchPlan = ((QueryImpl) query).getFetchPlan();
+ fetchPlan.addField(Case.class, "scheduledAssignments");
+
+ //Without the changes of OJ1424, this next call would cause an
+ //ArrayIndexOutOfBoundsException.
+ List<Case> allCases = query.getResultList();
+ }
+
+ public void insertLookups() {
+ lookup = new Lookup();
+ lookup.setName("XYZ");
+ lookup.setId(1);
+ save(lookup);
+ }
+
+ public void save(Object obj) {
+ em.getTransaction().begin();
+ em.persist(obj);
+ em.getTransaction().commit();
+ }
+
+ public Role insertJob() {
+ Role role = new Role();
+ role.setLookup(lookup);
+ save(role);
+ return role;
+ }
+
+ public Case insertCase(ScheduleDay sd) throws Exception {
+ Case kase = new Case();
+ kase.setScheduleDay(sd);
+ save(kase);
+ return kase;
+ }
+
+ public void insertScheduledAssignmentInCase(Role job, Case kase) {
+ ScheduledAssignment sa = new ScheduledAssignment();
+ sa.setRole(job);
+ sa.setCase(kase);
+ sa.setScheduleDay(kase.getScheduleDay());
+ save(sa);
+ }
+
+ public ScheduleDay insertScheduleDay(Date date) {
+ ScheduleDay sd = new ScheduleDay();
+ sd.setDate(date);
+ save(sd);
+ return sd;
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
------------------------------------------------------------------------------
svn:eol-style = native