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.document.business.autopublication;
35  
36  import fr.paris.lutece.plugins.document.business.spaces.DocumentSpace;
37  import fr.paris.lutece.portal.business.portlet.Portlet;
38  import fr.paris.lutece.util.sql.DAOUtil;
39  
40  import java.util.ArrayList;
41  import java.util.Collection;
42  
43  
44  /**
45   * This class provides Data Access methods for DocumentAutoPublication objects
46   *
47   */
48  public class DocumentAutoPublicationDAO implements IDocumentAutoPublicationDAO
49  {
50      private static final String SQL_QUERY_INSERT = "INSERT INTO document_auto_publication ( id_portlet , id_space ) VALUES ( ? , ? )";
51      private static final String SQL_QUERY_SELECT_BY_PRIMARY_KEY = "SELECT id_portlet, id_space FROM document_auto_publication WHERE id_portlet = ? AND id_space = ?";
52      private static final String SQL_QUERY_SELECT_ALL = "SELECT id_portlet, id_space FROM document_auto_publication ";
53      private static final String SQL_QUERY_SELECT_BY_PORTLET_ID = "SELECT id_space FROM document_auto_publication WHERE id_portlet = ? ";
54      private static final String SQL_QUERY_SELECT_BY_SPACE_ID = "SELECT id_portlet FROM document_auto_publication WHERE id_space = ? ";
55  
56      //    private static final String SQL_QUERY_UPDATE = "UPDATE document_auto_publication SET WHERE id_portlet = ? AND id_space = ? ";
57      private static final String SQL_QUERY_DELETE = "DELETE FROM document_auto_publication WHERE id_portlet= ? AND id_space= ? ";
58      private static final String SQL_QUERY_DELETE_ALL_SPACES = "DELETE FROM document_auto_publication WHERE id_portlet= ? ";
59  
60      /**
61       * Deletes records from a Document Auto Publication object identifier in the table document_auto_publication
62       *
63       * @param nPortletId the portlet identifier
64       * @param nSpaceId the {@link DocumentSpace} identifier
65       */
66      public void delete( int nPortletId, int nSpaceId )
67      {
68          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
69          daoUtil.setInt( 1, nPortletId );
70          daoUtil.setInt( 2, nSpaceId );
71          daoUtil.executeUpdate(  );
72          daoUtil.free(  );
73      }
74  
75      /**
76       * Delete records from a portlet
77       *
78       * @param nPortletId the portlet identifier
79       */
80      public void deleteAllSpaces( int nPortletId )
81      {
82          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_ALL_SPACES );
83          daoUtil.setInt( 1, nPortletId );
84          daoUtil.executeUpdate(  );
85          daoUtil.free(  );
86      }
87  
88      /**
89       * Insert a new record in the table document_auto_publication
90       *
91       * @param documentAutoPublication the instance of the
92       *            DocumentAutoPublication object to insert
93       */
94      public void insert( DocumentAutoPublication documentAutoPublication )
95      {
96          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
97          daoUtil.setInt( 1, documentAutoPublication.getIdPortlet(  ) );
98          daoUtil.setInt( 2, documentAutoPublication.getIdSpace(  ) );
99  
100         daoUtil.executeUpdate(  );
101         daoUtil.free(  );
102     }
103 
104     /**
105      * Loads the data of Document Auto Publication whose identifier is specified in parameter
106      *
107      * @param nPortletId The {@link Portlet} identifier
108      * @param nSpaceId The {@link DocumentSpace} identifier
109      * @return The {@link DocumentAutoPublication} object
110      */
111     public DocumentAutoPublication load( int nPortletId, int nSpaceId )
112     {
113         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_PRIMARY_KEY );
114         daoUtil.setInt( 1, nPortletId );
115         daoUtil.setInt( 2, nSpaceId );
116         daoUtil.executeQuery(  );
117 
118         DocumentAutoPublication documentAutoPublication = null;
119 
120         if ( daoUtil.next(  ) )
121         {
122             documentAutoPublication = new DocumentAutoPublication(  );
123             documentAutoPublication.setIdPortlet( daoUtil.getInt( 1 ) );
124             documentAutoPublication.setIdSpace( daoUtil.getInt( 2 ) );
125         }
126 
127         daoUtil.free(  );
128 
129         return documentAutoPublication;
130     }
131 
132     /**
133      * Loads all data Document Auto Publication
134      *
135      * @return The {@link Collection} of {@link DocumentAutoPublication} object
136      */
137     public Collection<DocumentAutoPublication> load(  )
138     {
139         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL );
140         daoUtil.executeQuery(  );
141 
142         Collection<DocumentAutoPublication> listDocumentAutoPublication = new ArrayList<DocumentAutoPublication>(  );
143 
144         while ( daoUtil.next(  ) )
145         {
146             DocumentAutoPublicationtion/DocumentAutoPublication.html#DocumentAutoPublication">DocumentAutoPublication documentAutoPublication = new DocumentAutoPublication(  );
147             documentAutoPublication.setIdPortlet( daoUtil.getInt( 1 ) );
148             documentAutoPublication.setIdSpace( daoUtil.getInt( 2 ) );
149             listDocumentAutoPublication.add( documentAutoPublication );
150         }
151 
152         daoUtil.free(  );
153 
154         return listDocumentAutoPublication;
155     }
156 
157     /**
158      * Load the list of Document Auto Publication whose portlet identifier is specified in parameter
159      *
160      * @param nPortletId The {@link Portlet} identifier
161      * @return The {@link DocumentAutoPublication} object
162      */
163     public Collection<DocumentAutoPublication> selectByPortletId( int nPortletId )
164     {
165         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_PORTLET_ID );
166         daoUtil.setInt( 1, nPortletId );
167         daoUtil.executeQuery(  );
168 
169         Collection<DocumentAutoPublication> listDocumentAutoPublication = new ArrayList<DocumentAutoPublication>(  );
170 
171         while ( daoUtil.next(  ) )
172         {
173             DocumentAutoPublicationtion/DocumentAutoPublication.html#DocumentAutoPublication">DocumentAutoPublication documentAutoPublication = new DocumentAutoPublication(  );
174             documentAutoPublication.setIdPortlet( nPortletId );
175             documentAutoPublication.setIdSpace( daoUtil.getInt( 1 ) );
176             listDocumentAutoPublication.add( documentAutoPublication );
177         }
178 
179         daoUtil.free(  );
180 
181         return listDocumentAutoPublication;
182     }
183 
184     /**
185      * Load the list of Document Auto Publication whose {@link DocumentSpace} identifier is specified in parameter
186      *
187      * @param nSpaceId The {@link DocumentSpace} identifier
188      * @return The {@link DocumentAutoPublication} object
189      */
190     public Collection<DocumentAutoPublication> selectBySpaceId( int nSpaceId )
191     {
192         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_SPACE_ID );
193         daoUtil.setInt( 1, nSpaceId );
194         daoUtil.executeQuery(  );
195 
196         Collection<DocumentAutoPublication> listDocumentAutoPublication = new ArrayList<DocumentAutoPublication>(  );
197 
198         while ( daoUtil.next(  ) )
199         {
200             DocumentAutoPublicationtion/DocumentAutoPublication.html#DocumentAutoPublication">DocumentAutoPublication documentAutoPublication = new DocumentAutoPublication(  );
201             documentAutoPublication.setIdPortlet( daoUtil.getInt( 1 ) );
202             documentAutoPublication.setIdSpace( nSpaceId );
203             listDocumentAutoPublication.add( documentAutoPublication );
204         }
205 
206         daoUtil.free(  );
207 
208         return listDocumentAutoPublication;
209     }
210 
211     /**
212      * Update the record in the table
213      *
214      * @param documentAutoPublication The DocumentAutoPublication to update
215      */
216     public void store( DocumentAutoPublication documentAutoPublication )
217     {
218         //        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
219         //
220         //        daoUtil.setInt( 1, documentAutoPublication.getIdPortlet(  ) );
221         //        daoUtil.setInt( 2, documentAutoPublication.getIdSpace(  ) );
222         //
223         //        daoUtil.executeUpdate(  );
224         //
225         //        daoUtil.free(  );
226     }
227 }