mirror of https://github.com/apache/openjpa.git
OPENJPA-2285: Revert prior changes.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1455204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e0bb4cd7c7
commit
9f0f92fc07
|
@ -49,7 +49,8 @@ import org.apache.openjpa.util.OptimisticException;
|
|||
* @author Patrick Linskey
|
||||
* @nojavadoc
|
||||
*/
|
||||
public class DataCacheStoreManager extends DelegatingStoreManager {
|
||||
public class DataCacheStoreManager
|
||||
extends DelegatingStoreManager {
|
||||
|
||||
// all the state managers changed in this transaction
|
||||
private Collection<OpenJPAStateManager> _inserts = null;
|
||||
|
@ -437,12 +438,9 @@ public class DataCacheStoreManager extends DelegatingStoreManager {
|
|||
DataCache cache = _mgr.selectCache(sm);
|
||||
|
||||
boolean found = false;
|
||||
int loadedFieldsBefore = sm.getLoaded().cardinality();
|
||||
if (cache == null || sm.isEmbedded() || bypass(fetch, StoreManager.FORCE_LOAD_NONE)) {
|
||||
found = super.load(sm, fields, fetch, lockLevel, edata);
|
||||
int loadedFieldsAfter = sm.getLoaded().cardinality();
|
||||
boolean changed = loadedFieldsAfter > loadedFieldsBefore;
|
||||
updateDataCache(found, sm, fetch, changed);
|
||||
updateDataCache(found, sm, fetch);
|
||||
return found;
|
||||
}
|
||||
|
||||
|
@ -460,12 +458,10 @@ public class DataCacheStoreManager extends DelegatingStoreManager {
|
|||
|
||||
// load from store manager; clone the set of still-unloaded fields
|
||||
// so that if the store manager decides to modify it it won't affect us
|
||||
found = super.load(sm,(BitSet) fields.clone() , fetch, lockLevel, edata);
|
||||
found = super.load(sm, (BitSet) fields.clone(), fetch, lockLevel, edata);
|
||||
|
||||
int loadedFieldsAfter = sm.getLoaded().cardinality();
|
||||
boolean changed = loadedFieldsAfter > loadedFieldsBefore;
|
||||
// Get new instance of cache after DB load since it may have changed
|
||||
updateDataCache(found, sm, fetch, changed);
|
||||
updateDataCache(found, sm, fetch);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
@ -477,13 +473,10 @@ public class DataCacheStoreManager extends DelegatingStoreManager {
|
|||
* @param found whether the entity was found by the store manager
|
||||
* @param sm the state manager
|
||||
* @param fetch fetch configuration
|
||||
* @param loadedFieldsChanged
|
||||
*/
|
||||
private void updateDataCache(boolean found, OpenJPAStateManager sm, FetchConfiguration fetch,
|
||||
boolean loadedFieldsChanged) {
|
||||
private void updateDataCache(boolean found, OpenJPAStateManager sm, FetchConfiguration fetch) {
|
||||
|
||||
if (!_ctx.getPopulateDataCache() || sm == null || sm.isEmbedded()
|
||||
|| fetch.getCacheStoreMode() == DataCacheStoreMode.BYPASS) {
|
||||
if (!_ctx.getPopulateDataCache() || sm == null || fetch.getCacheStoreMode() == DataCacheStoreMode.BYPASS) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -493,12 +486,10 @@ public class DataCacheStoreManager extends DelegatingStoreManager {
|
|||
}
|
||||
|
||||
DataCachePCData data = cache.get(sm.getObjectId());
|
||||
|
||||
// If loadedFieldsChanged = true, we don't care that data was already stored as we should update it.
|
||||
boolean alreadyCached = (data != null && !loadedFieldsChanged);
|
||||
DataCacheStoreMode storeMode = fetch.getCacheStoreMode();
|
||||
|
||||
if ((storeMode == DataCacheStoreMode.USE && !alreadyCached) || storeMode == DataCacheStoreMode.REFRESH) {
|
||||
boolean alreadyCached = data != null;
|
||||
|
||||
if ((fetch.getCacheStoreMode() == DataCacheStoreMode.USE && !alreadyCached) ||
|
||||
fetch.getCacheStoreMode() == DataCacheStoreMode.REFRESH) {
|
||||
// If not found in the DB and the item is in the cache, and not locking remove the item
|
||||
if (!found && data != null && !isLocking(fetch)) {
|
||||
cache.remove(sm.getObjectId());
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* 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 java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.persistence.EntityManagerImpl;
|
||||
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
||||
|
||||
public class TestDataCacheStoreLazyFk extends SQLListenerTestCase {
|
||||
Object[] p = new Object[] { CLEAR_TABLES, CachedEntityStatistics.class, "openjpa.DataCache", "true" };
|
||||
|
||||
public void setUp() {
|
||||
super.setUp(p);
|
||||
}
|
||||
|
||||
public void testCacheHit() throws Exception {
|
||||
EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
|
||||
// Change the eager field to lazy to make testing easier.
|
||||
ClassMetaData cmd =
|
||||
em.getConfiguration().getMetaDataRepositoryInstance().getMetaData(CachedEntityStatistics.class, null, true);
|
||||
cmd.getField("eagerList").setInDefaultFetchGroup(false);
|
||||
try {
|
||||
em.getTransaction().begin();
|
||||
CachedEntityStatistics e = new CachedEntityStatistics();
|
||||
CachedEntityStatistics lazy = new CachedEntityStatistics();
|
||||
Set<CachedEntityStatistics> lazyList = new HashSet<CachedEntityStatistics>();
|
||||
lazyList.add(lazy);
|
||||
e.setLazyList(lazyList);
|
||||
em.persist(e);
|
||||
em.persist(lazy);
|
||||
em.flush();
|
||||
em.clear();
|
||||
|
||||
// Should prime the cache
|
||||
em.find(CachedEntityStatistics.class, e.getId()).getLazyList();
|
||||
em.clear();
|
||||
sql.clear();
|
||||
|
||||
CachedEntityStatistics c = em.find(CachedEntityStatistics.class, e.getId());
|
||||
c.getLazyList();
|
||||
assertEquals(0, sql.size());
|
||||
|
||||
em.getTransaction().commit();
|
||||
} finally {
|
||||
if (em.getTransaction().isActive())
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -113,9 +113,6 @@ public class TestStatistics extends SingleEMFTestCase {
|
|||
read++;
|
||||
read++;
|
||||
write++;
|
||||
write++;
|
||||
write++;
|
||||
|
||||
write++;
|
||||
write++;
|
||||
assertion(cls, hit, read, write, stats);
|
||||
|
@ -155,8 +152,6 @@ public class TestStatistics extends SingleEMFTestCase {
|
|||
assertEquals(1, p.getLazyList().size());
|
||||
read++;
|
||||
write++;
|
||||
// +1 write for p which had its intermediate(fk) updated
|
||||
write++;
|
||||
assertion(cls, hit, read, write, stats);
|
||||
em.clear();
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue