openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r943663 - in /openjpa/branches/1.0.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/
Date Wed, 12 May 2010 20:03:34 GMT
Author: mikedd
Date: Wed May 12 20:03:34 2010
New Revision: 943663

URL: http://svn.apache.org/viewvc?rev=943663&view=rev
Log:
OPENJPA-708: 
Sub-sub-query generates SQL with syntax error.
Submitted By: Heath Thomann, based on Catalina's changes for trunk. 

Added:
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
  (with props)
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
  (with props)
Modified:
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=943663&r1=943662&r2=943663&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Wed May 12 20:03:34 2010
@@ -487,8 +487,13 @@ public class SelectImpl
                 _joinSyntax = _parent._joinSyntax;
         }
         
-        if (_parent.getAliases() == null || _subPath == null)
+        if (_parent.getAliases() == null || _subPath == null) {
             return;
+        }
+        
+        if (_parent._aliases.size() <= 1) {
+            return;
+        }
 
         // Do not remove aliases for databases that use SYNTAX_DATABASE (oracle)
         if(_parent._joinSyntax != JoinSyntaxes.SYNTAX_DATABASE) {

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java?rev=943663&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
Wed May 12 20:03:34 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.FetchType;
+import java.sql.Date;
+
+@Entity
+public class Magazine implements Serializable {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name="id")
+    private int id;
+
+    @Column(name="name")
+    private String name;
+    
+    @Column(name="date_published")
+    private Date datePublished;
+
+    @ManyToOne(fetch=FetchType.LAZY)
+    @JoinColumn(name="id_publisher")
+    private Publisher idPublisher;
+
+
+    private static final long serialVersionUID = 1L;
+
+    public int getId() {
+        return this.id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Publisher getIdPublisher() {
+        return this.idPublisher;
+    }
+
+    public void setIdPublisher(Publisher idPublisher) {
+        this.idPublisher = idPublisher;
+    }
+    
+    public Date getDatePublished() {
+        return datePublished;
+    }
+
+    public void setDatePublished(Date datePublished) {
+        this.datePublished = datePublished;
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java?rev=943663&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
Wed May 12 20:03:34 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.OneToMany;
+import java.util.Set;
+
+@Entity
+public class Publisher implements Serializable {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name="id")
+    private int id;
+
+    @Column(name="name")
+    private String name;
+
+    @OneToMany(mappedBy="idPublisher")
+    private Set<Magazine> magazineCollection;
+
+
+    private static final long serialVersionUID = 1L;
+
+    public int getId() {
+        return this.id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Set<Magazine> getMagazineCollection() {
+        return this.magazineCollection;
+    }
+
+    public void setMagazineCollection(Set<Magazine> magazineCollection) {
+        this.magazineCollection = magazineCollection;
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java?rev=943663&r1=943662&r2=943663&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
Wed May 12 20:03:34 2010
@@ -35,7 +35,7 @@ public class TestSubquery
     public void setUp() {
         setUp(Customer.class, Customer.CustomerKey.class, Order.class,
             OrderItem.class, Employee.class, Dependent.class,
-            DependentId.class, CLEAR_TABLES);
+            DependentId.class, Magazine.class, Publisher.class, CLEAR_TABLES);
     }
 
     static String[]  querys = new String[] {
@@ -71,6 +71,16 @@ public class TestSubquery
             " (select sum(o2.amount) from c.orders o2)",
         "select o1.oid, c.name from Order o1, Customer c where o1.amount = " +
             " any(select o2.amount from in(c.orders) o2)",
+        "SELECT p, m "+
+            "FROM Publisher p "+
+            "LEFT OUTER JOIN p.magazineCollection m "+
+            "WHERE m.id = (SELECT MAX(m2.id) "+
+            "FROM Magazine m2 "+
+            "WHERE m2.idPublisher.id = p.id "+
+            "AND m2.datePublished = "+
+            "(SELECT MAX(m3.datePublished) "+
+            "FROM Magazine m3 "+
+            "WHERE m3.idPublisher.id = p.id)) ", 
     // outstanding problem subqueries:
     //"select o from Order o where o.amount > (select count(o) from Order o)",
     //"select o from Order o where o.amount > (select count(o2) from Order o2)",



Mime
View raw message