#1270 - Multi-tenant - partition mode - Delete by id does not include tenantId value in predicate

This commit is contained in:
Rob Bygrave
2018-02-23 10:26:47 +13:00
parent 9aee7c892d
commit 4a243a76a7
7 changed files with 92 additions and 24 deletions
@@ -3155,6 +3155,13 @@ public class BeanDescriptor<T> implements BeanType<T> {
return versionProperty;
}
/**
* Return true if this type is tenant aware.
*/
public boolean isMultiTenant() {
return tenant != null;
}
/**
* Return the tenant property when multi-tenant partitioning support is used.
*/
@@ -578,6 +578,16 @@ public final class DefaultPersister implements Persister {
}
BeanDescriptor<?> descriptor = beanDescriptorManager.getBeanDescriptor(beanType);
boolean softDelete = !permanent && descriptor.isSoftDelete();
if (descriptor.isMultiTenant()) {
// convert to a delete by bean
for (Object id : ids) {
EntityBean bean = descriptor.createEntityBean();
descriptor.convertSetId(id, bean);
deleteRecurse(bean, transaction, permanent);
}
return ids.size();
}
ArrayList<Object> idList = new ArrayList<>(ids.size());
for (Object id : ids) {
@@ -585,7 +595,6 @@ public final class DefaultPersister implements Persister {
idList.add(descriptor.convertId(id));
}
boolean softDelete = !permanent && descriptor.isSoftDelete();
return delete(descriptor, null, idList, transaction, softDelete);
}
@@ -595,6 +604,14 @@ public final class DefaultPersister implements Persister {
@Override
public int delete(Class<?> beanType, Object id, Transaction transaction, boolean permanent) {
BeanDescriptor<?> descriptor = beanDescriptorManager.getBeanDescriptor(beanType);
if (descriptor.isMultiTenant()) {
// convert to a delete by bean
EntityBean bean = descriptor.createEntityBean();
descriptor.convertSetId(id, bean);
delete(bean, transaction, permanent);
return 1;
}
id = descriptor.convertId(id);
boolean softDelete = !permanent && descriptor.isSoftDelete();
return delete(descriptor, id, null, transaction, softDelete);
@@ -66,15 +66,4 @@ class BindableAssocOne implements Bindable {
}
}
/**
* Cast to an EntityBean allowing null.
*/
EntityBean castToEntityBean(Object objectValue) {
if (objectValue instanceof EntityBean || objectValue == null) {
return (EntityBean) objectValue;
} else {
throw new IllegalStateException("Bean " + objectValue.getClass() + " is not enhanced?");
}
}
}
@@ -0,0 +1,20 @@
package io.ebeaninternal.server.persist.dmlbind;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import java.sql.SQLException;
class BindableAssocTenant extends BindableAssocOne {
BindableAssocTenant(BeanPropertyAssocOne<?> assocOne) {
super(assocOne);
}
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean assocBean = (EntityBean) assocOne.getValue(bean);
importedId.bind(request, assocBean);
}
}
@@ -54,15 +54,4 @@ public class BindableProperty implements Bindable {
request.bind(value, prop);
}
/**
* For compound types bind one of the underlying scalar values for a compound type.
*/
public void dmlBindObject(BindableRequest request, Object bean) throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValueObject(bean);
}
request.bind(value, prop);
}
}
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.persist.dmlbind;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates a Bindable to support version concurrency where clauses.
@@ -36,6 +37,12 @@ public class FactoryVersion {
public Bindable createTenantId(BeanDescriptor<?> desc) {
BeanProperty tenant = desc.getTenantProperty();
return (tenant == null) ? null : new BindableProperty(tenant);
if (tenant == null) {
return null;
} else if (tenant instanceof BeanPropertyAssocOne) {
return new BindableAssocTenant((BeanPropertyAssocOne<?>) tenant);
} else {
return new BindableProperty(tenant);
}
}
}