OPENJPA-2151. Optimizations to StateManagerImpl.initialize and FieldMetaData access.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1307622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kevin W. Sutter 2012-03-30 21:26:31 +00:00
parent 83916ff986
commit c5d2d2c217
21 changed files with 120 additions and 46 deletions

View File

@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
class ECleanState class ECleanState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.setDirty(false); context.setDirty(false);
} }

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class ECopyState class ECopyState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
// no need to save fields, because this transition doesn't happen // no need to save fields, because this transition doesn't happen
// until the flush process begins // until the flush process begins
context.setLoaded(true); context.setLoaded(true);

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class EDirtyState class EDirtyState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.saveFields(false); context.saveFields(false);
} }

View File

@ -30,10 +30,14 @@ package org.apache.openjpa.kernel;
class ENonTransState class ENonTransState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
// spec says all proxies to second class objects should be reset // spec says all proxies to second class objects should be reset
context.proxyFields(true, true); context.proxyFields(true, true);
context.setDirty(false); context.setDirty(false);
context.clearSavedFields(); context.clearSavedFields();
} }

View File

@ -32,7 +32,8 @@ package org.apache.openjpa.kernel;
class HollowState class HollowState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.clearFields(); context.clearFields();
context.clearSavedFields(); context.clearSavedFields();
context.setDirty(false); context.setDirty(false);

View File

@ -161,7 +161,7 @@ public class PCState
/** /**
* Called when this state is first assigned to the given state manager. * Called when this state is first assigned to the given state manager.
*/ */
void initialize(StateManagerImpl context) { void initialize(StateManagerImpl context, PCState previousState) {
} }
/** /**

View File

@ -29,7 +29,11 @@ package org.apache.openjpa.kernel;
class PCleanState class PCleanState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
context.setDirty(false); context.setDirty(false);
} }

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class PDeletedState class PDeletedState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.saveFields(false); context.saveFields(false);
} }

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class PDirtyState class PDirtyState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.saveFields(false); context.saveFields(false);
} }

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class PNewFlushedDeletedFlushedState class PNewFlushedDeletedFlushedState
extends PNewFlushedDeletedState { extends PNewFlushedDeletedState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
} }
PCState persist(StateManagerImpl context) { PCState persist(StateManagerImpl context) {

View File

@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
class PNewProvisionalState class PNewProvisionalState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.setLoaded(true); context.setLoaded(true);
context.setDirty(true); context.setDirty(true);
context.saveFields(false); context.saveFields(false);

View File

@ -29,7 +29,11 @@ package org.apache.openjpa.kernel;
class PNewState class PNewState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
context.setLoaded(true); context.setLoaded(true);
context.setDirty(true); context.setDirty(true);
context.saveFields(false); context.saveFields(false);

View File

@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
class PNonTransDirtyState class PNonTransDirtyState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.saveFields(false); context.saveFields(false);
} }

View File

@ -28,7 +28,8 @@ package org.apache.openjpa.kernel;
class PNonTransNewState class PNonTransNewState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.setLoaded(true); context.setLoaded(true);
context.setDirty(true); context.setDirty(true);
} }

View File

@ -37,7 +37,11 @@ class PNonTransState
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage
(PNonTransState.class); (PNonTransState.class);
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
// spec says all proxies to second class objects should be reset // spec says all proxies to second class objects should be reset
context.proxyFields(true, false); context.proxyFields(true, false);

View File

@ -291,7 +291,7 @@ public class StateManagerImpl
else else
_broker.removeFromTransaction(this); _broker.removeFromTransaction(this);
_state.initialize(this); _state.initialize(this, prev);
if (_state.isDeleted() && !wasDeleted) if (_state.isDeleted() && !wasDeleted)
fireLifecycleEvent(LifecycleEvent.AFTER_DELETE); fireLifecycleEvent(LifecycleEvent.AFTER_DELETE);
} finally { } finally {
@ -356,27 +356,16 @@ public class StateManagerImpl
_flush = new BitSet(fmds.length); _flush = new BitSet(fmds.length);
_dirty = new BitSet(fmds.length); _dirty = new BitSet(fmds.length);
for (int i = 0; i < fmds.length; i++) { // mark primary key and non-persistent fields as loaded
// mark primary key and non-persistent fields as loaded for(int i : _meta.getPkAndNonPersistentManagedFmdIndexes()){
if (fmds[i].isPrimaryKey() _loaded.set(i);
|| fmds[i].getManagement() != fmds[i].MANAGE_PERSISTENT)
_loaded.set(i);
if (_meta.getIdentityType() == ClassMetaData.ID_APPLICATION) {
String mappedByIdValue = fmds[i].getMappedByIdValue();
if (mappedByIdValue != null) {
if (!ApplicationIds.isIdSet(_id, _meta, mappedByIdValue)) {
if (_mappedByIdFields == null)
_mappedByIdFields = new ArrayList<FieldMetaData>();
_mappedByIdFields.add(fmds[i]);
}
}
}
// record whether there are any managed inverse fields
if (_broker.getInverseManager() != null
&& fmds[i].getInverseMetaDatas().length > 0)
_flags |= FLAG_INVERSES;
} }
_mappedByIdFields = _meta.getMappyedByIdFields();
// record whether there are any managed inverse fields
if (_broker.getInverseManager() != null && _meta.hasInverseManagedFields())
_flags |= FLAG_INVERSES;
pc.pcSetDetachedState(null); pc.pcSetDetachedState(null);
_pc = pc; _pc = pc;
@ -1592,12 +1581,12 @@ public class StateManagerImpl
public void accessingField(int field) { public void accessingField(int field) {
// possibly change state // possibly change state
try { try {
// If this field is loaded, and not a PK field allow pass through // If this field is loaded, and not a PK field allow pass through
// TODO -- what about version fields? Could probably UT this // TODO -- what about version fields? Could probably UT this
if(_loaded.get(field) && !_meta.getField(field).isPrimaryKey()) if(_loaded.get(field) && !_meta.getField(field).isPrimaryKey())
return; return;
beforeRead(field); beforeRead(field);
beforeAccessField(field); beforeAccessField(field);
} catch (RuntimeException re) { } catch (RuntimeException re) {

View File

@ -30,11 +30,15 @@ package org.apache.openjpa.kernel;
class TCleanState class TCleanState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
// need to replace the second class objects with proxies that // need to replace the second class objects with proxies that
// listen for dirtying so we can track changes to these objects // listen for dirtying so we can track changes to these objects
context.proxyFields(true, false); context.proxyFields(true, false);
context.clearSavedFields(); context.clearSavedFields();
context.setLoaded(true); context.setLoaded(true);
context.setDirty(false); context.setDirty(false);

View File

@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
class TDirtyState class TDirtyState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.saveFields(false); context.saveFields(false);
context.setLoaded(true); context.setLoaded(true);
context.setDirty(true); context.setDirty(true);

View File

@ -31,7 +31,8 @@ package org.apache.openjpa.kernel;
class TLoadedState class TLoadedState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
context.setLoaded(true); context.setLoaded(true);
} }

View File

@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
class TransientState class TransientState
extends PCState { extends PCState {
void initialize(StateManagerImpl context) { @Override
void initialize(StateManagerImpl context, PCState previous) {
// mark r/w ok, remove from management // mark r/w ok, remove from management
context.unproxyFields(); context.unproxyFields();
context.getPersistenceCapable().pcReplaceStateManager(null); context.getPersistenceCapable().pcReplaceStateManager(null);

View File

@ -219,7 +219,11 @@ public class ClassMetaData
private boolean _abstract = false; private boolean _abstract = false;
private Boolean _hasAbstractPKField = null; private Boolean _hasAbstractPKField = null;
private Boolean _hasPKFieldsFromAbstractClass = null; private Boolean _hasPKFieldsFromAbstractClass = null;
private int[] _pkAndNonPersistentManagedFmdIndexes = null;
private Boolean inverseManagedFields = null;
private List<FieldMetaData> _mappedByIdFields;
private boolean _mappedByIdFieldsSet = false;
/** /**
* Constructor. Supply described type and repository. * Constructor. Supply described type and repository.
*/ */
@ -2763,5 +2767,53 @@ public class ClassMetaData
public String getSourceName(){ public String getSourceName(){
return _srcName; return _srcName;
} }
}
public int[] getPkAndNonPersistentManagedFmdIndexes() {
if (_pkAndNonPersistentManagedFmdIndexes == null) {
List<Integer> ids = new ArrayList<Integer>();
for (FieldMetaData fmd : getFields()) {
if (fmd.isPrimaryKey() || fmd.getManagement() != FieldMetaData.MANAGE_PERSISTENT) {
ids.add(fmd.getIndex());
}
}
int idsSize = ids.size();
_pkAndNonPersistentManagedFmdIndexes = new int[idsSize];
for(int i = 0; i<idsSize; i++){
_pkAndNonPersistentManagedFmdIndexes[i] = ids.get(i).intValue();
}
}
return _pkAndNonPersistentManagedFmdIndexes;
}
public boolean hasInverseManagedFields() {
if (inverseManagedFields == null) {
for(FieldMetaData fmd: getFields()){
if(fmd.getInverseMetaDatas().length > 0){
inverseManagedFields = Boolean.TRUE;
break;
}
}
}
return inverseManagedFields.booleanValue();
}
public List<FieldMetaData> getMappyedByIdFields() {
if (!_mappedByIdFieldsSet) {
List<FieldMetaData> fmdArray = null;
for (FieldMetaData fmd : getFields()) {
if (getIdentityType() == ClassMetaData.ID_APPLICATION) {
String mappedByIdValue = fmd.getMappedByIdValue();
if (mappedByIdValue != null) {
if (fmdArray == null) {
fmdArray = new ArrayList<FieldMetaData>();
}
fmdArray.add(fmd);
}
}
}
_mappedByIdFields = fmdArray;
_mappedByIdFieldsSet = true;
}
return _mappedByIdFields;
}
}