package jp.sf.amateras.mirage.session;

import java.util.Properties;

import jp.sf.amateras.mirage.exception.ConfigurationException;
import jp.sf.amateras.mirage.util.IOUtil;

public class SessionFactory {

	private static Session session;

	public synchronized static Session getSession() throws ConfigurationException {
		if(session == null){
			Properties properties = IOUtil.loadProperties("jdbc.properties");
			if(properties != null){
				String driver = properties.getProperty("jdbc.driver");
				String url = properties.getProperty("jdbc.url");
				String user = properties.getProperty("jdbc.user");
				String password = properties.getProperty("jdbc.password");

				session = new JDBCSessionImpl(driver, url, user, password);
			} else {
				throw new ConfigurationException("jdbc.properties is not found!");
			}
		}

		return session;
	}

}
