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
extends PCState {
void initialize(StateManagerImpl context) {
@Override
void initialize(StateManagerImpl context, PCState previous) {
context.setDirty(false);
}

View File

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

View File

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

View File

@ -30,7 +30,11 @@ package org.apache.openjpa.kernel;
class ENonTransState
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
context.proxyFields(true, true);

View File

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

View File

@ -161,7 +161,7 @@ public class PCState
/**
* 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
extends PCState {
void initialize(StateManagerImpl context) {
@Override
void initialize(StateManagerImpl context, PCState previous) {
if (previous == null)
return;
context.setDirty(false);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,11 @@ class PNonTransState
private static final Localizer _loc = Localizer.forPackage
(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
context.proxyFields(true, false);

View File

@ -291,7 +291,7 @@ public class StateManagerImpl
else
_broker.removeFromTransaction(this);
_state.initialize(this);
_state.initialize(this, prev);
if (_state.isDeleted() && !wasDeleted)
fireLifecycleEvent(LifecycleEvent.AFTER_DELETE);
} finally {
@ -356,28 +356,17 @@ public class StateManagerImpl
_flush = 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
if (fmds[i].isPrimaryKey()
|| 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;
// mark primary key and non-persistent fields as loaded
for(int i : _meta.getPkAndNonPersistentManagedFmdIndexes()){
_loaded.set(i);
}
_mappedByIdFields = _meta.getMappyedByIdFields();
// record whether there are any managed inverse fields
if (_broker.getInverseManager() != null && _meta.hasInverseManagedFields())
_flags |= FLAG_INVERSES;
pc.pcSetDetachedState(null);
_pc = pc;

View File

@ -30,7 +30,11 @@ package org.apache.openjpa.kernel;
class TCleanState
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
// listen for dirtying so we can track changes to these objects
context.proxyFields(true, false);

View File

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

View File

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

View File

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

View File

@ -219,6 +219,10 @@ public class ClassMetaData
private boolean _abstract = false;
private Boolean _hasAbstractPKField = 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.
@ -2763,5 +2767,53 @@ public class ClassMetaData
public String getSourceName(){
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;
}
}