일괄 처리 SQL

1751 단어 Java
package com.huawei.nis.fttxbaseline.basedata.mapper;
import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.Map;
/**
  • SQL 일괄 처리 추상 클래스 생 성
  • @author lWX501870


  • */ public abstract class BatchSQLProvider {
    /**
     *     
     * @param map
     * @return
     */
    public String insertBatchSQL(Map> map) {
    	List object = (List) map.get("list");  
        StringBuilder sb = new StringBuilder();  
        //       IGNORE,         ,            
        sb.append("INSERT IGNORE INTO ").append(tableName()).append("(");  
        sb.append(StringUtils.join(tableColumns(), ','));
        sb.append(") VALUES ");  
        values(object, sb);
        return sb.toString();  
    }
    
    /**
     *     
     * @param ids
     * @return
     */
    public String delBatchSQL(@Param("ids") List ids) {	
        StringBuilder sb = new StringBuilder();  
        sb.append("delete from ").append(tableName()).append(" where id in (");  
        sb.append(StringUtils.join(ids.toArray(), ','));
        sb.append(")");    
        return sb.toString();  
    }
    
    /*
     *     2
     */
    public String delArrBatchSQL(@Param("ids") Integer[] ids) {	
        StringBuilder sb = new StringBuilder();  
        sb.append("delete from ").append(tableName()).append(" where id in (");  
        sb.append(StringUtils.join(ids, ','));
        sb.append(")");    
        return sb.toString();  
    }
    
    
    abstract String tableName();
    
    abstract String[] tableColumns();
    
    abstract void values(List object, StringBuilder sb);
    

    }

    좋은 웹페이지 즐겨찾기