openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r984967 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query: Case.java Lookup.java Role.java ScheduleDay.java ScheduledAssignment.java TestOutOfBoundsEx.java
Date Thu, 12 Aug 2010 20:53:59 GMT
Author: mikedd
Date: Thu Aug 12 20:53:58 2010
New Revision: 984967

URL: http://svn.apache.org/viewvc?rev=984967&view=rev
Log:
OPENJPA-1424: adding testcase.
Submitted By: Heath Thomann, Daryl Stultz.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
Thu Aug 12 20:53:58 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Case.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
Thu Aug 12 20:53:58 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Lookup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
Thu Aug 12 20:53:58 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Role.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
Thu Aug 12 20:53:58 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;
+import javax.persistence.UniqueConstraint;
+
+@Entity
+@Table(name = "scheduledays", uniqueConstraints = @UniqueConstraint(columnNames = "scheduledate"))
+public class ScheduleDay {
+
+    @Id
+    @GeneratedValue
+    @Column(name = "scheduledayid")
+    private Integer id;
+    @Temporal(TemporalType.DATE)
+    @Column(name = "scheduledate", unique = true, nullable = false, 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduleDay.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
Thu Aug 12 20:53:58 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ScheduledAssignment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java?rev=984967&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
Thu Aug 12 20:53:58 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();
+		Role role2 = insertJob();
+		Case kase1 = 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestOutOfBoundsEx.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message