package com.mit.mimax.database;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DBConnectionPool implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 570444756010050887L;
	transient private static Context context = null;
	transient private static DataSource dataSource = null;
	
	/**
	 * private constructor for static class
	 */
	private DBConnectionPool() 
	{
	}


	public static Connection getConnection() throws SQLException 
	{
		try
		{
			if(context == null)
			{
				context = new InitialContext();
			}
			if(dataSource == null)
			{
				dataSource = (DataSource) context.lookup("MIMAX");
			}
			return dataSource.getConnection();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
			return null;
		}
	}
}
