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.htmldocs.business;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import java.util.ArrayList;
39 import java.util.List;
40
41
42
43
44
45 public final class DocumentPageTemplateDAO implements IDocumentPageTemplateDAO
46 {
47
48 private static final String SQL_QUERY_NEW_PK = " SELECT max( id_page_template_document ) FROM htmldocs_page_template";
49 private static final String SQL_QUERY_SELECT = " SELECT id_page_template_document, description, page_template_path, picture_path FROM htmldocs_page_template WHERE id_page_template_document = ?";
50 private static final String SQL_QUERY_INSERT = " INSERT INTO htmldocs_page_template ( id_page_template_document, description, page_template_path, picture_path ) VALUES ( ?, ?, ?, ? )";
51 private static final String SQL_QUERY_DELETE = " DELETE FROM htmldocs_page_template WHERE id_page_template_document = ?";
52 private static final String SQL_QUERY_UPDATE = " UPDATE htmldocs_page_template SET id_page_template_document = ?, description = ?, page_template_path = ?, picture_path = ? " +
53 " WHERE id_page_template_document = ?";
54 private static final String SQL_QUERY_SELECTALL = " SELECT id_page_template_document , description, page_template_path, picture_path FROM htmldocs_page_template ORDER BY id_page_template_document ";
55
56
57
58
59
60
61
62
63 int newPrimaryKey( )
64 {
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK );
66 daoUtil.executeQuery( );
67
68 int nKey;
69
70 if ( !daoUtil.next( ) )
71 {
72
73 nKey = 1;
74 }
75
76 nKey = daoUtil.getInt( 1 ) + 1;
77
78 daoUtil.free( );
79
80 return nKey;
81 }
82
83
84
85
86
87 public synchronized void insert( DocumentPageTemplate documentPageTemplate )
88 {
89 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
90
91 documentPageTemplate.setId( newPrimaryKey( ) );
92
93 daoUtil.setInt( 1, documentPageTemplate.getId( ) );
94 daoUtil.setString( 2, documentPageTemplate.getDescription( ) );
95 daoUtil.setString( 3, documentPageTemplate.getFile( ) );
96 daoUtil.setString( 4, documentPageTemplate.getPicture( ) );
97
98 daoUtil.executeUpdate( );
99 daoUtil.free( );
100 }
101
102
103
104
105
106
107
108 public DocumentPageTemplate load( int nPageTemplateId )
109 {
110 DocumentPageTemplate documentPageTemplate = null;
111 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
112 daoUtil.setInt( 1, nPageTemplateId );
113
114 daoUtil.executeQuery( );
115
116 if ( daoUtil.next( ) )
117 {
118 documentPageTemplate = new DocumentPageTemplate( );
119 documentPageTemplate.setId( daoUtil.getInt( 1 ) );
120 documentPageTemplate.setDescription( daoUtil.getString( 2 ) );
121 documentPageTemplate.setFile( daoUtil.getString( 3 ) );
122 documentPageTemplate.setPicture( daoUtil.getString( 4 ) );
123 }
124
125 daoUtil.free( );
126
127 return documentPageTemplate;
128 }
129
130
131
132
133
134 public void delete( int nPageTemplateId )
135 {
136 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
137 daoUtil.setInt( 1, nPageTemplateId );
138 daoUtil.executeUpdate( );
139 daoUtil.free( );
140 }
141
142
143
144
145
146 public void store( DocumentPageTemplate documentPageTemplate )
147 {
148 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
149
150 daoUtil.setInt( 1, documentPageTemplate.getId( ) );
151 daoUtil.setString( 2, documentPageTemplate.getDescription( ) );
152 daoUtil.setString( 3, documentPageTemplate.getFile( ) );
153 daoUtil.setString( 4, documentPageTemplate.getPicture( ) );
154 daoUtil.setInt( 5, documentPageTemplate.getId( ) );
155
156 daoUtil.executeUpdate( );
157 daoUtil.free( );
158 }
159
160
161
162
163
164 public List<DocumentPageTemplate> selectPageTemplatesList( )
165 {
166 List<DocumentPageTemplate> listDocumentPageTemplates = new ArrayList<DocumentPageTemplate>( );
167 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
168 daoUtil.executeQuery( );
169
170 while ( daoUtil.next( ) )
171 {
172 DocumentPageTemplate documentPageTemplate = new DocumentPageTemplate( );
173
174 documentPageTemplate.setId( daoUtil.getInt( 1 ) );
175 documentPageTemplate.setDescription( daoUtil.getString( 2 ) );
176 documentPageTemplate.setFile( daoUtil.getString( 3 ) );
177 documentPageTemplate.setPicture( daoUtil.getString( 4 ) );
178 listDocumentPageTemplates.add( documentPageTemplate );
179 }
180
181 daoUtil.free( );
182
183 return listDocumentPageTemplates;
184 }
185 }