openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r932661 - in /openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified: ./ path/ path/Division.java path/Employee.java path/PersonalInfo.java path/Phone.java path/TestQualifiedPath.java
Date Sat, 10 Apr 2010 02:29:50 GMT
Author: dwoods
Date: Sat Apr 10 02:29:49 2010
New Revision: 932661

URL: http://svn.apache.org/viewvc?rev=932661&view=rev
Log:
OPENJPA-1623 Add tests for qualified paths in JPQL.  Merged in from trunk r932487.  Contributed
by Dianne.

Added:
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java
  (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java
  (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java
  (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java
  (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java
  (with props)

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java?rev=932661&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java
Sat Apr 10 02:29:49 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.jdbc.maps.qualified.path;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="qual_path_Division")
+public class Division {
+    @Id
+    private int id;
+    
+    @ElementCollection
+    private Map<Employee, String> employees = new HashMap<Employee, String>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Map<Employee, String> getEmployees() {
+        return employees;
+    }
+
+    public void setEmployees(Map<Employee, String> employees) {
+        this.employees = employees;
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Division.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java?rev=932661&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java
Sat Apr 10 02:29:49 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.jdbc.maps.qualified.path;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="qual_path_Employee")
+public class Employee {
+    @Id
+    private int id;
+    
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    @Embedded
+    private PersonalInfo personalInfo;
+
+    public PersonalInfo getPersonalInfo() {
+        return personalInfo;
+    }
+
+    public void setPersonalInfo(PersonalInfo personalInfo) {
+        this.personalInfo = personalInfo;
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Employee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java?rev=932661&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java
Sat Apr 10 02:29:49 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.jdbc.maps.qualified.path;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class PersonalInfo {
+    private String firstName;
+    private String lastName;
+    
+    @ElementCollection
+    private Set<Phone> phones = new HashSet<Phone>();
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public Set<Phone> getPhones() {
+        return phones;
+    }
+
+    public void setPhones(Set<Phone> phones) {
+        this.phones = phones;
+    }
+
+    public void addPhone(Phone phone) {
+        phones.add(phone);
+    }
+
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/PersonalInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java?rev=932661&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java
Sat Apr 10 02:29:49 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.jdbc.maps.qualified.path;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="qual_path_Phone")
+public class Phone {
+    public final static String HOME= "home";
+    public final static String OFFICE = "office";
+    public final static String MOBILE = "mobile";
+    
+    @Id
+    private int id;
+    
+    private String type;
+    
+    private int number;
+
+    public int getId() {
+        return id;
+    }
+    
+    public Phone(int id, String type, int number) {
+        setId(id);
+        setType(type);
+        setNumber(number);
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/Phone.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java?rev=932661&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java
Sat Apr 10 02:29:49 2010
@@ -0,0 +1,145 @@
+/*
+ * 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.jdbc.maps.qualified.path;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/**
+ * Test queries containing qualified paths of the form:
+ * <pre>
+ * general_identification_variable.{single_valued_object_field.}*single_valued_object_field

+ *    or
+ * general_identification_variable.{single_valued_object_field.}*collection_valued_field

+ * </pre>
+ */
+public class TestQualifiedPath extends SQLListenerTestCase {
+    private int numDivisions = 2;
+    private int numEmployeesPerDivision = 3;
+    private int numMobilePhonesPerEmployee = 2;
+    
+    private int divisionId = 0;
+    private int employeeId = 0;
+    private int nameCount = 0;
+    private int phoneId = 0;
+    private int phoneNumber = 1234567890;
+    
+    OpenJPAEntityManager em;
+    
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+            Division.class, Employee.class, Phone.class, PersonalInfo.class);
+        assertNotNull(emf);
+        em = emf.createEntityManager();
+        assertNotNull(em);
+        createObj();
+    }
+
+    public void testQueries() {
+        em.clear();
+        String query = "select p " + 
+            " from Division d, in(d.employees) e, in(KEY(e).personalInfo.phones) p";
+        Query q = em.createQuery(query);
+        List<?> rs = q.getResultList();
+        assertEquals(numDivisions*numEmployeesPerDivision*(2 + numMobilePhonesPerEmployee),
rs.size());
+       
+        em.clear();
+        query = "select KEY(e) " +
+            "from Division d, in(d.employees) e " +
+            "where KEY(e).personalInfo.lastName = 'lName2'";
+        q = em.createQuery(query);
+        rs = q.getResultList();
+        assertEquals(1, rs.size());
+        Employee employee = (Employee)rs.get(0);
+        assertEquals("lName2", employee.getPersonalInfo().getLastName());
+        
+        em.clear();
+        query = "select KEY(e) " +
+            "from Division d, in(d.employees) e " +
+            "order by KEY(e).personalInfo.lastName";
+        q = em.createQuery(query);
+        rs = q.getResultList();
+        assertEquals(numDivisions * numEmployeesPerDivision, rs.size());
+        employee = (Employee)rs.get(0);
+        assertTrue(employee.getPersonalInfo().getLastName().equals("lName1"));
+        employee = (Employee)rs.get(1);
+        assertTrue(employee.getPersonalInfo().getLastName().equals("lName2"));
+        
+        em.clear();
+        query = "select KEY(e).personalInfo.lastName " +
+            "from Division d, in (d.employees) e " +
+            "group by KEY(e).personalInfo.lastName " +
+            "having KEY(e).personalInfo.lastName = 'lName3'";
+        q = em.createQuery(query);
+        rs = q.getResultList();
+        assertEquals(1, rs.size());
+    }
+    
+    private void createObj() {
+        em.getTransaction().begin();
+        for (int i = 0; i < numDivisions; i++) {
+            createDivision(divisionId++);
+        }
+        em.flush();
+        em.getTransaction().commit();
+    }
+    
+    private void createDivision(int id) {
+        Division division = new Division();
+        division.setId(id);
+        Map<Employee, String> employees = new HashMap<Employee, String>();
+        for (int i = 0; i < numEmployeesPerDivision; i++) {
+            Employee employee = createEmployee(employeeId++);
+            employees.put(employee, employee.getPersonalInfo().getLastName());
+        }
+        division.setEmployees(employees);
+        em.persist(division);
+    }
+    
+    private Employee createEmployee(int id) {
+        Employee employee = new Employee();
+        employee.setId(id);
+        
+        PersonalInfo personalInfo = new PersonalInfo();
+        personalInfo.setFirstName("fName" + nameCount++);
+        personalInfo.setLastName("lName" + nameCount);
+        
+        Phone homePhone = new Phone(phoneId++, Phone.HOME, phoneNumber++);
+        personalInfo.addPhone(homePhone);
+        Phone officePhone = new Phone(phoneId++, Phone.OFFICE, phoneNumber++);
+        personalInfo.addPhone(officePhone);
+        for (int i = 0; i < numMobilePhonesPerEmployee; i++) {
+            Phone mobilePhone = new Phone(phoneId++, Phone.MOBILE, phoneNumber++);
+            personalInfo.addPhone(mobilePhone);
+        }
+        
+        employee.setPersonalInfo(personalInfo);
+        
+        em.persist(employee);
+        
+        return employee;
+    }
+
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/qualified/path/TestQualifiedPath.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message