Dai Pessoal, criei esta classe para controlar minhas conexoes, so que nao sei se é correto utilizar o padrao singleton com data source?
Gostaria de saber a opiniao de vc ? valeu
public final class FactoryConnection {
private static FactoryConnection _instance;
private static DataSource dataSource = null;
private FactoryConnection() throws NamingException {
Context context = null;
try {
context = (Context) new InitialContext().lookup("java:/comp/env");
dataSource = (DataSource) context.lookup("nomeConfigurado");
} catch (NamingException e) {
throw e;
}
}
public final Connection getConnection() throws SQLException {
try {
// e se ocorrer um erro aqui, preciso avaliar o objeto dataSource ?
return dataSource.getConnection();
} catch (SQLException e) {
throw e;
}
}
public synchronized static final FactoryConnection getInstance()
throws Exception {
if (_instance == null) {
try {
_instance = new FactoryConnection();
} catch (NamingException e) {
throw new Exception(e);
}
}
return _instance;
}
}
ate