openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@bea.com>
Subject RE: Testing an OpenJPA module
Date Wed, 11 Apr 2007 17:36:18 GMT
>From findAllProviders():

        Enumeration<URL> resources = 
            loader.getResources("META-INF/services/" +
PersistenceProvider.class.getName());

If no resources are found, we've got a useful nugget of information: no
persistence providers are available in the current classloader.

Later in findAllProviders():

        for (String s : names) {
            try{
 
providers.add((PersistenceProvider)loader.loadClass(s).newInstance());
            } catch (ClassNotFoundException exc){
            } catch (InstantiationException exc){
            } catch (IllegalAccessException exc){
            }
        }

In each of these catch blocks, we're throwing away information. If we
get an exception here, it means that a resource was listed in the
services lookup, but one of the classes listed wasn't loadable.


>From createEntityManagerFactory():

            try{
                findAllProviders();
            } catch (IOException exc){};

It's unclear why this IOException would be consumed. It is propagated up
from the findAllProviders() resource-lookup code. Again, this is useful
information for the exception that's thrown later.


IMO, the methods in this class should do a better job of tracking
problems as they happen, and using this information for notifying the
calling code about why a failure might have happened. I would recommend
using the cause slot in the thrown exception for more detail, and
putting more descriptive text in place for certain common cases.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc. 

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Marina.Vatkina@Sun.COM [mailto:Marina.Vatkina@Sun.COM] 
> Sent: Wednesday, April 11, 2007 10:11 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Testing an OpenJPA module
> 
> Are we looking at different classes? I can't find the code in 
> javax.persistence.Persistence under GlassFish that looks up 
> persistence units. 
> It's all delegated to the providers.
> 
> thanks,
> -marina
> 
> Patrick Linskey wrote:
> >>If a provider does not qualify as the provider for the named 
> >>persistence unit, 
> >>it must return null when createEntityManagerFactory is 
> invoked on it.
> > 
> > 
> > That's what the provider must do when
> > PersistenceProvider.createEntityManagerFactory() is called, 
> not what the
> > Persistence class must do.
> > 
> > As you can see in the code, Persistence already throws 
> exceptions if it
> > can't find any persistence units. It could just be a bit more
> > informative about why. 
> > 
> > -Patrick
> > 
> 
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA
Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,
 copyrighted  and/or legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient, and have received
this message in error, please immediately return this by email and then delete it.

Mime
View raw message