rs.data.hibernate.HibernateDaoMaster Maven / Gradle / Ivy
/*
* This file is part of RS Library (Data Hibernate Library).
*
* RS Library is free software: you can redistribute it
* and/or modify it under the terms of version 3 of the GNU
* Lesser General Public License as published by the Free Software
* Foundation.
*
* RS 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 RS Library. If not, see
* .
*/
package rs.data.hibernate;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.SubnodeConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rs.baselib.io.FileFinder;
import rs.baselib.lang.LangUtils;
import rs.data.hibernate.util.DataSourceConnectionProvider;
import rs.data.impl.AbstractDaoMaster;
/**
* The DAO Master holding information about the DB connection and Hibernate instance.
* @author ralph
*
*/
public class HibernateDaoMaster extends AbstractDaoMaster {
public static final String DEFAULT_CONFIG_FILE = "config/hbm/hibernate.cfg.xml";
public static final String FACTORY_KEY = "hibernateDaoMaster";
private static final String DB_CONFIG_KEYS[] = new String[] {
"hibernate.connection.driver_class",
"hibernate.connection.url",
"hibernate.connection.username",
"hibernate.connection.password",
"hibernate.dialect"
};
private static Logger log = LoggerFactory.getLogger(HibernateDaoMaster.class);
private SessionFactory factory;
/**
* Constructor.
*/
public HibernateDaoMaster() {
}
/**
* {@inheritDoc}
*/
@Override
public void configure(Configuration cfg) throws ConfigurationException {
super.configure(cfg);
// Where is the config?
URL configFile = toURL("hbmconfig-file");
URL dbconfigFile = toURL("dbconfig-file");
log.info("Database Configuration: "+dbconfigFile.toString());
// Load all properties for hibernate now
Properties overriddenProperties = new Properties();
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy