package com.brilliance.isc.common.counter.mapper;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class CounterMapper {

    final String FNAME = this.getClass().getName();

    @Autowired
    public SqlSessionTemplate template;


    public Integer getCountValWithUpdate(String seqName){
        return template.selectOne(FNAME+".getCountValWithUpdate",seqName);
    }


    public int insertNewCounter(String nam, int start ,int stp){
        Map<String, Object> map = new HashMap<>();
        map.put("nam", nam);
        map.put("start",start);
        map.put("stp", stp);
        return template.insert(FNAME+".insertNewCounter",map);
    }


    public void updateCounter(String seqName){
        template.selectOne(FNAME+".updateCounter",seqName);
    }

    public int seqNextval(String seqName) {
        return template.selectOne(FNAME+".seqNextval",seqName);
    }

    public int dbCounter(String seqName){
        return template.selectOne(FNAME+".dbCounter",seqName);
    }
}