db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clute, Andrew" <Andrew.Cl...@osn.state.oh.us>
Subject RE: Pluggable IndirectionHandler
Date Fri, 02 Apr 2004 19:14:36 GMT
Seems like this might have gotten forgotten.

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


-----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

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
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
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.


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
2. Corrected  IndirectionHandlerImpl class declaration:
-public class IndirectionHandler implements InvocationHandler,
Serializable {
+public class IndirectionHandlerImpl implements IndirectionHandler {
3. Added new method to interface
     * @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
    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
Added the static variable that holds IndirectionHandler constructor (and
initializer for it) :

    private static final Constructor
    static {
        Class indirectionHandlerClass = null;
        try {
            PersistenceBrokerConfiguration config =
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
    public static IndirectionHandler createIndirectionHandler (PBKey
key, Identity realSubjectsIdentity) {
        if (indirectionHandlerConstructorUserDefined != null) {
            Object [] params = new Object [] { key,
            try {
                return (IndirectionHandler)
indirectionHandlerConstructorUserDefined.newInstance (params);
            } catch (Throwable e) {
                throw new PersistenceBrokerException("Error
instantiating custom IndirectionHandler", e);
        } else {
            return new IndirectionHandlerImpl (key,

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,
+            InvocationHandler handler = createIndirectionHandler(key,

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 =
+    private static Logger log;
    public IndirectionHandlerImpl(PBKey key, Identity oid)
        this.id = oid;
+        if (log == null)
+            log = LoggerFactory.getLogger(IndirectionHandler.class);

All the Best,

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

View raw message