mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1204 - Check presence of JAXB and javax @PostConstruct (which may not be present in minimal Java 9)
This commit is contained in:
@@ -54,6 +54,22 @@ public class ClassLoadConfig {
|
||||
return isPresent("javax.validation.constraints.NotNull");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if javax PostConstruct annotation is present (maybe not in java9).
|
||||
* If not we don't support PostConstruct lifecycle events.
|
||||
*/
|
||||
public boolean isJavaxPostConstructPresent() {
|
||||
return isPresent("javax.annotation.PostConstruct");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if javax JAXB is present (maybe not in java9).
|
||||
* If not we don't try to parse or support 'extra ddl'.
|
||||
*/
|
||||
public boolean isJavaxJAXBPresent() {
|
||||
return isPresent("javax.xml.bind.JAXBException");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if Jackson annotations like JsonIgnore are present.
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,7 @@ public class DdlGenerator {
|
||||
private final boolean generateDdl;
|
||||
private final boolean runDdl;
|
||||
private final boolean createOnly;
|
||||
private final boolean jaxbPresent;
|
||||
|
||||
private CurrentModel currentModel;
|
||||
private String dropAllContent;
|
||||
@@ -43,6 +44,7 @@ public class DdlGenerator {
|
||||
|
||||
public DdlGenerator(SpiEbeanServer server, ServerConfig serverConfig) {
|
||||
this.server = server;
|
||||
this.jaxbPresent = serverConfig.getClassLoadConfig().isJavaxJAXBPresent();
|
||||
this.generateDdl = serverConfig.isDdlGenerate();
|
||||
this.createOnly = serverConfig.isDdlCreateOnly();
|
||||
if (serverConfig.getTenantMode().isDynamicDataSource() && serverConfig.isDdlRun()) {
|
||||
@@ -139,7 +141,7 @@ public class DdlGenerator {
|
||||
runScript(false, createAllContent, getCreateFileName());
|
||||
|
||||
String ignoreExtraDdl = System.getProperty("ebean.ignoreExtraDdl");
|
||||
if (!"true".equalsIgnoreCase(ignoreExtraDdl)) {
|
||||
if (!"true".equalsIgnoreCase(ignoreExtraDdl) && jaxbPresent) {
|
||||
String extraApply = ExtraDdlXmlReader.buildExtra(server.getDatabasePlatform().getName());
|
||||
if (extraApply != null) {
|
||||
runScript(false, extraApply, "extra-dll");
|
||||
|
||||
@@ -227,7 +227,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
this.updateChangesOnly = serverConfig.isUpdateChangesOnly();
|
||||
|
||||
this.beanLifecycleAdapterFactory = new BeanLifecycleAdapterFactory();
|
||||
this.beanLifecycleAdapterFactory = new BeanLifecycleAdapterFactory(serverConfig);
|
||||
this.persistControllerManager = new PersistControllerManager(bootupClasses);
|
||||
this.postLoadManager = new PostLoadManager(bootupClasses);
|
||||
this.postConstructManager = new PostConstructManager(bootupClasses);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.annotation.PostSoftDelete;
|
||||
import io.ebean.annotation.PreSoftDelete;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.event.BeanPersistAdapter;
|
||||
import io.ebean.event.BeanPersistRequest;
|
||||
import io.ebean.event.BeanPostConstructListener;
|
||||
@@ -31,6 +32,12 @@ import java.util.List;
|
||||
*/
|
||||
class BeanLifecycleAdapterFactory {
|
||||
|
||||
private final boolean postConstructPresent;
|
||||
|
||||
BeanLifecycleAdapterFactory(ServerConfig serverConfig) {
|
||||
this.postConstructPresent = serverConfig.getClassLoadConfig().isJavaxPostConstructPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BeanPersistController for methods annotated with lifecycle events.
|
||||
*/
|
||||
@@ -41,7 +48,7 @@ class BeanLifecycleAdapterFactory {
|
||||
// look for annotated methods
|
||||
MethodsHolder methodHolder = new MethodsHolder();
|
||||
for (Method m : methods) {
|
||||
methodHolder.checkMethod(m);
|
||||
methodHolder.checkMethod(m, postConstructPresent);
|
||||
}
|
||||
|
||||
if (methodHolder.hasPersistMethods()) {
|
||||
@@ -86,7 +93,7 @@ class BeanLifecycleAdapterFactory {
|
||||
/**
|
||||
* Check the method for all the annotations we are interested in.
|
||||
*/
|
||||
private void checkMethod(Method method) {
|
||||
private void checkMethod(Method method, boolean postConstructPresent) {
|
||||
if (method.isAnnotationPresent(PrePersist.class)) {
|
||||
preInserts.add(method);
|
||||
hasPersistMethods = true;
|
||||
@@ -125,8 +132,10 @@ class BeanLifecycleAdapterFactory {
|
||||
if (method.isAnnotationPresent(PostLoad.class)) {
|
||||
postLoads.add(method);
|
||||
}
|
||||
if (method.isAnnotationPresent(PostConstruct.class)) {
|
||||
postConstructs.add(method);
|
||||
if (postConstructPresent) {
|
||||
if (method.isAnnotationPresent(PostConstruct.class)) {
|
||||
postConstructs.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user