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