View Javadoc
1   package org.miloss.fgsms.quartz;
2   
3   
4   import java.sql.Connection;
5   import java.sql.PreparedStatement;
6   import java.sql.SQLException;
7   import org.miloss.fgsms.common.DBUtils;
8   import org.quartz.utils.ConnectionProvider;
9   
10  /*
11   * To change this license header, choose License Headers in Project Properties.
12   * To change this template file, choose Tools | Templates
13   * and open the template in the editor.
14   */
15  
16  /**
17   *
18   * @author AO
19   */
20  public class EncryptedConnectionProvider implements ConnectionProvider {
21  
22      @Override
23      public Connection getConnection() throws SQLException {
24          Exception root = null;
25          try {
26              javax.naming.Context ctx1 = new javax.naming.InitialContext();
27              javax.sql.DataSource ds = (javax.sql.DataSource) ctx1.lookup("java:fgsmsQuartz");
28              Connection con = ds.getConnection();
29              PreparedStatement com = con.prepareStatement("select 1;");
30              try {
31                  com.execute();
32                  DBUtils.safeClose(com);
33                  return con;
34              } catch (Exception e) {
35                  root = e;
36                  //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + e.getLocalizedMessage(), e);
37                  //return GetAlternatePerformanceDBConnection();
38              } finally {
39                  DBUtils.safeClose(com);
40              }
41  
42          } catch (Exception ex) {
43              root = ex;
44              //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + ex.getLocalizedMessage(), ex);
45              //return GetAlternatePerformanceDBConnection();
46          }
47  
48          try {
49              javax.naming.Context ctx1 = new javax.naming.InitialContext();
50              javax.sql.DataSource ds = (javax.sql.DataSource) ctx1.lookup("java:/comp/env/jdbc/fgsmsQuartz");
51              Connection con = ds.getConnection();
52              PreparedStatement com = con.prepareStatement("select 1;");
53              try {
54                  com.execute();
55                  DBUtils.safeClose(com);
56                  return con;
57              } catch (Exception e) {
58                  root = e;
59                  //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + e.getLocalizedMessage(), e);
60              } finally {
61                  DBUtils.safeClose(com);
62              }
63          } catch (Exception ex) {
64              root = ex;
65              //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + ex.getLocalizedMessage(), ex);
66          }
67  
68          try {
69              javax.naming.Context ctx1 = new javax.naming.InitialContext();
70              javax.sql.DataSource ds = (javax.sql.DataSource) ctx1.lookup("jdbc/fgsmsQuartz");
71              Connection con = ds.getConnection();
72              PreparedStatement com = con.prepareStatement("select 1;");
73              try {
74                  com.execute();
75                  DBUtils.safeClose(com);
76                  return con;
77              } catch (Exception e) {
78                  root = e;
79                  //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + e.getLocalizedMessage(), e);
80              } finally {
81                  DBUtils.safeClose(com);
82              }
83          } catch (Exception ex) {
84              root = ex;
85              //log.log(Level.WARN, "Error obtaining primary pooled performance database connection, attempting alternate. msg:" + ex.getLocalizedMessage(), ex);
86          }
87          if (root!=null)
88              root.printStackTrace();
89          return null;
90      }
91  
92      @Override
93      public void shutdown() throws SQLException {
94          
95      }
96  
97  }