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 "Clute, Andrew" <An...@osn.state.oh.us> on 2004/04/02 21:14:36 UTC

RE: Pluggable IndirectionHandler

 
Seems like this might have gotten forgotten.

Has any have thoughts on when we could introduce this to the CVS tree?

-Andrew




-----Original Message-----
From: Clute, Andrew [mailto:Andrew.Clute@osn.state.oh.us] 
Sent: Wednesday, February 18, 2004 1:23 PM
To: Andy Malakov; Brian McCallister; Armin Waibel
Cc: OJB Developers List
Subject: RE: Pluggable IndirectionHandler

Andy,
 
That code looks exactly like I had done before it was suggested to
create the IndirectionHandlerInterface ... so, looks good to me!
 
Couple points it made me think of though...
 
1) If the goal is to have a clean interface for IH -- should we not
create an AbstractIndirectionHandler that contains the majority of the
code, but with the materalizeSubject() method marked as abstract, and
then move the implementation of that method to IndirectionHandlerImpl?
This will allow for other implementations to extend the Abstract class,
and only have to worry about coding the materalizeSubject() method --
which is really the one and only point of differantation between
implementations?
 
2) Should we mutate CollectionsProxy to use the same pattern as
IndirectionHandler? Both need to worry about have to materialize
subjects -- but CollectionsProxy right now is a single concrete class
that needs to be extended, which we tried to get away from doing with
IH.
 
Thoughts?
 
Personally, I would like to see this code introduced to the tree ASAP,
so I can continue on my path, even it is added to another branch, as not
to taint the 1.0 release.
 
-Andrew
 
 

________________________________

From: Andy Malakov [mailto:andy@transdecisions.com]
Sent: Tuesday, February 17, 2004 7:44 PM
To: Brian McCallister; Clute, Andrew; Armin Waibel
Subject: Re: Pluggable IndirectionHandler


Hello guys,
 
These changes work on my current build and I would be happy if you
eventually incorporate them into OJB.
 
Here is the list of changes that I did :
 
1. Renamed org.apache.ojb.broker.accesslayer.IndirectionHandler as
IndirectionHandlerImpl and created interface IndirectionHandler
(attached).
 
2. Corrected  IndirectionHandlerImpl class declaration:
 
-public class IndirectionHandler implements InvocationHandler,
Serializable {
+public class IndirectionHandlerImpl implements IndirectionHandler {
 
3. Added new method to interface
org.apache.ojb.broker.core.PersistenceBrokerConfiguration:
 
    /**
     * @return subclass of IndirectionHandler that will be used as
InvocationHandler for proxy objects.
     */
    public Class getIndirectionHandlerClass ();
 
4. Provided implementation for the above new method in
org.apache.ojb.broker.util.configuration.impl.OjbConfiguration:
 
    private Class indirectionHandlerClass;
 

    protected void load()
    {
     ...
+        // load IndirectionHandler Class
+        indirectionHandlerClass = getClass("IndirectionHandlerClass",
IndirectionHandlerImpl.class, IndirectionHandler.class);
    }
    
    /**
     * @return subclass of IndirectionHandler that will be used as
InvocationHandler for proxy objects.
     */
    public Class getIndirectionHandlerClass () {
        return indirectionHandlerClass;
    }    
    
5. Changed class org.apache.ojb.broker.VirtualProxy to use customizable
IndirectionHandler. 
 
Added the static variable that holds IndirectionHandler constructor (and
initializer for it) :
 

    private static final Constructor
indirectionHandlerConstructorUserDefined;
 
    static {
        Class indirectionHandlerClass = null;
        try {
            PersistenceBrokerConfiguration config =
                (PersistenceBrokerConfiguration)
OjbConfigurator.getInstance ().getConfigurationFor (null);
 
            indirectionHandlerClass = config.getCollectionProxyClass ();
            if (indirectionHandlerClass != null &&
indirectionHandlerClass != IndirectionHandlerImpl.class) {
                Class paramType[] = {PBKey.class, Identity.class};
                indirectionHandlerConstructorUserDefined =
indirectionHandlerClass.getConstructor (paramType);
            } else {
                indirectionHandlerConstructorUserDefined = null; // will
use default IndirectionHandlerImpl
            }
        } catch (Exception e) {
            throw new PersistenceBrokerException ("Could not build
constructor for indirectionHandler class [" +
 
indirectionHandlerClass + "] defined in configuration", e);
        }
    }
    
 
Created new factory method for IndirectionHandler instance creation:
 
    
    /**
     * Static factory method for IndirectionHandler instances
     * @param key the PersistenceBroker Key
     * @param realSubjectsIdentity org.apache.ojb.broker.Identity
     * @return IndirectionHandler or user-defined subclass of
IndirectionHandler
     */
    public static IndirectionHandler createIndirectionHandler (PBKey
key, Identity realSubjectsIdentity) {
        if (indirectionHandlerConstructorUserDefined != null) {
            Object [] params = new Object [] { key,
realSubjectsIdentity};
            try {
                return (IndirectionHandler)
indirectionHandlerConstructorUserDefined.newInstance (params);
            } catch (Throwable e) {
                throw new PersistenceBrokerException("Error
instantiating custom IndirectionHandler", e);
            }
        } else {
            return new IndirectionHandlerImpl (key,
realSubjectsIdentity);
        }
    }

Changed the places where OJB constructs IndirectionHandler to call new
factoty method (below)
 
    public VirtualProxy(PBKey key, Identity oid)
    {
-        this.indirectionHandler = new IndirectionHandler(key, oid);
+        this.indirectionHandler = createIndirectionHandler(key, oid);
    }
 

    /**
     * static factory method creates VirtualProxy instances of a given
subclass and an real subjects identity.
     * @return org.apache.ojb.app.VirtualProxy
     * @param proxyClass java.lang.Class
     * @param realSubjectsIdentity org.apache.ojb.broker.Identity
     * @param key the PersistenceBroker Key
     *
     * @throws PersistenceBrokerException if there is an error creating
the proxy object
     */
    public static Object createProxy(PBKey key, Class proxyClass,
Identity realSubjectsIdentity)
    {
        ...
-            InvocationHandler handler = new IndirectionHandler(key,
realSubjectsIdentity);
+            InvocationHandler handler = createIndirectionHandler(key,
realSubjectsIdentity);
        ...
    }
    

6. To workaround circular dependecny Logger-Configuration changed the
way IndirectionHandlerImpl creates Logger (see "chicken and egg"
discussion topic in OJB-DEV). 
 
-    private static Logger log =
LoggerFactory.getLogger(IndirectionHandler.class);
+    private static Logger log;
 
    public IndirectionHandlerImpl(PBKey key, Identity oid)
    {
        this.id = oid;
+        if (log == null)
+            log = LoggerFactory.getLogger(IndirectionHandler.class);
 
        setBrokerKey(key);
    }


All the Best,
Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


RE: Pluggable IndirectionHandler

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Fri, 2 Apr 2004, Clute, Andrew wrote:

> Seems like this might have gotten forgotten.
> 
> Has any have thoughts on when we could introduce this to the CVS tree?

Too bad you didn't discuss this on the dev list, otherwise I'd have had
integrated this already ;-) If nobody else has time, I could add it next
week.

Two little things:

* the name of the existing IndirectionHandler implementation should
perhaps have a 'Default' in its name, e.g. IndirectionHandlerDefaultImpl 
or DefaultIndirectionHandlerImpl or the like

* the handling in ProxyHelper has been missed but is important; also some
of the stuff (e.g. createIndirectionHandler, createProxy) should rather be
in ProxyHelper to have it all in one place

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org