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.style;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import java.sql.Statement;
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45 public final class PageTemplateDAO implements IPageTemplateDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = " SELECT id_template, description, file_name, picture FROM core_page_template WHERE id_template = ?";
49 private static final String SQL_QUERY_INSERT = " INSERT INTO core_page_template ( description, file_name, picture ) VALUES ( ?, ?, ? )";
50 private static final String SQL_QUERY_DELETE = " DELETE FROM core_page_template WHERE id_template = ?";
51 private static final String SQL_QUERY_UPDATE = " UPDATE core_page_template SET id_template = ?, description = ?, file_name = ?, picture = ? "
52 + " WHERE id_template = ?";
53 private static final String SQL_QUERY_SELECTALL = " SELECT id_template , description, file_name, picture FROM core_page_template ORDER BY id_template ";
54 private static final String SQL_CHECK_PAGE_TEMPLATE_IS_USED = " SELECT id_template FROM core_page WHERE id_template = ? ";
55
56
57
58
59
60
61
62
63
64
65 public void insert( PageTemplate pageTemplate )
66 {
67 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS ) )
68 {
69 int nIndex = 1;
70 daoUtil.setString( nIndex++, pageTemplate.getDescription( ) );
71 daoUtil.setString( nIndex++, pageTemplate.getFile( ) );
72 daoUtil.setString( nIndex, pageTemplate.getPicture( ) );
73
74 daoUtil.executeUpdate( );
75
76 if ( daoUtil.nextGeneratedKey( ) )
77 {
78 pageTemplate.setId( daoUtil.getGeneratedKeyInt( 1 ) );
79 }
80 }
81 }
82
83
84
85
86
87
88
89
90 public PageTemplate load( int nPageTemplateId )
91 {
92 PageTemplate pageTemplate = null;
93 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
94 {
95 daoUtil.setInt( 1, nPageTemplateId );
96
97 daoUtil.executeQuery( );
98
99 if ( daoUtil.next( ) )
100 {
101 pageTemplate = new PageTemplate( );
102 pageTemplate.setId( daoUtil.getInt( 1 ) );
103 pageTemplate.setDescription( daoUtil.getString( 2 ) );
104 pageTemplate.setFile( daoUtil.getString( 3 ) );
105 pageTemplate.setPicture( daoUtil.getString( 4 ) );
106 }
107
108 }
109
110 return pageTemplate;
111 }
112
113
114
115
116
117
118
119 public void delete( int nPageTemplateId )
120 {
121 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
122 {
123 daoUtil.setInt( 1, nPageTemplateId );
124 daoUtil.executeUpdate( );
125 }
126 }
127
128
129
130
131
132
133
134 public void store( PageTemplate pageTemplate )
135 {
136 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
137 {
138
139 daoUtil.setInt( 1, pageTemplate.getId( ) );
140 daoUtil.setString( 2, pageTemplate.getDescription( ) );
141 daoUtil.setString( 3, pageTemplate.getFile( ) );
142 daoUtil.setString( 4, pageTemplate.getPicture( ) );
143 daoUtil.setInt( 5, pageTemplate.getId( ) );
144
145 daoUtil.executeUpdate( );
146 }
147 }
148
149
150
151
152
153
154 public List<PageTemplate> selectPageTemplatesList( )
155 {
156 List<PageTemplate> listPageTemplates = new ArrayList<>( );
157 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
158 {
159 daoUtil.executeQuery( );
160
161 while ( daoUtil.next( ) )
162 {
163 PageTemplateyle/PageTemplate.html#PageTemplate">PageTemplate pageTemplate = new PageTemplate( );
164
165 pageTemplate.setId( daoUtil.getInt( 1 ) );
166 pageTemplate.setDescription( daoUtil.getString( 2 ) );
167 pageTemplate.setFile( daoUtil.getString( 3 ) );
168 pageTemplate.setPicture( daoUtil.getString( 4 ) );
169 listPageTemplates.add( pageTemplate );
170 }
171
172 }
173
174 return listPageTemplates;
175 }
176
177
178
179
180
181
182
183
184 public boolean checkPageTemplateIsUsed( int nPageTemplateId )
185 {
186 boolean check = false;
187 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_CHECK_PAGE_TEMPLATE_IS_USED ) )
188 {
189
190 daoUtil.setInt( 1, nPageTemplateId );
191 daoUtil.executeQuery( );
192
193 if ( !daoUtil.next( ) )
194 {
195 check = true;
196 }
197
198 }
199
200 return check;
201 }
202 }