rmannibucau commented on code in PR #321:
URL: https://github.com/apache/openjpa/pull/321#discussion_r4691940195
##########
openjpa-kernel/src/main/java/org/apache/openjpa/cdi/EntityListenerFactoryValue.java:
##########
@@ -29,10 +30,29 @@ public class EntityListenerFactoryValue extends PluginValue
{
public EntityListenerFactoryValue() {
super(KEY, false);
String[] aliases = new String[] {
- DEFAULT_ALIAS,
EntityListenerFactoryImpl.class.getName()
+ DEFAULT_ALIAS,
EntityListenerCachedFactory.class.getName()
};
setAliases(aliases);
setDefault(aliases[0]);
}
+ @Override
+ public Object instantiate(Class<?> type, Configuration c, boolean
fatal) {
+ if (isBeanManagerAPIAvailable()) {
+
setClassName("org.apache.openjpa.cdi.EntityListenerCDIFactory");
+ } else {
+
setClassName(EntityListenerCachedFactory.class.getName());
+ }
+ return super.instantiate(type, c, fatal);
+ }
+
+ private boolean isBeanManagerAPIAvailable() {
+ try {
+ // false avoids running static initializers just to
check existence
+
Class.forName("jakarta.enterprise.inject.spi.BeanManager", false,
EntityListenerCDIFactory.class.getClassLoader());
Review Comment:
maybe dont test if the api is there but if the BM is available (do the
lookup)
this is not perfect and has several pitfall but it is better than testing
API presence (for ex at some point it was in maven which doesnt have any cdi
impl)
alternative is to just not enable it automatically which will avoid the cost
to lookup the BM when not needed (most cases I guess)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]