package cn.edu.whu.boot.xml.service.impl;

import cn.edu.whu.boot.xml.mapper.TableMapper;
import cn.edu.whu.boot.xml.service.ITableService;
import cn.edu.whu.boot.xml.domain.Task;
import cn.edu.whu.boot.xml.domain.XmlEnity;
import cn.edu.whu.boot.xml.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TableServiceImpl implements ITableService{

    private final TableMapper tableMapper;
    private final ITaskService taskService;

    @Autowired
    public TableServiceImpl(TableMapper tableMapper, ITaskService taskService){
        this.tableMapper = tableMapper;
        this.taskService = taskService;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void createTableAndUpdateTask(Task task, XmlEnity xmlEnity, String createTableSqlString){
        tableMapper.createTable(createTableSqlString);
        task.setHasCreateTables(Task.HAS_CREATE_TABLES);
        task.setCreateTablesMd5code(xmlEnity.getMd5Code());
        taskService.updateTask(task);
    }
}
