Search in sources :

Example 1 with SourceDbDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceDbDetailEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method saveDetailOpt.

/**
 * Save data source details
 */
@Transactional(rollbackFor = Throwable.class)
int saveDetailOpt(SourceDbDetailInfo detailInfo, String operator) {
    // DB type judgment uniqueness: if the same groupId, streamId, dbName, connectionName
    // correspond to the same data source
    String groupId = detailInfo.getInlongGroupId();
    String streamId = detailInfo.getInlongStreamId();
    String dbName = detailInfo.getDbName();
    String connectionName = detailInfo.getConnectionName();
    Integer count = dbDetailMapper.selectDetailExist(groupId, streamId, dbName, connectionName);
    if (count > 0) {
        LOGGER.error("db source detail already exists, groupId={}, streamId={}, dbName={}, connectionName={}", groupId, streamId, dbName, connectionName);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
    }
    SourceDbDetailEntity dbEntity = CommonBeanUtils.copyProperties(detailInfo, SourceDbDetailEntity::new);
    dbEntity.setStatus(EntityStatus.AGENT_ADD.getCode());
    dbEntity.setCreator(operator);
    dbEntity.setModifier(operator);
    dbEntity.setCreateTime(new Date());
    dbDetailMapper.insertSelective(dbEntity);
    return dbEntity.getId();
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SourceDbDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceDbDetailEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method logicDeleteBasic.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
    LOGGER.info("begin to delete db data source basic, id={}", id);
    Preconditions.checkNotNull(id, "db data source basic's id is null");
    SourceDbBasicEntity entity = dbBasicMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source basic not found by id={}, delete failed", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
    }
    String groupId = entity.getInlongGroupId();
    String streamId = entity.getInlongStreamId();
    // Check if it can be deleted
    this.checkGroupIsTempStatus(groupId);
    // If there are related data source details, it is not allowed to delete
    List<SourceDbDetailEntity> detailEntities = dbDetailMapper.selectByIdentifier(groupId, streamId);
    if (CollectionUtils.isNotEmpty(detailEntities)) {
        LOGGER.error("the data source basic have [{}] details, delete failed", detailEntities.size());
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_DELETE_HAS_DETAIL);
    }
    entity.setIsDeleted(1);
    entity.setModifier(operator);
    int resultCount = dbBasicMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete db data source basic");
    return resultCount >= 0;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbBasicEntity(org.apache.inlong.manager.dao.entity.SourceDbBasicEntity) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SourceDbDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceDbDetailEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method getDetailById.

@Override
public SourceDbDetailInfo getDetailById(Integer id) {
    LOGGER.info("begin to get db data source detail by id={}", id);
    Preconditions.checkNotNull(id, "db data source detail's id is null");
    SourceDbDetailEntity entity = dbDetailMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source detail not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
    }
    SourceDbDetailInfo detailInfo = CommonBeanUtils.copyProperties(entity, SourceDbDetailInfo::new);
    LOGGER.info("success to get db data source detail");
    return detailInfo;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailInfo(org.apache.inlong.manager.common.pojo.source.SourceDbDetailInfo) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity)

Example 4 with SourceDbDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceDbDetailEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method updateDetail.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean updateDetail(SourceDbDetailInfo detailInfo, String operator) {
    LOGGER.info("begin to update db data source detail={}", detailInfo);
    Preconditions.checkNotNull(detailInfo, "db data source detail is empty");
    Preconditions.checkNotNull(detailInfo.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
    Preconditions.checkNotNull(detailInfo.getInlongStreamId(), Constant.STREAM_ID_IS_EMPTY);
    // The groupId may be modified, it is necessary to determine whether the inlong group status of
    // the modified groupId supports modification
    this.checkGroupIsTempStatus(detailInfo.getInlongGroupId());
    // id exists, update, otherwise add
    if (detailInfo.getId() != null) {
        SourceDbDetailEntity entity = dbDetailMapper.selectByPrimaryKey(detailInfo.getId());
        if (entity == null) {
            LOGGER.error("db data source detail not found by id=" + detailInfo.getId());
            throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
        }
        SourceDbDetailEntity dbEntity = CommonBeanUtils.copyProperties(detailInfo, SourceDbDetailEntity::new);
        dbEntity.setStatus(EntityStatus.GROUP_CONFIG_ING.getCode());
        dbEntity.setModifier(operator);
        dbDetailMapper.updateByPrimaryKeySelective(dbEntity);
    } else {
        saveDetailOpt(detailInfo, operator);
    }
    LOGGER.info("success to update db data source detail");
    return true;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SourceDbDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceDbDetailEntity in project incubator-inlong by apache.

the class SourceDbServiceImpl method logicDeleteDetail.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteDetail(Integer id, String operator) {
    LOGGER.info("begin to delete db data source detail, id={}", id);
    Preconditions.checkNotNull(id, "db data source detail's id is null");
    SourceDbDetailEntity entity = dbDetailMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("db data source detail not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
    }
    // Check if it can be deleted
    this.checkGroupIsTempStatus(entity.getInlongGroupId());
    entity.setIsDeleted(1);
    entity.setModifier(operator);
    int resultCount = dbDetailMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete db data source detail");
    return resultCount >= 0;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceDbDetailEntity(org.apache.inlong.manager.dao.entity.SourceDbDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)5 SourceDbDetailEntity (org.apache.inlong.manager.dao.entity.SourceDbDetailEntity)5 Transactional (org.springframework.transaction.annotation.Transactional)4 Date (java.util.Date)1 SourceDbDetailInfo (org.apache.inlong.manager.common.pojo.source.SourceDbDetailInfo)1 SourceDbBasicEntity (org.apache.inlong.manager.dao.entity.SourceDbBasicEntity)1