Author: arminw
Date: Mon Aug 14 07:39:53 2006
New Revision: 431354
URL: http://svn.apache.org/viewvc?rev=431354&view=rev
Log:
minor performance improvement, update comments
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
URL:
http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java?rev=431354&r1=431353&r2=431354&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
(original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
Mon Aug 14 07:39:53 2006
@@ -57,7 +57,9 @@
constructor call of Identity class we can run into problems when an
object is stored/deleted/stored in
the same PB-tx, because then the PK of the object can change (e.g.
when DB identity columns are used)
but the cached Identity object will always be the same when the
Identity object is requested by the
- IdentityFactory
+ IdentityFactory. The IdentityFactory needs notification about each
object declared for deletion.
+ NOTE: Before we use such a cache we should run some serious
performance tests. Maybe such a cache
+ doesn't improve performance.
*/
//this.persistentIdentityMap = new
ReferenceIdentityMap(ReferenceIdentityMap.WEAK, ReferenceIdentityMap.HARD,
true);
this.transientSequenceManager = new
SequenceManagerTransientImpl(broker);
@@ -73,7 +75,11 @@
protected Identity createTransientOrRealIdentity(ClassDescriptor cld,
final Object objOrProxy)
{
if(objOrProxy == null) throw new NullPointerException("Can't create
Identity for 'null'-object");
+
Identity result = null;
+ //Identity result = (Identity) persistentIdentityMap.get(objOrProxy);
+ //if(result != null) return result;
+
Class topLevelClass = null;
Class realClass = null;
Object[] pks = null;
@@ -86,51 +92,46 @@
}
else
{
- //result = (Identity) persistentIdentityMap.get(objOrProxy);
- if(result == null)
+ // now we are sure that the specified object is not a proxy
+ realClass = objOrProxy.getClass();
+ topLevelClass = broker.getTopLevelClass(realClass);
+ if(cld == null)
{
- // now we are sure that the specified object is not a proxy
- realClass = objOrProxy.getClass();
- topLevelClass =
broker.getTopLevelClass(objOrProxy.getClass());
- if(cld == null)
- {
- cld = broker.getClassDescriptor(objOrProxy.getClass());
- }
- BrokerHelper helper = broker.serviceBrokerHelper();
+ cld = broker.getClassDescriptor(realClass);
+ }
+ BrokerHelper helper = broker.serviceBrokerHelper();
- FieldDescriptor[] fields = cld.getPkFields();
- pks = new Object[fields.length];
- FieldDescriptor fld;
- for(int i = 0; i < fields.length; i++)
+ FieldDescriptor[] fields = cld.getPkFields();
+ pks = new Object[fields.length];
+ FieldDescriptor fld;
+ for(int i = 0; i < fields.length; i++)
+ {
+ fld = fields[i];
+ /*
+ we check all PK fields for 'null'-values
+ */
+ Object value = fld.getPersistentField().get(objOrProxy);
+ if(helper.representsNull(fld, value))
{
- fld = fields[i];
- /*
- we check all PK fields for 'null'-values
- */
- Object value =
fld.getPersistentField().get(objOrProxy);
- if(helper.representsNull(fld, value))
+ result = (Identity)
transientIdentityMap.get(objOrProxy);
+ if(result == null)
{
- result = (Identity)
transientIdentityMap.get(objOrProxy);
- if(result == null)
- {
- pks[i] =
transientSequenceManager.getUniqueValue(fld);
- result = new Identity(realClass,
topLevelClass, pks, true);
- //if(activeTx)
objectToIdentityMap.put(objOrProxy, result);
- transientIdentityMap.put(objOrProxy, result);
- }
- break;
- }
- else
- {
- pks[i] = value;
+ pks[i] =
transientSequenceManager.getUniqueValue(fld);
+ result = new Identity(realClass, topLevelClass,
pks, true);
+ transientIdentityMap.put(objOrProxy, result);
}
+ break;
}
- if(result == null)
+ else
{
- result = new Identity(realClass, topLevelClass, pks,
false);
- //persistentIdentityMap.put(objOrProxy, result);
+ pks[i] = value;
}
}
+ if(result == null)
+ {
+ result = new Identity(realClass, topLevelClass, pks,
false);
+ //persistentIdentityMap.put(objOrProxy, result);
+ }
}
}
catch(ClassNotPersistenceCapableException e)
@@ -147,7 +148,7 @@
/** @see org.apache.ojb.broker.IdentityFactory#buildIdentity(Object) */
public Identity buildIdentity(final Object obj)
{
- return
createTransientOrRealIdentity(broker.getClassDescriptor(broker.getProxyFactory().getRealClass(obj)),
obj);
+ return createTransientOrRealIdentity(null, obj);
}
/** @see org.apache.ojb.broker.IdentityFactory#buildIdentity(Object) */
@@ -326,15 +327,12 @@
public void beforeRollback(PBStateEvent event)
{
}
-
public void afterOpen(PBStateEvent event)
{
}
-
public void beforeBegin(PBStateEvent event)
{
}
-
public void beforeCommit(PBStateEvent event)
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]