1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public static DataSource getDatasource(String aPoolName) throws TechniqueException
{
// Recuperation du datasource correspondant au pool
DataSource ds = (DataSource) fDataSourceManager.get(aPoolName);
if (ds == null)
{
// Recuperation du datasource
try
{
Context ctx = new InitialContext();
ctx = (Context) ctx.lookup("java:comp/env");
ds = (javax.sql.DataSource) ctx.lookup(aPoolName);
}
catch (NamingException e)
{
Logger log = Logger.getLogger(BoAncestorBean.class);
LoggerUtil.printStackTraceToLogger(log,e,Level.FATAL);
throw new TechniqueException(null,"Impossible de recuperer le pool " + aPoolName + " " + e);
}
// Si datasource existant
if (ds != null)
fDataSourceManager.put(aPoolName, ds);
else
throw new TechniqueException(null,"le pool " + aPoolName + " n'existe pas !");
}
return ds;
} |
Partager