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());
}
}
}
Views
Replies
Total Likes
Could you please let know
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.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies