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
45 public final class AdminRoleDAO implements IAdminRoleDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = " SELECT role_key, role_description FROM core_admin_role WHERE role_key = ? ";
49 private static final String SQL_QUERY_INSERT = " INSERT INTO core_admin_role ( role_key, role_description ) VALUES ( ?, ? ) ";
50 private static final String SQL_QUERY_DELETE = " DELETE FROM core_admin_role WHERE role_key = ? ";
51 private static final String SQL_QUERY_UPDATE = " UPDATE core_admin_role SET role_key = ?, role_description = ? WHERE role_key = ? ";
52 private static final String SQL_QUERY_SELECTALL = " SELECT role_key, role_description FROM core_admin_role ORDER BY role_key";
53
54
55
56
57
58
59 public void insert( AdminRole role )
60 {
61 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
62 daoUtil.setString( 1, role.getKey( ) );
63 daoUtil.setString( 2, role.getDescription( ) );
64
65 daoUtil.executeUpdate( );
66 daoUtil.free( );
67 }
68
69
70
71
72
73
74
75 public AdminRole load( String strRoleKey )
76 {
77 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
78 daoUtil.setString( 1, strRoleKey );
79 daoUtil.executeQuery( );
80
81 AdminRole role = null;
82
83 if ( daoUtil.next( ) )
84 {
85 role = new AdminRole( );
86 role.setKey( daoUtil.getString( 1 ) );
87 role.setDescription( daoUtil.getString( 2 ) );
88 }
89
90 daoUtil.free( );
91
92 return role;
93 }
94
95
96
97
98
99 public void delete( String strRoleKey )
100 {
101 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
102 daoUtil.setString( 1, strRoleKey );
103
104 daoUtil.executeUpdate( );
105 daoUtil.free( );
106 }
107
108
109
110
111
112
113 public void store( String strRoleKey, AdminRole role )
114 {
115 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
116 daoUtil.setString( 1, role.getKey( ) );
117 daoUtil.setString( 2, role.getDescription( ) );
118 daoUtil.setString( 3, strRoleKey );
119
120 daoUtil.executeUpdate( );
121 daoUtil.free( );
122 }
123
124
125
126
127
128 public Collection<AdminRole> selectRoleList( )
129 {
130 Collection<AdminRole> listRoles = new ArrayList<AdminRole>( );
131 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
132 daoUtil.executeQuery( );
133
134 while ( daoUtil.next( ) )
135 {
136 AdminRole role = new AdminRole( );
137 role.setKey( daoUtil.getString( 1 ) );
138 role.setDescription( daoUtil.getString( 2 ) );
139
140 listRoles.add( role );
141 }
142
143 daoUtil.free( );
144
145 return listRoles;
146 }
147
148
149
150
151
152
153 public boolean checkExistRole( String strRoleKey )
154 {
155 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
156 daoUtil.setString( 1, strRoleKey );
157 daoUtil.executeQuery( );
158
159 if ( daoUtil.next( ) )
160 {
161 daoUtil.free( );
162
163 return true;
164 }
165 else
166 {
167 daoUtil.free( );
168
169 return false;
170 }
171 }
172 }