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