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.util.sql;
35  
36  import fr.paris.lutece.portal.service.database.AppConnectionService;
37  import fr.paris.lutece.portal.service.database.PluginConnectionService;
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.util.AppException;
40  import fr.paris.lutece.portal.service.util.AppLogService;
41  import fr.paris.lutece.portal.service.util.NoDatabaseException;
42  
43  import org.apache.log4j.Logger;
44  
45  import org.springframework.jdbc.datasource.DataSourceUtils;
46  
47  import org.springframework.transaction.support.TransactionSynchronizationManager;
48  
49  import java.io.InputStream;
50  
51  import java.sql.Blob;
52  import java.sql.Connection;
53  import java.sql.Date;
54  import java.sql.PreparedStatement;
55  import java.sql.ResultSet;
56  import java.sql.SQLException;
57  import java.sql.Time;
58  import java.sql.Timestamp;
59  import java.sql.Types;
60  
61  import java.text.MessageFormat;
62  
63  import javax.sql.DataSource;
64  
65  
66  /**
67   * Prepared statement util class
68   *
69   * @since version 1.3
70   */
71  public class DAOUtil
72  {
73      public static final String MSG_EXCEPTION_SELECT_ERROR = "Error selecting row id : ";
74      private static final String DEFAULT_MODULE_NAME = "lutece";
75      private static final String LOGGER_DEBUG_SQL = "lutece.debug.sql.";
76  
77      /** Connection Service providing connection from a defined pool */
78      private PluginConnectionService _connectionService;
79  
80      /** JDBC Connection */
81      private Connection _connection;
82  
83      /** Plugin name */
84      private String _strPluginName;
85  
86      /** Prepared statement */
87      private PreparedStatement _statement;
88  
89      /** result set */
90      private ResultSet _resultSet;
91  
92      /** True if SQL request are logged */
93      private boolean _bReleased;
94      private String _strSQL;
95      private boolean _bTransactionnal;
96  
97      /** The debug logger */
98      private Logger _logger;
99      private StringBuffer _sbLogs = new StringBuffer(  );
100 
101     /**
102      * Creates a new DAOUtil object.
103      *
104      * @param sql Sql Query for prepared Statement
105      */
106     public DAOUtil( String sql )
107     {
108         this( sql, null );
109     }
110 
111     /**
112      * Creates a new DAOUtil object.
113      *
114      * @param strSQL sql query for prepared Statement
115      * @param plugin The plugin using this database access
116      */
117     public DAOUtil( String strSQL, Plugin plugin )
118     {
119         _bReleased = false;
120         _strSQL = strSQL;
121 
122         if ( plugin != null )
123         {
124             _strPluginName = plugin.getName(  );
125             _connectionService = plugin.getConnectionService(  );
126         }
127         else
128         {
129             _strPluginName = DEFAULT_MODULE_NAME;
130             _connectionService = AppConnectionService.getDefaultConnectionService(  );
131         }
132 
133         if ( _connectionService == null )
134         {
135             throw new NoDatabaseException( 
136                 "Database access error. Please check component installations and db.properties." );
137         }
138 
139         // Use the logger name "lutece.debug.sql.<plugin_name>" to filter logs by plugins
140         _logger = Logger.getLogger( LOGGER_DEBUG_SQL + _strPluginName );
141 
142         if ( _logger.isDebugEnabled(  ) )
143         {
144             log( "Module : '" + _strPluginName + "' - SQL Statement : " + _strSQL );
145         }
146 
147         try
148         {
149             MultiPluginTransaction transaction = TransactionManager.getCurrentTransaction( plugin );
150 
151             if ( transaction != null )
152             {
153                 _bTransactionnal = true;
154             }
155             else
156             {
157                 // We check if there is a managed transaction to get the transactionnal connection
158                 if ( TransactionSynchronizationManager.isSynchronizationActive(  ) )
159                 {
160                     _bTransactionnal = true;
161 
162                     DataSource ds = AppConnectionService.getPoolManager(  )
163                                                         .getDataSource( _connectionService.getPoolName(  ) );
164                     _connection = DataSourceUtils.getConnection( ds );
165 
166                     if ( _logger.isDebugEnabled(  ) )
167                     {
168                         _logger.debug( "Transactionnal context is used for pool " + _connectionService.getPoolName(  ) );
169                     }
170                 }
171                 else
172                 {
173                     // no transaction found, use the connection service directly
174                     _connection = _connectionService.getConnection(  );
175                 }
176             }
177 
178             if ( transaction != null )
179             {
180                 _statement = transaction.prepareStatement( _strSQL );
181             }
182             else if ( _connection != null )
183             {
184                 _statement = _connection.prepareStatement( _strSQL );
185             }
186             else
187             {
188                 throw new AppException( "Database access error for component '" + _strPluginName +
189                     "'. Please check plugin installation and db.properties." );
190             }
191         }
192         catch ( SQLException e )
193         {
194             free(  );
195             throw new AppException( getErrorMessage( e ), e );
196         }
197     }
198 
199     /**
200      * Build a formatted error message for a given exception
201      * @param e The exception
202      * @return The error message
203      */
204     private String getErrorMessage( Exception e )
205     {
206         free(  );
207 
208         StringBuilder sbError = new StringBuilder( "DAOUtil error : " );
209         sbError.append( e.getMessage(  ) );
210         sbError.append( " - SQL statement : " );
211         sbError.append( " - Plugin : " );
212         sbError.append( _strPluginName );
213 
214         return sbError.toString(  );
215     }
216 
217     /**
218      * Executes the update request and throws an error if the result is not 1
219      */
220     public void executeUpdate(  )
221     {
222         try
223         {
224             _statement.executeUpdate(  );
225         }
226         catch ( SQLException e )
227         {
228             free(  );
229             throw new AppException( getErrorMessage( e ), e );
230         }
231     }
232 
233     /**
234      * Executes a query
235      */
236     public void executeQuery(  )
237     {
238         try
239         {
240             _resultSet = _statement.executeQuery(  );
241         }
242         catch ( SQLException e )
243         {
244             free(  );
245             throw new AppException( getErrorMessage( e ), e );
246         }
247     }
248 
249     /**
250      * Log a message
251      * @param strMessage The message to log
252      */
253     private void log( String strMessage )
254     {
255         if ( _logger.isDebugEnabled(  ) )
256         {
257             _sbLogs.append( strMessage );
258         }
259     }
260 
261     /**
262      * Log a parameter
263      * @param oName The parameter name
264      * @param oValue The parameter value
265      */
266     private void logParameter( Object oName, Object oValue )
267     {
268         Object[] args = { oName, oValue };
269         log( MessageFormat.format( "\n               Index : ''{0}''       Value : ''{1}'' ", args ) );
270     }
271 
272     /**
273      * Writes logs
274      */
275     private void writeLogs(  )
276     {
277         if ( _logger.isDebugEnabled(  ) )
278         {
279             _logger.debug( _sbLogs.toString(  ) );
280         }
281     }
282 
283     /**
284      * Free connection
285      */
286     public final void free(  )
287     {
288         writeLogs(  );
289 
290         try
291         {
292             // Close statement if necessary
293             if ( _statement != null )
294             {
295                 _statement.close(  );
296             }
297         }
298         catch ( SQLException e )
299         {
300             throw new AppException( e.getMessage(  ), e );
301         }
302         finally
303         {
304             // Free the connection - the connection is freed some other way in transactionnal context.
305             if ( ( _connectionService != null ) && !_bTransactionnal )
306             {
307                 _connectionService.freeConnection( _connection );
308                 _connectionService = null;
309             }
310 
311             _bReleased = true;
312         }
313     }
314 
315     /**
316      * Moves the cursor to the first row in this ResultSet object.
317      * @deprecated Use {@link #next()} instead
318      * @return true if the cursor is on a valid row; false if there are no rows
319      *         in the result set
320      */
321     @Deprecated
322     public boolean first(  )
323     {
324         try
325         {
326             return _resultSet.first(  );
327         }
328         catch ( SQLException e )
329         {
330             free(  );
331             throw new AppException( getErrorMessage( e ), e );
332         }
333     }
334 
335     /**
336      * Indicates whether the cursor is on the last row of this ResultSet object.
337      * @return true if the cursor is on the last row; false otherwise
338      */
339     public boolean isLast(  )
340     {
341         try
342         {
343             return _resultSet.isLast(  );
344         }
345         catch ( SQLException e )
346         {
347             free(  );
348             throw new AppException( getErrorMessage( e ), e );
349         }
350     }
351 
352     /**
353      * Fills the prepared statement with a date value
354      *
355      * @param nIndex parameter index
356      * @param date date value
357      */
358     public void setDate( int nIndex, Date date )
359     {
360         try
361         {
362             _statement.setDate( nIndex, date );
363         }
364         catch ( SQLException e )
365         {
366             free(  );
367             throw new AppException( getErrorMessage( e ), e );
368         }
369     }
370 
371     /**
372      * Fills the prepared statement with a time value
373      *
374      * @param nIndex parameter index
375      * @param time time value
376      */
377     public void setTime( int nIndex, Time time )
378     {
379         try
380         {
381             _statement.setTime( nIndex, time );
382         }
383         catch ( SQLException e )
384         {
385             free(  );
386             throw new AppException( getErrorMessage( e ), e );
387         }
388     }
389 
390     /**
391      * Fills the prepared statement with a binary value stream
392      * @param nIndex parameter index
393      * @param iStream the java input stream which contains the binary parameter
394      *            value
395      * @param nBlength the number of bytes in the stream
396      */
397     public void setBinaryStream( int nIndex, InputStream iStream, int nBlength )
398     {
399         try
400         {
401             _statement.setBinaryStream( nIndex, iStream, nBlength );
402         }
403         catch ( SQLException e )
404         {
405             free(  );
406             throw new AppException( getErrorMessage( e ), e );
407         }
408     }
409 
410     /**
411      * Gets a binary stream from a resultSet
412      *
413      * @param nIndex column index
414      * @return InputStream instance
415      */
416     public InputStream getBinaryStream( int nIndex )
417     {
418         try
419         {
420             return _resultSet.getBinaryStream( nIndex );
421         }
422         catch ( SQLException e )
423         {
424             free(  );
425             throw new AppException( getErrorMessage( e ), e );
426         }
427     }
428 
429     /**
430      * Gets a blob from a resultset
431      *
432      * @param nIndex column index
433      * @return Blob instance
434      */
435     public Blob getBlob( int nIndex )
436     {
437         try
438         {
439             return _resultSet.getBlob( nIndex );
440         }
441         catch ( SQLException e )
442         {
443             free(  );
444             throw new AppException( getErrorMessage( e ), e );
445         }
446     }
447 
448     /**
449      * Gets a blob from a resultset
450      *
451      * @param strColumnName column name
452      *
453      * @return Blob instance
454      */
455     public Blob getBlob( String strColumnName )
456     {
457         try
458         {
459             return _resultSet.getBlob( strColumnName );
460         }
461         catch ( SQLException e )
462         {
463             free(  );
464             throw new AppException( getErrorMessage( e ), e );
465         }
466     }
467 
468     /**
469      * Gets a byte array from a resultset
470      *
471      * @param nIndex column index
472      *
473      * @return byte[] instance
474      */
475     public byte[] getBytes( int nIndex )
476     {
477         try
478         {
479             return _resultSet.getBytes( nIndex );
480         }
481         catch ( SQLException e )
482         {
483             free(  );
484             throw new AppException( getErrorMessage( e ), e );
485         }
486     }
487 
488     /**
489      * Gets a byte array from a resultset
490      *
491      * @param strColumnName column name
492      *
493      * @return byte[] instance
494      */
495     public byte[] getBytes( String strColumnName )
496     {
497         try
498         {
499             return _resultSet.getBytes( strColumnName );
500         }
501         catch ( SQLException e )
502         {
503             free(  );
504             throw new AppException( getErrorMessage( e ), e );
505         }
506     }
507 
508     /**
509      * Fills the prepared statement with a int value
510      *
511      * @param nIndex parameter index in the prepared statement
512      * @param nValue int value
513      */
514     public void setInt( int nIndex, int nValue )
515     {
516         try
517         {
518             _statement.setInt( nIndex, nValue );
519 
520             if ( _logger.isDebugEnabled(  ) )
521             {
522                 logParameter( nIndex, nValue );
523             }
524         }
525         catch ( SQLException e )
526         {
527             free(  );
528             throw new AppException( getErrorMessage( e ), e );
529         }
530     }
531 
532     /**
533      * Fills the prepared statement with a Boolean value
534      *
535      * @param nIndex parameter index in the prepared statement
536      * @param bValue Boolean value
537      */
538     public void setBoolean( int nIndex, boolean bValue )
539     {
540         try
541         {
542             // _statement.setBoolean( nIndex, bValue.booleanValue(  ) );
543             _statement.setInt( nIndex, ( bValue ) ? 1 : 0 );
544         }
545         catch ( SQLException e )
546         {
547             free(  );
548             throw new AppException( getErrorMessage( e ), e );
549         }
550     }
551 
552     /**
553      * Fills the prepared statement with a byte array value
554      *
555      * @param nIndex parameter index in the prepared statement
556      * @param tbValue byte array value
557      */
558     public void setBytes( int nIndex, byte[] tbValue )
559     {
560         try
561         {
562             _statement.setBytes( nIndex, tbValue );
563         }
564         catch ( SQLException e )
565         {
566             free(  );
567             throw new AppException( getErrorMessage( e ), e );
568         }
569     }
570 
571     /**
572      * Fills the prepared statement with a string value
573      *
574      * @param nIndex parameter index in the prepared statement
575      * @param strValue string value
576      */
577     public void setString( int nIndex, String strValue )
578     {
579         try
580         {
581             _statement.setString( nIndex, strValue );
582 
583             if ( _logger.isDebugEnabled(  ) )
584             {
585                 logParameter( nIndex, strValue );
586             }
587         }
588         catch ( SQLException e )
589         {
590             free(  );
591             throw new AppException( getErrorMessage( e ), e );
592         }
593     }
594 
595     /**
596      * Fills the prepared statement with a timestamp value
597      *
598      * @param nIndex parameter index in the prepared statement
599      * @param ts timestamp value
600      */
601     public void setTimestamp( int nIndex, Timestamp ts )
602     {
603         try
604         {
605             _statement.setTimestamp( nIndex, ts );
606         }
607         catch ( SQLException e )
608         {
609             free(  );
610             throw new AppException( getErrorMessage( e ), e );
611         }
612     }
613 
614     /**
615      * Fills the prepared statement with a double value
616      * @param nIndex parameter index in the prepared statement
617      * @param dValue The value
618      */
619     public void setDouble( int nIndex, double dValue )
620     {
621         try
622         {
623             _statement.setDouble( nIndex, dValue );
624         }
625         catch ( SQLException e )
626         {
627             free(  );
628             throw new AppException( getErrorMessage( e ), e );
629         }
630     }
631 
632     /**
633      * Sets null value for a "double" column
634      * @param nIndex the index
635      */
636     public void setDoubleNull( int nIndex )
637     {
638         try
639         {
640             _statement.setNull( nIndex, Types.DOUBLE );
641         }
642         catch ( SQLException e )
643         {
644             free(  );
645             throw new AppException( getErrorMessage( e ), e );
646         }
647     }
648 
649     /**
650      * Gets the value of the designated column in the current row of this
651      * ResultSet
652      * object as a java.sql.Date object in the Java programming language.
653      *
654      * @param nIndex the first column is 1, the second is 2, ...
655      *
656      * @return the column value; if the value is SQL NULL, the value returned is
657      *         null
658      */
659     public Date getDate( int nIndex )
660     {
661         try
662         {
663             return _resultSet.getDate( nIndex );
664         }
665         catch ( SQLException e )
666         {
667             free(  );
668             throw new AppException( getErrorMessage( e ), e );
669         }
670     }
671 
672     /**
673      * Gets the value of the designated column in the current row of this
674      * ResultSet
675      * object as a java.sql.Date object in the Java programming language.
676      *
677      * @param strColumnName name of the column, ...
678      *
679      * @return the column value; if the value is SQL NULL, the value returned is
680      *         null
681      */
682     public Date getDate( String strColumnName )
683     {
684         try
685         {
686             return _resultSet.getDate( strColumnName );
687         }
688         catch ( SQLException e )
689         {
690             free(  );
691             throw new AppException( getErrorMessage( e ), e );
692         }
693     }
694 
695     /**
696      * Gets the value of the designated column in the current row of this
697      * ResultSet
698      * object as a java.sql.Time object in the Java programming language.
699      *
700      * @param nIndex the first column is 1, the second is 2, ...
701      *
702      * @return the column value; if the value is SQL NULL, the value returned is
703      *         null
704      */
705     public Time getTime( int nIndex )
706     {
707         try
708         {
709             return _resultSet.getTime( nIndex );
710         }
711         catch ( SQLException e )
712         {
713             free(  );
714             throw new AppException( getErrorMessage( e ), e );
715         }
716     }
717 
718     /**
719      * Gets the value of the designated column in the current row of this
720      * ResultSet
721      * object as a java.sql.Time object in the Java programming language.
722      *
723      * @param strColumnName name of the column, ...
724      *
725      * @return the column value; if the value is SQL NULL, the value returned is
726      *         null
727      */
728     public Time getTime( String strColumnName )
729     {
730         try
731         {
732             return _resultSet.getTime( strColumnName );
733         }
734         catch ( SQLException e )
735         {
736             free(  );
737             throw new AppException( getErrorMessage( e ), e );
738         }
739     }
740 
741     /**
742      * Gets the value of the designated column in the current row of this
743      * ResultSet
744      * object as a int
745      *
746      * @param nIndex the first column is 1, the second is 2, ...
747      *
748      * @return the column value; if the value is SQL NULL, the value returned is
749      *         0
750      */
751     public int getInt( int nIndex )
752     {
753         try
754         {
755             return _resultSet.getInt( nIndex );
756         }
757         catch ( SQLException e )
758         {
759             free(  );
760             throw new AppException( getErrorMessage( e ), e );
761         }
762     }
763 
764     /**
765      * Gets the value of the designated column in the current row of this
766      * ResultSet
767      * object as a int
768      *
769      * @param strColumnName column name
770      *
771      * @return the column value; if the value is SQL NULL, the value returned is
772      *         0
773      */
774     public int getInt( String strColumnName )
775     {
776         try
777         {
778             return _resultSet.getInt( strColumnName );
779         }
780         catch ( SQLException e )
781         {
782             free(  );
783             throw new AppException( getErrorMessage( e ), e );
784         }
785     }
786 
787     /**
788      * Gets the value of the designated column in the current row of this
789      * ResultSet
790      * object as a Boolean
791      *
792      * @param nIndex the first column is 1, the second is 2, ...
793      *
794      * @return the column value; if the value is SQL NULL, the value returned is
795      *         FALSE
796      */
797     public boolean getBoolean( int nIndex )
798     {
799         try
800         {
801             return ( _resultSet.getInt( nIndex ) == 0 ) ? false : true;
802         }
803         catch ( SQLException e )
804         {
805             free(  );
806             throw new AppException( getErrorMessage( e ), e );
807         }
808     }
809 
810     /**
811      * Gets the value of the designated column in the current row of this
812      * ResultSet
813      * object as a Boolean
814      *
815      * @param strColumnName column name
816      *
817      * @return the column value; if the value is SQL NULL, the value returned is
818      *         FALSE
819      */
820     public boolean getBoolean( String strColumnName )
821     {
822         try
823         {
824             return ( _resultSet.getInt( strColumnName ) == 0 ) ? false : true;
825         }
826         catch ( SQLException e )
827         {
828             free(  );
829             throw new AppException( getErrorMessage( e ), e );
830         }
831     }
832 
833     /**
834      * Gets the value of the designated column in the current row of this
835      * ResultSet
836      * object as a string
837      *
838      * @param nIndex the first column is 1, the second is 2, ...
839      *
840      * @return the column value; if the value is SQL NULL, the value returned is
841      *         NULL
842      */
843     public String getString( int nIndex )
844     {
845         try
846         {
847             return _resultSet.getString( nIndex );
848         }
849         catch ( SQLException e )
850         {
851             free(  );
852             throw new AppException( getErrorMessage( e ), e );
853         }
854     }
855 
856     /**
857      * Gets the value of the designated column in the current row of this
858      * ResultSet
859      * object as a string
860      *
861      * @param strColumnName column name
862      *
863      * @return the column value; if the value is SQL NULL, the value returned is
864      *         NULL
865      */
866     public String getString( String strColumnName )
867     {
868         try
869         {
870             return _resultSet.getString( strColumnName );
871         }
872         catch ( SQLException e )
873         {
874             free(  );
875             throw new AppException( getErrorMessage( e ), e );
876         }
877     }
878 
879     /**
880      * Gets the value of the designated column in the current row of this
881      * ResultSet
882      * object as a timestamp
883      *
884      * @param nIndex the first column is 1, the second is 2, ...
885      *
886      * @return the column value; if the value is SQL NULL, the value returned is
887      *         NULL
888      */
889     public Timestamp getTimestamp( int nIndex )
890     {
891         try
892         {
893             return _resultSet.getTimestamp( nIndex );
894         }
895         catch ( SQLException e )
896         {
897             free(  );
898             throw new AppException( getErrorMessage( e ), e );
899         }
900     }
901 
902     /**
903      * Gets the value of the designated column in the current row of this
904      * ResultSet
905      * object as a Timestamp
906      *
907      * @param strColumnName column name
908      *
909      * @return the column value; if the value is SQL NULL, the value returned is
910      *         NULL
911      */
912     public Timestamp getTimestamp( String strColumnName )
913     {
914         try
915         {
916             return _resultSet.getTimestamp( strColumnName );
917         }
918         catch ( SQLException e )
919         {
920             free(  );
921             throw new AppException( getErrorMessage( e ), e );
922         }
923     }
924 
925     /**
926      * Gets the value of the designated column in the current row of this
927      * ResultSet
928      * object as a double
929      * @param strColumnName column name
930      * @return the column value; if the value is SQL NULL, the value returned is
931      *         NULL
932      */
933     public double getDouble( String strColumnName )
934     {
935         try
936         {
937             return _resultSet.getDouble( strColumnName );
938         }
939         catch ( SQLException e )
940         {
941             free(  );
942             throw new AppException( getErrorMessage( e ), e );
943         }
944     }
945 
946     /**
947      * Gets the value of the designated column in the current row of this
948      * ResultSet
949      * object as a double
950      * @param nIndex the first column is 1, the second is 2, ...
951      *
952      * @return the column value; if the value is SQL NULL, the value returned is
953      *         0
954      */
955     public double getDouble( int nIndex )
956     {
957         try
958         {
959             return _resultSet.getDouble( nIndex );
960         }
961         catch ( SQLException e )
962         {
963             free(  );
964             throw new AppException( getErrorMessage( e ), e );
965         }
966     }
967 
968     /**
969      * Gets the value of the designated column in the current row of this
970      * ResultSet
971      * object as a Object
972      *
973      * @param nIndex the first column is 1, the second is 2, ...
974      *
975      * @return the column value; if the value is SQL NULL, the value returned is
976      *         NULL
977      */
978     public Object getObject( int nIndex )
979     {
980         try
981         {
982             return _resultSet.getObject( nIndex );
983         }
984         catch ( SQLException e )
985         {
986             free(  );
987             throw new AppException( getErrorMessage( e ), e );
988         }
989     }
990 
991     /**
992      * Get the ResultSet
993      * @return the resultSet
994      */
995     public ResultSet getResultSet(  )
996     {
997         return _resultSet;
998     }
999 
1000     /**
1001      * Gets the value of the designated column in the current row of this
1002      * ResultSet
1003      * object as an Object
1004      *
1005      * @param strColumnName column name
1006      *
1007      * @return the column value; if the value is SQL NULL, the value returned is
1008      *         NULL
1009      */
1010     public Object getObject( String strColumnName )
1011     {
1012         try
1013         {
1014             return _resultSet.getObject( strColumnName );
1015         }
1016         catch ( SQLException e )
1017         {
1018             free(  );
1019             throw new AppException( getErrorMessage( e ), e );
1020         }
1021     }
1022 
1023     /**
1024      * Moves the cursor down one row from its current position in the ResultSet.
1025      *
1026      * @return true if the new current row is valid; false if there are no more
1027      *         rows
1028      */
1029     public boolean next(  )
1030     {
1031         try
1032         {
1033             return _resultSet.next(  );
1034         }
1035         catch ( SQLException e )
1036         {
1037             free(  );
1038             throw new AppException( getErrorMessage( e ), e );
1039         }
1040     }
1041 
1042     /**
1043      * Fills the prepared statement with a int null value
1044      * @param nIndex parameter index
1045      */
1046     public void setIntNull( int nIndex )
1047     {
1048         try
1049         {
1050             _statement.setNull( nIndex, Types.INTEGER );
1051         }
1052         catch ( SQLException e )
1053         {
1054             free(  );
1055             throw new AppException( getErrorMessage( e ), e );
1056         }
1057     }
1058 
1059     /**
1060      * Sets null value for a "long" column
1061      * @param nIndex the index
1062      */
1063     public void setLongNull( int nIndex )
1064     {
1065         try
1066         {
1067             _statement.setNull( nIndex, Types.BIGINT );
1068         }
1069         catch ( SQLException e )
1070         {
1071             free(  );
1072             throw new AppException( getErrorMessage( e ), e );
1073         }
1074     }
1075 
1076     /**
1077      * Sets a long value
1078      * @param nIndex the index
1079      * @param lValue the value
1080      */
1081     public void setLong( int nIndex, long lValue )
1082     {
1083         try
1084         {
1085             _statement.setLong( nIndex, lValue );
1086         }
1087         catch ( SQLException e )
1088         {
1089             free(  );
1090             throw new AppException( getErrorMessage( e ), e );
1091         }
1092     }
1093 
1094     /**
1095      * Gets the long value
1096      * @param nIndex the index
1097      * @return the long value
1098      */
1099     public long getLong( int nIndex )
1100     {
1101         try
1102         {
1103             return _resultSet.getLong( nIndex );
1104         }
1105         catch ( SQLException e )
1106         {
1107             free(  );
1108             throw new AppException( getErrorMessage( e ), e );
1109         }
1110     }
1111 
1112     /**
1113      * Gets the long value
1114      * @param strColumnName the column name
1115      * @return the long value
1116      */
1117     public long getLong( String strColumnName )
1118     {
1119         try
1120         {
1121             return _resultSet.getLong( strColumnName );
1122         }
1123         catch ( SQLException e )
1124         {
1125             free(  );
1126             throw new AppException( getErrorMessage( e ), e );
1127         }
1128     }
1129 
1130     /**
1131      * {@inheritDoc}
1132      */
1133     @Override
1134     protected void finalize(  ) throws Throwable
1135     {
1136         if ( !_bReleased )
1137         {
1138             free(  );
1139             AppLogService.error( 
1140                 "A call to DAOUtil.free() seems to be missing or an unexpected exception has occured during the use of a DAOUtil object - plugin : " +
1141                 _strPluginName + " - SQL statement : " + _strSQL );
1142         }
1143 
1144         super.finalize(  );
1145     }
1146 }