openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: JPA2 - When should createEMF() return an Exception vs. NULL?
Date Fri, 24 Jul 2009 01:18:24 GMT

The bootstrap should ask all (say N) available providers to createEMF().
If any of them throws exception or return null, the bootstrap should
continue asking rest of the providers.
After all N provides have been queried by the bootstrap, let us say M
providers have returned a valid EMF.


1. Log exceptions or null, as the case may be, for each of the (N-M) failed
providers to give a deployer a chance to know what went wrong.

2. if (M == 1)
   return the only good one. 
else if (M > 1)
   tricky. Non-partisan approach will be to throw exception explaining that
providers are behaving badly.
   Partisan behavior will be to return OpenJPA provider, if exists. If not
the first one (unfair, because *first* is ambiguous/non-deterministic).
else // M = 0
   return null or throw exception

The key points are
a) robust: not to let one *failed* provider spoil the chance of other good
ones
b) fair: not to prefer one provider over another (slight bias towards
OpenJPA is OK:). This will address the  case of more than one provider
returning non-null EMF. Also do not return immediately at the first non-null
EMF. Because the ordering on provider is inherently non-deterministic due to
the nature of the discovery process.
c) helpful: provide as much contextual info as possible for diagnosis (the
deployer/developer will be pleased)
   

So if OpenJPA is throwing exception on unsupported openjpa.Specification
property value, let it continue to do so. Others may return null under
certain circumstances, or throw exception in another.

Absorb the provider implementation variations in the bootstrap. 


-----
Pinaki 
-- 
View this message in context: http://n2.nabble.com/JPA2---When-should-createEMF%28%29-return-an-Exception-vs.-NULL--tp3312130p3313234.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Mime
View raw message