|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kew.useroptions.dao.impl;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.sql.Connection;  | 
  |  19 |     | 
   import java.sql.PreparedStatement;  | 
  |  20 |     | 
   import java.sql.ResultSet;  | 
  |  21 |     | 
   import java.sql.SQLException;  | 
  |  22 |     | 
     | 
  |  23 |     | 
   import javax.sql.DataSource;  | 
  |  24 |     | 
     | 
  |  25 |     | 
   import org.apache.log4j.Logger;  | 
  |  26 |     | 
   import org.kuali.rice.kew.useroptions.dao.ReloadActionListDAO;  | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
   public class ReloadActionListDaoJdbcImpl implements ReloadActionListDAO { | 
  |  35 |     | 
             | 
  |  36 |     | 
           private static final String RELOAD_ACTION_LIST = "RELOAD_ACTION_LIST";  | 
  |  37 |     | 
     | 
  |  38 |    0 |            private static final Logger LOG = Logger.getLogger(ReloadActionListDaoJdbcImpl.class);  | 
  |  39 |     | 
             | 
  |  40 |     | 
           DataSource nonTxDataSource;  | 
  |  41 |     | 
             | 
  |  42 |     | 
             | 
  |  43 |     | 
     | 
  |  44 |     | 
     | 
  |  45 |     | 
     | 
  |  46 |    0 |            public ReloadActionListDaoJdbcImpl(DataSource nonTxDataSource) { | 
  |  47 |    0 |                    this.nonTxDataSource = nonTxDataSource;   | 
  |  48 |    0 |            }  | 
  |  49 |     | 
     | 
  |  50 |     | 
             | 
  |  51 |     | 
     | 
  |  52 |     | 
     | 
  |  53 |     | 
           @Override  | 
  |  54 |     | 
           public void setReloadActionListFlag(String userId) { | 
  |  55 |    0 |                    Connection conn = null;  | 
  |  56 |    0 |                    PreparedStatement preparedStatement = null;  | 
  |  57 |     | 
                     | 
  |  58 |     | 
                   try { | 
  |  59 |    0 |                            conn = nonTxDataSource.getConnection();  | 
  |  60 |     | 
                             | 
  |  61 |    0 |                            preparedStatement = conn.prepareStatement("insert into KREW_USR_OPTN_T (PRSN_OPTN_ID, PRNCPL_ID, VAL, VER_NBR) VALUES (?, ?, ?, ?)"); | 
  |  62 |    0 |                            preparedStatement.setString(1, RELOAD_ACTION_LIST);  | 
  |  63 |    0 |                            preparedStatement.setString(2, userId);  | 
  |  64 |    0 |                            preparedStatement.setString(3, "true");  | 
  |  65 |    0 |                            preparedStatement.setInt(4, 1);  | 
  |  66 |    0 |                            int result = preparedStatement.executeUpdate();  | 
  |  67 |     | 
                             | 
  |  68 |    0 |                    } catch (SQLException e) { | 
  |  69 |     | 
                             | 
  |  70 |     | 
                   } finally { | 
  |  71 |    0 |                            if (preparedStatement != null) { | 
  |  72 |     | 
                                   try { | 
  |  73 |    0 |                                            preparedStatement.close();  | 
  |  74 |    0 |                                    } catch (SQLException e) { | 
  |  75 |    0 |                                            LOG.error("couldn't close PreparedStatement", e); | 
  |  76 |    0 |                                    }  | 
  |  77 |     | 
                           }  | 
  |  78 |    0 |                            if (conn != null) { | 
  |  79 |     | 
                                   try { | 
  |  80 |    0 |                                            conn.close();  | 
  |  81 |    0 |                                    } catch (SQLException e) { | 
  |  82 |    0 |                                            LOG.error("couldn't close Connection", e); | 
  |  83 |    0 |                                    }  | 
  |  84 |     | 
                           }  | 
  |  85 |     | 
                   }  | 
  |  86 |    0 |            }  | 
  |  87 |     | 
     | 
  |  88 |     | 
             | 
  |  89 |     | 
             | 
  |  90 |     | 
     | 
  |  91 |     | 
     | 
  |  92 |     | 
           @Override  | 
  |  93 |     | 
           public boolean checkAndResetReloadActionListFlag(String userId) { | 
  |  94 |    0 |                    Connection conn = null;  | 
  |  95 |    0 |                    PreparedStatement preparedStatement = null;  | 
  |  96 |    0 |                    int updatedCount = 0;  | 
  |  97 |     | 
                     | 
  |  98 |     | 
                   try { | 
  |  99 |    0 |                            conn = nonTxDataSource.getConnection();  | 
  |  100 |     | 
                             | 
  |  101 |    0 |                            preparedStatement = conn.prepareStatement("delete from KREW_USR_OPTN_T where PRSN_OPTN_ID = ? and PRNCPL_ID = ?"); | 
  |  102 |    0 |                            preparedStatement.setString(1, RELOAD_ACTION_LIST);  | 
  |  103 |    0 |                            preparedStatement.setString(2, userId);  | 
  |  104 |    0 |                            updatedCount = preparedStatement.executeUpdate();  | 
  |  105 |     | 
                             | 
  |  106 |    0 |                    } catch (SQLException e) { | 
  |  107 |    0 |                            LOG.error("unable to delete RELOAD_ACTION_LIST preference", e); | 
  |  108 |     | 
                   } finally { | 
  |  109 |    0 |                            if (preparedStatement != null) { | 
  |  110 |     | 
                                   try { | 
  |  111 |    0 |                                            preparedStatement.close();  | 
  |  112 |    0 |                                    } catch (SQLException e) { | 
  |  113 |    0 |                                            LOG.error("couldn't close PreparedStatement", e); | 
  |  114 |    0 |                                    }  | 
  |  115 |     | 
                           }  | 
  |  116 |    0 |                            if (conn != null) { | 
  |  117 |     | 
                                   try { | 
  |  118 |    0 |                                            conn.close();  | 
  |  119 |    0 |                                    } catch (SQLException e) { | 
  |  120 |    0 |                                            LOG.error("couldn't close Connection", e); | 
  |  121 |    0 |                                    }  | 
  |  122 |     | 
                           }  | 
  |  123 |     | 
                   }  | 
  |  124 |     | 
                     | 
  |  125 |    0 |                    return updatedCount == 1;  | 
  |  126 |     | 
           }  | 
  |  127 |     | 
             | 
  |  128 |     | 
             | 
  |  129 |     | 
   }  |