You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2009/09/23 21:21:04 UTC
svn commit: r818217 - in
/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src:
main/java/org/apache/openjpa/persistence/jdbc/
test/java/org/apache/openjpa/persistence/jdbc/strategy/
test/resources/META-INF/
Author: dwoods
Date: Wed Sep 23 19:21:03 2009
New Revision: 818217
URL: http://svn.apache.org/viewvc?rev=818217&view=rev
Log:
OPENJPA-1116 Annotation Strategy not working. Checking in testcases and code patch already committed in trunk. Patches contributed by Ashish Paliwal.
Added:
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java (with props)
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java (with props)
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java (with props)
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java (with props)
Modified:
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=818217&r1=818216&r2=818217&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java (original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java Wed Sep 23 19:21:03 2009
@@ -1134,7 +1134,7 @@
parseOrderColumn(fm, (OrderColumn) anno);
break;
case STRAT:
- fm.getValueInfo().setStrategy(((Strategy) anno).value());
+ fm.getMappingInfo().setStrategy(((Strategy) anno).value());
break;
case UNIQUE:
parseUnique(fm,
Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java?rev=818217&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java Wed Sep 23 19:21:03 2009
@@ -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.jdbc.strategy;
+
+import java.util.*;
+import javax.persistence.*;
+
+@Entity
+public class Address {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id_address")
+ private long idAddress;
+
+ @Basic
+ @Column(nullable = false, length = 30)
+ private String city;
+
+
+ public Address() {}
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public long getIdAddress() {
+ return idAddress;
+ }
+
+ public void setIdAddress(long idAddress) {
+ this.idAddress = idAddress;
+ }
+}
+
Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Address.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java?rev=818217&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java Wed Sep 23 19:21:03 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.strategy;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+public class InnerJoinStrategy extends RelationFieldStrategy {
+ public void selectEagerJoin(Select sel, OpenJPAStateManager sm,
+ JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode) {
+
+ // add field to inner join to make sure that "inner join" is made
+ // rather than default "left outer join"
+ fetch.addFetchInnerJoin(field.getFullName(false));
+ super.selectEagerJoin(sel, sm, store, fetch, eagerMode);
+ }
+}
+
Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/InnerJoinStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java?rev=818217&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java Wed Sep 23 19:21:03 2009
@@ -0,0 +1,81 @@
+/*
+ * 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.strategy;
+
+import java.util.*;
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.jdbc.Strategy;
+import org.apache.openjpa.persistence.jdbc.Strategy;
+
+@Entity
+public class Person {
+
+ private long idPerson;
+
+ private String name;
+
+ private int age;
+
+ private Address address;
+
+ public Person() {}
+
+ @Basic
+ @Column(nullable = false)
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ @Basic
+ @Column(nullable = false, length = 30)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ @Column(name = "id_person")
+ public long getIdPerson() {
+ return idPerson;
+ }
+
+ public void setIdPerson(long idPerson) {
+ this.idPerson = idPerson;
+ }
+
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @Strategy(value = "org.apache.openjpa.persistence.jdbc.strategy.InnerJoinStrategy" )
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
+
Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/Person.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java?rev=818217&view=auto
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java (added)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java Wed Sep 23 19:21:03 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.jdbc.strategy;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+
+public class TestStrategyAnnotaion extends SingleEMFTestCase {
+ public void testStrategy() {
+ EntityManagerFactory emf = Persistence.
+ createEntityManagerFactory("testStrategy", System.getProperties());
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ Person person = new Person();
+ person.setName("parul");
+ person.setAge(21);
+
+ // no address entered for person.
+ em.persist(person);
+ em.getTransaction().commit();
+ em.clear();
+
+ // In case of inner join, the result set should be empty
+ List pers = em.createQuery("select p from Person p").getResultList();
+ assertTrue(pers.isEmpty());
+ }
+}
+
Propchange: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestStrategyAnnotaion.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=818217&r1=818216&r2=818217&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Wed Sep 23 19:21:03 2009
@@ -101,4 +101,12 @@
<mapping-file>org/apache/openjpa/persistence/annotations/xml/orm.xml</mapping-file>
</persistence-unit>
+ <persistence-unit name="testStrategy" transaction-type="RESOURCE_LOCAL">
+ <class>org.apache.openjpa.persistence.jdbc.strategy.Person</class>
+ <class>org.apache.openjpa.persistence.jdbc.strategy.Address</class>
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+ </properties>
+ </persistence-unit>
+
</persistence>