ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Ferguson" <mark.fergu...@port.ac.uk>
Subject day/night night config.
Date Thu, 10 Feb 2005 15:10:40 GMT
I have a working Dao manager/SqlMap implementaion for a portal.

How would I change the configuration or implementation so that I can use a  
diferent dao.xml file at night than during the day without compromising  
connection pooling etc.

Originaly my dao config looed like this

public class DaoConfig {

	private static final DaoManager daoManager;

	static {

		try {
			String resource = "com/uop/struts/dao/dao.xml";
			Reader reader = Resources.getResourceAsReader(resource);
			daoManager = DaoManagerBuilder.buildDaoManager(reader);
		} catch (Exception e) {
			throw new RuntimeException(
					"Could not initialize DaoConfig.  Cause: " + e);
		}
	}

	public static DaoManager getDaomanager() {
		return daoManager;
	}
}

I then changed it to this :-

public class DaoConfig {

private static DaoManager daoManager;

public static DaoManager getDaomanager() {
	try {
		String resource = null;
		Calendar date = new GregorianCalendar();
		if (date.get(Calendar.HOUR_OF_DAY) > 8 &&  
(date.get(Calendar.HOUR_OF_DAY) < 20) {
			resource = "com/uop/struts/dao/daoDay.xml";
		} else {
			resource = "com/uop/struts/dao/daoNight.xml";
		}
		Reader reader = Resources.getResourceAsReader(resource);
		daoManager = DaoManagerBuilder.buildDaoManager(reader);

		} catch (Exception e) {
		throw new RuntimeException(
				"Could not initialize DaoConfig.  Cause: " + e);
	}
	return daoManager;
}

However each time I call
DaoConfig.getDaomanager() it looks as though it creates a new DaoManager  
rather than returning the existing one for the current period.

does this make sense?
any help greatfully received
thanks

-- 
Mark Ferguson

Mime
View raw message