Coverage Report - org.kuali.rice.kew.useroptions.dao.impl.ReloadActionListDaoJdbcImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ReloadActionListDaoJdbcImpl
0%
0/46
0%
0/10
4.333
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Implementation of ReloadActionListDAO.  This needs to be straight JDBC since it ignores SQLException in one case.
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
          * This constructs a ReloadActionListDaoJdbcImpl
 44  
          * 
 45  
          */
 46  0
         public ReloadActionListDaoJdbcImpl(DataSource nonTxDataSource) {
 47  0
                 this.nonTxDataSource = nonTxDataSource; 
 48  0
         }
 49  
 
 50  
         /**
 51  
          * @see org.kuali.rice.kew.useroptions.dao.ReloadActionListDAO#setReloadActionListFlag(java.lang.String)
 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  
                         // this is normal if the preference is already set.
 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  
          * @see org.kuali.rice.kew.useroptions.dao.ReloadActionListDAO#checkAndResetReloadActionListFlag(java.lang.String)
 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  
 }