package com.eactive.eai.rms.bap.common.service;

import java.util.HashMap;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;

@Repository("bapLogTableDao")
public class BapLogTableDao  extends SqlMapClientTemplateDao {

    final Logger logger = Logger.getLogger(BapLogTableDao.class);
    
    @SuppressWarnings("deprecation")
	public long [] clearLogTable(HashMap<String, String> paramMap, int keyLevel) {

    	long [] cnt = new long[3];
    	
    	cnt[0] = 0;
    	cnt[1] = 0;
    	cnt[2] = 0;

    	for (int inx = 0; inx < power( 16, keyLevel); inx++) {
    		paramMap.put("uuid", toHex(inx,keyLevel));		
    		cnt[0] += this.template.update("BapLogDelete.clearStage", paramMap);
    		cnt[1] += this.template.update("BapLogDelete.clearNoFileStage", paramMap);
    		cnt[2] += this.template.update("BapLogDelete.clearNoFileMaster", paramMap);
    	}
    	return cnt;
    }
    private int power( int x, int y ){
    	if ( y == 1 )
    		return x;
    	return x * power( x, y -1);
    }

    private String toHex( int val, int len){
    	StringBuffer sb = new StringBuffer();
    	String sval = Integer.toHexString(val);
    	for ( int inx = 0; inx < len - sval.length(); inx++){
    		sb.append('0');
    	}
    	sb.append(sval);
    	return sb.toString();
    }

}
