mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix multi tenant bean change (#982)
* FIX: beanChange has tenant-id * FIX: NPE in DefaultServer.currentTenantId()
This commit is contained in:
committed by
Rob Bygrave
parent
23e1ab4bfd
commit
5f63d5c35f
@@ -14,6 +14,11 @@ public class BeanChange {
|
||||
*/
|
||||
String table;
|
||||
|
||||
/**
|
||||
* The tenantId value.
|
||||
*/
|
||||
Object tenantId;
|
||||
|
||||
/**
|
||||
* The id value.
|
||||
*/
|
||||
@@ -37,8 +42,9 @@ public class BeanChange {
|
||||
/**
|
||||
* Construct with all the details.
|
||||
*/
|
||||
public BeanChange(String table, Object id, ChangeType type, Map<String, ValuePair> values) {
|
||||
public BeanChange(String table, Object tenantId, Object id, ChangeType type, Map<String, ValuePair> values) {
|
||||
this.table = table;
|
||||
this.tenantId = tenantId;
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.eventTime = System.currentTimeMillis();
|
||||
@@ -53,7 +59,7 @@ public class BeanChange {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "table:" + table + " id:" + id + " values:" + values;
|
||||
return "table:" + table + " tenantId: " + tenantId + " id:" + id + " values:" + values;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +76,20 @@ public class BeanChange {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the tenant id.
|
||||
*/
|
||||
public Object getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bean id (for JSON tools).
|
||||
*/
|
||||
public void setTenantId(Object tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object id.
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,9 @@ public class ChangeJsonBuilder {
|
||||
writeBeanTransactionDetails(gen, changeSet, position);
|
||||
|
||||
gen.writeStringField("object", bean.getTable());
|
||||
if (bean.getTenantId() != null) {
|
||||
gen.writeStringField("tenantId", bean.getTenantId().toString());
|
||||
}
|
||||
gen.writeStringField("objectId", bean.getId().toString());
|
||||
gen.writeStringField("change", bean.getType().getCode());
|
||||
gen.writeNumberField("eventTime", bean.getEventTime());
|
||||
|
||||
@@ -314,7 +314,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
|
||||
@Override
|
||||
public Object currentTenantId() {
|
||||
return currentTenantProvider.currentId();
|
||||
return currentTenantProvider == null ? null : currentTenantProvider.currentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -837,7 +837,8 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
}
|
||||
|
||||
private BeanChange newBeanChange(Object id, ChangeType changeType, Map<String, ValuePair> values) {
|
||||
return new BeanChange(getBaseTable(), id, changeType, values);
|
||||
Object tenantId = ebeanServer.currentTenantId();
|
||||
return new BeanChange(getBaseTable(), tenantId, id, changeType, values);
|
||||
}
|
||||
|
||||
public SqlUpdate deleteById(Object id, List<Object> idList, boolean softDelete) {
|
||||
|
||||
Reference in New Issue
Block a user