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 private static final Logger LOG = Logger.getLogger(ReloadActionListDaoJdbcImpl.class);
39
40 DataSource nonTxDataSource;
41
42
43
44
45
46 public ReloadActionListDaoJdbcImpl(DataSource nonTxDataSource) {
47 this.nonTxDataSource = nonTxDataSource;
48 }
49
50
51
52
53 @Override
54 public void setReloadActionListFlag(String userId) {
55 Connection conn = null;
56 PreparedStatement preparedStatement = null;
57
58 try {
59 conn = nonTxDataSource.getConnection();
60
61 preparedStatement = conn.prepareStatement("insert into KREW_USR_OPTN_T (PRSN_OPTN_ID, PRNCPL_ID, VAL, VER_NBR) VALUES (?, ?, ?, ?)");
62 preparedStatement.setString(1, RELOAD_ACTION_LIST);
63 preparedStatement.setString(2, userId);
64 preparedStatement.setString(3, "true");
65 preparedStatement.setInt(4, 1);
66 int result = preparedStatement.executeUpdate();
67
68 } catch (SQLException e) {
69
70 } finally {
71 if (preparedStatement != null) {
72 try {
73 preparedStatement.close();
74 } catch (SQLException e) {
75 LOG.error("couldn't close PreparedStatement", e);
76 }
77 }
78 if (conn != null) {
79 try {
80 conn.close();
81 } catch (SQLException e) {
82 LOG.error("couldn't close Connection", e);
83 }
84 }
85 }
86 }
87
88
89
90
91
92 @Override
93 public boolean checkAndResetReloadActionListFlag(String userId) {
94 Connection conn = null;
95 PreparedStatement preparedStatement = null;
96 int updatedCount = 0;
97
98 try {
99 conn = nonTxDataSource.getConnection();
100
101 preparedStatement = conn.prepareStatement("delete from KREW_USR_OPTN_T where PRSN_OPTN_ID = ? and PRNCPL_ID = ?");
102 preparedStatement.setString(1, RELOAD_ACTION_LIST);
103 preparedStatement.setString(2, userId);
104 updatedCount = preparedStatement.executeUpdate();
105
106 } catch (SQLException e) {
107 LOG.error("unable to delete RELOAD_ACTION_LIST preferences for " + userId, e);
108 } finally {
109 if (preparedStatement != null) {
110 try {
111 preparedStatement.close();
112 } catch (SQLException e) {
113 LOG.error("couldn't close PreparedStatement", e);
114 }
115 }
116 if (conn != null) {
117 try {
118 conn.close();
119 } catch (SQLException e) {
120 LOG.error("couldn't close Connection", e);
121 }
122 }
123 }
124
125 return updatedCount == 1;
126 }
127
128
129 }