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.plugins.participatorybudget.business.vote;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 public class UserAccessVoteDAO implements IUserAccessVoteDAO
40 {
41
42 private static final String SQL_QUERY_INSERT = "INSERT INTO participatorybudget_user_access_vote ( id_user, has_acces_vote ) VALUES ( ?, ? ) ";
43 private static final String SQL_QUERY_UPDATE = "UPDATE participatorybudget_user_access_vote SET has_acces_vote = ? WHERE id_user = ? ";
44 private static final String SQL_QUERY_DELETE = "DELETE FROM participatorybudget_user_access_vote WHERE id_user = ?";
45 private static final String SQL_QUERY_SELECTALL = "SELECT id_user, has_acces_vote FROM participatorybudget_user_access_vote";
46 private static final String SQl_QUERY_SELECT = SQL_QUERY_SELECTALL + " where id_user= ?";
47
48 @Override
49 public void insert( UserAccessVote userVote, Plugin plugin )
50 {
51 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
52 {
53 daoUtil.setString( 1, userVote.getId( ) );
54 daoUtil.setBoolean( 2, userVote.isHasAccessVote( ) );
55
56 daoUtil.executeUpdate( );
57 }
58
59 }
60
61 @Override
62 public void update( UserAccessVote userVote, Plugin plugin )
63 {
64 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
65 {
66 daoUtil.setBoolean( 1, userVote.isHasAccessVote( ) );
67 daoUtil.setString( 2, userVote.getId( ) );
68
69 daoUtil.executeUpdate( );
70 }
71 }
72
73 @Override
74 public void delete( String strUserId, Plugin plugin )
75 {
76 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
77 {
78 daoUtil.setString( 1, strUserId );
79
80 daoUtil.executeUpdate( );
81 }
82 }
83
84 @Override
85 public UserAccessVote select( String strUserId, Plugin plugin )
86 {
87 UserAccessVote userAccessVote = null;
88
89 try ( DAOUtil daoUtil = new DAOUtil( SQl_QUERY_SELECT, plugin ) )
90 {
91 daoUtil.setString( 1, strUserId );
92 daoUtil.executeQuery( );
93
94 if ( daoUtil.next( ) )
95 {
96 userAccessVote = new UserAccessVote( );
97 userAccessVote.setId( daoUtil.getString( 1 ) );
98 userAccessVote.setHasAccessVote( daoUtil.getBoolean( 2 ) );
99
100 }
101 }
102
103 return userAccessVote;
104 }
105
106 }