TenantId factory method fromUUID added to reduce optimize TenantId instances count in heap memory. Factory as default @JsonCreator
This commit is contained in:
parent
6f19efd539
commit
48ac1a256e
@ -15,23 +15,31 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.id;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class TenantId extends UUIDBased implements EntityId {
|
||||
|
||||
@JsonIgnore
|
||||
public static final TenantId SYS_TENANT_ID = new TenantId(EntityId.NULL_UUID);
|
||||
|
||||
static final ConcurrentReferenceHashMap<UUID, TenantId> tenants = new ConcurrentReferenceHashMap<>(16, ReferenceType.SOFT);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonCreator
|
||||
public TenantId(@JsonProperty("id") UUID id) {
|
||||
public static TenantId fromUUID(@JsonProperty("id") UUID id) {
|
||||
return tenants.computeIfAbsent(id, TenantId::new);
|
||||
}
|
||||
|
||||
public TenantId(UUID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user