Title: RE: [Hibernate] SpringFramework Hibernate code submission

Thats what I do now, but I feel the logic being added to the JndiTemplate would be of great use by _many_ people.  As such, I want to submit it as a patch to Jira to be added to Spring's core and not something that users would have to create on their own.  If the Spring developers don't want it, fine...but I at least want to try.

Any objections?  I'll only submit it if Gavin or Christian gives their stamp of approval...

Les

-----Original Message-----
From: Ebersole, Steve [mailto:[EMAIL PROTECTED]]
Sent: Thu 3/25/2004 10:31 AM
To: Les Hazlewood; [EMAIL PROTECTED]
Subject: RE: [Hibernate] SpringFramework Hibernate code submission

I can't speak for the usage of the code.

However, I can say that this is easy enough to handle in Spring as-is.  Simply create a JndiCallback impl which does what you're looking for.  Here's mine that does this functionality:



public class CustomBindCallback implements JndiCallback {
    private String namespace;
    private Object objectToBind;

    public CustomBindCallback(String namespace, Object objectToBind) {
        this.namespace = namespace;
        this.objectToBind = objectToBind;
    }

    public void doInContext(Context context) throws NamingException
    {
        Context tempContext = context;
        StringTokenizer tokens = new StringTokenizer(namespace, "/");
        while ( tokens.hasMoreTokens() ) {
            final String subContextName = tokens.nextToken();
            if ( tokens.hasMoreTokens() ) {
                tempContext = tempContext.createSubcontext(subContextName);
            }
            else {
                tempContext.bind(subContextName, objectToBind);
            }
        }
    }

}

Then, instead of jndiTemplate.bind(...)

just do

jndiTemplate.execute( new CustomBindCallback(...) );



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Les Hazlewood
Sent: Thursday, March 25, 2004 7:53 AM
To: [EMAIL PROTECTED]
Subject: [Hibernate] SpringFramework Hibernate code submission



Gavin, Christian, et. al,

I'm sure all of you here are aware of the Spring Framework to some extent.

I'm a user of both Spring and Hibernate, and I've come across a section of code both projects duplicate to some extent.  The code deals with JNDI lookups, binding, etc.

Spring's class that handles these things is named JndiTemplate:

http://cvs.sourceforge.net/viewcvs.py/springframework/spring/src/org/springframework/jndi/JndiTemplate.java?rev=1.6 <http://cvs.sourceforge.net/viewcvs.py/springframework/spring/src/org/springframework/jndi/JndiTemplate.java?rev=1.6&view=auto> &view=auto

Hibernate's class is net.sf.hibernate.util.NamingHelper

In attempting to use JndiTemplate's bind method, I realized it just attempts to call context.bind without checking for subcontexts and other things as Hibernate's NamingHelper.bind does so elegantly.  When using Spring's JndiTemplate.bind, I had all sorts of exceptions thrown when trying to bind to subcontexts that didn't exist (i.e. I wanted them to be created automatically). NamingHelper worked just great.

I would _really_ like to have the NamingHelper.bind logic inside of JndiTemplate to handle elegant binding, as its used so many places in Spring applications.

So, I'm here to ask your permission if I can submit code from NamingHelper.bind as a patch to Spring's JndiTemplate...from one LGPL project to another.

What do you think?  This would save a lot of folks from having to write the same logic in their custom applications because Spring doesn't handle it (like I've had to do so far).  I'm not even sure the Spring folks would accept the patch, but I'd really like to give it a try if you approve...

Any thoughts are appreciated,

Les Hazlewood




Reply via email to