|
|
@ -64,8 +64,10 @@ import java.util.Arrays; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
import java.util.HashSet; |
|
|
import java.util.HashSet; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.concurrent.locks.Lock; |
|
|
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE; |
|
|
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE; |
|
|
import static org.thingsboard.server.dao.service.Validator.validateId; |
|
|
import static org.thingsboard.server.dao.service.Validator.validateId; |
|
|
@ -101,6 +103,8 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CacheManager cacheManager; |
|
|
private CacheManager cacheManager; |
|
|
|
|
|
|
|
|
|
|
|
private final Lock findOrCreateLock = new ReentrantLock(); |
|
|
|
|
|
|
|
|
@Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#deviceProfileId.id}") |
|
|
@Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#deviceProfileId.id}") |
|
|
@Override |
|
|
@Override |
|
|
public DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|
|
public DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|
|
@ -220,7 +224,15 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D |
|
|
log.trace("Executing findOrCreateDefaultDeviceProfile"); |
|
|
log.trace("Executing findOrCreateDefaultDeviceProfile"); |
|
|
DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name); |
|
|
DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name); |
|
|
if (deviceProfile == null) { |
|
|
if (deviceProfile == null) { |
|
|
deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default")); |
|
|
try { |
|
|
|
|
|
findOrCreateLock.lock(); |
|
|
|
|
|
deviceProfile = findDeviceProfileByName(tenantId, name); |
|
|
|
|
|
if (deviceProfile == null) { |
|
|
|
|
|
deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default")); |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
|
|
|
findOrCreateLock.unlock(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
return deviceProfile; |
|
|
return deviceProfile; |
|
|
} |
|
|
} |
|
|
|