package org.seasar.hibernate.dao.impl;


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

import org.seasar.hibernate.S2SessionFactory;
import org.seasar.hibernate.dao.HibernateDaoMetaData;
import org.seasar.hibernate.dao.HibernateDaoMetaDataFactory;

/**
 * @author kenichi_okazaki
 */
public class HibernateDaoMetaDataFactoryImpl implements HibernateDaoMetaDataFactory {

	private S2SessionFactory s2sessionFactory_;
	private Map daoMetaDataCache_ = new HashMap();

	public HibernateDaoMetaDataFactoryImpl(S2SessionFactory s2sessionFactory) {
		s2sessionFactory_ = s2sessionFactory;
	}

	public HibernateDaoMetaData getDaoMetaData(Class daoClass) {
		HibernateDaoMetaData dmd = (HibernateDaoMetaData) daoMetaDataCache_.get(daoClass
				.getName());
		if (dmd != null) {
			return dmd;
		}
		synchronized (this) {
			dmd = (HibernateDaoMetaData) daoMetaDataCache_.get(daoClass.getName());
			if (dmd != null) {
				return dmd;
			}
			dmd = new HibernateDaoMetaDataImpl( s2sessionFactory_ ,daoClass);
			daoMetaDataCache_.put(daoClass.getName(), dmd);
		}
		return dmd;
	}
}