package org.seasar.dao.impl;

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

import javax.sql.DataSource;

import org.seasar.dao.DaoMetaData;
import org.seasar.dao.DaoMetaDataFactory;
import org.seasar.extension.jdbc.ResultSetFactory;

/**
 * @author higa
 *  
 */
public class DaoMetaDataFactoryImpl implements DaoMetaDataFactory {

	private Map daoMetaDataCache_ = new HashMap();

	private DataSource dataSource_;

	private ResultSetFactory resultSetFactory_;

	public DaoMetaDataFactoryImpl(DataSource dataSource,
			ResultSetFactory resultSetFactory) {
		dataSource_ = dataSource;
		resultSetFactory_ = resultSetFactory;
	}

	public DaoMetaData getDaoMetaData(Class daoClass) {
		String key = daoClass.getName();
		DaoMetaData dmd = (DaoMetaData) daoMetaDataCache_.get(key);
		if (dmd != null) {
			return dmd;
		}
		synchronized (this) {
			dmd = (DaoMetaData) daoMetaDataCache_.get(key);
			if (dmd != null) {
				return dmd;
			}
			dmd = new DaoMetaDataImpl(daoClass, dataSource_, resultSetFactory_);
			daoMetaDataCache_.put(key, dmd);
		}
		return dmd;
	}
}