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.announce.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42 public class AnnounceNotifyDAO implements IAnnounceNotifyDAO
43 {
44
45 private static final String SQL_QUERY_SELECT_ALL = "SELECT id, id_announce FROM announce_notify";
46 private static final String SQL_QUERY_INSERT = "INSERT INTO announce_notify ( id, id_announce) VALUES (?,?)";
47 private static final String SQL_QUERY_DELETE = "DELETE FROM announce_notify WHERE id = ? ";
48
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id ) FROM announce_notify";
50
51 @Override
52 public void insert( AnnounceNotify announce, Plugin plugin )
53 {
54
55 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
56 {
57 daoUtil.setInt( 1, newPrimaryKey( plugin ) );
58 daoUtil.setInt( 2, announce.getIdAnnounce( ) );
59
60 daoUtil.executeUpdate( );
61 }
62 }
63
64 @Override
65 public void delete( int nIdAnnounce, Plugin plugin )
66 {
67 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
68 {
69 daoUtil.setInt( 1, nIdAnnounce );
70 daoUtil.executeUpdate( );
71 }
72 }
73
74 @Override
75 public List<AnnounceNotify> load( Plugin plugin )
76 {
77
78 List<AnnounceNotify> announceList = new ArrayList<>( );
79 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL, plugin ) )
80 {
81 daoUtil.executeQuery( );
82
83 AnnounceNotify announceNotify;
84 while ( daoUtil.next( ) )
85 {
86 announceNotify = new AnnounceNotify( );
87 announceNotify.setId( daoUtil.getInt( 1 ) );
88 announceNotify.setIdAnnounce( daoUtil.getInt( 2 ) );
89 announceList.add( announceNotify );
90 }
91
92 }
93
94 return announceList;
95 }
96
97 public int newPrimaryKey( Plugin plugin )
98 {
99 int nKey = 1;
100 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
101 {
102 daoUtil.executeQuery( );
103
104 if ( daoUtil.next( ) )
105 {
106 nKey = daoUtil.getInt( 1 ) + 1;
107 }
108 }
109 return nKey;
110 }
111 }