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.directory.modules.exportfile.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.Collection;
42  
43  /**
44   * This class provides Data Access methods for FileName objects
45   */
46  
47  public final class FileNameDAO implements IFileNameDAO
48  {
49      // Constants
50      private static final String SQL_QUERY_SELECT = "SELECT mapping_entry, attribute, number_char, order_name FROM exportfile_fileName WHERE mapping_entry = ?";
51      private static final String SQL_QUERY_INSERT = "INSERT INTO exportfile_fileName ( mapping_entry, attribute, number_char, order_name ) VALUES ( ?, ?, ?, ? ) ";
52      private static final String SQL_QUERY_DELETE = "DELETE FROM exportfile_fileName WHERE mapping_entry=?  AND attribute = ?";
53      private static final String SQL_QUERY_DELETE_BY_IDMAPPING = "DELETE FROM exportfile_fileName WHERE mapping_entry=? ";
54  
55      /**
56       * {@inheritDoc }
57       */
58      @Override
59      public void insert( FileName fileName, Plugin plugin )
60      {
61  
62          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
63  
64          daoUtil.setInt( 1, fileName.getMappingEntry( ) );
65          daoUtil.setString( 2, fileName.getAttribute( ) );
66          daoUtil.setInt( 3, fileName.getNumberChar( ) );
67          daoUtil.setInt( 4, fileName.getOrder( ) );
68  
69          daoUtil.executeUpdate( );
70          daoUtil.free( );
71  
72      }
73  
74      /**
75       * {@inheritDoc }
76       */
77      @Override
78      public void store( FileName fileName, Plugin plugin )
79      {
80          // TODO Auto-generated method stub
81  
82      }
83  
84      /**
85       * {@inheritDoc }
86       */
87      @Override
88      public void delete( FileName fileName, Plugin plugin )
89      {
90          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
91          daoUtil.setInt( 1, fileName.getMappingEntry( ) );
92          daoUtil.setString( 1, fileName.getAttribute( ) );
93          daoUtil.executeUpdate( );
94          daoUtil.free( );
95      }
96  
97      /**
98       * {@inheritDoc }
99       */
100     @Override
101     public void delete( int nKey, Plugin plugin )
102     {
103         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_BY_IDMAPPING, plugin );
104         daoUtil.setInt( 1, nKey );
105         daoUtil.executeUpdate( );
106         daoUtil.free( );
107     }
108 
109     @Override
110     public Collection<FileName> selectFilesNameList( int nMappingEntry, Plugin plugin )
111     {
112         Collection<FileName> fileNameList = new ArrayList<FileName>( );
113         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
114         daoUtil.setInt( 1, nMappingEntry );
115         daoUtil.executeQuery( );
116 
117         while ( daoUtil.next( ) )
118         {
119             FileName fileName = new FileName( );
120 
121             fileName.setMappingEntry( daoUtil.getInt( 1 ) );
122             fileName.setAttribute( daoUtil.getString( 2 ) );
123             fileName.setNumberChar( daoUtil.getInt( 3 ) );
124             fileName.setOrder( daoUtil.getInt( 4 ) );
125 
126             fileNameList.add( fileName );
127         }
128 
129         daoUtil.free( );
130         return fileNameList;
131     }
132 }