openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r816289 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/
Date Thu, 17 Sep 2009 17:22:50 GMT
Author: dwoods
Date: Thu Sep 17 17:22:49 2009
New Revision: 816289

URL: http://svn.apache.org/viewvc?rev=816289&view=rev
Log:
OPENJPA-1213 Compatibility tests showing change in query.setParameter() behaviour.  Contributed
by Tim McConnell, but with some package name and OpenJPAVersion checks added.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.compat;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.jdbc.ElementClassCriteria;
+
+/**
+ * Persistent entity with collection whose element type belongs to inheritance
+ * hierarchy mapped to a SINGLE_TABLE. Hence relationship loading will require
+ * 
+ */
+@Entity
+@Table(name = "DEPT")
+@IdClass(DepartmentId.class)
+public class Department {
+
+    @Id
+    private String name;
+
+    @OneToMany(mappedBy = "dept", cascade = CascadeType.PERSIST)
+    @ElementClassCriteria
+    private Collection<PartTimeEmployee> partTimeEmployees;
+
+    @OneToMany(mappedBy = "dept", cascade = CascadeType.PERSIST)
+    @ElementClassCriteria
+    private Collection<FullTimeEmployee> fullTimeEmployees;
+
+    public Collection<FullTimeEmployee> getFullTimeEmployees() {
+        return fullTimeEmployees;
+    }
+
+    public void addEmployee(FullTimeEmployee e) {
+        if (fullTimeEmployees == null)
+            fullTimeEmployees = new ArrayList<FullTimeEmployee>();
+        this.fullTimeEmployees.add(e);
+        e.setDept(this);
+    }
+
+    public Collection<PartTimeEmployee> getPartTimeEmployees() {
+        return partTimeEmployees;
+    }
+
+    public void addEmployee(PartTimeEmployee e) {
+        if (partTimeEmployees == null)
+            partTimeEmployees = new ArrayList<PartTimeEmployee>();
+        this.partTimeEmployees.add(e);
+        e.setDept(this);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Department.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.compat;
+
+import java.io.Serializable;
+
+public class DepartmentId implements Serializable {
+    private String name;
+
+    public DepartmentId() {
+        this(null);
+    }
+
+    public DepartmentId(String name) {
+        this.name = name;
+    }
+
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof DepartmentId)) {
+            return false;
+        }
+
+        DepartmentId other = (DepartmentId) obj;
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        return true;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/DepartmentId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.compat;
+
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "EMP")
+@IdClass(EmployeeId.class)
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "TYPE")
+public abstract class Employee {
+
+    @Id
+    private String ssn;
+
+    @ManyToOne
+    private Department dept;
+
+    public String getSsn() {
+        return ssn;
+    }
+
+    public void setSsn(String ssn) {
+        this.ssn = ssn;
+    }
+
+    public Department getDept() {
+        return dept;
+    }
+
+    public void setDept(Department dept) {
+        this.dept = dept;
+    }
+
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Employee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.compat;
+
+import java.io.Serializable;
+
+public class EmployeeId implements Serializable {
+    
+    private String ssn;
+    
+    public EmployeeId(){
+    }
+    public EmployeeId(String ssn){
+        this.ssn = ssn;
+    }
+    public boolean equals (Object other)
+    {
+        if (other == this)
+            return true;
+        if (!(other instanceof EmployeeId))
+            return false;
+
+        EmployeeId obj = (EmployeeId) other;
+        if (ssn == null) {
+            if (obj.ssn != null) {
+                return false;
+            }
+        } else if (!ssn.equals(obj.ssn)) {
+            return false;
+        }
+        
+        return (true);
+    }
+     
+   
+    public int hashCode ()
+    {
+        return (ssn.hashCode());
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/EmployeeId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.compat;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("F")
+public class FullTimeEmployee extends Employee {
+    @Column(name = "salary")
+    private double salary;
+
+    public double getSalary() {
+        return salary;
+    }
+
+    public void setSalary(double salary) {
+        this.salary = salary;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/FullTimeEmployee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.compat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.*;
+
+@Entity
+@IdClass(InvoiceKey.class)
+public class Invoice {
+
+    @Id
+    private int id;
+    @Id
+    private String brandName;
+    
+    private double price;
+
+    @OneToMany(cascade={CascadeType.ALL})
+    private List<LineItem> lineItems = new ArrayList<LineItem>();
+
+    public Invoice() {
+    }
+
+    public Invoice(int id, String brandName, double price) {
+        this.id = id;
+        this.brandName = brandName;
+        this.price = price;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
+
+    public double getPrice() {
+        return price;
+    }
+
+    public void setPrice(double price) {
+        this.price = price;
+    }
+
+    public List<LineItem> getLineItems() {
+        return lineItems;
+    }
+
+    public void setLineItems(List<LineItem> lineItems) {
+        this.lineItems = lineItems;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/Invoice.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.compat;
+
+public class InvoiceKey {
+
+    private int id;
+    private String brandName;
+
+    public InvoiceKey() {
+    }
+
+    public InvoiceKey(int id, String brandName) {
+        this.id = id;
+        this.brandName = brandName;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        InvoiceKey invoiceKey = (InvoiceKey) o;
+
+        if (id != invoiceKey.id) return false;
+        if (!brandName.equals(invoiceKey.brandName)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id;
+        result = 31 * result + brandName.hashCode();
+        return result;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/InvoiceKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java
Thu Sep 17 17:22:49 2009
@@ -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.compat;
+
+import javax.persistence.*;
+
+@Entity
+public class LineItem {
+
+    @Id
+    private String id;
+    private int quantity;
+    
+    @ManyToOne
+    private Invoice invoice;
+
+    public LineItem() {
+    }
+
+    public LineItem(String id, int quantity) {
+        this.id = id;
+        this.quantity = quantity;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        this.quantity = quantity;
+    }
+
+    public Invoice getInvoice() {
+        return invoice;
+    }
+
+    public void setInvoice(Invoice invoice) {
+        this.invoice = invoice;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/LineItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.compat;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("P")
+public class PartTimeEmployee extends Employee {
+    @Column(name = "wage")
+    private double hourlyWage;
+
+    public double getHourlyWage() {
+        return hourlyWage;
+    }
+
+    public void setHourlyWage(double hourlyWage) {
+        this.hourlyWage = hourlyWage;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/PartTimeEmployee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java?rev=816289&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java
Thu Sep 17 17:22:49 2009
@@ -0,0 +1,146 @@
+/*
+ * 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.compat;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import org.apache.openjpa.conf.OpenJPAVersion;
+import org.apache.openjpa.persistence.ArgumentException;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/**
+ * Tests that find() queries that use non-primary keys can be cached
+ * 
+ *
+ * <b>Compatible testcases</b> are used to test various backwards compatibility
scenarios between JPA 2.0 and JPA 1.2
+ * 
+ * <p>The following scenarios are tested:
+ * <ol>
+ * <li>query.setParameter()
+ * </ol>
+ * <p> 
+ * <b>Note(s):</b>
+ * <ul>
+ * <li>The proper openjpa.Compatibility value(s) must be provided in order for the
testcase(s) to succeed
+ * </ul>
+ */
+public class TestNonPrimaryKeyQueryParameters extends SQLListenerTestCase {
+    private static final int FULLTIME_EMPLOYEE_COUNT = 3;
+    private static final int PARTTIME_EMPLOYEE_COUNT = 2;
+    private static final int LINEITEM_PER_INVOICE = 1;
+    private static final String DEPT_NAME = "ENGINEERING";
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES, Department.class, Employee.class,
+                FullTimeEmployee.class, PartTimeEmployee.class,
+                Invoice.class, LineItem.class,
+                "openjpa.jdbc.QuerySQLCache", "true");
+        createDepartment(DEPT_NAME);
+        createInvoice();
+        sql.clear();
+    }
+
+    public void testSelectQueryWithNoParameter() {
+        EntityManager em = emf.createEntityManager();
+
+        try {
+            Query query = em.createQuery("SELECT d from Department d");
+            query.setParameter(1, DEPT_NAME);
+            Department dept = (Department) query.getSingleResult();
+
+            if (((OpenJPAVersion.MAJOR_RELEASE == 1) &&
+                 (OpenJPAVersion.MINOR_RELEASE >= 3)) ||
+                (OpenJPAVersion.MAJOR_RELEASE >= 2)) {
+                // should never get here, as parameter substitution should fail
+                fail("Test should have failed on OpenJPA 1.3 or above.");
+            } else {
+                // OpenJPA 1.2.x and earlier ignored unused parameters
+                assertEquals(FULLTIME_EMPLOYEE_COUNT, dept.getFullTimeEmployees().size());
+                assertEquals(PARTTIME_EMPLOYEE_COUNT, dept.getPartTimeEmployees().size());
+                assertSQL(".* AND t0.TYPE = .*");
+            }
+        } catch (ArgumentException ae) {
+            if ((OpenJPAVersion.MAJOR_RELEASE == 1) &&
+                 (OpenJPAVersion.MINOR_RELEASE >= 3)) {
+                // expected exception for new behavior
+            } else {
+                // unexpected exception
+                throw ae;
+            }
+        } catch (IllegalArgumentException iae) {
+            if (OpenJPAVersion.MAJOR_RELEASE >= 2) {
+                // expected exception for new behavior
+            } else {
+                // unexpected exception
+                throw iae;
+            }
+        } finally {
+            em.close();
+        }
+    } 
+
+    private void createDepartment(String deptName) {
+        if (count(Department.class) > 0)
+            return;
+
+        Department dept = new Department();
+        dept.setName(deptName);
+
+        for (int i = 1; i <= FULLTIME_EMPLOYEE_COUNT; i++) {
+            FullTimeEmployee e = new FullTimeEmployee();
+            e.setSsn("888-PP-001" + i);
+            e.setSalary(100000);
+            dept.addEmployee(e);
+        }
+        for (int i = 1; i <= PARTTIME_EMPLOYEE_COUNT; i++) {
+            PartTimeEmployee e = new PartTimeEmployee();
+            e.setSsn("999-PP-001" + i);
+            e.setHourlyWage(20);
+            dept.addEmployee(e);
+        }
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(dept);
+        em.getTransaction().commit();
+        em.close();
+
+    }
+    
+    private void createInvoice() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Invoice invoice = new Invoice(1, "Red", 1.30);
+        for (int i = 1;  i <= LINEITEM_PER_INVOICE; i++) {
+            LineItem item = new LineItem(String.valueOf(i), 10);
+            item.setInvoice(invoice);
+            invoice.getLineItems().add(item);
+            em.persist(invoice);
+        }
+        em.flush();
+        tran.commit();
+        em.close();        
+    }   
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestNonPrimaryKeyQueryParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message