OPENJPA-2285: Don't recache data from an Embedded StateManager.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1409420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2012-11-14 21:31:27 +00:00
parent 0633d68005
commit 160c71e068
5 changed files with 325 additions and 1 deletions

View File

@ -482,7 +482,8 @@ public class DataCacheStoreManager extends DelegatingStoreManager {
private void updateDataCache(boolean found, OpenJPAStateManager sm, FetchConfiguration fetch,
boolean loadedFieldsChanged) {
if (!_ctx.getPopulateDataCache() || sm == null || fetch.getCacheStoreMode() == DataCacheStoreMode.BYPASS) {
if (!_ctx.getPopulateDataCache() || sm == null || sm.isEmbedded()
|| fetch.getCacheStoreMode() == DataCacheStoreMode.BYPASS) {
return;
}

View File

@ -0,0 +1,96 @@
/*
* 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.datacache;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.apache.openjpa.persistence.datacache.entities.ContactInfo;
import org.apache.openjpa.persistence.datacache.entities.Person;
import org.apache.openjpa.persistence.datacache.entities.Phone;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestJPAEmbeddableDataCache extends SingleEMFTestCase {
Object[] params = new Object[] { Person.class, ContactInfo.class, Phone.class, "openjpa.DataCache", "true",
CLEAR_TABLES };
protected void setUp(Object... props) {
super.setUp(params);
}
public void test() {
EntityManager em = emf.createEntityManager();
try {
Person p = loadPerson();
String sql = "SELECT p.ci FROM Person p WHERE p.id = :id";
TypedQuery<ContactInfo> query = em.createQuery(sql, ContactInfo.class);
query.setParameter("id", p.getId());
query.getSingleResult();
em.clear();
query = em.createQuery(sql, ContactInfo.class);
query.setParameter("id", p.getId());
query.getSingleResult();
} finally {
if (em.getTransaction().isActive())
em.getTransaction().rollback();
em.close();
}
}
Person loadPerson() {
Person p = null;
EntityManager em = emf.createEntityManager();
try {
p = new Person();
ContactInfo ci = new ContactInfo();
Phone phone = new Phone();
p.setCi(ci);
ci.setPhone(phone);
phone.setOwner(p);
p.setFirst("first");
p.setMiddle("middle");
p.setLast("last");
phone.setNumber("507-555-1076");
phone.setSomethingElse("something-" + System.currentTimeMillis());
ci.setCity("cittttY");
ci.setStreet("street-" + System.currentTimeMillis());
ci.setZip("90210");
em.getTransaction().begin();
em.persist(p);
em.persist(phone);
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive())
em.getTransaction().rollback();
em.close();
}
return p;
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.datacache.entities;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.OneToOne;
@Embeddable
public class ContactInfo {
String city, street, zip;
@OneToOne(cascade = CascadeType.ALL)
Phone phone;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public Phone getPhone() {
return phone;
}
public void setPhone(Phone phone) {
this.phone = phone;
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.datacache.entities;
import javax.persistence.Basic;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "oaopde_person")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
int id;
@Version
int version;
@Basic
String first, middle, last;
@Embedded
ContactInfo ci;
public Person() {
}
public String getFirst() {
return first;
}
public void setFirst(String first) {
this.first = first;
}
public String getMiddle() {
return middle;
}
public void setMiddle(String middle) {
this.middle = middle;
}
public String getLast() {
return last;
}
public void setLast(String last) {
this.last = last;
}
public ContactInfo getCi() {
return ci;
}
public void setCi(ContactInfo ci) {
this.ci = ci;
}
public int getId() {
return id;
}
}

View File

@ -0,0 +1,77 @@
/*
* 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.datacache.entities;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "oaopde_phone")
public class Phone {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
int id;
@Version
int version;
String somethingElse;
String number;
@OneToOne(mappedBy = "ci.phone", cascade = CascadeType.ALL)
Person owner;
public Phone() {
}
public String getSomethingElse() {
return somethingElse;
}
public void setSomethingElse(String somethingElse) {
this.somethingElse = somethingElse;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
public int getId() {
return id;
}
public void setNumber(String n) {
number = n;
}
public String getNumber() {
return number;
}
}