package com.eactive.eai.rms.common.base;

import java.util.Iterator;
import java.util.Map;

import javax.sql.DataSource;

import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.common.login.LoginVo;
import com.eactive.eai.rms.common.login.SessionManager;
import com.eactive.eai.rms.common.util.CommonConstants;
import com.ibatis.sqlmap.client.SqlMapClient;

@SuppressWarnings(value = { "unchecked", "deprecation" })
public class SchemaIdConfiguredSqlMapForMonitoringTemplate extends SchemaIdConfiguredSqlMapTemplate {
    
	protected Object addParameterObject(String statementName, Object parameterObject) {

		if (parameterObject instanceof Map) {
			Map<String, Object> paramMap = (Map<String, Object>) parameterObject;

			if (paramMap.get(CommonConstants.schemaId_KEY) == null) {
				paramMap.put(CommonConstants.schemaId_KEY, DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.MONITORING).getSchema());
			}
			// login user °ü·Ã
			if (paramMap.get(CommonConstants.loginId_KEY) == null) {
				LoginVo loginVo = SessionManager.getLoginVo();
				if (loginVo != null) {
					paramMap.put(CommonConstants.loginId_KEY, loginVo.getUserId());
				}
			}
			if (logger.isDebugEnabled()) {

				StringBuilder sb = new StringBuilder();
				sb.append("Statement Name : " + statementName).append("\n");
				for (Iterator<String> it = paramMap.keySet().iterator(); it.hasNext();) {

					String key = it.next();
					sb.append(key + "=" + paramMap.get(key)).append(", ");
				}
				logger.debug("SQLMap Parameters : " + sb.toString());
			}
			return paramMap;
		}
		return parameterObject;
	}

    public SchemaIdConfiguredSqlMapForMonitoringTemplate() {
        super();
    }

    public SchemaIdConfiguredSqlMapForMonitoringTemplate(DataSource dataSource,
            SqlMapClient sqlMapClient) {
        super(dataSource, sqlMapClient);
    }

    public SchemaIdConfiguredSqlMapForMonitoringTemplate(SqlMapClient sqlMapClient) {
        super(sqlMapClient);
    }


}
