

package gov.va.med.cds.persistence;


import gov.va.med.cds.exception.ErrorCodeEnum;
import gov.va.med.cds.exception.InitializationException;

import java.sql.DriverManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;


public class DBConnectionHandler
    implements
        InitializingBean
{
    private static final Log logger = LogFactory.getLog( DBConnectionHandler.class );

    private static String dbLoginTimeout = null;


    public static String getDbLoginTimeout( )
    {
        return dbLoginTimeout;
    }


    public static void setDbLoginTimeout( String dbLoginTimeout )
    {
        DBConnectionHandler.dbLoginTimeout = dbLoginTimeout;
        DriverManager.setLoginTimeout( Integer.parseInt( dbLoginTimeout ) );
    }


    @Override
    /**
     * Method called by Spring Framework after context file has been processed.
     * Check for missing dependencies.
     */
    public void afterPropertiesSet( )
        throws Exception
    {
        if ( dbLoginTimeout == null )
        {
            throw new InitializationException( ErrorCodeEnum.DB_LOGIN_TIMEOUT_NOT_CONFIGURED_AND_NULL );
        }

    }

}
