You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2005/03/23 13:32:15 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java RuntimeObject.java TransactionImpl.java
arminw 2005/03/23 04:32:15
Modified: src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
ObjectEnvelopeTable.java RuntimeObject.java
TransactionImpl.java
Log:
fix performance hot spot in ObjectEnvelopeTable
make minor performance improvements
Revision Changes Path
No revision
No revision
1.32.2.14 +1 -0 db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
Index: ObjectEnvelopeTable.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
retrieving revision 1.32.2.13
retrieving revision 1.32.2.14
diff -u -r1.32.2.13 -r1.32.2.14
--- ObjectEnvelopeTable.java 22 Mar 2005 17:49:59 -0000 1.32.2.13
+++ ObjectEnvelopeTable.java 23 Mar 2005 12:32:15 -0000 1.32.2.14
@@ -676,6 +676,7 @@
if(!isNewAssociatedObject(mod.getIdentity()))
{
cascadeDeleteFor(mod, alreadyPrepared);
+ alreadyPrepared.clear();
}
}
markedForDeletionList.clear();
1.1.2.2 +57 -22 db-ojb/src/java/org/apache/ojb/odmg/Attic/RuntimeObject.java
Index: RuntimeObject.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/Attic/RuntimeObject.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- RuntimeObject.java 22 Mar 2005 17:08:37 -0000 1.1.2.1
+++ RuntimeObject.java 23 Mar 2005 12:32:15 -0000 1.1.2.2
@@ -23,7 +23,8 @@
*/
/**
- * Helper object encapsulates common used object properties/states.
+ * Helper object encapsulates common used object properties/states, help to reduce
+ * needless metadata calls.
*
* @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
* @version $Id$
@@ -34,17 +35,18 @@
private Identity identity;
private final TransactionImpl tx;
private Boolean isNew;
- private boolean isProxy;
private ClassDescriptor cld;
+ private IndirectionHandler handler;
RuntimeObject(final Object obj, final TransactionImpl tx)
{
this.tx = tx;
this.obj = obj;
init(tx);
+ doIsNewObjectCheck(tx);
}
- RuntimeObject(final Object obj, final TransactionImpl tx, boolean isNew)
+ RuntimeObject(final Object obj, final TransactionImpl tx, final boolean isNew)
{
this.tx = tx;
this.obj = obj;
@@ -52,31 +54,40 @@
init(tx);
}
- RuntimeObject(final Object obj, final Identity oid, final ClassDescriptor cld, boolean isNew, boolean isProxy)
+ RuntimeObject(final Object obj, final Identity oid, final ClassDescriptor cld, final boolean isNew, final boolean isProxy)
{
this.tx = null;
this.obj = obj;
this.identity = oid;
this.isNew = isNew ? Boolean.TRUE : Boolean.FALSE;
- this.isProxy = isProxy;
this.cld = cld;
+ if(isProxy)
+ {
+ this.handler = ProxyHelper.getIndirectionHandler(obj);
+ }
}
/*
- try to avoid redundant and unused method calls to provide
+ try to avoid needless and unused method calls to provide
best performance, thus create Identity object only if needed
and do 'is new object' check only if needed.
*/
-
- private void init(TransactionImpl tx)
+ private void init(final TransactionImpl tx)
{
- IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
+ final IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
if(handler != null)
{
- isProxy = true;
+ this.handler = handler;
isNew = Boolean.FALSE;
identity = handler.getIdentity();
- cld = tx.getBroker().getClassDescriptor(identity.getObjectsRealClass());
+ if(handler.alreadyMaterialized())
+ {
+ cld = tx.getBroker().getClassDescriptor(handler.getRealSubject().getClass());
+ }
+ else
+ {
+ cld = tx.getBroker().getClassDescriptor(identity.getObjectsRealClass());
+ }
}
else
{
@@ -84,7 +95,7 @@
}
}
- void doIsNewObjectCheck()
+ void doIsNewObjectCheck(final TransactionImpl tx)
{
/*
detection of new objects is costly (select of ID in DB to check if object
@@ -93,13 +104,13 @@
b. check if the object is already registered
c. lookup from cache and if not found, last option select on DB
*/
- PersistenceBroker pb = tx.getBroker();
+ final PersistenceBroker pb = tx.getBroker();
boolean isNew = pb.serviceBrokerHelper().hasNullPKField(cld, obj);
if(!isNew)
{
// use method call to guaratee creation of oid
- Identity oid = getIdentity();
- ObjectEnvelope mod = tx.objectEnvelopeTable.getByIdentity(oid);
+ final Identity oid = getIdentity();
+ final ObjectEnvelope mod = tx.objectEnvelopeTable.getByIdentity(oid);
if(mod != null)
{
// already registered object, use current state
@@ -116,11 +127,26 @@
this.isNew = isNew ? Boolean.TRUE : Boolean.FALSE;
}
+ /**
+ * Return the associated persistent object.
+ */
public Object getObj()
{
return obj;
}
+ /**
+ * Returns the materialized object (if proxy is materialized or a "normal"
+ * persistent object) or <em>null</em> if associated with unmaterialized proxy object.
+ */
+ public Object getObjMaterialized()
+ {
+ return handler != null ? (handler.alreadyMaterialized() ? handler.getRealSubject() : null) : obj;
+ }
+
+ /**
+ * Returns the associated object {@link org.apache.ojb.broker.Identity}.
+ */
public Identity getIdentity()
{
if(identity == null)
@@ -130,23 +156,31 @@
return identity;
}
+ /**
+ * Returns the associated object {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
+ */
public ClassDescriptor getCld()
{
return cld;
}
+ /**
+ *
+ * @return
+ */
public boolean isNew()
{
- if(isNew == null)
- {
- doIsNewObjectCheck();
- }
return isNew.booleanValue();
}
public boolean isProxy()
{
- return isProxy;
+ return handler != null;
+ }
+
+ public IndirectionHandler getHandler()
+ {
+ return handler;
}
public String toString()
@@ -154,7 +188,8 @@
return new ToStringBuilder(this)
.append("identity", identity)
.append("isNew", isNew)
- .append("isProxy", isProxy)
+ .append("isProxy", handler != null)
+ .append("handler", handler)
.append("tx", tx)
.toString();
}
1.59.2.11 +10 -5 db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
Index: TransactionImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
retrieving revision 1.59.2.10
retrieving revision 1.59.2.11
diff -u -r1.59.2.10 -r1.59.2.11
--- TransactionImpl.java 22 Mar 2005 17:08:37 -0000 1.59.2.10
+++ TransactionImpl.java 23 Mar 2005 12:32:15 -0000 1.59.2.11
@@ -254,8 +254,10 @@
}
else
{
+ log.error("Unexpected failure while locking", t);
throw new LockNotGrantedException("Locking failed for "
- + rtObject.getIdentity()+ ", nested message is: " + t.getMessage());
+ + rtObject.getIdentity()+ ", nested message is: [" + t.getCause().getClass()
+ + ": " + t.getMessage() + "]");
}
}
}
@@ -829,7 +831,7 @@
*/
if(rtObject.isProxy())
{
- IndirectionHandler handler = ProxyHelper.getIndirectionHandler(rtObject.getObj());
+ IndirectionHandler handler = rtObject.getHandler();
if(handler == null)
{
throw new OJBRuntimeException("Unexpected error, expect an proxy object as indicated: " + rtObject);
@@ -880,8 +882,11 @@
// register associated objects
if(cascade)
{
- lockAndRegisterReferences(rtObject.getCld(), rtObject.getObj(), getImpliciteLockType(lockMode));
- lockAndRegisterCollections(rtObject.getCld(), rtObject.getObj(), getImpliciteLockType(lockMode));
+ // it's save to call RTO#getObjMaterialized because we know that
+ // the object is a non-null normal object or an materialized proxy
+ // and the method returns in any case the real object
+ lockAndRegisterReferences(rtObject.getCld(), rtObject.getObjMaterialized(), getImpliciteLockType(lockMode));
+ lockAndRegisterCollections(rtObject.getCld(), rtObject.getObjMaterialized(), getImpliciteLockType(lockMode));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org