NEW: CustomDeployParser

This commit is contained in:
Jonas Pöhler committed 2021-10-22 15:04:46 +02:00
1 parent 60cf9fa078
commit 50824f1d7f
15 files changed
+287 -6

No files matched your search

@@ -168,6 +168,7 @@ public final class DefaultContainer implements SpiContainer {
bootup.addPersistListeners(config.getPersistListeners());
bootup.addQueryAdapters(config.getQueryAdapters());
bootup.addServerConfigStartup(config.getServerConfigStartupListeners());
bootup.addCustomDeployParser(config.getCustomDeployParsers());
bootup.addChangeLogInstances(config);
bootup.runServerConfigStartup(config);
return bootup;
@@ -11,6 +11,7 @@ import io.ebean.event.changelog.ChangeLogPrepare;
import io.ebean.event.changelog.ChangeLogRegister;
import io.ebean.event.readaudit.ReadAuditLogger;
import io.ebean.event.readaudit.ReadAuditPrepare;
import io.ebean.plugin.CustomDeployParser;
import io.ebean.util.AnnotationUtil;
import io.ebeaninternal.api.CoreLog;
import org.slf4j.Logger;
@@ -51,6 +52,7 @@ public class BootupClasses implements Predicate<Class<?>> {
private final List<Class<? extends BeanPersistListener>> beanPersistListenerCandidates = new ArrayList<>();
private final List<Class<? extends BeanQueryAdapter>> beanQueryAdapterCandidates = new ArrayList<>();
private final List<Class<? extends ServerConfigStartup>> serverConfigStartupCandidates = new ArrayList<>();
private final List<Class<? extends CustomDeployParser>> customDeployParserCandidates = new ArrayList<>();
private final List<IdGenerator> idGeneratorInstances = new ArrayList<>();
private final List<BeanPersistController> beanPersistControllerInstances = new ArrayList<>();
@@ -60,6 +62,7 @@ public class BootupClasses implements Predicate<Class<?>> {
private final List<BeanPersistListener> beanPersistListenerInstances = new ArrayList<>();
private final List<BeanQueryAdapter> beanQueryAdapterInstances = new ArrayList<>();
private final List<ServerConfigStartup> serverConfigStartupInstances = new ArrayList<>();
private final List<CustomDeployParser> customDeployParserInstances = new ArrayList<>();
// single objects
private Class<? extends ChangeLogPrepare> changeLogPrepareClass;
@@ -169,6 +172,10 @@ public class BootupClasses implements Predicate<Class<?>> {
add(startupInstances, serverConfigStartupInstances, serverConfigStartupCandidates);
}
public void addCustomDeployParser(List<CustomDeployParser> customDeployParser) {
add(customDeployParser, customDeployParserInstances, customDeployParserCandidates);
}
public void addChangeLogInstances(DatabaseConfig config) {
readAuditPrepare = config.getReadAuditPrepare();
readAuditLogger = config.getReadAuditLogger();
@@ -285,6 +292,10 @@ public class BootupClasses implements Predicate<Class<?>> {
return createAdd(beanQueryAdapterInstances, beanQueryAdapterCandidates);
}
public List<CustomDeployParser> getCustomDeployParsers() {
return createAdd(customDeployParserInstances, customDeployParserCandidates);
}
/**
* Return the list of Embeddable classes.
*/
@@ -404,6 +415,11 @@ public class BootupClasses implements Predicate<Class<?>> {
interesting = true;
}
if (CustomDeployParser.class.isAssignableFrom(cls)) {
customDeployParserCandidates.add((Class<? extends CustomDeployParser>) cls);
interesting = true;
}
// single instances, last assigned wins
if (ChangeLogListener.class.isAssignableFrom(cls)) {
changeLogListenerClass = (Class<? extends ChangeLogListener>) cls;
@@ -74,6 +74,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
private final BeanFinderManager beanFinderManager;
private final PersistListenerManager persistListenerManager;
private final BeanQueryAdapterManager beanQueryAdapterManager;
private final CustomDeployParserManager customDeployParserManager;
private final NamingConvention namingConvention;
private final DeployCreateProperties createProperties;
private final BeanManagerFactory beanManagerFactory;
@@ -154,6 +155,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
this.persistListenerManager = new PersistListenerManager(bootupClasses);
this.beanQueryAdapterManager = new BeanQueryAdapterManager(bootupClasses);
this.beanFinderManager = new BeanFinderManager(bootupClasses);
this.customDeployParserManager = new CustomDeployParserManager(bootupClasses);
this.transientProperties = new TransientProperties();
this.changeLogPrepare = config.changeLogPrepare(bootupClasses.getChangeLogPrepare());
this.changeLogListener = config.changeLogListener(bootupClasses.getChangeLogListener());
@@ -301,6 +303,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
readEntityBeanTable();
readEntityDeploymentAssociations();
readInheritedIdGenerators();
deployInfoMap.values().forEach(customDeployParserManager::parse);
// creates the BeanDescriptors
readEntityRelationships();
List<BeanDescriptor<?>> list = new ArrayList<>(descMap.values());
@@ -0,0 +1,23 @@
package io.ebeaninternal.server.deploy;
import java.util.List;
import io.ebean.plugin.CustomDeployParser;
import io.ebeaninternal.server.core.bootup.BootupClasses;
import io.ebeaninternal.server.deploy.parse.DeployBeanInfo;
public class CustomDeployParserManager {
private final List<CustomDeployParser> parsers;
public CustomDeployParserManager(BootupClasses bootupClasses) {
parsers = bootupClasses.getCustomDeployParsers();
}
public void parse(DeployBeanInfo<?> value) {
for (CustomDeployParser parser : parsers) {
parser.parse(value.getDescriptor(), value.getUtil().getDbPlatform());
}
}
}
@@ -16,6 +16,7 @@ import io.ebean.event.BeanPostConstructListener;
import io.ebean.event.BeanPostLoad;
import io.ebean.event.BeanQueryAdapter;
import io.ebean.event.changelog.ChangeLogFilter;
import io.ebean.plugin.DeployBeanDescriptorMeta;
import io.ebean.text.PathProperties;
import io.ebean.util.AnnotationUtil;
import io.ebean.util.SplitName;
@@ -55,7 +56,7 @@ import java.util.Set;
/**
* Describes Beans including their deployment information.
*/
public class DeployBeanDescriptor<T> {
public class DeployBeanDescriptor<T> implements DeployBeanDescriptorMeta {
private static final Map<String, String> EMPTY_NAMED_QUERY = new HashMap<>();
@@ -199,7 +200,7 @@ public class DeployBeanDescriptor<T> {
/**
* Return the DeployBeanInfo for the given bean class.
*/
DeployBeanInfo<?> getDeploy(Class<?> cls) {
public DeployBeanInfo<?> getDeploy(Class<?> cls) {
return manager.deploy(cls);
}
@@ -619,6 +620,7 @@ public class DeployBeanDescriptor<T> {
* Return the base table. Only properties mapped to the base table are by
* default persisted.
*/
@Override
public String getBaseTable() {
return baseTable;
}
@@ -696,6 +698,7 @@ public class DeployBeanDescriptor<T> {
/**
* Get a BeanProperty by its name.
*/
@Override
public DeployBeanProperty getBeanProperty(String propName) {
return propMap.get(propName);
}
@@ -815,6 +818,7 @@ public class DeployBeanDescriptor<T> {
/**
* Return a collection of all BeanProperty deployment information.
*/
@Override
public Collection<DeployBeanProperty> propertiesAll() {
return propMap.values();
}
@@ -884,6 +888,7 @@ public class DeployBeanDescriptor<T> {
/**
* Return the BeanProperty that is the Id.
*/
@Override
public DeployBeanProperty idProperty() {
if (idProperty != null) {
return idProperty;
@@ -1180,4 +1185,14 @@ public class DeployBeanDescriptor<T> {
}
return base;
}
@Override
public String getDiscriminatorColumn() {
return inheritInfo == null ? null : inheritInfo.getDiscriminatorColumn();
}
@Override
public DeployBeanDescriptorMeta getDeployBeanDescriptorMeta(Class<?> propertyType) {
return getDeploy(propertyType).getDescriptor();
}
}
@@ -1,11 +1,25 @@
package io.ebeaninternal.server.deploy.meta;
import io.ebean.annotation.*;
import io.ebean.annotation.CreatedTimestamp;
import io.ebean.annotation.DocCode;
import io.ebean.annotation.DocProperty;
import io.ebean.annotation.DocSortable;
import io.ebean.annotation.Formula;
import io.ebean.annotation.MutationDetection;
import io.ebean.annotation.Platform;
import io.ebean.annotation.SoftDelete;
import io.ebean.annotation.UpdatedTimestamp;
import io.ebean.annotation.WhenCreated;
import io.ebean.annotation.WhenModified;
import io.ebean.annotation.Where;
import io.ebean.annotation.WhoCreated;
import io.ebean.annotation.WhoModified;
import io.ebean.config.ScalarTypeConverter;
import io.ebean.config.dbplatform.DbDefaultValue;
import io.ebean.config.dbplatform.DbEncrypt;
import io.ebean.config.dbplatform.DbEncryptFunction;
import io.ebean.core.type.ScalarType;
import io.ebean.plugin.DeployBeanPropertyMeta;
import io.ebean.util.AnnotationUtil;
import io.ebeaninternal.server.core.InternString;
import io.ebeaninternal.server.deploy.BeanProperty;
@@ -35,7 +49,7 @@ import java.util.Set;
* Description of a property of a bean. Includes its deployment information such
* as database column mapping information.
*/
public class DeployBeanProperty {
public class DeployBeanProperty implements DeployBeanPropertyMeta {
private static final int ID_ORDER = 1000000;
private static final int UNIDIRECTIONAL_ORDER = 100000;
@@ -406,6 +420,7 @@ public class DeployBeanProperty {
this.owningType = owningType;
}
@Override
public Class<?> getOwningType() {
return owningType;
}
@@ -434,6 +449,7 @@ public class DeployBeanProperty {
/**
* Return the name of the property.
*/
@Override
public String getName() {
return name;
}
@@ -448,6 +464,7 @@ public class DeployBeanProperty {
/**
* Return the bean Field associated with this property.
*/
@Override
public Field getField() {
return field;
}
@@ -551,6 +568,7 @@ public class DeployBeanProperty {
/**
* The property is based on a formula.
*/
@Override
public void setSqlFormula(String formulaSelect, String formulaJoin) {
this.sqlFormulaSelect = formulaSelect;
this.sqlFormulaJoin = formulaJoin.isEmpty() ? null : formulaJoin;
@@ -654,6 +672,7 @@ public class DeployBeanProperty {
/**
* The database column name this is mapped to.
*/
@Override
public String getDbColumn() {
if (sqlFormulaSelect != null) {
return sqlFormulaSelect;
@@ -847,6 +866,7 @@ public class DeployBeanProperty {
/**
* Return the property type.
*/
@Override
public Class<?> getPropertyType() {
return propertyType;
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.deploy.meta;
import io.ebean.plugin.DeployBeanPropertyAssocMeta;
import io.ebeaninternal.server.deploy.BeanCascadeInfo;
import io.ebeaninternal.server.deploy.BeanTable;
import io.ebeaninternal.server.deploy.PropertyForeignKey;
@@ -7,7 +8,7 @@ import io.ebeaninternal.server.deploy.PropertyForeignKey;
/**
* Abstract base for properties mapped to an associated bean, list, set or map.
*/
public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty implements DeployBeanPropertyAssocMeta {
/**
* The type of the joined bean.
@@ -129,6 +130,7 @@ public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
* this 'master' bean.
* </p>
*/
@Override
public String getMappedBy() {
return mappedBy;
}
@@ -173,4 +175,9 @@ public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
public void setTargetType(Class<?> targetType) {
this.targetType = (Class<T>)targetType;
}
@Override
public String getBaseTable() {
return getBeanTable().getBaseTable();
}
}