View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.portal.business.right;
35  
36  import fr.paris.lutece.util.sql.DAOUtil;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * This class provides Data Access methods for feature group objects
43   */
44  public final class FeatureGroupDAO implements IFeatureGroupDAO
45  {
46      // Constants
47      private static final String SQL_SELECT = " SELECT id_feature_group, feature_group_description, feature_group_label, feature_group_order, feature_group_icon";
48      private static final String SQL_QUERY_SELECT = SQL_SELECT + " FROM core_feature_group " + " WHERE id_feature_group = ? ";
49      private static final String SQL_QUERY_INSERT = " INSERT INTO core_feature_group ( id_feature_group , feature_group_description, feature_group_label, feature_group_order, feature_group_icon ) "
50              + " VALUES ( ?, ?, ?, ?, ?  )";
51      private static final String SQL_QUERY_DELETE = " DELETE FROM core_feature_group WHERE id_feature_group = ? ";
52      private static final String SQL_QUERY_UPDATE = " UPDATE core_feature_group SET feature_group_description = ?, "
53              + " feature_group_label = ? , feature_group_order = ?, feature_group_icon = ? " + " WHERE id_feature_group = ?";
54      private static final String SQL_QUERY_SELECTALL = SQL_SELECT + " FROM core_feature_group ORDER BY feature_group_order ASC";
55      private static final String SQL_QUERY_COUNT_FEATUREGROUP = " SELECT COUNT(id_feature_group)FROM core_feature_group";
56  
57      // /////////////////////////////////////////////////////////////////////////////////////
58      // Access methods to data
59  
60      /**
61       * Insert a new record in the table.
62       * 
63       * @param featureGroup
64       *            instance of the feature group to insert
65       */
66      public void insert( FeatureGroup featureGroup )
67      {
68          try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
69          {
70  
71              daoUtil.setString( 1, featureGroup.getId( ) );
72              daoUtil.setString( 2, featureGroup.getDescriptionKey( ) );
73              daoUtil.setString( 3, featureGroup.getLabelKey( ) );
74              daoUtil.setInt( 4, featureGroup.getOrder( ) );
75              daoUtil.setString( 5, featureGroup.getIcon( ) );
76  
77              daoUtil.executeUpdate( );
78          }
79      }
80  
81      /**
82       * load the data of FeatureGroup from the table
83       * 
84       * @param strIdFeatureGroup
85       *            The indentifier of the object FeatureGroup
86       * @return The Instance of the object Page
87       */
88      public FeatureGroup load( String strIdFeatureGroup )
89      {
90          FeatureGroup featureGroup = null;
91          try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
92          {
93              daoUtil.setString( 1, strIdFeatureGroup );
94  
95              daoUtil.executeQuery( );
96  
97              if ( daoUtil.next( ) )
98              {
99                  featureGroup = new FeatureGroup( );
100                 featureGroup.setId( daoUtil.getString( 1 ) );
101                 featureGroup.setDescriptionKey( daoUtil.getString( 2 ) );
102                 featureGroup.setLabelKey( daoUtil.getString( 3 ) );
103                 featureGroup.setOrder( daoUtil.getInt( 4 ) );
104                 featureGroup.setIcon( daoUtil.getString( 5 ) );
105             }
106 
107         }
108 
109         return featureGroup;
110     }
111 
112     /**
113      * Delete a record from the table
114      * 
115      * @param strIdFeatureGroup
116      *            The indentifier of the object FeatureGroup
117      */
118     public void delete( String strIdFeatureGroup )
119     {
120         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
121         {
122             daoUtil.setString( 1, strIdFeatureGroup );
123             daoUtil.executeUpdate( );
124         }
125     }
126 
127     /**
128      * Update the record in the table
129      * 
130      * @param featureGroup
131      *            the reference of the feature group
132      */
133     public void store( FeatureGroup featureGroup )
134     {
135         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
136         {
137 
138             daoUtil.setString( 1, featureGroup.getDescriptionKey( ) );
139             daoUtil.setString( 2, featureGroup.getLabelKey( ) );
140             daoUtil.setInt( 3, featureGroup.getOrder( ) );
141             daoUtil.setString( 4, featureGroup.getIcon( ) );
142             daoUtil.setString( 5, featureGroup.getId( ) );
143 
144             daoUtil.executeUpdate( );
145         }
146     }
147 
148     /**
149      * Loads the data of all the feature groups and returns them in form of a collection
150      * 
151      * @return the list which contains the data of all the feature groups
152      */
153     public List<FeatureGroup> selectFeatureGroupsList( )
154     {
155         List<FeatureGroup> featureGroupList = new ArrayList<>( );
156         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
157         {
158             daoUtil.executeQuery( );
159 
160             while ( daoUtil.next( ) )
161             {
162                 FeatureGroupght/FeatureGroup.html#FeatureGroup">FeatureGroup featureGroup = new FeatureGroup( );
163 
164                 featureGroup.setId( daoUtil.getString( 1 ) );
165                 featureGroup.setDescriptionKey( daoUtil.getString( 2 ) );
166                 featureGroup.setLabelKey( daoUtil.getString( 3 ) );
167                 featureGroup.setOrder( daoUtil.getInt( 4 ) );
168                 featureGroup.setIcon( daoUtil.getString( 5 ) );
169 
170                 featureGroupList.add( featureGroup );
171             }
172 
173         }
174 
175         return featureGroupList;
176     }
177 
178     /**
179      * Returns the count of groups
180      * 
181      * @return the count of all the feature groups
182      */
183     public int selectFeatureGroupsCount( )
184     {
185         int nCount = 0;
186         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_COUNT_FEATUREGROUP ) )
187         {
188 
189             daoUtil.executeQuery( );
190             while ( daoUtil.next( ) )
191             {
192                 nCount = daoUtil.getInt( 1 );
193             }
194 
195         }
196 
197         return nCount;
198     }
199 }