View Javadoc
1   /*
2    * Copyright (c) 2002-2015, 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  
35  package fr.paris.lutece.plugins.modulenotifygrumappingmanager.business;
36  
37  import fr.paris.lutece.portal.service.plugin.Plugin;
38  import fr.paris.lutece.util.sql.DAOUtil;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * This class provides Data Access methods for NotifygruMappingManager objects
45   */
46  
47  public final class NotifygruMappingManagerDAO implements INotifygruMappingManagerDAO
48  {
49      // Constants
50      private static final String SQL_QUERY_NEW_PK = "SELECT max( id_notifygrumappingmanager ) FROM workflow_task_notify_gru_mapping_manager";
51      private static final String SQL_QUERY_SELECT = "SELECT id_notifygrumappingmanager, beanKey, connection_id, customer_id, mobilePhoneNumber, fixedPhoneNumber, email, demandetype, demand_reference FROM workflow_task_notify_gru_mapping_manager WHERE id_notifygrumappingmanager = ?";
52      private static final String SQL_QUERY_SELECT_BY_KEY = "SELECT id_notifygrumappingmanager, beanKey, connection_id, customer_id, mobilePhoneNumber, fixedPhoneNumber, email, demandetype, demand_reference FROM workflow_task_notify_gru_mapping_manager WHERE beanKey = ?";
53      private static final String SQL_QUERY_INSERT = "INSERT INTO workflow_task_notify_gru_mapping_manager ( id_notifygrumappingmanager, beanKey, connection_id, customer_id, mobilePhoneNumber, fixedPhoneNumber, email, demandetype, demand_reference ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
54      private static final String SQL_QUERY_DELETE = "DELETE FROM workflow_task_notify_gru_mapping_manager WHERE id_notifygrumappingmanager = ? ";
55      private static final String SQL_QUERY_UPDATE = "UPDATE workflow_task_notify_gru_mapping_manager SET id_notifygrumappingmanager = ?, beanKey = ?, connection_id = ?, customer_id = ?,  mobilePhoneNumber = ?, fixedPhoneNumber = ?, email = ?, demandetype = ?, demand_reference = ? WHERE id_notifygrumappingmanager = ?";
56      private static final String SQL_QUERY_SELECTALL = "SELECT id_notifygrumappingmanager, beanKey, connection_id, customer_id, mobilePhoneNumber, fixedPhoneNumber, email, demandetype, demand_reference FROM workflow_task_notify_gru_mapping_manager";
57      private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_notifygrumappingmanager FROM workflow_task_notify_gru_mapping_manager";
58  
59      /**
60       * Generates a new primary key
61       * 
62       * @param plugin
63       *            The Plugin
64       * @return The new primary key
65       */
66      public int newPrimaryKey( Plugin plugin )
67      {
68          int nKey = 1;
69          try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
70          {
71              daoUtil.executeQuery( );
72      
73              if ( daoUtil.next( ) )
74              {
75                  nKey = daoUtil.getInt( 1 ) + 1;
76              }
77          }
78  
79          return nKey;
80      }
81  
82      /**
83       * {@inheritDoc }
84       */
85      @Override
86      public void insert( NotifygruMappingManager notifygruMappingManager, Plugin plugin )
87      {
88          try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
89          {    
90              notifygruMappingManager.setId( newPrimaryKey( plugin ) );
91      
92              int nIndex = 1;
93              daoUtil.setInt( nIndex++, notifygruMappingManager.getId( ) );
94      
95              daoUtil.setString( nIndex++, notifygruMappingManager.getBeanKey( ) );
96              daoUtil.setInt( nIndex++, notifygruMappingManager.getConnectionId( ) );
97              daoUtil.setInt( nIndex++, notifygruMappingManager.getCustomerId( ) );
98              daoUtil.setInt( nIndex++, notifygruMappingManager.getMobilePhoneNumber( ) );
99              daoUtil.setInt( nIndex++, notifygruMappingManager.getFixedPhoneNumber( ) );
100             daoUtil.setInt( nIndex++, notifygruMappingManager.getEmail( ) );
101             daoUtil.setInt( nIndex++, notifygruMappingManager.getDemandeTypeId( ) );
102             daoUtil.setInt( nIndex++, notifygruMappingManager.getDemandReference( ) );
103     
104             daoUtil.executeUpdate( );
105         }
106     }
107 
108     /**
109      * {@inheritDoc }
110      */
111     @Override
112     public NotifygruMappingManager load( int nKey, Plugin plugin )
113     {
114         NotifygruMappingManager notifygruMappingManager = null;
115         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
116         {
117             daoUtil.setInt( 1, nKey );
118             daoUtil.executeQuery( );
119     
120             if ( daoUtil.next( ) )
121             {
122                 int nIndex = 1;
123                 notifygruMappingManager = new NotifygruMappingManager( );
124                 notifygruMappingManager.setId( daoUtil.getInt( nIndex++ ) );
125                 notifygruMappingManager.setBeanKey( daoUtil.getString( nIndex++ ) );
126                 notifygruMappingManager.setConnectionId( daoUtil.getInt( nIndex++ ) );
127                 notifygruMappingManager.setCustomerId( daoUtil.getInt( nIndex++ ) );
128                 notifygruMappingManager.setMobilePhoneNumber( daoUtil.getInt( nIndex++ ) );
129                 notifygruMappingManager.setFixedPhoneNumber( daoUtil.getInt( nIndex++ ) );
130                 notifygruMappingManager.setEmail( daoUtil.getInt( nIndex++ ) );
131                 notifygruMappingManager.setDemandeTypeId( daoUtil.getInt( nIndex++ ) );
132                 notifygruMappingManager.setDemandReference( daoUtil.getInt( nIndex++ ) );
133             }
134         }
135         return notifygruMappingManager;
136     }
137 
138     /**
139      * {@inheritDoc }
140      */
141     @Override
142     public NotifygruMappingManager load( String strKey, Plugin plugin )
143     {
144         NotifygruMappingManager notifygruMappingManager = null;
145         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_KEY, plugin ) )
146         {
147             daoUtil.setString( 1, strKey );
148             daoUtil.executeQuery( );
149     
150             if ( daoUtil.next( ) )
151             {
152                 int nIndex = 1;
153                 notifygruMappingManager = new NotifygruMappingManager( );
154                 notifygruMappingManager.setId( daoUtil.getInt( nIndex++ ) );
155                 notifygruMappingManager.setBeanKey( daoUtil.getString( nIndex++ ) );
156                 notifygruMappingManager.setConnectionId( daoUtil.getInt( nIndex++ ) );
157                 notifygruMappingManager.setCustomerId( daoUtil.getInt( nIndex++ ) );
158                 notifygruMappingManager.setMobilePhoneNumber( daoUtil.getInt( nIndex++ ) );
159                 notifygruMappingManager.setFixedPhoneNumber( daoUtil.getInt( nIndex++ ) );
160                 notifygruMappingManager.setEmail( daoUtil.getInt( nIndex++ ) );
161                 notifygruMappingManager.setDemandeTypeId( daoUtil.getInt( nIndex++ ) );
162                 notifygruMappingManager.setDemandReference( daoUtil.getInt( nIndex++ ) );
163             }
164         }
165         return notifygruMappingManager;
166     }
167 
168     /**
169      * {@inheritDoc }
170      */
171     @Override
172     public void delete( int nKey, Plugin plugin )
173     {
174         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
175         {
176             daoUtil.setInt( 1, nKey );
177             daoUtil.executeUpdate( );
178         }
179     }
180 
181     /**
182      * {@inheritDoc }
183      */
184     @Override
185     public void store( NotifygruMappingManager notifygruMappingManager, Plugin plugin )
186     {
187         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
188         {    
189             int nIndex = 1;
190             daoUtil.setInt( nIndex++, notifygruMappingManager.getId( ) );
191             daoUtil.setString( nIndex++, notifygruMappingManager.getBeanKey( ) );
192             daoUtil.setInt( nIndex++, notifygruMappingManager.getConnectionId( ) );
193             daoUtil.setInt( nIndex++, notifygruMappingManager.getCustomerId( ) );
194             daoUtil.setInt( nIndex++, notifygruMappingManager.getMobilePhoneNumber( ) );
195             daoUtil.setInt( nIndex++, notifygruMappingManager.getFixedPhoneNumber( ) );
196             daoUtil.setInt( nIndex++, notifygruMappingManager.getEmail( ) );
197             daoUtil.setInt( nIndex++, notifygruMappingManager.getDemandeTypeId( ) );
198             daoUtil.setInt( nIndex++, notifygruMappingManager.getDemandReference( ) );
199             daoUtil.setInt( nIndex, notifygruMappingManager.getId( ) );
200     
201             daoUtil.executeUpdate( );
202         }
203     }
204 
205     /**
206      * {@inheritDoc }
207      */
208     @Override
209     public List<NotifygruMappingManager> selectNotifygruMappingManagersList( Plugin plugin )
210     {
211         List<NotifygruMappingManager> notifygruMappingManagerList = new ArrayList<>( );
212         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
213         {
214             daoUtil.executeQuery( );
215     
216             while ( daoUtil.next( ) )
217             {
218                 NotifygruMappingManagersiness/NotifygruMappingManager.html#NotifygruMappingManager">NotifygruMappingManager notifygruMappingManager = new NotifygruMappingManager( );
219                 int nIndex = 1;
220                 notifygruMappingManager.setId( daoUtil.getInt( nIndex++ ) );
221                 notifygruMappingManager.setBeanKey( daoUtil.getString( nIndex++ ) );
222                 notifygruMappingManager.setConnectionId( daoUtil.getInt( nIndex++ ) );
223                 notifygruMappingManager.setCustomerId( daoUtil.getInt( nIndex++ ) );
224                 notifygruMappingManager.setMobilePhoneNumber( daoUtil.getInt( nIndex++ ) );
225                 notifygruMappingManager.setFixedPhoneNumber( daoUtil.getInt( nIndex++ ) );
226                 notifygruMappingManager.setEmail( daoUtil.getInt( nIndex++ ) );
227                 notifygruMappingManager.setDemandeTypeId( daoUtil.getInt( nIndex++ ) );
228                 notifygruMappingManager.setDemandReference( daoUtil.getInt( nIndex++ ) );
229     
230                 notifygruMappingManagerList.add( notifygruMappingManager );
231             }
232         }
233         return notifygruMappingManagerList;
234     }
235 
236     /**
237      * {@inheritDoc }
238      */
239     @Override
240     public List<Integer> selectIdNotifygruMappingManagersList( Plugin plugin )
241     {
242         List<Integer> notifygruMappingManagerList = new ArrayList<>( );
243         try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin ) )
244         {
245             daoUtil.executeQuery( );
246     
247             while ( daoUtil.next( ) )
248             {
249                 notifygruMappingManagerList.add( daoUtil.getInt( 1 ) );
250             }
251         }
252         return notifygruMappingManagerList;
253     }
254 }