use of com.dtstack.taier.dao.domain.BatchReadWriteLock in project Taier by DTStack.
the class ReadWriteLockService method getLockBasicInfo.
private ReadWriteLockVO getLockBasicInfo(Long tenantId, long relationId, ReadWriteLockType type) {
BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(tenantId, relationId, type.name());
if (readWriteLock == null) {
throw new RdosDefineException(ErrorCode.LOCK_IS_NOT_EXISTS);
}
ReadWriteLockVO readWriteLockVO = new ReadWriteLockVO();
readWriteLockVO.setGmtModified(readWriteLock.getGmtModified());
readWriteLockVO.setLastKeepLockUserName(userService.getUserName(readWriteLock.getModifyUserId()));
return readWriteLockVO;
}
use of com.dtstack.taier.dao.domain.BatchReadWriteLock in project Taier by DTStack.
the class ReadWriteLockService method getLocks.
/**
* 根据 锁对象ids 批量获取锁信息
* @param tenantId
* @param type
* @param relationIds
* @param userId
* @param names
* @return
*/
public Map<Long, ReadWriteLockVO> getLocks(Long tenantId, ReadWriteLockType type, List<Long> relationIds, long userId, Map<Long, String> names) {
List<BatchReadWriteLock> ls = developReadWriteLockDao.getLocksByIds(tenantId, type.name(), relationIds);
Map<Long, BatchReadWriteLock> records = ls.stream().collect(Collectors.toMap(r -> r.getRelationId(), r -> r, (v1, v2) -> v2));
Map<Long, ReadWriteLockVO> result = Maps.newHashMap();
for (Long id : relationIds) {
if (records.containsKey(id)) {
BatchReadWriteLock readWriteLock = records.get(id);
ReadWriteLockVO readWriteLockVO = ReadWriteLockVO.toVO(readWriteLock);
readWriteLockVO.setLastKeepLockUserName(getUserNameInMemory(names, readWriteLockVO.getModifyUserId()));
result.put(id, readWriteLockVO);
} else {
ReadWriteLockVO readWriteLockVO = new ReadWriteLockVO();
readWriteLockVO.setLastKeepLockUserName(null);
readWriteLockVO.setGmtModified(null);
result.put(id, readWriteLockVO);
}
}
return result;
}
use of com.dtstack.taier.dao.domain.BatchReadWriteLock in project Taier by DTStack.
the class ReadWriteLockService method addOrUpdateLock.
/**
* 新增、更新 锁信息
* @param tenantId
* @param userId
* @param type
* @param fileId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public ReadWriteLockVO addOrUpdateLock(Long tenantId, Long userId, String type, Long fileId) {
ReadWriteLockVO readWriteLockVO;
BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(tenantId, fileId, type);
if (readWriteLock == null) {
readWriteLockVO = this.insert(tenantId, fileId, type, userId);
} else {
Integer result = 0;
result = developReadWriteLockDao.updateVersionAndModifyUserId(readWriteLock.getId(), null, userId);
readWriteLock = developReadWriteLockDao.getOne(readWriteLock.getId());
readWriteLockVO = ReadWriteLockVO.toVO(readWriteLock);
String userName = userService.getUserName(readWriteLock.getModifyUserId());
readWriteLockVO.setLastKeepLockUserName(userName);
}
return readWriteLockVO;
}
Aggregations