mirror of https://github.com/apache/openjpa.git
OPENJPA-1545: Refectored code. Fixed bug where unloaded fields were being loaded due to detach.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@919657 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b074cd80c8
commit
b0eefe6ea8
|
@ -289,7 +289,7 @@ public class ManagedClassSubclasser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void debugBytecodes(BCClass bc) throws IOException {
|
public static void debugBytecodes(BCClass bc) throws IOException {
|
||||||
// Write the bytecodes to disk for debugging purposes.
|
// Write the bytecodes to disk for debugging purposes.
|
||||||
if ("true".equals(System.getProperty(
|
if ("true".equals(System.getProperty(
|
||||||
ManagedClassSubclasser.class.getName() + ".dumpBytecodes")))
|
ManagedClassSubclasser.class.getName() + ".dumpBytecodes")))
|
||||||
|
|
|
@ -3348,10 +3348,12 @@ public class BrokerImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void detachAllInternalLite() {
|
private void detachAllInternalLite() {
|
||||||
Collection<StateManagerImpl> states = getManagedStates();
|
ManagedCache old = _cache;
|
||||||
// TODO : should I call clear on old cache first? perhaps a memory leak?
|
|
||||||
// Clear out all persistence context caches.
|
|
||||||
_cache = new ManagedCache(this);
|
_cache = new ManagedCache(this);
|
||||||
|
// TODO : should I call clear on old cache first? perhaps a memory leak?
|
||||||
|
Collection<StateManagerImpl> states = old.copy();
|
||||||
|
|
||||||
|
// Clear out all persistence context caches.
|
||||||
if (_transCache != null) {
|
if (_transCache != null) {
|
||||||
_transCache.clear();
|
_transCache.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.kernel;
|
package org.apache.openjpa.kernel;
|
||||||
|
|
||||||
|
import java.util.BitSet;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.openjpa.enhance.PersistenceCapable;
|
import org.apache.openjpa.enhance.PersistenceCapable;
|
||||||
|
@ -30,10 +31,7 @@ import org.apache.openjpa.util.Proxy;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DetachManagerLite {
|
public class DetachManagerLite {
|
||||||
final TransferFieldManager _fm;
|
|
||||||
|
|
||||||
public DetachManagerLite() {
|
public DetachManagerLite() {
|
||||||
_fm = new TransferFieldManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,13 +41,17 @@ public class DetachManagerLite {
|
||||||
* The StateManagers to be detached.
|
* The StateManagers to be detached.
|
||||||
*/
|
*/
|
||||||
public void detachAll(Collection<StateManagerImpl> states) {
|
public void detachAll(Collection<StateManagerImpl> states) {
|
||||||
|
TransferFieldManager fm = new TransferFieldManager();
|
||||||
for (StateManagerImpl sm : states) {
|
for (StateManagerImpl sm : states) {
|
||||||
ClassMetaData cmd = sm.getMetaData();
|
ClassMetaData cmd = sm.getMetaData();
|
||||||
if (sm.isPersistent() && cmd.isDetachable()) {
|
if (sm.isPersistent() && cmd.isDetachable()) {
|
||||||
PersistenceCapable pc = sm.getPersistenceCapable();
|
PersistenceCapable pc = sm.getPersistenceCapable();
|
||||||
// Detach proxy fields.
|
// Detach proxy fields.
|
||||||
|
BitSet loaded = sm.getLoaded();
|
||||||
for (FieldMetaData fmd : cmd.getProxyFields()) {
|
for (FieldMetaData fmd : cmd.getProxyFields()) {
|
||||||
detachProxyField(fmd, pc, sm);
|
if (loaded.get(fmd.getIndex())) {
|
||||||
|
detachProxyField(fmd, pc, sm, fm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pc.pcReplaceStateManager(null);
|
pc.pcReplaceStateManager(null);
|
||||||
}
|
}
|
||||||
|
@ -66,20 +68,20 @@ public class DetachManagerLite {
|
||||||
* @param sm
|
* @param sm
|
||||||
* The StateManagerImpl that the PersistenceCapable belongs to.
|
* The StateManagerImpl that the PersistenceCapable belongs to.
|
||||||
*/
|
*/
|
||||||
private void detachProxyField(FieldMetaData fmd, PersistenceCapable pc, StateManagerImpl sm) {
|
private void detachProxyField(FieldMetaData fmd, PersistenceCapable pc, StateManagerImpl sm, TransferFieldManager fm) {
|
||||||
int fieldIndex = fmd.getIndex();
|
int fieldIndex = fmd.getIndex();
|
||||||
if (fmd.isLRS() == true) {
|
if (fmd.isLRS() == true) {
|
||||||
// need to null out LRS fields.
|
// need to null out LRS fields.
|
||||||
nullField(fieldIndex, pc, sm);
|
nullField(fieldIndex, pc, sm, fm);
|
||||||
} else {
|
} else {
|
||||||
Object o = sm.fetchObject(fieldIndex);
|
Object o = sm.fetchObject(fieldIndex);
|
||||||
if (o instanceof Proxy) {
|
if (o instanceof Proxy) {
|
||||||
// Get unproxied object and replace
|
// Get unproxied object and replace
|
||||||
Proxy proxy = (Proxy) o;
|
Proxy proxy = (Proxy) o;
|
||||||
Object unproxied = proxy.copy(proxy);
|
Object unproxied = proxy.copy(proxy);
|
||||||
_fm.storeObjectField(fieldIndex, unproxied);
|
fm.storeObjectField(fieldIndex, unproxied);
|
||||||
sm.replaceField(pc, _fm, fieldIndex);
|
sm.replaceField(pc, fm, fieldIndex);
|
||||||
_fm.clear();
|
fm.clear();
|
||||||
// clean up old proxy
|
// clean up old proxy
|
||||||
proxy.setOwner(null, -1);
|
proxy.setOwner(null, -1);
|
||||||
if (proxy.getChangeTracker() != null) {
|
if (proxy.getChangeTracker() != null) {
|
||||||
|
@ -99,9 +101,9 @@ public class DetachManagerLite {
|
||||||
* @param sm
|
* @param sm
|
||||||
* The StateManagerImpl that the PersistenceCapable belongs to.
|
* The StateManagerImpl that the PersistenceCapable belongs to.
|
||||||
*/
|
*/
|
||||||
private void nullField(int fieldIndex, PersistenceCapable pc, StateManagerImpl sm) {
|
private void nullField(int fieldIndex, PersistenceCapable pc, StateManagerImpl sm, TransferFieldManager fm) {
|
||||||
_fm.storeObjectField(fieldIndex, null);
|
fm.storeObjectField(fieldIndex, null);
|
||||||
sm.replaceField(pc, _fm, fieldIndex);
|
sm.replaceField(pc, fm, fieldIndex);
|
||||||
_fm.clear();
|
fm.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue