/**
 * Multimud Helper.
 * 
 * Copyright (C) 2009 Benjamin Lerman<br>
 * Copyright (C) 2009 Jacques ???
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.ambre.multimud_helper;

import java.io.IOException;
import java.sql.SQLException;

import net.ambre.multimud_helper.bean.Item;
import net.ambre.multimud_helper.config.Configuration;

import org.apache.commons.configuration.ConfigurationException;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 * the starting class of the application.
 */
public class Main {
    /**
     * Starting method of the application.
     * 
     * @param args the command line arguments.
     * @throws IOException if unable to delete db directory.
     * @throws ConfigurationException if unable to retrieve user configuration.
     */
    public static void main(String[] args) throws IOException, ConfigurationException {

        // TestBase testBase = new TestBase();
        // Temporarily until database format is fixed.

        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/net/ambre/multimud_helper/spring/context.xml");
        Configuration configuration = (Configuration) applicationContext.getBean("configuration");
        applicationContext.close();
        // FileUtils.deleteDirectory(configuration.getDatabaseDirectory());

        applicationContext = new ClassPathXmlApplicationContext("/net/ambre/multimud_helper/spring/context.xml");
        new HibernateTemplate((SessionFactory) applicationContext.getBean("hibernateSessionFactory")).execute(new HibernateCallback() {

            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                session.save(new Item());
                return null;
            }

        });
        applicationContext.close();

        // Start here.
    }
}
