Pessoal,
Estou tentando implementar um pool de conexoes para uma base oracle, mas para cada requisicao, em vez de aproveitar as conexoes abertas ele cria novas conexoes. Segue abaixo meu codigo:
import java.sql.SQLException;
import java.util.Properties;
import org.apache.log4j.Logger;
import oracle.jdbc.pool.OracleConnectionCacheImpl;
import oracle.jdbc.pool.OracleConnectionPoolDataSource;
public class PoolConexaoSingleton {
public static PoolConexaoSingleton instance;
private OracleConnectionPoolDataSource ocpds = null;
private OracleConnectionCacheImpl ods = null;
private static Logger logger = Logger.getLogger(Utilitarios.class);
private Utilitarios objUtil = new Utilitarios();
private Properties appProps = objUtil.carregaPropriedades();
private PoolConexaoSingleton(String tpAmb){
try{
String ip = appProps.getProperty(ip);
String port = appProps.getProperty(port);
String sid = appProps.getProperty(sid);
String user = appProps.getProperty(user);
String pass = appProps.getProperty(pass);
ocpds = new OracleConnectionPoolDataSource();
ocpds.setURL("jdbc:oracle:thin:@" + ip + ":" + port + ":" + sid);
ocpds.setUser(user);
ocpds.setPassword(pass);
ods = new OracleConnectionCacheImpl(ocpds);
ods.setMinLimit(10);
ods.setMaxLimit(30);
ods.setCacheScheme(OracleConnectionCacheImpl.FIXED_WAIT_SCHEME);
}catch(SQLException se){
logger.info("Exception PoolConexaoSiebel -> [" + se.getMessage() + "]");
}
}
public static PoolConexaoSingleton getInstance(String tpAmb){
if (instance == null)
instance = new PoolConexaoSiebelSingleton(tpAmb);
return instance;
}
public OracleConnectionCacheImpl getOracleConnectionCacheImpl(){
return this.ods;
}
public OracleConnectionPoolDataSource getOracleConnectionPoolDataSource(){
return this.ocpds;
}
}
Classe que chema o singleton
import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.Properties;
import oracle.jdbc.driver.OracleTypes;
import org.apache.log4j.Logger;
import br.com.alcatellucent.gvpws.lib.PoolConexaoSiebelSingleton;
import br.com.alcatellucent.gvpws.lib.Utilitarios;
import br.com.alcatellucent.gvpws.lib.XmlHandler;
public class WsApi043 {
private Utilitarios objUtil = new Utilitarios();
private static Logger logger = Logger.getLogger(Utilitarios.class);
private Properties appProps = objUtil.carregaPropriedades();
private String resposta = "02;";
private String status = "";
private String msisdn = "";
private String[][] matRetorno = new String[1][2];
private String xmlRetorno = "";
private int timeOut = 26000;
private Connection conn = null;
private String idRequisicao = "";
private String processo = "";
public String executarTransacao(String tpAmb, String dadosEntrada, String timeout){
try
{
this.timeOut = Integer.parseInt(timeout);
}
catch (Exception ex)
{
this.timeOut = 26000;
}
// Realizando parse do XML de entrada para obter indentificador_requisicao e processo
// Estes valores serão utilizados na inserção do novo registro
XmlHandler xmlFields = new XmlHandler(dadosEntrada, true);
if(xmlFields.ready()){
this.msisdn = xmlFields.get("m");
this.idRequisicao = xmlFields.get("identificador_requisicao");
this.processo = xmlFields.get("processo");
}else
logger.error("ID de Requisicao e(ou) Processo nao foi encontrado no xml de entrada.");
try{
conn = PoolConexaoSingleton.getInstance(tpAmb).getOracleConnectionCacheImpl().getConnection();
logger.info("Connection Instance -> [" + conn.toString() + "]");
CallableStatement cs = conn.prepareCall("{call pkg.prc_principal (?, ?)}");
cs.setString(1, this.campo);
cs.registerOutParameter(2, OracleTypes.VARCHAR);
cs.execute();
if (cs.getString(2) != null && !cs.getString(2).trim().equals("")){
this.resposta = "00;";
this.status = cs.getString(2);
}
cs.close();
}catch(Exception se){
logger.info("Exception -> [" + se.getMessage() + "]");
this.resposta += se.getMessage();
}
//Matriz fonte para montar XML de retorno para URA
matRetorno[0][0] = "STATUS";
matRetorno[0][1] = this.status;
//Cria um XML em formato string através da matriz fonte
try{
xmlRetorno = xmlFields.Build(matRetorno);
}catch(Exception e){
logger.info("Erro criar xml -> [" + e.getMessage() + "]");
}
resposta += xmlRetorno;
try{
//if (conn != null)
// conn.close();
}catch(Exception ex1){
logger.info("Exception ao desconectar -> [" + ex1.getMessage() + "]");
resposta += ex1.getMessage();
}
xmlFields = null;
return resposta;
}
}
Se alguem já passou por isso e puder me ajudar agradeço.