> > I might explore moving this from the configuration file to the OM
> > objects. E.g. instead of calling Torque.getManager() the base
> > object/peer has a default manager which can be over-ridden in the
> > extension class. Does this sound like a good idea?
> 
> It sounds like a good addition, but I don't think it can replace the
> Torque.getManager().  I see a chicken/egg problem.

I've attached a patch that lets you not specify managers in the
configuration and instead they default to the generated peers. It could
be considered a hack, but I think it works. 

Basically in the managers template, I added DEFAULT_MANAGER_CLASSNAME,
which is a static string of the manager class itself. Then in
getManager(), instead of just calling Torque.getManager(key), I pass
that static string as the default classname.

Inside the Torque.getManager(key, defaultClassname), it checks to see if
the key is already in the managers map. If not, it adds the key with the
defaultClassname, just as if it had come from the configuration via the
initManager method.

So you can't use the straight Torque.getManager("ThisClass") from your
client code, but you can use ThisClassManager.getInstance() and it'll
work fine (and unless I'm using the managers wrong, I go with the
ThisClassManager.getInstance method anyway).

- Stephen
Index: src/templates/om/BaseManager.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/BaseManager.vm,v
retrieving revision 1.7
diff -r1.7 BaseManager.vm
44a45,48
>     
>     /** The name of our class to pass to Torque as the default manager. */
>     protected static String DEFAULT_MANAGER_CLASS
>         = "${package}.${interfaceName}Manager";
55c59,60
<             Torque.getManager(${interfaceName}Manager.MANAGER_NAME);    
---
>             Torque.getManager(${interfaceName}Manager.MANAGER_NAME, 
>                 ${interfaceName}Manager.DEFAULT_MANAGER_CLASS);

Index: src/java/org/apache/torque/Torque.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.61
diff -r1.61 Torque.java
602c602,646
<         return (AbstractBaseManager) managers.get(name);
---
>         AbstractBaseManager m = (AbstractBaseManager) managers.get(name);
>         if (m == null)
>         {
>             category.error("No configured manager for key " + name + ".");
>         }
>         return m;
>     }
> 
>     /**
>      * This methods returns either the Manager from the configuration file,
>      * or the default one provided by the generated code.
>      *
>      * @param name
>      * @param defaultClassName the class to use if name has not been configured
>      * @return a Manager
>      */
>     public static AbstractBaseManager getManager(String name, String 
>defaultClassName)
>     {
>         AbstractBaseManager m = (AbstractBaseManager) managers.get(name);
>         if (m == null)
>         {
>             // Synchronize just in case?
>             synchronized(Torque.class)
>             {
>                 if (managers.get(name) == null)
>                 {
>                     category.debug("Added Mapping for Manager: "
>                         + name + " -> " + defaultClassName);
> 
>                     try
>                     {
>                         initManager(name, defaultClassName);
>                     }
>                     catch (TorqueException e)
>                     {
>                         category.error(e.getMessage(), e);
>                     }
>                 }
>             }
> 
>             // Try again now that the default manager should be in the managers map
>             m = (AbstractBaseManager) managers.get(name);
>         }
> 
>         return m;

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to