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.digglike.business;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  import fr.paris.lutece.util.sql.DAOUtil;
38  
39  
40  public class DiggUserInfoDAO implements IDiggUserInfoDAO
41  {
42      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT first_name,last_name,business_mail,home_mail,login " +
43          "FROM digglike_digg_user_info WHERE lutece_user_key = ?  ";
44      private static final String SQL_QUERY_INSERT = "INSERT INTO digglike_digg_user_info ( lutece_user_key,first_name,last_name,business_mail,home_mail,login ) " +
45          "VALUES(?,?,?,?,?,?)";
46      private static final String SQL_QUERY_DELETE = "DELETE FROM digglike_digg_user_info WHERE lutece_user_key= ? ";
47      private static final String SQL_QUERY_UPDATE = "UPDATE digglike_digg_user_info SET " +
48          "first_name= ?,last_name= ?,business_mail=?,home_mail=?,login= ?" + " WHERE lutece_user_key= ? ";
49  
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      public void insert( DiggUserInfo diggUserInfo, Plugin plugin )
55      {
56          int ncpt = 1;
57          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
58  
59          daoUtil.setString( ncpt++, diggUserInfo.getLuteceUserKey(  ) );
60          daoUtil.setString( ncpt++, diggUserInfo.getFirstName(  ) );
61          daoUtil.setString( ncpt++, diggUserInfo.getLastName(  ) );
62          daoUtil.setString( ncpt++, diggUserInfo.getBusinessMail(  ) );
63          daoUtil.setString( ncpt++, diggUserInfo.getHomeMail(  ) );
64          daoUtil.setString( ncpt++, diggUserInfo.getLogin(  ) );
65          daoUtil.executeUpdate(  );
66          daoUtil.free(  );
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      @Override
73      public void update( DiggUserInfo diggUserInfo, Plugin plugin )
74      {
75          int ncpt = 1;
76          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
77  
78          daoUtil.setString( ncpt++, diggUserInfo.getFirstName(  ) );
79          daoUtil.setString( ncpt++, diggUserInfo.getLastName(  ) );
80          daoUtil.setString( ncpt++, diggUserInfo.getBusinessMail(  ) );
81          daoUtil.setString( ncpt++, diggUserInfo.getHomeMail(  ) );
82          daoUtil.setString( ncpt++, diggUserInfo.getLogin(  ) );
83          daoUtil.setString( ncpt++, diggUserInfo.getLuteceUserKey(  ) );
84          daoUtil.executeUpdate(  );
85          daoUtil.free(  );
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public DiggUserInfo load( String strLuteceUserKey, Plugin plugin )
93      {
94          DiggUserInfo submitUserInfo = null;
95  
96          int ncpt = 1;
97  
98          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
99  
100         daoUtil.setString( 1, strLuteceUserKey );
101 
102         daoUtil.executeQuery(  );
103 
104         if ( daoUtil.next(  ) )
105         {
106             submitUserInfo = new DiggUserInfo(  );
107 
108             submitUserInfo.setLuteceUserKey( strLuteceUserKey );
109             submitUserInfo.setFirstName( daoUtil.getString( ncpt++ ) );
110             submitUserInfo.setLastName( daoUtil.getString( ncpt++ ) );
111             submitUserInfo.setBusinesMail( daoUtil.getString( ncpt++ ) );
112             submitUserInfo.setHomeMail( daoUtil.getString( ncpt++ ) );
113             submitUserInfo.setLogin( daoUtil.getString( ncpt++ ) );
114         }
115 
116         daoUtil.free(  );
117 
118         return submitUserInfo;
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public void delete( String strLuteceUserKey, Plugin plugin )
126     {
127         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
128         daoUtil.setString( 1, strLuteceUserKey );
129         daoUtil.executeUpdate(  );
130         daoUtil.free(  );
131     }
132 }