db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Armin Waibel" <ar...@code-au-lait.de>
Subject Re: [Proxy & Identity problem] Bug? & solution
Date Sun, 25 May 2003 00:01:54 GMT
Hi all,

>
> currently I checked in some modified test cases
> using references. I think (but I don't know) we
> have a bug using extent classes as reference.
>

I checked in the described changes
(see below). The test is passing now. Seems
that are no side-effects in related tests.
Please review the made changes.

regards,
Armin

> ********************
> problem
> ********************
> See
> org.apache.ojb.broker.ReferenceTest
> one test fail
>
>
[org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl]
> ERROR: while set field:
> object class[ org.apache.ojb.broker.ReferenceTest$Repository
> target field: refA
> target field type: interface
> org.apache.ojb.broker.ReferenceTest$ReferenceAIF
> object value class: org.apache.ojb.broker.ReferenceTest$Reference
> object value: org.apache.ojb.broker.ReferenceTest$Reference@1024864]
> .....
>
> The field 'refA' is a reference. I use the following data structure:
>
> class Repository is the main persistent object, containing
> three references of type:
> ReferenceIF    (field called ref)
> ReferenceAIF extends ReferenceIF   (field called refA)
> ReferenceBIF extends ReferenceIF   (field called refB)
>
> <snip>
> public static class Repository implements Serializable
>     {
>         private Integer repId;
>
>         private Integer refId;
>         private Integer refAId;
>         private Integer refBId;
>
>         private ReferenceIF ref;
>         private ReferenceAIF refA;
>         private ReferenceBIF refB;
> ....
> </snip>
>
> Repository class field 'refA' expect type ReferenceAIF,
> but OJB try to set a value of type Reference (the implementation
> class of ReferenceIF).
> ***************************
> causation
> ***************************
> method getReferencedObject(Object obj, ObjectReferenceDescriptor rds,
> ClassDescriptor cld)
> in PersistenceBrokerImpl always use to top-level class to get the
> reference object --> in our case the top-level class of class
ReferenceA
> is class Reference and this is exactly what's going wrong.
>
> The main problem is Identity class. Identity discriminate between
> 'objectsClass' and 'objectsRealClass' (better synonyms could be
> 'topLevelClass'/'realClass' ), but many times in code we
> only set the top-level class by using the
> Identity(Class aClass, Object[] pkValues)
> constructor.
> **************************
> solution??
> **************************
> Local I adopt a new constructor
> Identity(Class realClass, Class topLevel, Object[] pkValues)
>
> in PBImpl I changed
>
> private Object getReferencedObject(Object obj,
ObjectReferenceDescriptor
> rds, ClassDescriptor cld)
>     {
>         .....
>
>         // ensure that top-level extents are used for Identities
>         referencedClass =
> descriptorRepository.getTopLevelClass(rds.getItemClass());
>
>         if (rds.isLazy())
>         {
>             /*
>             arminw:
>             use real reference class instead of the top-level class,
>             because we want to use a proxy representing the real class
>             not only the top-level class - right?
>             */
>             ###> referencedProxy =
> getClassDescriptor(rds.getItemClass()).getDynamicProxyClass();
>         }
>         else
>         {
>             referencedProxy = rds.getItemProxyClass();
>         }
>
>         if (referencedProxy != null)
>         {
>             try
>             {
> ###>                return VirtualProxy.createProxy(getPBKey(),
> referencedProxy, new Identity(rds.getItemClass(),referencedClass,
> pkVals));
>             }
>             catch (Exception e)
>             {
>                 logger.error("Error instantiating obj: " +
> e.getMessage(), e);
>                 throw new PersistenceBrokerException(e);
>             }
>         }
>         else
>         {
> ###>            return getObjectByIdentity(new
> Identity(rds.getItemClass(), referencedClass, pkVals));
>         }
>     }
>
> After this modifications all tests passed well.
>
> What do you think? Bug&solution or do I misinterpret
> things in OJB?
>
> regards,
> Armin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>



Mime
View raw message