View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.tagcloud.business.portlet;
35  
36  import fr.paris.lutece.portal.business.portlet.Portlet;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  import java.util.ArrayList;
40  import java.util.Collection;
41  
42  
43  /**
44   * This class provides Data Access methods for TagCloudPortlet objects
45   */
46  public final class TagCloudPortletDAO implements ITagCloudPortletDAO
47  {
48      // Constants
49      private static final String SQL_QUERY_SELECT = "SELECT id_portlet, id_cloud FROM tagcloud_portlet WHERE id_portlet = ?";
50      private static final String SQL_QUERY_INSERT = "INSERT INTO tagcloud_portlet ( id_portlet, id_cloud ) VALUES ( ?, ? ) ";
51      private static final String SQL_QUERY_DELETE = "DELETE FROM tagcloud_portlet WHERE id_portlet = ? ";
52      private static final String SQL_QUERY_UPDATE = "UPDATE tagcloud_portlet SET id_portlet = ?, id_cloud = ? WHERE id_portlet = ?";
53      private static final String SQL_QUERY_SELECTALL = "SELECT id_portlet, id_cloud FROM tagcloud_portlet";
54      private static final String SQL_QUERY_SELECT_TAGCLOUD_BY_PORTLET = "SELECT id_cloud FROM tagcloud_portlet WHERE id_portlet = ?";
55  
56      /**
57       * Insert a new record in the table.
58       *
59       * @param tagCloudPortlet instance of the TagCloudPortlet object to insert
60       */
61      public void insert( TagCloudPortlet tagCloudPortlet )
62      {
63      }
64  
65      /**
66       * Load the data of the tagCloudPortlet from the table
67       *
68       * @return the instance of the TagCloudPortlet
69       * @param nId The identifier of the tagCloudPortlet
70       */
71      public TagCloudPortlet load( int nId )
72      {
73          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
74          daoUtil.setInt( 1, nId );
75          daoUtil.executeQuery(  );
76  
77          TagCloudPortlet tagCloudPortlet = null;
78  
79          if ( daoUtil.next(  ) )
80          {
81              tagCloudPortlet = new TagCloudPortlet(  );
82  
83              tagCloudPortlet.setIdPortlet( daoUtil.getInt( 1 ) );
84              tagCloudPortlet.setIdCloud( daoUtil.getInt( 2 ) );
85          }
86  
87          daoUtil.free(  );
88  
89          return tagCloudPortlet;
90      }
91  
92      /**
93       * Delete a record from the table
94       *
95       * @param nTagCloudPortletId The identifier of the tagCloudPortlet
96       */
97      public void delete( int nTagCloudPortletId )
98      {
99          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
100         daoUtil.setInt( 1, nTagCloudPortletId );
101         daoUtil.executeUpdate(  );
102         daoUtil.free(  );
103     }
104 
105     /**
106      * Update the record in the table
107      * @param tagCloudPortlet The reference of the tagCloudPortlet
108      */
109     public void store( TagCloudPortlet tagCloudPortlet )
110     {
111     }
112 
113     /**
114      * Load the data of all the tagCloudPortlets and returns them as a collection
115      *
116      * @return The Collection which contains the data of all the tagCloudPortlets
117      */
118     public Collection<TagCloudPortlet> selectTagCloudPortletsList(  )
119     {
120         Collection<TagCloudPortlet> tagCloudPortletList = new ArrayList<TagCloudPortlet>(  );
121         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
122         daoUtil.executeQuery(  );
123 
124         while ( daoUtil.next(  ) )
125         {
126             TagCloudPortletness/portlet/TagCloudPortlet.html#TagCloudPortlet">TagCloudPortlet tagCloudPortlet = new TagCloudPortlet(  );
127 
128             tagCloudPortlet.setIdPortlet( daoUtil.getInt( 1 ) );
129             tagCloudPortlet.setIdCloud( daoUtil.getInt( 2 ) );
130 
131             tagCloudPortletList.add( tagCloudPortlet );
132         }
133 
134         daoUtil.free(  );
135 
136         return tagCloudPortletList;
137     }
138 
139     /**
140      * A collection of integer
141      * @param nPortletId The portlet id
142      * @return A collection
143      */
144     public Collection<Integer> selectTagCloudByPortlet( int nPortletId )
145     {
146         Collection<Integer> tagCloudPortletList = new ArrayList<Integer>(  );
147         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_TAGCLOUD_BY_PORTLET );
148         daoUtil.setInt( 1, nPortletId );
149         daoUtil.executeQuery(  );
150 
151         while ( daoUtil.next(  ) )
152         {
153             tagCloudPortletList.add( daoUtil.getInt( 1 ) );
154         }
155 
156         daoUtil.free(  );
157 
158         return tagCloudPortletList;
159     }
160 
161     /**
162      * Associates a portlet to a tagcloud
163      * @param nPortletId The portlet id
164      * @param nCloudId The cloud id
165      */
166     public void insertCloud( int nPortletId, int nCloudId )
167     {
168         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
169 
170         daoUtil.setInt( 1, nPortletId );
171         daoUtil.setInt( 2, nCloudId );
172 
173         daoUtil.executeUpdate(  );
174         daoUtil.free(  );
175     }
176 
177     /**
178     * Updates association of a portlet to a tagcloud
179     * @param nPortletId The portlet id
180     * @param nCloudId The cloud id
181     */
182     public void storeCloud( int nPortletId, int nCloudId )
183     {
184         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
185 
186         daoUtil.setInt( 1, nPortletId );
187         daoUtil.setInt( 2, nCloudId );
188         daoUtil.setInt( 3, nPortletId );
189 
190         daoUtil.executeUpdate(  );
191         daoUtil.free(  );
192     }
193 
194     /**
195      * Associates a portlet to a tagcloud
196      * @param portlet The portlet
197      */
198     public void insert( Portlet portlet )
199     {
200         TagCloudPortlet./../../../../fr/paris/lutece/plugins/tagcloud/business/portlet/TagCloudPortlet.html#TagCloudPortlet">TagCloudPortlet port = (TagCloudPortlet) portlet;
201         insertCloud( port.getId(  ), port.getIdCloud(  ) );
202     }
203 
204     /**
205      * A dummy store method
206      * @param portlet The portlet
207      */
208     public void store( Portlet portlet )
209     {
210         //Not implemented
211     }
212 }