/**
 * 
 * Date: Feb 17, 2005
 * Time: 8:09:05 AM
 * IbatisSqlMapManager.java
 * @author rabaker
 */
package com.ball.persistence.ibatis.dao;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.sqlmap.client.SqlMapClient;

import java.io.Reader;
import java.io.IOException;
import java.util.Iterator;

import org.apache.log4j.Logger;


public class IbatisSqlMapManager  {
    private static IbatisSqlMapManager ourInstance = new IbatisSqlMapManager();
    private static SqlMapClientImpl sqlMap;
    private static final Logger log = Logger.getLogger(IbatisSqlMapManager.class);

    public static IbatisSqlMapManager getInstance() {
        return ourInstance;
    }

    private IbatisSqlMapManager() {

        try
        {
            Reader reader = Resources.getResourceAsReader("com/ball/persistence/ibatis/maps/sqlMapConfig.xml");
            sqlMap = (SqlMapClientImpl)SqlMapClientBuilder.buildSqlMapClient(reader);
            SqlMapExecutorDelegate delegate = sqlMap.getDelegate();
            for(Iterator iter = delegate.getMappedStatementNames();iter.hasNext();)
            {
                log.debug((String)iter.next());
            }
        }
        catch(IOException e)
        {
            log.fatal("Could not load file com/ball/persistence/ibatis/maps/sqlMapConfig.xml");
        }
    }

    public static SqlMapClient getSqlMap()
    {
        return getInstance().sqlMap;
    }


}
