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.myportal.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
43
44
45
46
47 public final class ColumnStyleDAO implements IWidgetStyleDAO
48 {
49
50 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_style ) FROM myportal_column_style";
51 private static final String SQL_QUERY_SELECT = "SELECT id_style, name, css_class FROM myportal_column_style WHERE id_style = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO myportal_column_style ( id_style, name, css_class ) VALUES ( ?, ?, ? ) ";
53 private static final String SQL_QUERY_DELETE = "DELETE FROM myportal_column_style WHERE id_style = ? ";
54 private static final String SQL_QUERY_UPDATE = "UPDATE myportal_column_style SET id_style = ?, name = ?, css_class = ? WHERE id_style = ?";
55 private static final String SQL_QUERY_SELECTALL = "SELECT id_style, name, css_class FROM myportal_column_style";
56
57
58
59
60
61
62
63
64 public int newPrimaryKey( Plugin plugin )
65 {
66 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
67 daoUtil.executeQuery( );
68
69 int nKey;
70
71 if ( !daoUtil.next( ) )
72 {
73
74 nKey = 1;
75 }
76
77 nKey = daoUtil.getInt( 1 ) + 1;
78 daoUtil.free( );
79
80 return nKey;
81 }
82
83
84
85
86
87
88
89
90
91 public void insert( Style style, Plugin plugin )
92 {
93 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
94
95 style.setId( newPrimaryKey( plugin ) );
96
97 daoUtil.setInt( 1, style.getId( ) );
98 daoUtil.setString( 2, style.getName( ) );
99 daoUtil.setString( 3, style.getCssClass( ) );
100
101 daoUtil.executeUpdate( );
102 daoUtil.free( );
103 }
104
105
106
107
108
109
110
111
112
113
114 public Style load( int nId, Plugin plugin )
115 {
116 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
117 daoUtil.setInt( 1, nId );
118 daoUtil.executeQuery( );
119
120 Style style = null;
121
122 if ( daoUtil.next( ) )
123 {
124 style = new Style( );
125
126 style.setId( daoUtil.getInt( 1 ) );
127 style.setName( daoUtil.getString( 2 ) );
128 style.setCssClass( daoUtil.getString( 3 ) );
129 }
130
131 daoUtil.free( );
132
133 return style;
134 }
135
136
137
138
139
140
141
142
143
144 public void delete( int nStyleId, Plugin plugin )
145 {
146 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
147 daoUtil.setInt( 1, nStyleId );
148 daoUtil.executeUpdate( );
149 daoUtil.free( );
150 }
151
152
153
154
155
156
157
158
159
160 public void store( Style style, Plugin plugin )
161 {
162 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
163
164 daoUtil.setInt( 1, style.getId( ) );
165 daoUtil.setString( 2, style.getName( ) );
166 daoUtil.setString( 3, style.getCssClass( ) );
167 daoUtil.setInt( 4, style.getId( ) );
168
169 daoUtil.executeUpdate( );
170 daoUtil.free( );
171 }
172
173
174
175
176
177
178
179
180 public List<Style> selectStylesList( Plugin plugin )
181 {
182 List<Style> styleList = new ArrayList<Style>( );
183 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
184 daoUtil.executeQuery( );
185
186 while ( daoUtil.next( ) )
187 {
188 Styleins/myportal/business/Style.html#Style">Style style = new Style( );
189
190 style.setId( daoUtil.getInt( 1 ) );
191 style.setName( daoUtil.getString( 2 ) );
192 style.setCssClass( daoUtil.getString( 3 ) );
193
194 styleList.add( style );
195 }
196
197 daoUtil.free( );
198
199 return styleList;
200 }
201 }