package m05bClasses;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;


public class m05bConexion {
	
	m05bFileLog miLog = new m05bFileLog();
	
   /***************************************************************************************
	***
	***
	***************************************************************************************/
	/**
   	* Coge una conexión del Pool de conexiones.
   	* El nombre del pool se coge de la propiedades del EJB. ( Se indica al hacer el deploy )
   	* @return java.sql.Connection
   	* @exception java.sql.SQLException
   	*/

     /*   public Connection getConnection() throws SQLException{
		Connection conn = null;
        	try{
           		Class.forName("weblogic.jdbc.pool.Driver").newInstance();
           		conn = DriverManager.getConnection("jdbc:weblogic:pool:m05bPool", null);
        	}
        	catch (Exception e){
       		}
		return conn;
    	}
    */	
    	
    public Connection getConnection() throws SQLException{

		InitialContext ctx=null;
		java.sql.Connection conn=null;
    
    	try  {
    		Hashtable ht = new Hashtable();
    		ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
 			ctx = new InitialContext(ht);
         	
         	javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("m05b.m05bDataSource");
         	conn = ds.getConnection();
         	
    	}	catch (Exception e){
        		miLog.addTraza("Usuario", "Get Conection",  "EXCEPTION: " + e.toString(), m05bConstantes.LOG_NIVEL_ALTO);

       	}	finally  {
       			try { 
       					ctx.close();  
       			} catch(Exception e) {
       					miLog.addTraza("Usuario", "Get Connection",  "EXCEPTION FINALLY: " + e.toString(), m05bConstantes.LOG_NIVEL_ALTO);
       			}
       		}
       		
       	return conn;
	}
	
    public Connection getConnectionJ47() throws SQLException{

		InitialContext ctx=null;
		java.sql.Connection conn=null;
    
    	try  {
    		Hashtable ht = new Hashtable();
    		ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
 			ctx = new InitialContext(ht);
         	
         	javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("m05b.m05bDataSource_j47");
         	conn = ds.getConnection();
         	
    	}	catch (Exception e){
        		miLog.addTraza("Usuario", "Get Connection J47",  "EXCEPTION: " + e.toString(), m05bConstantes.LOG_NIVEL_ALTO);

       	}	finally  {
       			try { 
       					ctx.close();  
       			}  catch(Exception e) {
       					miLog.addTraza("Usuario", "Get Conection",  "EXCEPTION FINALLY: " + e.toString(), m05bConstantes.LOG_NIVEL_ALTO);
       			}
       	}
       	
       	return conn;
	}
	
// Fin clase		
}