package eg;

import java.lang.annotation.Annotation;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Alternative;

import org.seamframework.sql.ConnectionFactory;

@Alternative @Dependent
class TestConnectionFactory implements ConnectionFactory {
	{
		try {
			Class.forName("org.hsqldb.jdbcDriver" );
		}
		catch (ClassNotFoundException cnfe) {
			throw new RuntimeException(cnfe);
		}
	}
	
	@Override
	public Connection getConnection(Annotation qualifier) {
		try {
			return DriverManager.getConnection("jdbc:hsqldb:mem:db", "sa", "");
		}
		catch (SQLException sqle) {
			throw new RuntimeException(sqle);
		}
	}
}