Search in sources :

Example 6 with BatchReadWriteLock

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;
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock)

Example 7 with BatchReadWriteLock

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;
}
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)

Example 8 with BatchReadWriteLock

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;
}
Also used : ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BatchReadWriteLock (com.dtstack.taier.dao.domain.BatchReadWriteLock)8 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)8 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)5 Transactional (org.springframework.transaction.annotation.Transactional)3 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 BatchTask (com.dtstack.taier.dao.domain.BatchTask)1 DevelopReadWriteLockDao (com.dtstack.taier.dao.mapper.DevelopReadWriteLockDao)1 BatchTaskBatchVO (com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO)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