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.portlet;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.List;
39
40 import fr.paris.lutece.util.ReferenceList;
41 import fr.paris.lutece.util.sql.DAOUtil;
42
43
44
45
46 public final class AliasPortletDAO implements IAliasPortletDAO
47 {
48
49 private static final String SQL_QUERY_INSERT = "INSERT INTO core_portlet_alias ( id_portlet , id_alias ) VALUES ( ?, ? )";
50 private static final String SQL_QUERY_DELETE = "DELETE FROM core_portlet_alias WHERE id_portlet = ?";
51 private static final String SQL_QUERY_SELECT = "SELECT id_alias FROM core_portlet_alias WHERE id_portlet = ? ";
52 private static final String SQL_QUERY_UPDATE = "UPDATE core_portlet_alias SET id_alias=? WHERE id_portlet = ?";
53 private static final String SQL_QUERY_SELECT_PORTLETS_BY_TYPE = "SELECT id_portlet, name FROM core_portlet WHERE id_portlet_type = ? ORDER BY name";
54 private static final String SQL_QUERY_SELECT_ALIAS_ID = "SELECT id_alias FROM core_portlet_alias WHERE id_portlet= ? ";
55 private static final String SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST = "SELECT id_portlet, name FROM core_portlet WHERE accept_alias = 1 ";
56 private static final String SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST_DETAIL = "SELECT id_portlet, id_page, name FROM core_portlet WHERE accept_alias = 1 ORDER BY id_page";
57
58
59
60
61
62
63
64 public synchronized void insert( Portlet portlet )
65 {
66 AliasPortlet/../../../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet alias = (AliasPortlet) portlet;
67
68
69 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
70 {
71 daoUtil.setInt( 1, alias.getId( ) );
72 daoUtil.setInt( 2, alias.getAliasId( ) );
73
74 daoUtil.executeUpdate( );
75 }
76 }
77
78
79
80
81 public void delete( int nPortletId )
82 {
83 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
84 {
85 daoUtil.setInt( 1, nPortletId );
86
87 daoUtil.executeUpdate( );
88 }
89 }
90
91
92
93
94 public Portlet load( int nIdPortlet )
95 {
96 AliasPortletss/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet portlet = new AliasPortlet( );
97 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
98 {
99 daoUtil.setInt( 1, nIdPortlet );
100 daoUtil.executeQuery( );
101
102 if ( daoUtil.next( ) )
103 {
104 portlet.setAliasId( daoUtil.getInt( 1 ) );
105 }
106
107 }
108
109 return portlet;
110 }
111
112
113
114
115 public void store( Portlet portlet )
116 {
117 AliasPortlet./../../../../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet r = (AliasPortlet) portlet;
118
119 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
120 {
121 daoUtil.setInt( 1, r.getAliasId( ) );
122 daoUtil.setInt( 2, portlet.getId( ) );
123
124 daoUtil.executeUpdate( );
125 }
126 }
127
128
129
130
131 public ReferenceList selectPortletsByTypeList( String strPortletTypeId )
132 {
133 ReferenceListnceList.html#ReferenceList">ReferenceList list = new ReferenceList( );
134 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLETS_BY_TYPE ) )
135 {
136 daoUtil.setString( 1, strPortletTypeId );
137 daoUtil.executeQuery( );
138
139 while ( daoUtil.next( ) )
140 {
141 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
142 }
143
144 }
145
146 return list;
147 }
148
149
150
151
152 public int selectAliasId( int nIdPortlet )
153 {
154 int nAliasId = 0;
155 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALIAS_ID ) )
156 {
157 daoUtil.setInt( 1, nIdPortlet );
158 daoUtil.executeQuery( );
159
160 if ( daoUtil.next( ) )
161 {
162 nAliasId = daoUtil.getInt( 1 );
163 }
164
165 }
166
167 return nAliasId;
168 }
169
170
171
172
173 public ReferenceList selectAcceptAliasPortletRefList( )
174 {
175 ReferenceListnceList.html#ReferenceList">ReferenceList list = new ReferenceList( );
176 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST ) )
177 {
178 daoUtil.executeQuery( );
179
180 while ( daoUtil.next( ) )
181 {
182 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
183 }
184
185 }
186
187 return list;
188 }
189
190
191
192
193 public Collection<Portlet> selectAcceptAliasPortletList( )
194 {
195 List<Portlet> list = new ArrayList<>( );
196 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST_DETAIL ) )
197 {
198 daoUtil.executeQuery( );
199
200 while ( daoUtil.next( ) )
201 {
202 PortletImpless/portlet/PortletImpl.html#PortletImpl">PortletImpl portlet = new PortletImpl( );
203 portlet.setId( daoUtil.getInt( 1 ) );
204 portlet.setPageId( daoUtil.getInt( 2 ) );
205 portlet.setName( daoUtil.getString( 3 ) );
206 list.add( portlet );
207 }
208
209 }
210
211 return list;
212 }
213
214 }