View Javadoc
1   /*
2    * Copyright (c) 2002-2013, 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  
36  package fr.paris.lutece.plugins.dataviz.business;
37  
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.util.ReferenceList;
40  import fr.paris.lutece.util.sql.DAOUtil;
41  
42  import java.util.ArrayList;
43  import java.util.Collection;
44  
45  
46  /**
47   * This class provides Data Access methods for Stat objects
48   */
49  
50  public final class StatDAO implements IStatDAO
51  {
52  //	
53  //	// Constants
54  //	private static final String SQL_QUERY_NEW_PK = "SELECT max( id ) FROM dataviz_stat";
55  //	private static final String SQL_QUERY_SELECT = "SELECT id, description, requete_sql FROM dataviz_stat WHERE id = ?";
56  //	private static final String SQL_QUERY_INSERT = "INSERT INTO dataviz_stat ( id, description, requete_sql ) VALUES ( ?, ?, ? ) ";
57  //	private static final String SQL_QUERY_DELETE = "DELETE FROM dataviz_stat WHERE id = ? ";
58  //	private static final String SQL_QUERY_UPDATE = "UPDATE dataviz_stat SET id = ?, description = ?, requete_sql = ? WHERE id = ?";
59  //	private static final String SQL_QUERY_SELECTALL = "SELECT id, description, requete_sql FROM dataviz_stat";
60  //
61  //
62  //	
63  //	/**
64  //	 * Generates a new primary key
65  //	 * @param plugin The Plugin
66  //	 * @return The new primary key
67  //	 */
68  //	public int newPrimaryKey( Plugin plugin)
69  //	{
70  //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK , plugin  );
71  //		daoUtil.executeQuery( );
72  //
73  //		int nKey = 1;
74  //
75  //		if( daoUtil.next( ) )
76  //		{
77  //			nKey = daoUtil.getInt( 1 ) + 1;
78  //		}
79  //
80  //		daoUtil.free();
81  //
82  //		return nKey;
83  //	}
84  //
85  //
86  //
87  //
88  //	/**
89  //	 * {@inheritDoc }
90  //	 */
91  //	@Override
92  //	public void insert( Stat stat, Plugin plugin )
93  //	{
94  //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
95  //				
96  //		stat.setId( newPrimaryKey( plugin ) );
97  //				
98  //		daoUtil.setInt( 1, stat.getId( ) );
99  //		daoUtil.setString( 2, stat.getDescription( ) );
100 //		daoUtil.setString( 3, stat.getRequeteSql( ) );
101 //
102 //		daoUtil.executeUpdate( );
103 //		daoUtil.free( );
104 //	}
105 //
106 //
107 //	/**
108 //	 * {@inheritDoc }
109 //	 */
110 //	@Override
111 //	public Stat load( int nKey, Plugin plugin )
112 //	{
113 //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
114 //		daoUtil.setInt( 1 , nKey );
115 //		daoUtil.executeQuery( );
116 //
117 //		Stat stat = null;
118 //
119 //		if ( daoUtil.next( ) )
120 //		{
121 //			stat = new Stat();
122 //			stat.setId( daoUtil.getInt(  1 ) );
123 //			stat.setDescription( daoUtil.getString(  2 ) );
124 //			stat.setRequeteSql( daoUtil.getString(  3 ) );
125 //		}
126 //
127 //		daoUtil.free( );
128 //		return stat;
129 //	}
130 //
131 //
132 //	/**
133 //	 * {@inheritDoc }
134 //	 */
135 //	@Override
136 //	public void delete( int nStatId, Plugin plugin )
137 //	{
138 //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
139 //		daoUtil.setInt( 1 , nStatId );
140 //		daoUtil.executeUpdate( );
141 //		daoUtil.free( );
142 //	}
143 //
144 //
145 //	/**
146 //	 * {@inheritDoc }
147 //	 */
148 //	@Override
149 //	public void store( Stat stat, Plugin plugin )
150 //	{
151 //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
152 //				
153 //		daoUtil.setInt( 1, stat.getId( ) );
154 //		daoUtil.setString( 2, stat.getDescription( ) );
155 //		daoUtil.setString( 3, stat.getRequeteSql( ) );
156 //		daoUtil.setInt( 4, stat.getId( ) );
157 //				
158 //		daoUtil.executeUpdate( );
159 //		daoUtil.free( );
160 //	}
161 //
162 //
163 //
164 //	/**
165 //	 * {@inheritDoc }
166 //	 */
167 //	@Override
168 //	public Collection<Stat> selectStatsList( Plugin plugin )
169 //	{
170 //		Collection<Stat> statList = new ArrayList<Stat>(  );
171 //		DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
172 //		daoUtil.executeQuery(  );
173 //
174 //		while ( daoUtil.next(  ) )
175 //		{
176 //				Stat stat = new Stat(  );
177 //
178 //					stat.setId( daoUtil.getInt( 1 ) );
179 //					stat.setDescription( daoUtil.getString( 2 ) );
180 //					stat.setRequeteSql( daoUtil.getString( 3 ) );
181 //
182 //				statList.add( stat );
183 //		}
184 //
185 //		daoUtil.free( );
186 //		return statList;
187 //	}
188 
189         @Override
190         public int getSingleResult( String sql, Plugin plugin )
191         {
192             int nResult = 0;
193             DAOUtil daoUtil = new DAOUtil( sql, plugin );
194             daoUtil.executeQuery(  );
195 
196             if ( daoUtil.next(  ) )
197             {
198                 nResult = daoUtil.getInt( 1 );
199             }
200 
201             daoUtil.free(  );
202 
203             return ( nResult );
204         }
205 
206         @Override
207         public Object getListResult ( String sql, Plugin plugin )
208         {
209             ReferenceList list = new ReferenceList ();
210             DAOUtil daoUtil = new DAOUtil( sql, plugin );
211             daoUtil.executeQuery(  );
212 
213             while ( daoUtil.next(  ) )
214             {
215                 list.addItem( daoUtil.getObject( 1 ).toString(), daoUtil.getObject( 2 ).toString());
216             }
217             daoUtil.free(  );
218 
219             return list;
220         }
221 }