1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.rbac;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import java.util.ArrayList;
39 import java.util.Collection;
40
41
42
43
44 public final class RBACRoleDAO implements IRBACRoleDAO
45 {
46
47 private static final String SQL_QUERY_SELECT = " SELECT role_key, role_description FROM core_admin_role WHERE role_key = ? ";
48 private static final String SQL_QUERY_INSERT = " INSERT INTO core_admin_role ( role_key, role_description ) VALUES ( ?, ? ) ";
49 private static final String SQL_QUERY_DELETE = " DELETE FROM core_admin_role WHERE role_key = ? ";
50 private static final String SQL_QUERY_UPDATE = " UPDATE core_admin_role SET role_key = ?, role_description = ? WHERE role_key = ? ";
51 private static final String SQL_QUERY_SELECTALL = " SELECT role_key, role_description FROM core_admin_role ORDER BY role_key";
52
53
54
55
56
57
58
59 public void insert( RBACRole role )
60 {
61 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
62 {
63 daoUtil.setString( 1, role.getKey( ) );
64 daoUtil.setString( 2, role.getDescription( ) );
65
66 daoUtil.executeUpdate( );
67 }
68 }
69
70
71
72
73
74
75
76
77 public RBACRole load( String strRoleKey )
78 {
79 RBACRole role = null;
80 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
81 {
82 daoUtil.setString( 1, strRoleKey );
83 daoUtil.executeQuery( );
84
85 if ( daoUtil.next( ) )
86 {
87 role = new RBACRole( );
88 role.setKey( daoUtil.getString( 1 ) );
89 role.setDescription( daoUtil.getString( 2 ) );
90 }
91
92 }
93
94 return role;
95 }
96
97
98
99
100
101
102
103 public void delete( String strRoleKey )
104 {
105 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
106 {
107 daoUtil.setString( 1, strRoleKey );
108
109 daoUtil.executeUpdate( );
110 }
111 }
112
113
114
115
116
117
118
119
120
121 public void store( String strRoleKey, RBACRole role )
122 {
123 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
124 {
125 daoUtil.setString( 1, role.getKey( ) );
126 daoUtil.setString( 2, role.getDescription( ) );
127 daoUtil.setString( 3, strRoleKey );
128
129 daoUtil.executeUpdate( );
130 }
131 }
132
133
134
135
136
137
138 public Collection<RBACRole> selectRoleList( )
139 {
140 Collection<RBACRole> listRoles = new ArrayList<>( );
141 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
142 {
143 daoUtil.executeQuery( );
144
145 while ( daoUtil.next( ) )
146 {
147 RBACRole/business/rbac/RBACRole.html#RBACRole">RBACRole role = new RBACRole( );
148 role.setKey( daoUtil.getString( 1 ) );
149 role.setDescription( daoUtil.getString( 2 ) );
150
151 listRoles.add( role );
152 }
153
154 }
155
156 return listRoles;
157 }
158
159
160
161
162
163
164
165
166 public boolean checkExistRole( String strRoleKey )
167 {
168 boolean check = false;
169 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
170 {
171 daoUtil.setString( 1, strRoleKey );
172 daoUtil.executeQuery( );
173
174 if ( daoUtil.next( ) )
175 {
176 check = true;
177 }
178 }
179
180 return check;
181 }
182 }