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.calendar.business.portlet;
35  
36  import fr.paris.lutece.portal.business.portlet.Portlet;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  
40  /**
41   * This class provides Data Access methods for CalendarPortlet objects
42   */
43  public final class MiniCalendarPortletDAO implements IMiniCalendarPortletDAO
44  {
45      // Constants
46      private static final String SQL_QUERY_SELECT = "SELECT id_portlet FROM core_portlet WHERE id_portlet = ?";
47      private static final String SQL_QUERY_SELECT_TOP_EVENT = "SELECT top_event FROM calendar_mini_portlet";
48      private static final String SQL_QUERY_UPDATE_TOP_EVENT = "UPDATE calendar_mini_portlet SET top_event= ?";
49  
50      ///////////////////////////////////////////////////////////////////////////////////////
51      //Access methods to data
52  
53      /**
54       * Inserts a new record in the table. Not implemented.
55       * 
56       * @param portlet the object to be inserted
57       */
58      public void insert( Portlet portlet )
59      {
60          // Not implemented.
61      }
62  
63      /**
64       * Deletes a record from the table.
65       * 
66       * @param nPortletId the portlet id
67       * 
68       */
69      public void delete( int nPortletId )
70      {
71          // Not implemented.
72      }
73  
74      /**
75       * Loads the data of the portlet from the table.
76       * 
77       * @param nPortletId the portlet id
78       * @return the Portlet object
79       */
80      public Portlet load( int nPortletId )
81      {
82          MiniCalendarPortlet portlet = new MiniCalendarPortlet( );
83  
84          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
85  
86          daoUtil.setInt( 1, nPortletId );
87  
88          daoUtil.executeQuery( );
89  
90          if ( daoUtil.next( ) )
91          {
92              portlet.setId( nPortletId );
93          }
94  
95          daoUtil.free( );
96  
97          return portlet;
98      }
99  
100     /**
101      * Updates the record in the table. Not implemented.
102      * 
103      * @param portlet
104      *            the instance of Portlet class to be updated
105      */
106     public void store( Portlet portlet )
107     {
108         // Not implemented.
109     }
110 
111     /**
112      * Define top events are displayed or not
113      * @return true if shows top event else false
114      */
115     public boolean showTopEvent( )
116     {
117         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_TOP_EVENT );
118         daoUtil.executeQuery( );
119 
120         boolean bTopEvent = false;
121 
122         while ( daoUtil.next( ) )
123         {
124             bTopEvent = daoUtil.getBoolean( 1 );
125         }
126 
127         daoUtil.free( );
128 
129         return bTopEvent;
130     }
131 
132     /**
133      * Define top events are displayed or not
134      * @param top_event The top_event
135      */
136     public void updateTopEvent( boolean top_event )
137     {
138         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_TOP_EVENT );
139         daoUtil.setBoolean( 1, top_event );
140         daoUtil.executeUpdate( );
141     }
142 }