Wednesday, 21 March 2018

OIM API - How to get Database Connection through Data Source Name in Plugins?

public Connection getOIMDBConnection() {
        final String logp = CN + ":: getOIMDataSource - ";
        LOGGER.debug(logp + "START");
       
        Connection conn = null;
       
        try {
            String oimDatasourceName = "jdbc/operationsDB";
            LOGGER.debug(logp + "OIM Datasource Name = " + oimDatasourceName);
           
            Context context = new InitialContext();
            DataSource ds = (DataSource) context.lookup(oimDatasourceName);
            LOGGER.info(logp + "Successfully looked up OIM datasource");
           
            if (null != ds) {
                    conn = ds.getConnection();
                    LOGGER.debug(logp + "Successfully obtained OIM database connection");
            }
        } catch (Exception e) {
                LOGGER.error(logp + "Exception while getting DB connection - " + e, e);
        }
       
        LOGGER.debug(logp + "END");
        return conn;
    }

Happy Learning!!!

No comments:

Post a Comment