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.htmldocs.business.rss;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  import java.util.ArrayList;
40  import java.util.List;
41  
42  /**
43   *
44   * class HtmlDocResourceRssConfigDAO
45   *
46   */
47  public class HtmlDocResourceRssConfigDAO implements IHtmlDocResourceRssConfigDAO
48  {
49      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_rss,id_portlet " + "FROM htmldocs_rss_cf  WHERE id_rss=?";
50      private static final String SQL_QUERY_INSERT = "INSERT INTO htmldocs_rss_cf( " + "id_rss, id_portlet )" + "VALUES (?, ?)";
51      private static final String SQL_QUERY_UPDATE = "UPDATE htmldocs_rss_cf " + "SET id_rss=?, id_portlet=?" + " WHERE id_rss=?";
52      private static final String SQL_QUERY_DELETE = "DELETE FROM htmldocs_rss_cf WHERE id_rss=? ";
53      private static final String SQL_QUERY_FIND_ALL = "SELECT id_rss, id_portlet " + "FROM htmldocs_rss_cf";
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public synchronized void insert( HtmlDocResourceRssConfig config, Plugin plugin )
60      {
61          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
62  
63          int nPos = 0;
64  
65          daoUtil.setInt( ++nPos, config.getIdRss( ) );
66          daoUtil.setInt( ++nPos, config.getIdPortlet() );
67  
68  
69          daoUtil.executeUpdate( );
70          daoUtil.free( );
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public void store( HtmlDocResourceRssConfig config, Plugin plugin )
78      {
79          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
80  
81          int nPos = 0;
82  
83          daoUtil.setInt( ++nPos, config.getIdRss( ) );
84          daoUtil.setInt( ++nPos, config.getIdPortlet() );
85  
86  
87          daoUtil.setInt( ++nPos, config.getIdRss( ) );
88          daoUtil.executeUpdate( );
89          daoUtil.free( );
90      }
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public HtmlDocResourceRssConfig load( int nIdRss, Plugin plugin )
97      {
98          HtmlDocResourceRssConfig config = null;
99          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
100 
101         daoUtil.setInt( 1, nIdRss );
102 
103         daoUtil.executeQuery( );
104 
105         int nPos = 0;
106 
107         if ( daoUtil.next( ) )
108         {
109             config = new HtmlDocResourceRssConfig( );
110             config.setIdRss( daoUtil.getInt( ++nPos ) );
111             config.setIdPortlet( daoUtil.getInt( ++nPos ) );
112 
113         }
114 
115         daoUtil.free( );
116 
117         return config;
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     @Override
124     public void delete( int nIdRss, Plugin plugin )
125     {
126         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
127 
128         daoUtil.setInt( 1, nIdRss );
129         daoUtil.executeUpdate( );
130         daoUtil.free( );
131     }
132 
133     /**
134      * {@inheritDoc}
135      */
136     @Override
137     public List<HtmlDocResourceRssConfig> loadAll( Plugin plugin )
138     {
139         List<HtmlDocResourceRssConfig> configList = new ArrayList<HtmlDocResourceRssConfig>( );
140         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_ALL, plugin );
141 
142         daoUtil.executeQuery( );
143 
144         int nPos = 0;
145 
146         if ( daoUtil.next( ) )
147         {
148             HtmlDocResourceRssConfig config = new HtmlDocResourceRssConfig( );
149             config.setIdRss( daoUtil.getInt( ++nPos ) );
150             config.setIdPortlet( daoUtil.getInt( ++nPos ) );
151 
152 
153             configList.add( config );
154         }
155 
156         daoUtil.free( );
157 
158         return configList;
159     }
160 }