1    package com.instantbank.collections.ach;
2    
3    import java.sql.PreparedStatement;
4    import java.sql.ResultSet;
5    import java.sql.SQLException;
6    import java.util.List;
7    import javax.naming.NamingException;
8    import java.io.Serializable;
9    
10   public class ClearingHouseDO
11       implements DataObject, Serializable {
12   
13     private static final String SEQUENCE_NAME = "ACH_CLEARHOUSE_SEQ";
14   
15     private ClearingHouse clearingHouse = null;
16     private long id = -1;
17     private long cmpId = -1;
18     private long csId = -1;
19     private long lastChangedBy = -1;
20     private String lastChangedDate = null;
21   
22   
23     public ClearingHouseDO() {
24       super();
25     }
26   
27   
28     public ClearingHouseDO(long primaryKey) {
29       setId(primaryKey);
30     }
31   
32   
33     public ClearingHouseDO(ClearingHouse theClearingHouse, long theId, long theCmpId,
34                            long theCsId, long theLastChangedBy,
35                            String theLastChangedDate) {
36   
37       setClearingHouse(theClearingHouse);
38       setId(theId);
39       setCmpId(theCmpId);
40       setCsId(theCsId);
41       setLastChangedBy(theLastChangedBy);
42       setLastChangedDate(theLastChangedDate);
43     }
44   
45   
46     public ClearingHouse getClearingHouse() {
47       return clearingHouse;
48     }
49   
50   
51     public long getId() {
52       return id;
53     }
54   
55   
56     public long getCmpId() {
57       return cmpId;
58     }
59   
60   
61     public long getCsId() {
62       return csId;
63     }
64   
65   
66     public long getLastChangedBy() {
67       return lastChangedBy;
68     }
69   
70   
71     public String getLastChangedDate() {
72       return lastChangedDate;
73     }
74   
75   
76     public String getFindByPrimaryKeySQL() {
77       return FIND_BY_PK;
78     }
79   
80   
81     public String getSequenceObjectName() {
82       return SEQUENCE_NAME;
83     }
84   
85   
86     public String getCreateSQL() {
87       return CREATE_SQL;
88     }
89   
90   
91     public String getUpdateSQL() {
92       return UPDATE_SQL;
93     }
94   
95   
96     public String getRemoveSQL() {
97       return REMOVE_SQL;
98     }
99   
100  
101    public void setClearingHouse(ClearingHouse ch) {
102      clearingHouse = ch;
103    }
104  
105  
106    public void setId(long l) {
107      id = l;
108    }
109  
110  
111    public void setCmpId(long l) {
112      cmpId = l;
113    }
114  
115  
116    public void setCsId(long l) {
117      csId = l;
118    }
119  
120  
121    public void setLastChangedBy(long l) {
122      lastChangedBy = l;
123    }
124  
125  
126    public void setLastChangedDate(String s) {
127      lastChangedDate = s;
128    }
129  
130  
131    /**
132     * Returns a list of LongWrapper objects of keys for this DataObject
133     *
134     * @param companyId Description of the Parameter
135     * @param csId Description of the Parameter
136     * @return The primaryKeys value
137     * @throws SQLException Description of the Exception
138     * @throws NamingException Description of the Exception
139     */
140    public static List getPrimaryKeys(long companyId, long csId) throws SQLException, NamingException {
141      return AchDAO.getPrimaryKeys(
142        "select ACHC_ID from ach_clearhouse where ACHC_CMP_ID="
143        + companyId + " and ACHC_CS_ID=" + csId);
144    }
145  
146    // Sql to populate all fields of this object
147    private static final String FIND_BY_PK =
148      "SELECT ACHC_CMP_ID, ACHC_CS_ID, ACHC_INTERFACE_CODE, ACHC_DEST_NAME, " +
149      "ACHC_DEST, ACHC_ORIGIN_NAME, ACHC_ORIGIN, ACHC_STATUS, ACHC_BATCH_NUMBER, " +
150      "ACHC_BATCH_DESC, ACHC_BANK_COMPANY_CODE, ACHC_LAST_CHANGED_BY, " +
151      "to_char(ACHC_LAST_CHANGED_DATE,  'mm-dd-yyyy') " +
152      "FROM  ACH_CLEARHOUSE " +
153      "WHERE ACHC_ID = ?";
154  
155    // Populate an object that, so far, only has a primary key in it
156    public void populate(ResultSet rs) throws SQLException {
157      if(rs == null) {
158        return;
159      }
160      setClearingHouse(new ClearingHouse(rs.getString(3), rs.getString(4),
161        rs.getString(5), rs.getString(6), rs.getString(7),
162        rs.getString(8), rs.getInt(9), rs.getString(10),
163        rs.getString(11)));
164      setCmpId(rs.getLong(1));
165      setCsId(rs.getLong(2));
166      setLastChangedBy(rs.getLong(12));
167      setLastChangedDate(rs.getString(13));
168    }
169  
170  
171    // Sql to store this object
172    private static final String CREATE_SQL =
173      "insert into ach_clearhouse " +
174      "(achc_id, ACHC_CMP_ID, ACHC_CS_ID, ACHC_INTERFACE_CODE, ACHC_DEST_NAME, " +
175      "ACHC_DEST, ACHC_ORIGIN_NAME, ACHC_ORIGIN, ACHC_STATUS, ACHC_BATCH_NUMBER, " +
176      "ACHC_BATCH_DESC, ACHC_BANK_COMPANY_CODE, ACHC_LAST_CHANGED_BY, ACHC_LAST_CHANGED_DATE) " +
177      "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)";
178  
179  
180    public void prepareCreateStatement(PreparedStatement ps) throws SQLException {
181      if(ps == null) {
182        return;
183      }
184      ps.setLong(1, this.getId());
185      ps.setLong(2, this.getCmpId());
186      ps.setLong(3, this.getCsId());
187      ps.setString(4, this.getClearingHouse().getInterfaceCode());
188      ps.setString(5, this.getClearingHouse().getDestName());
189      ps.setString(6, this.getClearingHouse().getDest());
190      ps.setString(7, this.getClearingHouse().getOriginName());
191      ps.setString(8, this.getClearingHouse().getOrigin());
192      ps.setString(9, this.getClearingHouse().getStatus());
193      ps.setInt(10, this.getClearingHouse().getBatchNumber());
194      ps.setString(11, this.getClearingHouse().getBatchDesc());
195      ps.setString(12, this.getClearingHouse().getBankCompanyCode());
196      ps.setLong(13, this.getLastChangedBy());
197    }
198  
199  
200    // Sql to update this object
201    private static final String UPDATE_SQL =
202      "update ach_clearhouse " +
203      "set    ACHC_CMP_ID= ?, ACHC_CS_ID= ?, ACHC_INTERFACE_CODE= ?, ACHC_DEST_NAME= ?, " +
204      "ACHC_DEST= ?, ACHC_ORIGIN_NAME= ?, ACHC_ORIGIN= ?, ACHC_STATUS= ? , ACHC_BATCH_NUMBER= ?, " +
205      "ACHC_BATCH_DESC= ?, ACHC_BANK_COMPANY_CODE= ?, ACHC_LAST_CHANGED_BY= ?, ACHC_LAST_CHANGED_DATE=sysdate " +
206      "where achc_id= ? ";
207  
208  
209    public void prepareUpdateStatement(PreparedStatement ps) throws SQLException {
210      if(ps == null) {
211        return;
212      }
213      ps.setLong(1, this.getCmpId());
214      ps.setLong(2, this.getCsId());
215      ps.setString(3, this.getClearingHouse().getInterfaceCode());
216      ps.setString(4, this.getClearingHouse().getDestName());
217      ps.setString(5, this.getClearingHouse().getDest());
218      ps.setString(6, this.getClearingHouse().getOriginName());
219      ps.setString(7, this.getClearingHouse().getOrigin());
220      ps.setString(8, this.getClearingHouse().getStatus());
221      ps.setInt(9, this.getClearingHouse().getBatchNumber());
222      ps.setString(10, this.getClearingHouse().getBatchDesc());
223      ps.setString(11, this.getClearingHouse().getBankCompanyCode());
224      ps.setLong(12, this.getLastChangedBy());
225      ps.setLong(13, this.getId());
226    }
227  
228    // Sql to remove this object from the database
229    private static final String REMOVE_SQL =
230      "delete from ach_clearhouse " +
231      "where achc_id= ? ";
232  
233  
234    public void prepareRemoveStatement(PreparedStatement ps) throws SQLException {
235      if(ps == null) {
236        return;
237      }
238      ps.setLong(1, this.getId());
239    }
240  
241  
242    public String toString() {
243      return "[" + id + '|' + clearingHouse == null ? "" : clearingHouse.toString() + '|' + cmpId + '|' + csId
244        + '|' + lastChangedBy + '|' + lastChangedDate + "]";
245    }
246  }
247