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.role;
35
36 import fr.paris.lutece.util.ReferenceList;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.Collection;
41
42
43
44
45 public final class RoleDAO implements IRoleDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = " SELECT role, role_description, workgroup_key FROM core_role WHERE role = ?";
49 private static final String SQL_QUERY_SELECTALL = " SELECT role , role_description, workgroup_key FROM core_role ORDER BY role";
50 private static final String SQL_QUERY_INSERT = " INSERT INTO core_role ( role, role_description, workgroup_key ) VALUES ( ?, ?, ? )";
51 private static final String SQL_QUERY_DELETE = " DELETE FROM core_role WHERE role = ? ";
52 private static final String SQL_QUERY_UPDATE = " UPDATE core_role SET role_description = ?, workgroup_key = ? WHERE role = ?";
53
54
55
56
57
58
59
60
61
62
63 public void insert( Role role )
64 {
65 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
66 {
67
68 daoUtil.setString( 1, role.getRole( ) );
69 daoUtil.setString( 2, role.getRoleDescription( ) );
70 daoUtil.setString( 3, role.getWorkgroup( ) );
71
72 daoUtil.executeUpdate( );
73 }
74 }
75
76
77
78
79
80
81
82
83 public Role load( String strRole )
84 {
85 Role role = null;
86 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
87 {
88 daoUtil.setString( 1, strRole );
89
90 daoUtil.executeQuery( );
91
92 if ( daoUtil.next( ) )
93 {
94 role = new Role( );
95 role.setRole( daoUtil.getString( 1 ) );
96 role.setRoleDescription( daoUtil.getString( 2 ) );
97 role.setWorkgroup( daoUtil.getString( 3 ) );
98 }
99
100 }
101
102 return role;
103 }
104
105
106
107
108
109
110
111 public void delete( String strRole )
112 {
113 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
114 {
115 daoUtil.setString( 1, strRole );
116 daoUtil.executeUpdate( );
117 }
118 }
119
120
121
122
123
124
125
126 public void store( Role role )
127 {
128 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
129 {
130
131 daoUtil.setString( 1, role.getRoleDescription( ) );
132 daoUtil.setString( 2, role.getWorkgroup( ) );
133 daoUtil.setString( 3, role.getRole( ) );
134
135 daoUtil.executeUpdate( );
136 }
137 }
138
139
140
141
142
143
144 public ReferenceList selectRolesList( )
145 {
146 ReferenceListist.html#ReferenceList">ReferenceList roleList = new ReferenceList( );
147 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
148 {
149 daoUtil.executeQuery( );
150
151 while ( daoUtil.next( ) )
152 {
153 Rolertal/business/role/Role.html#Role">Role role = new Role( );
154 role.setRole( daoUtil.getString( 1 ) );
155 role.setRoleDescription( daoUtil.getString( 2 ) );
156
157 roleList.addItem( role.getRole( ), role.getRoleDescription( ) );
158 }
159
160 }
161
162 return roleList;
163 }
164
165
166
167
168
169
170 public Collection<Role> selectAll( )
171 {
172 Collection<Role> listRoles = new ArrayList<>( );
173 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
174 {
175 daoUtil.executeQuery( );
176
177 while ( daoUtil.next( ) )
178 {
179 Rolertal/business/role/Role.html#Role">Role role = new Role( );
180 role.setRole( daoUtil.getString( 1 ) );
181 role.setRoleDescription( daoUtil.getString( 2 ) );
182 role.setWorkgroup( daoUtil.getString( 3 ) );
183
184 listRoles.add( role );
185 }
186
187 }
188
189 return listRoles;
190 }
191 }