package org.clubrockisen.entrycounter.database;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.clubrockisen.entrycounter.common.Party;

import com.alexrnl.commons.database.DataBaseConfigurationError;
import com.alexrnl.commons.database.dao.AbstractDAOFactory;
import com.alexrnl.commons.database.dao.DataSourceConfiguration;
import com.alexrnl.commons.database.h2.H2Utils;
import com.alexrnl.commons.error.ExceptionUtils;

/**
 * DAO Factory for a H2 database.
 * @author Alex
 */
public class H2DAOFactory extends AbstractDAOFactory {
	/** Logger */
	private static Logger	lg	= Logger.getLogger(H2DAOFactory.class.getName());
	
	/** The connection to the database. */
	private Connection		connection;
	
	/**
	 * Constructor #1.<br />
	 */
	private H2DAOFactory () {
		super();
	}
	
	@Override
	protected void init () {
		final DataSourceConfiguration dbInfos = getDataSourceConfiguration();
		H2Utils.initDatabase(dbInfos);
		
		try {
			connection = DriverManager.getConnection(dbInfos.getUrl(), dbInfos.getUsername(), dbInfos.getPassword());
			if (connection.isValid(0)) {
				connection.setAutoCommit(true);
				if (lg.isLoggable(Level.INFO)) {
					lg.info("Connection to H2 database at " + dbInfos.getUrl() + " is successfull");
				}
			} else {
				throw new SQLException("Connection to H2 database is not valid");
			}
			addDAO(Party.class, new PartyDAO(connection));
		} catch (final SQLException e) {
			lg.warning("Could not create H2 database connection: " + ExceptionUtils.display(e));
			throw new DataBaseConfigurationError("Error while creating H2 database connection", e);
		}
	}

	@Override
	public void close () throws IOException {
		super.close();
		try {
			connection.close();
		} catch (final SQLException e) {
			lg.warning("Error while closing H2 database connection: " + ExceptionUtils.display(e));
			throw new IOException("Error while closing H2 database", e);
		}
	}
	
}

@@ -883,136 +883,176 @@
 %0A%09 *
-/%0A%09private H2DAOFactory () %7B%0A%09%09super();%0A%09%7D%0A%09%0A%09@Override%0A%09protected void init () %7B%0A%09%09final DataSourceConfiguration dbInfos = getD
+ @param dataSourceConfiguration%0A%09 *        the data source configuration.%0A%09 */%0A%09private H2DAOFactory (final DataSourceConfiguration dataSourceConfiguration) %7B%0A%09%09super(d
 ataS
@@ -1069,17 +1069,16 @@
 guration
-(
 );%0A%09%09H2U
@@ -1096,22 +1096,38 @@
 tabase(d
-bInfos
+ataSourceConfiguration
 );%0A%09%09%0A%09%09
@@ -1181,55 +1181,113 @@
 on(d
-bInfos.getUrl(), dbInfos.getUsername(), dbInfos
+ataSourceConfiguration.getUrl(),%0A%09%09%09%09%09dataSourceConfiguration.getUsername(),%0A%09%09%09%09%09dataSourceConfiguration
 .get
@@ -1456,14 +1456,30 @@
  + d
-bInfos
+ataSourceConfiguration
 .get

Update H2DAOFactory to match new version of Commons