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.newsletter.business.topic;
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
43
44
45 public class FreeHtmlTopicDao implements IFreeHtmlTopicDAO
46 {
47 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = " SELECT id_topic, html_content FROM newsletter_topic_free_html WHERE id_topic = ? ";
48 private static final String SQL_QUERY_UPDATE = " UPDATE newsletter_topic_free_html SET html_content = ? WHERE id_topic = ? ";
49 private static final String SQL_QUERY_INSERT = " INSERT INTO newsletter_topic_free_html (id_topic, html_content) VALUES (?,?) ";
50 private static final String SQL_QUERY_DELETE = " DELETE FROM newsletter_topic_free_html WHERE id_topic = ? ";
51 private static final String SQL_QUERY_FIND_BY_ID_LIST = " SELECT id_topic, html_content FROM newsletter_topic_free_html WHERE id_topic IN ( ";
52
53 private static final String CONSTANT_COMMA = ",";
54 private static final String CONSTANT_CLOSE_PARENTHESIS = ")";
55
56
57
58
59 @Override
60 public FreeHtmlTopic findByPrimaryKey( int nId, Plugin plugin )
61 {
62 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
63 daoUtil.setInt( 1, nId );
64 FreeHtmlTopic topic = null;
65
66 daoUtil.executeQuery( );
67 if ( daoUtil.next( ) )
68 {
69 topic = new FreeHtmlTopic( );
70 topic.setId( daoUtil.getInt( 1 ) );
71 topic.setHtmlContent( daoUtil.getString( 2 ) );
72 }
73 daoUtil.free( );
74 return topic;
75 }
76
77
78
79
80 @Override
81 public void insert( FreeHtmlTopic freeHtmlTopic, Plugin plugin )
82 {
83 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
84 daoUtil.setInt( 1, freeHtmlTopic.getId( ) );
85 daoUtil.setString( 2, freeHtmlTopic.getHtmlContent( ) );
86 daoUtil.executeUpdate( );
87 daoUtil.free( );
88 }
89
90
91
92
93 @Override
94 public void update( FreeHtmlTopic freeHtmlTopic, Plugin plugin )
95 {
96 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
97 daoUtil.setString( 1, freeHtmlTopic.getHtmlContent( ) );
98 daoUtil.setInt( 2, freeHtmlTopic.getId( ) );
99 daoUtil.executeUpdate( );
100 daoUtil.free( );
101 }
102
103
104
105
106 @Override
107 public void remove( int nId, Plugin plugin )
108 {
109 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
110 daoUtil.setInt( 1, nId );
111 daoUtil.executeUpdate( );
112 daoUtil.free( );
113 }
114
115
116
117
118 @Override
119 public List<FreeHtmlTopic> findCollection( List<Integer> listIds, Plugin plugin )
120 {
121 List<FreeHtmlTopic> listTopic = new ArrayList<FreeHtmlTopic>( );
122 if ( listIds != null )
123 {
124 List<Integer> listPrivIds = new ArrayList<Integer>( listIds );
125 StringBuilder sbSql = new StringBuilder( SQL_QUERY_FIND_BY_ID_LIST );
126 if ( listIds.size( ) > 0 )
127 {
128 sbSql.append( listPrivIds.get( 0 ) );
129 listPrivIds.remove( 0 );
130 }
131 for ( int nId : listPrivIds )
132 {
133 sbSql.append( CONSTANT_COMMA );
134 sbSql.append( nId );
135 }
136 sbSql.append( CONSTANT_CLOSE_PARENTHESIS );
137 DAOUtil daoUtil = new DAOUtil( sbSql.toString( ), plugin );
138 int nIndex = 1;
139 for ( int nId : listIds )
140 {
141 daoUtil.setInt( nIndex++, nId );
142 }
143
144 daoUtil.executeQuery( );
145 while ( daoUtil.next( ) )
146 {
147 FreeHtmlTopicewsletter/business/topic/FreeHtmlTopic.html#FreeHtmlTopic">FreeHtmlTopic topic = new FreeHtmlTopic( );
148 topic.setId( daoUtil.getInt( 1 ) );
149 topic.setHtmlContent( daoUtil.getString( 2 ) );
150 listTopic.add( topic );
151 }
152 daoUtil.free( );
153 }
154 return listTopic;
155 }
156 }