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