
net.smartlab.web.config.TomcatConfigurationStrategy Maven / Gradle / Ivy
/*
* The SmartWeb Framework
* Copyright (C) 2004-2006
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* For further informations on the SmartWeb Framework please visit
*
* http://smartweb.sourceforge.net
*/
package net.smartlab.web.config;
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import net.smartlab.web.BusinessObjectFactory;
import net.smartlab.web.Domain;
/**
* The Hibernate configuration file used must reside into the
* META-INF
directory of the topmost packaging archive and should
* be named smartweb.jar.hcf
or have the name of the JAR file
* containing the subclass followed by the .hcf
suffix.
*
* @author rlogiacco
*/
public class TomcatConfigurationStrategy implements FactoryConfigurationStrategy {
/**
* TODO documentation
*/
private Map factories = new TreeMap();
/**
* Provides logging capabilities to the strategy.
*/
protected final Log logger = LogFactory.getLog(TomcatConfigurationStrategy.class);
/**
* @see net.smartlab.web.config.FactoryConfigurationStrategy#getSessionFactory(net.smartlab.web.BusinessObjectFactory)
*/
public SessionFactory getSessionFactory(BusinessObjectFactory bof) {
synchronized (BusinessObjectFactory.class) {
String archive = Domain.getLastArchiveName(bof.getClass());
URL file = Domain.getResource(bof.getClass(), new String[] {"/META-INF/" + archive + ".hcf",
"/META-INF/smartweb.jar.hcf"});
try {
if (!factories.containsKey(file.toString())) {
// Session factory not found in cache
logger.warn("getSessionFactory() - configure hibernate without JNDI");
SessionFactory factory = new Configuration().configure(file).buildSessionFactory();
factories.put(file.toString(), factory);
}
return (SessionFactory)factories.get(file.toString());
} catch (Exception e) {
logger.error("getSessionFactory() - error", e);
return null;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy