You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by ht...@apache.org on 2012/11/29 05:25:26 UTC
svn commit: r1415037 - in /openjpa/branches/2.0.x:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/
Author: hthomann
Date: Thu Nov 29 04:25:25 2012
New Revision: 1415037
URL: http://svn.apache.org/viewvc?rev=1415037&view=rev
Log:
OPENJPA-2289: Applied Albert's patch to 2.0.x.
Added:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryEntity.java
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryMapEntity.java
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/TestSubQuery.java
Modified:
openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1415037&r1=1415036&r2=1415037&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Thu Nov 29 04:25:25 2012
@@ -1855,6 +1855,10 @@ public class DBDictionary
else if (!StringUtils.isEmpty(syntax))
throw new IllegalArgumentException(syntax);
}
+
+ public boolean isImplicitJoin() {
+ return false;
+ }
/**
* Return a SQL string to act as a placeholder for the given column.
Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=1415037&r1=1415036&r2=1415037&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java (original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java Thu Nov 29 04:25:25 2012
@@ -1420,4 +1420,8 @@ public class OracleDictionary
row.setBlob(col, getEmptyBlob());
}
}
+
+ public boolean isImplicitJoin() {
+ return joinSyntax == SYNTAX_DATABASE;
+ }
}
Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=1415037&r1=1415036&r2=1415037&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Thu Nov 29 04:25:25 2012
@@ -2784,7 +2784,11 @@ public class SelectImpl
|| _sel._from != null) {
// don't make any joins, but update the path if a variable
// has been set
- this.append(this.var);
+ if (this.var != null) {
+ this.append(this.var);
+ } else if (this.path == null && this.correlatedVar != null && _sel._dict.isImplicitJoin()) {
+ this.append(this.correlatedVar);
+ }
this.var = null;
_outer = false;
return this;
Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryEntity.java?rev=1415037&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryEntity.java (added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryEntity.java Thu Nov 29 04:25:25 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.query.sub;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "OPENJPA_MAXQUERY_ENTITY")
+public class MaxQueryEntity {
+
+ public MaxQueryEntity() {
+ }
+
+ public MaxQueryEntity(int id, int domainId, int revision) {
+ this.id = id;
+ this.domainId = domainId;
+ this.revision = revision;
+ }
+
+ @Id
+ private int id;
+
+ private int domainId;
+
+ private int revision;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getRevision() {
+ return revision;
+ }
+
+ public void setRevision(int revision) {
+ this.revision = revision;
+ }
+
+ public int getDomainId() {
+ return domainId;
+ }
+
+ public void setDomainId(int domainId) {
+ this.domainId = domainId;
+ }
+
+}
Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryMapEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryMapEntity.java?rev=1415037&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryMapEntity.java (added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/MaxQueryMapEntity.java Thu Nov 29 04:25:25 2012
@@ -0,0 +1,83 @@
+/*
+ * 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.query.sub;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "OPENJPA_MAXQUERY_MAPENTITY")
+public class MaxQueryMapEntity {
+
+ public MaxQueryMapEntity(int id, int revision, String selectCriteria) {
+ this.id = id;
+ this.revision = revision;
+ this.selectCriteria = selectCriteria;
+ }
+
+ public MaxQueryMapEntity() {
+ }
+
+ @Id
+ private int id;
+
+ private int revision;
+
+ @ManyToOne
+ @JoinColumn(name = "refEntity")
+ private MaxQueryEntity refEntity;
+
+ private String selectCriteria;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getRevision() {
+ return revision;
+ }
+
+ public void setRevision(int revision) {
+ this.revision = revision;
+ }
+
+ public MaxQueryEntity getRefEntity() {
+ return refEntity;
+ }
+
+ public void setRefEntity(MaxQueryEntity refEntity) {
+ this.refEntity = refEntity;
+ }
+
+ public String getSelectCriteria() {
+ return selectCriteria;
+ }
+
+ public void setSelectCriteria(String selectCriteria) {
+ this.selectCriteria = selectCriteria;
+ }
+
+}
Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/TestSubQuery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/TestSubQuery.java?rev=1415037&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/TestSubQuery.java (added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/sub/TestSubQuery.java Thu Nov 29 04:25:25 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.query.sub;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSubQuery extends SingleEMFTestCase {
+ public void setUp() throws Exception {
+ super.setUp(CLEAR_TABLES, MaxQueryEntity.class, MaxQueryMapEntity.class);
+ populate();
+ }
+
+ public void populate() {
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tran = em.getTransaction();
+ tran.begin();
+
+ MaxQueryEntity mqe = new MaxQueryEntity(1, 1, 1);
+ MaxQueryMapEntity mqme = new MaxQueryMapEntity(1, 1, "A1");
+ MaxQueryMapEntity mqme2 = new MaxQueryMapEntity(2, 2, "A2");
+ mqme.setRefEntity(mqe);
+ mqme2.setRefEntity(mqe);
+ em.persist(mqe);
+ em.persist(mqme);
+ em.persist(mqme2);
+
+ mqe = new MaxQueryEntity(2, 2, 1);
+ mqme = new MaxQueryMapEntity(3, 1, "B1");
+ mqme.setRefEntity(mqe);
+ em.persist(mqe);
+ em.persist(mqme);
+ mqme = new MaxQueryMapEntity(4, 2, "B2");
+ mqme.setRefEntity(mqe);
+ em.persist(mqme);
+ mqme = new MaxQueryMapEntity(5, 3, "B3");
+ mqme.setRefEntity(mqe);
+ em.persist(mqme);
+
+ mqe = new MaxQueryEntity(3, 3, 1);
+ mqme = new MaxQueryMapEntity(6, 4, "C1");
+ mqme.setRefEntity(mqe);
+ em.persist(mqe);
+ em.persist(mqme);
+
+ tran.commit();
+ em.close();
+ }
+
+ public void test() {
+ EntityManager em = emf.createEntityManager();
+
+ Query query =
+ em
+ .createQuery("SELECT e FROM MaxQueryEntity e, MaxQueryMapEntity map "
+ + "WHERE "
+// + " map.selectCriteria = 'B3' "
+// + " AND map.refEntity = e "
+// + " AND e.revision = ( SELECT MAX(e_.revision)"
+// + " FROM MaxQueryEntity e_"
+// + " WHERE e_.domainId = e.domainId )"
+// + " AND "
+ + " map.revision = ( SELECT MAX(map_.revision)"
+ + " FROM MaxQueryMapEntity map_"
+ + " WHERE map_.refEntity = map.refEntity )"
+ );
+
+// assertEquals(1, query.getResultList().size());
+ assertEquals(9, query.getResultList().size());
+
+ em.close();
+ }
+}