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 CompanySystemDO
11       implements DataObject, Serializable {
12   
13     private static final String SEQUENCE_NAME = "company_system_SEQ";
14   
15     private CompanySystem companySystem = null;
16     private long id = -1;
17     private long lastChangedBy = -1;
18     private String lastChangedDate = null;
19   
20   
21     public CompanySystemDO() {
22       super();
23     }
24   
25   
26     public CompanySystemDO(long primaryKey) {
27       setId(primaryKey);
28     }
29   
30   
31     public CompanySystemDO(CompanySystem theCompanySystem, long theId,
32                            long theLastChangedBy, String theLastChangedDate) {
33   
34       setCompanySystem(theCompanySystem);
35       setId(theId);
36       setLastChangedBy(theLastChangedBy);
37       setLastChangedDate(theLastChangedDate);
38     }
39   
40   
41     public CompanySystem getCompanySystem() {
42       return companySystem;
43     }
44   
45   
46     public long getId() {
47       return id;
48     }
49   
50   
51     public long getLastChangedBy() {
52       return lastChangedBy;
53     }
54   
55   
56     public String getLastChangedDate() {
57       return lastChangedDate;
58     }
59   
60   
61     public String getFindByPrimaryKeySQL() {
62       return FIND_BY_PK;
63     }
64   
65   
66     public String getSequenceObjectName() {
67       return SEQUENCE_NAME;
68     }
69   
70   
71     public String getCreateSQL() {
72       return CREATE_SQL;
73     }
74   
75   
76     public String getUpdateSQL() {
77       return UPDATE_SQL;
78     }
79   
80   
81     public String getRemoveSQL() {
82       return REMOVE_SQL;
83     }
84   
85   
86     public void setCompanySystem(CompanySystem ch) {
87       companySystem = ch;
88     }
89   
90   
91     public void setId(long l) {
92       id = l;
93     }
94   
95   
96     public void setLastChangedBy(long l) {
97       lastChangedBy = l;
98     }
99   
100  
101    public void setLastChangedDate(String s) {
102      lastChangedDate = s;
103    }
104  
105  
106    /**
107     * Returns a list of LongWrapper objects of keys for this DataObject
108     *
109     * @param companyId Description of the Parameter
110     * @return The primaryKeys value
111     * @throws SQLException Description of the Exception
112     * @throws NamingException Description of the Exception
113     */
114    public static List getPrimaryKeys(long companyId) throws SQLException, NamingException {
115      return AchDAO.getPrimaryKeys(
116        "select CS_ID from company_system where cs_cmp_id="
117        + companyId);
118    }
119  
120    // Sql to populate all fields of this object
121    private static final String FIND_BY_PK =
122      "SELECT CS_CMP_ID, CS_SYSTEM_ID, cs_LAST_CHANGED_BY, cs_LAST_CHANGED_DATE " +
123      "FROM  COMPANY_SYSTEM " +
124      "WHERE CS_ID = ?";
125  
126    // Populate an object that, so far, only has a primary key in it
127    public void populate(ResultSet rs) throws SQLException {
128      if(rs == null) {
129        return;
130      }
131      setCompanySystem(new CompanySystem(rs.getLong(1), rs.getLong(2)));
132      setLastChangedBy(rs.getLong(3));
133      setLastChangedDate(rs.getString(4));
134    }
135  
136  
137    // Sql to store this object
138    private static final String CREATE_SQL =
139      "insert into COMPANY_SYSTEM " +
140      "(CS_ID, CS_CMP_ID, CS_SYSTEM_ID, cs_LAST_CHANGED_BY, cs_LAST_CHANGED_DATE) " +
141      "values (?, ?, ?, ?, sysdate)";
142  
143  
144    public void prepareCreateStatement(PreparedStatement ps) throws SQLException {
145      if(ps == null) {
146        return;
147      }
148      ps.setLong(1, this.getId());
149      ps.setLong(2, this.getCompanySystem().getCompanyId());
150      ps.setLong(3, this.getCompanySystem().getSystemId());
151      ps.setLong(4, this.getLastChangedBy());
152    }
153  
154  
155    // Sql to update this object
156    private static final String UPDATE_SQL =
157      "update COMPANY_SYSTEM " +
158      "set    CS_CMP_ID= ?, CS_SYSTEM_ID= ?, cs_LAST_CHANGED_BY= ?, " +
159      "cs_LAST_CHANGED_DATE=sysdate " +
160      "where cs_id= ? ";
161  
162  
163    public void prepareUpdateStatement(PreparedStatement ps) throws SQLException {
164      if(ps == null) {
165        return;
166      }
167      ps.setLong(1, this.getCompanySystem().getCompanyId());
168      ps.setLong(2, this.getCompanySystem().getSystemId());
169      ps.setLong(3, this.getLastChangedBy());
170      ps.setLong(4, this.getId());
171    }
172  
173    // Sql to remove this object from the database
174    private static final String REMOVE_SQL =
175      "delete from COMPANY_SYSTEM " +
176      "where cs_id= ? ";
177  
178  
179    public void prepareRemoveStatement(PreparedStatement ps) throws SQLException {
180      if(ps == null) {
181        return;
182      }
183      ps.setLong(1, this.getId());
184    }
185  
186  
187    public String toString() {
188      return "[" + id + '|' + companySystem == null ? "" : companySystem.toString() + '|' + lastChangedBy
189        + '|' + lastChangedDate + ']';
190    }
191  }
192