Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15x] Remove Inheritance support #3211

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions ebean-api/src/main/java/io/ebean/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -1643,28 +1643,6 @@ default Query<T> setUseQueryCache(boolean enabled) {
*/
Class<T> getBeanType();

/**
* Restrict the query to only return subtypes of the given inherit type.
*
* <pre>{@code
*
* List<Animal> animals =
* new QAnimal()
* .name.startsWith("Fluffy")
* .setInheritType(Cat.class)
* .findList();
*
* }</pre>
*
* @param type An inheritance subtype of the
*/
Query<T> setInheritType(Class<? extends T> type);

/**
* Returns the inherit type. This is normally the same as getBeanType() returns as long as no other type is set.
*/
Class<? extends T> getInheritType();

/**
* Return the type of query being executed.
*/
Expand Down
47 changes: 0 additions & 47 deletions ebean-api/src/main/java/io/ebean/plugin/BeanType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import io.ebean.event.BeanQueryAdapter;

import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

/**
* Information and methods on BeanDescriptors made available to plugins.
Expand Down Expand Up @@ -144,49 +142,4 @@ public interface BeanType<T> {
*/
IdType idType();

/**
* Add the discriminator value to the query if needed.
*/
void addInheritanceWhere(Query<?> query);

/**
* Return the root bean type for an inheritance hierarchy.
*/
BeanType<?> root();

/**
* Return true if this bean type has an inheritance hierarchy.
*/
boolean hasInheritance();

/**
* Return true if this object is the root level object in its entity
* inheritance.
*/
boolean isInheritanceRoot();

/**
* Returns all direct children of this beantype
*/
List<BeanType<?>> inheritanceChildren();

/**
* Returns the parent in inheritance hierarchy
*/
BeanType<?> inheritanceParent();

/**
* Visit all children recursively
*/
void visitAllInheritanceChildren(Consumer<BeanType<?>> visitor);

/**
* Return the discriminator column.
*/
String discColumn();

/**
* Create a bean given the discriminator value.
*/
T createBeanUsingDisc(Object discValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,4 @@ public interface LoadContext {
*/
void register(String path, BeanPropertyAssocMany<?> many, BeanCollection<?> bc);

/**
* Use soft-references for streaming queries, so unreachable entries can be garbage collected.
*/
void useReferences(boolean useReferences);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public final class CachedBeanData implements Externalizable {

private long whenCreated;
private long version;
private String discValue;
private Map<String, Object> data;
/**
* The sharable bean is effectively transient (near cache only).
Expand All @@ -25,10 +24,9 @@ public final class CachedBeanData implements Externalizable {
/**
* Construct from a loaded bean.
*/
public CachedBeanData(Object sharableBean, String discValue, Map<String, Object> data, long version) {
public CachedBeanData(Object sharableBean, Map<String, Object> data, long version) {
this.whenCreated = System.currentTimeMillis();
this.sharableBean = sharableBean;
this.discValue = discValue;
this.data = data;
this.version = version;
}
Expand All @@ -43,11 +41,6 @@ public CachedBeanData() {
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(version);
out.writeLong(whenCreated);
boolean hasDisc = discValue != null;
out.writeBoolean(hasDisc);
if (hasDisc) {
out.writeUTF(discValue);
}
out.writeInt(data.size());
for (Map.Entry<String, Object> entry : data.entrySet()) {
out.writeUTF(entry.getKey());
Expand All @@ -59,9 +52,6 @@ public void writeExternal(ObjectOutput out) throws IOException {
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
version = in.readLong();
whenCreated = in.readLong();
if (in.readBoolean()) {
discValue = in.readUTF();
}
data = new LinkedHashMap<>();
int count = in.readInt();
for (int i = 0; i < count; i++) {
Expand All @@ -85,7 +75,7 @@ public CachedBeanData update(Map<String, Object> changes, long version) {
Map<String, Object> copy = new HashMap<>();
copy.putAll(data);
copy.putAll(changes);
return new CachedBeanData(null, discValue, copy, version);
return new CachedBeanData(null, copy, version);
}

/**
Expand All @@ -102,13 +92,6 @@ public long getVersion() {
return version;
}

/**
* Return the raw discriminator value.
*/
public String getDiscValue() {
return discValue;
}

/**
* Return a sharable (immutable read only) bean. Near cache only use.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static CachedBeanData extract(BeanDescriptor<?> desc, EntityBean bean) {

long version = desc.getVersion(bean);
EntityBean sharableBean = createSharableBean(desc, bean, ebi);
return new CachedBeanData(sharableBean, desc.discValue(), data, version);
return new CachedBeanData(sharableBean, data, version);
}

private static EntityBean createSharableBean(BeanDescriptor<?> desc, EntityBean bean, EntityBeanIntercept beanEbi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public static void load(BeanDescriptor<?> desc, EntityBean bean, CachedBeanData
// any future lazy loading skips L2 bean cache
ebi.setLoadedFromCache(true);
BeanProperty idProperty = desc.idProperty();
if (desc.inheritInfo() != null) {
desc = desc.inheritInfo().readType(bean.getClass()).desc();
}
if (idProperty != null) {
// load the id property
loadProperty(bean, cacheBeanData, ebi, idProperty, context);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.InheritInfo;
import io.ebeaninternal.server.dto.DtoBeanDescriptor;
import io.ebeaninternal.server.dto.DtoBeanManager;
import io.ebeaninternal.server.el.ElFilter;
Expand Down Expand Up @@ -595,25 +594,7 @@ public <T> T reference(Class<T> type, Object id) {
return (T) existing;
}
}
InheritInfo inheritInfo = desc.inheritInfo();
if (inheritInfo == null || inheritInfo.isConcrete()) {
return (T) desc.contextRef(pc, null, false, id);
}
return referenceFindOne(type, id, desc);
}

private <T> T referenceFindOne(Class<T> type, Object id, BeanDescriptor<?> desc) {
BeanProperty idProp = desc.idProperty();
if (idProp == null) {
throw new PersistenceException("No ID properties for this type? " + desc);
}
// we actually need to do a query because we don't know the type without the discriminator
// value, just select the id property and discriminator column (auto added)
T bean = find(type).select(idProp.name()).setId(id).findOne();
if (bean == null) {
throw new EntityNotFoundException("Could not find reference bean " + id + " for " + desc);
}
return bean;
return (T) desc.contextRef(pc, null, false, id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
import io.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
import io.ebeaninternal.server.deploy.parse.DeployCreateProperties;
import io.ebeaninternal.server.deploy.parse.DeployInherit;
import io.ebeaninternal.server.deploy.parse.DeployUtil;
import io.ebeaninternal.server.dto.DtoBeanManager;
import io.ebeaninternal.server.expression.DefaultExpressionFactory;
Expand Down Expand Up @@ -64,7 +63,6 @@ public final class InternalConfiguration {
private final DatabaseConfig config;
private final BootupClasses bootupClasses;
private final DatabasePlatform databasePlatform;
private final DeployInherit deployInherit;
private final TypeManager typeManager;
private final DtoBeanManager dtoBeanManager;
private final ClockService clockService;
Expand Down Expand Up @@ -105,7 +103,6 @@ public final class InternalConfiguration {
this.expressionFactory = initExpressionFactory(config);
this.typeManager = new DefaultTypeManager(config, bootupClasses);
this.multiValueBind = createMultiValueBind(databasePlatform.platform());
this.deployInherit = new DeployInherit(bootupClasses);
this.deployCreateProperties = new DeployCreateProperties(typeManager);
this.deployUtil = new DeployUtil(typeManager, config);
this.serverCachePlugin = initServerCachePlugin();
Expand Down Expand Up @@ -295,10 +292,6 @@ BeanDescriptorManager getBeanDescriptorManager() {
return beanDescriptorManager;
}

public DeployInherit getDeployInherit() {
return deployInherit;
}

public DeployCreateProperties getDeployCreateProperties() {
return deployCreateProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public void initTransIfRequired() {
persistenceContext.beginIterate();
}
loadContext = new DLoadContext(this, secondaryQueries);
loadContext.useReferences(Type.ITERATE == query.type());
}

/**
Expand Down
Loading