1    package com.instantbank.collections.commonQueuing.web;
2    
3    import java.util.LinkedList;
4    import java.util.List;
5    import java.sql.Connection;
6    import java.sql.PreparedStatement;
7    import java.sql.ResultSet;
8    import com.instantbank.collections.util.DataAccess;
9    import com.instantbank.collections.util.InstantbankException;
10   
11   public class DownloadDAO {
12   
13     // Sql prepared statement constants
14     private static final String RETRIEVE_DOWNLOADTYPE_KEYS =
15       "SELECT downt_down_id "
16       + "FROM   download_types "
17       + "WHERE  downt_cmp_id= ?  ";
18   
19     private static final String RETRIEVE_DOWNLOADTYPE_NAME =
20       "SELECT  downt_name "
21       + "FROM    download_types "
22       + "WHERE   downt_down_id = ? ";
23   
24   
25     public List getFileTypeKeys(long cmpId)
26        throws InstantbankException {
27   
28       Connection con = null;
29       PreparedStatement ps = null;
30       ResultSet rs = null;
31       DataAccess da = new DataAccess();
32   
33       List ret = new LinkedList();
34   
35       try {
36         da.connect();
37         con = da.getConnection();
38         ps = con.prepareStatement(RETRIEVE_DOWNLOADTYPE_KEYS);
39         ps.setLong(1, cmpId);
40         rs = ps.executeQuery();
41         while(rs.next()) {
42           ret.add(new Long(rs.getLong(1)));
43         }
44       }
45       catch(Exception e) {
46         e.printStackTrace();
47         throw new InstantbankException(e, "811000", "Error searching for Download Types");
48       }
49       finally {
50         try {
51           if(rs != null) {
52             rs.close();
53           }
54           if(ps != null) {
55             ps.close();
56           }
57           if(da != null) {
58             da.disconnect();
59           }
60         }
61         catch(Exception e) {
62           e.printStackTrace();
63         }
64       }
65   
66       return ret;
67     }
68   
69   
70     public static String retrieveDownloadTypeDesc(long downId)
71        throws InstantbankException {
72       Connection con = null;
73       PreparedStatement ps = null;
74       ResultSet rs = null;
75       DataAccess da = new DataAccess();
76       String desc = " ";
77   
78       try {
79         da.connect();
80         con = da.getConnection();
81         ps = con.prepareStatement(RETRIEVE_DOWNLOADTYPE_NAME);
82   
83         ps.setLong(1, downId);
84         rs = ps.executeQuery();
85         if(rs.next()) {
86           desc = rs.getString(1);
87   
88         }
89       }
90       catch(Exception e) {
91         e.printStackTrace();
92         throw new InstantbankException(e, "811001", "Error searching for Download name");
93       }
94       finally {
95         try {
96           if(rs != null) {
97             rs.close();
98           }
99           if(ps != null) {
100            ps.close();
101          }
102          if(da != null) {
103            da.disconnect();
104          }
105        }
106        catch(Exception e) {
107          e.printStackTrace();
108        }
109      }
110  
111      return desc;
112    }
113  
114  }
115