View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of 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.quicklinks.business.portlet;
35  
36  import fr.paris.lutece.portal.business.portlet.Portlet;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  /**
40   * This class provides Data Access methods for QuicklinksPortlet objects
41   */
42  public final class QuicklinksPortletDAO implements IQuicklinksPortletDAO
43  {
44      private static final String SQL_QUERY_INSERT = "INSERT INTO quicklinks_portlet ( id_portlet , id_quicklinks ) VALUES ( ? , ? )";
45      private static final String SQL_QUERY_SELECT = "SELECT id_portlet , id_quicklinks FROM quicklinks_portlet WHERE id_portlet = ? ";
46      private static final String SQL_QUERY_SELECT_COUNT_PORTLET_BY_ID_QUICKLINKS = "SELECT COUNT(id_portlet) "
47              + "FROM quicklinks_portlet WHERE id_quicklinks = ? ";
48      private static final String SQL_QUERY_UPDATE = "UPDATE quicklinks_portlet SET id_portlet = ?, id_quicklinks = ? WHERE id_portlet = ? ";
49      private static final String SQL_QUERY_DELETE = "DELETE FROM quicklinks_portlet WHERE id_portlet= ? ";
50  
51      ///////////////////////////////////////////////////////////////////////////////////////
52      // Access methods to data
53  
54      /**
55       * Insert a new record in the table quicklinks_portlet
56       *
57       *
58       * @param portlet the instance of the Portlet object to insert
59       */
60      public void insert( Portlet portlet )
61      {
62          QuicklinksPortlet../../../../../fr/paris/lutece/plugins/quicklinks/business/portlet/QuicklinksPortlet.html#QuicklinksPortlet">QuicklinksPortlet p = (QuicklinksPortlet) portlet;
63  
64          try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
65          {
66              daoUtil.setInt( 1, p.getId( ) );
67              daoUtil.setInt( 2, p.getQuicklinksId( ) );
68  
69              daoUtil.executeUpdate( );
70          }
71      }
72  
73      /**
74       * Deletes records for a portlet identifier in the table quicklinks_portlet
75       *
76       *
77       * @param nPortletId the portlet identifier
78       */
79      public void delete( int nPortletId )
80      {
81          try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
82          {
83              daoUtil.setInt( 1, nPortletId );
84              daoUtil.executeUpdate( );
85          }
86      }
87  
88      /**
89       * Loads the data of Quicklinks Portlet whose identifier is specified in
90       * parameter
91       *
92       *
93       * @param nPortletId The Portlet identifier
94       * @return theDocumentListPortlet object
95       */
96      public Portlet load( int nPortletId )
97      {
98          QuicklinksPortletnks/business/portlet/QuicklinksPortlet.html#QuicklinksPortlet">QuicklinksPortlet portlet = new QuicklinksPortlet( );
99          try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
100         {
101             daoUtil.setInt( 1, nPortletId );
102             daoUtil.executeQuery( );
103 
104             if ( daoUtil.next( ) )
105             {
106                 portlet.setId( daoUtil.getInt( 1 ) );
107                 portlet.setQuicklinksId( daoUtil.getInt( 2 ) );
108             }
109         }
110         return portlet;
111     }
112 
113     /**
114      * return number of quicklinks portlet who are associate to the id quicklinks
115      * 
116      * @param nIdQuicklinks the id of the quicklinks
117      * @return number of quicklinks portlet who are associate to the id quicklinks
118      */
119     public int selectCountPortletByIdQuicklinks( int nIdQuicklinks )
120     {
121         int nCountPortlet = 0;
122         try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_COUNT_PORTLET_BY_ID_QUICKLINKS ) )
123         {
124             daoUtil.setInt( 1, nIdQuicklinks );
125             daoUtil.executeQuery( );
126 
127             if ( daoUtil.next( ) )
128             {
129                 nCountPortlet = daoUtil.getInt( 1 );
130             }
131 
132         }
133 
134         return nCountPortlet;
135     }
136 
137     /**
138      * Update the record in the table
139      *
140      *
141      * @param portlet A portlet
142      */
143     public void store( Portlet portlet )
144     {
145         QuicklinksPortlet../../../../../fr/paris/lutece/plugins/quicklinks/business/portlet/QuicklinksPortlet.html#QuicklinksPortlet">QuicklinksPortlet p = (QuicklinksPortlet) portlet;
146         try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
147         {
148             daoUtil.setInt( 1, p.getId( ) );
149             daoUtil.setInt( 2, p.getQuicklinksId( ) );
150             daoUtil.setInt( 3, p.getId( ) );
151             daoUtil.executeUpdate( );
152         }
153     }
154 }