Search in sources :

Example 1 with ReadWriteLockType

use of com.dtstack.taier.common.enums.ReadWriteLockType 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;
}
Also used : UserService(com.dtstack.taier.develop.service.user.UserService) ReadWriteLockType(com.dtstack.taier.common.enums.ReadWriteLockType) Timestamp(java.sql.Timestamp) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Callback(com.dtstack.taier.common.Callback) List(java.util.List) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) DevelopReadWriteLockDao(com.dtstack.taier.dao.mapper.DevelopReadWriteLockDao) TaskLockStatus(com.dtstack.taier.common.enums.TaskLockStatus) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) Transactional(org.springframework.transaction.annotation.Transactional) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock)

Aggregations

Callback (com.dtstack.taier.common.Callback)1 ReadWriteLockType (com.dtstack.taier.common.enums.ReadWriteLockType)1 TaskLockStatus (com.dtstack.taier.common.enums.TaskLockStatus)1 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 BatchReadWriteLock (com.dtstack.taier.dao.domain.BatchReadWriteLock)1 DevelopReadWriteLockDao (com.dtstack.taier.dao.mapper.DevelopReadWriteLockDao)1 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)1 UserService (com.dtstack.taier.develop.service.user.UserService)1 Maps (com.google.common.collect.Maps)1 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1