Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

no data source with name "testConn" after asking 0 providers (Oracle AEM integration using jdbcpool configs)

Avatar

Level 2

Everytime after the deploying project bundle jdbc pool osgi config need to be resaved manually, or else I am getting the error at DataSourcePool.getDataSource("testConn")
unable to find the datasource with name "testConn", oracle bundle and my project bundles are active, how to make it pick automatically,

DataSourcePool.getDataSource("testConn") will be called everytime when the code attempts connecting to oracle

 

Config Name: com.day.commons.datasource.jdbcpool.JdbcPoolService-archival.config

 

Have tried to get the dataSource on every query exection, but still facing same

 

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.commons.datasource.poolservice.DataSourceNotFoundException;
import com.day.commons.datasource.poolservice.DataSourcePool;

@Component(service = OracleConnectorService.class, immediate = true)
public class OracleConnectorServiceImpl implements OracleConnectorService {

   private static final Logger LOG = LoggerFactory.getLogger(OracleConnectorServiceImpl.class);

   @reference
   private DataSourcePool dataSourceService;

   Connection dbConnection = null;
   PreparedStatement preStmt = null;
   ResultSet rs = null;
   DataSource dataSource = null;

   @activate
   @MODIFIED
   public void activate() {
      try {
         dataSource = (DataSource) dataSourceService.getDataSource(ArchivalConstants.ORACLE_DATASOURCE);
      } catch (DataSourceNotFoundException e) {
         LOG.error("Unable to establish db connections = {} ", e.getMessage());
      }

   }

   @Override
   public ResultSet getResultSet(PreparedStatement preStmt) {
      try {
         rs = preStmt.executeQuery();
         return rs;
      } catch (SQLException e) {
         LOG.error("get db results error = {} ", e);
      }
      return null;
   }

   @Override
   public int modifyData(PreparedStatement preStmt) {
      try {
         return preStmt.executeUpdate();
      } catch (SQLException e) {
         LOG.error("exception while executing update query {} ", e);
      }
      return 0;
   }

   @Override
   public PreparedStatement constructStmt(String query) {
      setDataBaseConnection();
      try {
         if (null != dbConnection) {
            preStmt = dbConnection.prepareStatement(query);
            return preStmt;
         }
      } catch (SQLException e) {
         LOG.error("exception while constructing statement {} ", e.getMessage());
      }
      return null;
   }

   @Override
   public void closeConnections() {
      try {
         if (null != preStmt)
            preStmt.close();
         if (null != rs)
            rs.close();
         if (null != dbConnection)
            dbConnection.close();
      } catch (SQLException e) {
         LOG.error("Unable to close db connections {} ", e.getMessage());
      }

   }

   public void setDataBaseConnection() {
      try {
         dbConnection = dataSource.getConnection();
         if (null != dbConnection)
            LOG.debug("Connection getMetaData = {} ", dbConnection.getMetaData().getURL());
      } catch (SQLException e) {
         LOG.error("Unable to establish db connections = {} ", e.getMessage());
      }
   }

}

 

5 Replies

Avatar

Community Advisor

Hi @HimaNagaUdayKiran,

Could you please let know

  • If the OSGi config factory instance of (Day Commons JDBC Connections Pool) is created with unique identifier. If possible, share the config node name you have used.
  • Place where you are instantiating the DB connection (DataSourcePool.getDataSource("testConn") ..) Is it in the activate method ?

Avatar

Community Advisor

Hi @HimaNagaUdayKiran,

Can you move the logic written in @Activate/@Modified method(DataSource retrieval as well) to setDataBaseConnection() 

Hope @Reference and @Activate is a typo(lowercase) while pasting the snippet here. 

Avatar

Community Advisor

Hi,

Just wondering in your code below is typo or the annotations are wrong,

it looks like in this thread they are auto changing. But did you try creating repository based configuartion?

 

@activate
   @MODIFIED
   public void activate() {

 e.g.

 

 

  
  /*
  @activate
  @MODIFIED
*/

 

 



Arun Patidar

Avatar

Level 2
hi @arunpatidar, saved oracle related data inside file com.day.commons.datasource.jdbcpool.JdbcPoolService-archival.config for specific run modes, Yes @Moadified & @activate is happening only in this thread