KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > db > jdbc > CompanyDAOImplJDBC


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/jdbc/CompanyDAOImplJDBC.java,v 1.29 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.29 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Tran Van Giang
39  */

40 package com.mvnforum.db.jdbc;
41
42 import java.sql.*;
43 import java.util.*;
44
45 import com.mvnforum.db.*;
46 import net.myvietnam.mvncore.db.DBUtils;
47 import net.myvietnam.mvncore.exception.*;
48 import net.myvietnam.mvncore.util.DateUtil;
49 import org.apache.commons.logging.Log;
50 import org.apache.commons.logging.LogFactory;
51
52 public class CompanyDAOImplJDBC implements CompanyDAO {
53
54     private static Log log = LogFactory.getLog(CompanyDAOImplJDBC.class);
55
56     // this variable will support caching if cache for this class is needed
57
private static boolean m_dirty = true;
58
59     public CompanyDAOImplJDBC() {
60     }
61
62     protected static boolean isDirty() {
63         return m_dirty;
64     }
65
66     protected static void setDirty(boolean dirty) {
67         m_dirty = dirty;
68     }
69
70     public void findByPrimaryKey(int companyID)
71         throws ObjectNotFoundException, DatabaseException {
72
73         Connection connection = null;
74         PreparedStatement statement = null;
75         ResultSet resultSet = null;
76         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
77         sql.append("SELECT CompanyID");
78         sql.append(" FROM " + TABLE_NAME);
79         sql.append(" WHERE CompanyID = ?");
80         try {
81             connection = DBUtils.getConnection();
82             statement = connection.prepareStatement(sql.toString());
83             statement.setInt(1, companyID);
84             resultSet = statement.executeQuery();
85             if (!resultSet.next()) {
86                 throw new ObjectNotFoundException("Cannot find the primary key (" + companyID + ") in table 'Company'.");
87             }
88         } catch(SQLException sqle) {
89             log.error("Sql Execution Error!", sqle);
90             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByPrimaryKey.");
91         } finally {
92             DBUtils.closeResultSet(resultSet);
93             DBUtils.closeStatement(statement);
94             DBUtils.closeConnection(connection);
95         }
96     }
97
98     public void findByAlternateKey_GroupID(int groupID)
99         throws ObjectNotFoundException, DatabaseException {
100
101         Connection connection = null;
102         PreparedStatement statement = null;
103         ResultSet resultSet = null;
104         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
105         sql.append("SELECT GroupID");
106         sql.append(" FROM " + TABLE_NAME);
107         sql.append(" WHERE GroupID = ?");
108         try {
109             connection = DBUtils.getConnection();
110             statement = connection.prepareStatement(sql.toString());
111             statement.setInt(1, groupID);
112             resultSet = statement.executeQuery();
113             if (!resultSet.next()) {
114                 throw new ObjectNotFoundException("Cannot find the alternate key [GroupID] (" + groupID + ") in table 'Company'.");
115             }
116         } catch(SQLException sqle) {
117             log.error("Sql Execution Error!", sqle);
118             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_GroupID.");
119         } finally {
120             DBUtils.closeResultSet(resultSet);
121             DBUtils.closeStatement(statement);
122             DBUtils.closeConnection(connection);
123         }
124     }
125
126     public void findByAlternateKey_CompanyName(String JavaDoc companyName)
127         throws ObjectNotFoundException, DatabaseException {
128
129         Connection connection = null;
130         PreparedStatement statement = null;
131         ResultSet resultSet = null;
132         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
133         sql.append("SELECT CompanyName");
134         sql.append(" FROM " + TABLE_NAME);
135         sql.append(" WHERE CompanyName = ?");
136         try {
137             connection = DBUtils.getConnection();
138             statement = connection.prepareStatement(sql.toString());
139             statement.setString(1, companyName);
140             resultSet = statement.executeQuery();
141             if (!resultSet.next()) {
142                 throw new ObjectNotFoundException("Cannot find the alternate key [CompanyName] (" + companyName + ") in table 'Company'.");
143             }
144         } catch(SQLException sqle) {
145             log.error("Sql Execution Error!", sqle);
146             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanyName.");
147         } finally {
148             DBUtils.closeResultSet(resultSet);
149             DBUtils.closeStatement(statement);
150             DBUtils.closeConnection(connection);
151         }
152     }
153
154     public void findByAlternateKey_CompanyEmail(String JavaDoc companyEmail)
155         throws ObjectNotFoundException, DatabaseException {
156
157         Connection connection = null;
158         PreparedStatement statement = null;
159         ResultSet resultSet = null;
160         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
161         sql.append("SELECT CompanyEmail");
162         sql.append(" FROM " + TABLE_NAME);
163         sql.append(" WHERE CompanyEmail = ?");
164         try {
165             connection = DBUtils.getConnection();
166             statement = connection.prepareStatement(sql.toString());
167             statement.setString(1, companyEmail);
168             resultSet = statement.executeQuery();
169             if (!resultSet.next()) {
170                 throw new ObjectNotFoundException("Cannot find the alternate key [CompanyEmail] (" + companyEmail + ") in table 'Company'.");
171             }
172         } catch(SQLException sqle) {
173             log.error("Sql Execution Error!", sqle);
174             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanyEmail.");
175         } finally {
176             DBUtils.closeResultSet(resultSet);
177             DBUtils.closeStatement(statement);
178             DBUtils.closeConnection(connection);
179         }
180     }
181
182     public void findByAlternateKey_CompanySpaceName(String JavaDoc companySpaceName)
183         throws ObjectNotFoundException, DatabaseException {
184
185         Connection connection = null;
186         PreparedStatement statement = null;
187         ResultSet resultSet = null;
188         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
189         sql.append("SELECT CompanySpaceName");
190         sql.append(" FROM " + TABLE_NAME);
191         sql.append(" WHERE CompanySpaceName = ?");
192         try {
193             connection = DBUtils.getConnection();
194             statement = connection.prepareStatement(sql.toString());
195             statement.setString(1, companySpaceName);
196             resultSet = statement.executeQuery();
197             if (!resultSet.next()) {
198                 throw new ObjectNotFoundException("Cannot find the alternate key [CompanySpaceName] (" + companySpaceName + ") in table 'Company'.");
199             }
200         } catch(SQLException sqle) {
201             log.error("Sql Execution Error!", sqle);
202             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanySpaceName.");
203         } finally {
204             DBUtils.closeResultSet(resultSet);
205             DBUtils.closeStatement(statement);
206             DBUtils.closeConnection(connection);
207         }
208     }
209
210     /*
211      * Included columns: GroupID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP,
212      * CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite,
213      * CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber,
214      * CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
215      * Excluded columns: CompanyID
216      */

217     public void create(int groupID, String JavaDoc companyName, String JavaDoc companyAddress,
218                         String JavaDoc companyCity, String JavaDoc companyCAP, String JavaDoc companyProvince,
219                         String JavaDoc companyRegion, String JavaDoc companyPhone, String JavaDoc companyFax,
220                         String JavaDoc companyWebsite, String JavaDoc companyEmail, String JavaDoc companySpaceName,
221                         String JavaDoc companySpaceHeader, String JavaDoc companySpaceFooter, String JavaDoc companyVATNumber,
222                         String JavaDoc companyLogo, String JavaDoc companyCss, Timestamp companyCreationDate,
223                         Timestamp companyModifiedDate)
224         throws CreateException, DatabaseException, DuplicateKeyException, ForeignKeyNotFoundException {
225
226         // @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
227
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
228
try {
229             //Check if alternate key already exists
230
findByAlternateKey_GroupID(groupID);
231             //If so, then we have to throw an exception
232
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [GroupID] (" + groupID + ").");
233         } catch(ObjectNotFoundException e) {
234             //Otherwise we can go ahead
235
}
236
237         // @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
238
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
239
try {
240             //Check if alternate key already exists
241
findByAlternateKey_CompanyName(companyName);
242             //If so, then we have to throw an exception
243
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [CompanyName] (" + companyName + ").");
244         } catch(ObjectNotFoundException e) {
245             //Otherwise we can go ahead
246
}
247
248         // @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
249
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
250
try {
251             //Check if alternate key already exists
252
findByAlternateKey_CompanyEmail(companyEmail);
253             //If so, then we have to throw an exception
254
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [CompanyEmail] (" + companyEmail + ").");
255         } catch(ObjectNotFoundException e) {
256             //Otherwise we can go ahead
257
}
258
259         // @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
260
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
261
try {
262             //Check if alternate key already exists
263
findByAlternateKey_CompanySpaceName(companySpaceName);
264             //If so, then we have to throw an exception
265
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [CompanySpaceName] (" + companySpaceName + ").");
266         } catch(ObjectNotFoundException e) {
267             //Otherwise we can go ahead
268
}
269
270         try {
271             // @todo: modify the parameter list as needed
272
// You may have to regenerate this method if the needed columns dont have attribute 'include'
273
DAOFactory.getGroupsDAO().findByPrimaryKey(groupID);
274         } catch(ObjectNotFoundException e) {
275             throw new ForeignKeyNotFoundException("Foreign key refers to table 'Groups' does not exist. Cannot create new Company.");
276         }
277
278         Connection connection = null;
279         PreparedStatement statement = null;
280         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
281         sql.append("INSERT INTO " + TABLE_NAME + " (GroupID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP, CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite, CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate)");
282         sql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
283         try {
284             connection = DBUtils.getConnection();
285             statement = connection.prepareStatement(sql.toString());
286
287             statement.setInt(1, groupID);
288             statement.setString(2, companyName);
289             statement.setString(3, companyAddress);
290             statement.setString(4, companyCity);
291             statement.setString(5, companyCAP);
292             statement.setString(6, companyProvince);
293             statement.setString(7, companyRegion);
294             statement.setString(8, companyPhone);
295             statement.setString(9, companyFax);
296             statement.setString(10, companyWebsite);
297             statement.setString(11, companyEmail);
298             statement.setString(12, companySpaceName);
299             statement.setString(13, companySpaceHeader);
300             statement.setString(14, companySpaceFooter);
301             statement.setString(15, companyVATNumber);
302             statement.setString(16, companyLogo);
303             statement.setString(17, companyCss);
304             statement.setTimestamp(18, companyCreationDate);
305             statement.setTimestamp(19, companyModifiedDate);
306
307             if (statement.executeUpdate() != 1) {
308                 throw new CreateException("Error adding a row into table 'Company'.");
309             }
310             m_dirty = true;
311         } catch(SQLException sqle) {
312             log.error("Sql Execution Error!", sqle);
313             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.create.");
314         } finally {
315             DBUtils.closeStatement(statement);
316             DBUtils.closeConnection(connection);
317         }
318     }
319
320     public void delete(int companyID)
321         throws DatabaseException, ObjectNotFoundException {
322
323         Connection connection = null;
324         PreparedStatement statement = null;
325         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
326         sql.append("DELETE FROM " + TABLE_NAME);
327         sql.append(" WHERE CompanyID = ?");
328
329         try {
330             connection = DBUtils.getConnection();
331             statement = connection.prepareStatement(sql.toString());
332             statement.setInt(1, companyID);
333             if (statement.executeUpdate() != 1) {
334                 throw new ObjectNotFoundException("Cannot delete a row in table Company where primary key = (" + companyID + ").");
335             }
336             m_dirty = true;
337         } catch(SQLException sqle) {
338             log.error("Sql Execution Error!", sqle);
339             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.delete.");
340         } finally {
341             DBUtils.closeStatement(statement);
342             DBUtils.closeConnection(connection);
343         }
344     }
345
346     /*
347      * Included columns: CompanyName, CompanyAddress, CompanyCity, CompanyCAP, CompanyProvince,
348      * CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite, CompanyEmail,
349      * CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyModifiedDate
350      * Excluded columns: CompanyID, GroupID, CompanyLogo, CompanyCss, CompanyCreationDate
351      */

352     public void updateCompanyInfo(int companyID, // primary key
353
String JavaDoc companyName, String JavaDoc companyAddress, String JavaDoc companyCity,
354                         String JavaDoc companyCAP, String JavaDoc companyProvince, String JavaDoc companyRegion,
355                         String JavaDoc companyPhone, String JavaDoc companyFax, String JavaDoc companyWebsite,
356                         String JavaDoc companyEmail, String JavaDoc companySpaceName, String JavaDoc companySpaceHeader,
357                         String JavaDoc companySpaceFooter, String JavaDoc companyVATNumber, Timestamp companyModifiedDate)
358         throws ObjectNotFoundException, DatabaseException, DuplicateKeyException {
359
360         CompanyBean bean = getCompany(companyID);
361
362         if ( !companyName.equals(bean.getCompanyName()) ) {
363             // Company tries to change its alternate key <CompanyName>, so we must check if it already exist
364
try {
365                 findByAlternateKey_CompanyName(companyName);
366                 throw new DuplicateKeyException("Alternate key [CompanyName] (" + companyName + ")already exists. Cannot update Company.");
367             } catch(ObjectNotFoundException e) {
368                 //Otherwise we can go ahead
369
}
370         }
371
372         if ( !companyEmail.equals(bean.getCompanyEmail()) ) {
373             // Company tries to change its alternate key <CompanyEmail>, so we must check if it already exist
374
try {
375                 findByAlternateKey_CompanyEmail(companyEmail);
376                 throw new DuplicateKeyException("Alternate key [CompanyEmail] (" + companyEmail + ")already exists. Cannot update Company.");
377             } catch(ObjectNotFoundException e) {
378                 //Otherwise we can go ahead
379
}
380         }
381
382         if ( !companySpaceName.equals(bean.getCompanySpaceName()) ) {
383             // Company tries to change its alternate key <CompanySpaceName>, so we must check if it already exist
384
try {
385                 findByAlternateKey_CompanySpaceName(companySpaceName);
386                 throw new DuplicateKeyException("Alternate key [CompanySpaceName] (" + companySpaceName + ")already exists. Cannot update Company.");
387             } catch(ObjectNotFoundException e) {
388                 //Otherwise we can go ahead
389
}
390         }
391
392         Connection connection = null;
393         PreparedStatement statement = null;
394         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
395         sql.append("UPDATE " + TABLE_NAME + " SET CompanyName = ?, CompanyAddress = ?, CompanyCity = ?, CompanyCAP = ?, CompanyProvince = ?, CompanyRegion = ?, CompanyPhone = ?, CompanyFax = ?, CompanyWebsite = ?, CompanyEmail = ?, CompanySpaceName = ?, CompanySpaceHeader = ?, CompanySpaceFooter = ?, CompanyVATNumber = ?, CompanyModifiedDate = ?");
396         sql.append(" WHERE CompanyID = ?");
397         try {
398             connection = DBUtils.getConnection();
399             statement = connection.prepareStatement(sql.toString());
400
401             // // column(s) to update
402
statement.setString(1, companyName);
403             statement.setString(2, companyAddress);
404             statement.setString(3, companyCity);
405             statement.setString(4, companyCAP);
406             statement.setString(5, companyProvince);
407             statement.setString(6, companyRegion);
408             statement.setString(7, companyPhone);
409             statement.setString(8, companyFax);
410             statement.setString(9, companyWebsite);
411             statement.setString(10, companyEmail);
412             statement.setString(11, companySpaceName);
413             statement.setString(12, companySpaceHeader);
414             statement.setString(13, companySpaceFooter);
415             statement.setString(14, companyVATNumber);
416             statement.setTimestamp(15, companyModifiedDate);
417
418             // primary key column(s)
419
statement.setInt(16, companyID);
420
421             if (statement.executeUpdate() != 1) {
422                 throw new ObjectNotFoundException("Cannot update table Company where primary key = (" + companyID + ").");
423             }
424             m_dirty = true;
425         } catch(SQLException sqle) {
426             log.error("Sql Execution Error!", sqle);
427             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.updateCompanyInfo.");
428         } finally {
429             DBUtils.closeStatement(statement);
430             DBUtils.closeConnection(connection);
431         }
432     }
433
434     public void updateCompanyLogo(int companyID, // primary key
435
String JavaDoc companyLogo)
436         throws ObjectNotFoundException, DatabaseException {
437
438         Connection connection = null;
439         PreparedStatement statement = null;
440         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
441         sql.append("UPDATE " + TABLE_NAME + " SET CompanyLogo = ?");
442         sql.append(" WHERE CompanyID = ?");
443         try {
444             connection = DBUtils.getConnection();
445             statement = connection.prepareStatement(sql.toString());
446
447             // // column(s) to update
448
statement.setString(1, companyLogo);
449
450             // primary key column(s)
451
statement.setInt(2, companyID);
452
453             if (statement.executeUpdate() != 1) {
454                 throw new ObjectNotFoundException("Cannot update table Company where primary key = (" + companyID + ").");
455             }
456             m_dirty = true;
457         } catch(SQLException sqle) {
458             log.error("Sql Execution Error!", sqle);
459             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.updateCompanyLogo.");
460         } finally {
461             DBUtils.closeStatement(statement);
462             DBUtils.closeConnection(connection);
463         }
464     }
465
466     public void updateCompanyCss(int companyID, // primary key
467
String JavaDoc companyCss)
468         throws ObjectNotFoundException, DatabaseException {
469
470         Connection connection = null;
471         PreparedStatement statement = null;
472         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
473         sql.append("UPDATE " + TABLE_NAME + " SET CompanyCss = ?");
474         sql.append(" WHERE CompanyID = ?");
475         try {
476             connection = DBUtils.getConnection();
477             statement = connection.prepareStatement(sql.toString());
478
479             // // column(s) to update
480
statement.setString(1, companyCss);
481
482             // primary key column(s)
483
statement.setInt(2, companyID);
484
485             if (statement.executeUpdate() != 1) {
486                 throw new ObjectNotFoundException("Cannot update table Company where primary key = (" + companyID + ").");
487             }
488             m_dirty = true;
489         } catch(SQLException sqle) {
490             log.error("Sql Execution Error!", sqle);
491             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.updateCompanyCss.");
492         } finally {
493             DBUtils.closeStatement(statement);
494             DBUtils.closeConnection(connection);
495         }
496     }
497
498     public int getCompanyIDFromGroupID(int groupID)
499         throws ObjectNotFoundException, DatabaseException {
500
501         Connection connection = null;
502         PreparedStatement statement = null;
503         ResultSet resultSet = null;
504         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
505         sql.append("SELECT CompanyID");
506         sql.append(" FROM " + TABLE_NAME);
507         sql.append(" WHERE GroupID = ?");
508         try {
509             connection = DBUtils.getConnection();
510             statement = connection.prepareStatement(sql.toString());
511             statement.setInt(1, groupID);
512             resultSet = statement.executeQuery();
513             if(!resultSet.next()) {
514                 throw new ObjectNotFoundException("Cannot find the row in table Company where alternate key [GroupID] = (" + groupID + ").");
515             }
516
517             return resultSet.getInt("CompanyID");
518         } catch(SQLException sqle) {
519             log.error("Sql Execution Error!", sqle);
520             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getCompanyIDFromGroupID(ak).");
521         } finally {
522             DBUtils.closeResultSet(resultSet);
523             DBUtils.closeStatement(statement);
524             DBUtils.closeConnection(connection);
525         }
526     }
527
528     public int getCompanyIDFromCompanyEmail(String JavaDoc companyEmail)
529         throws ObjectNotFoundException, DatabaseException {
530
531         Connection connection = null;
532         PreparedStatement statement = null;
533         ResultSet resultSet = null;
534         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
535         sql.append("SELECT CompanyID");
536         sql.append(" FROM " + TABLE_NAME);
537         sql.append(" WHERE CompanyEmail = ?");
538         try {
539             connection = DBUtils.getConnection();
540             statement = connection.prepareStatement(sql.toString());
541             statement.setString(1, companyEmail);
542             resultSet = statement.executeQuery();
543             if(!resultSet.next()) {
544                 throw new ObjectNotFoundException("Cannot find the row in table Company where alternate key [CompanyEmail] = (" + companyEmail + ").");
545             }
546
547             return resultSet.getInt("CompanyID");
548         } catch(SQLException sqle) {
549             log.error("Sql Execution Error!", sqle);
550             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getCompanyIDFromCompanyEmail(ak).");
551         } finally {
552             DBUtils.closeResultSet(resultSet);
553             DBUtils.closeStatement(statement);
554             DBUtils.closeConnection(connection);
555         }
556     }
557
558     public int getCompanyIDFromCompanySpaceName(String JavaDoc companySpaceName)
559         throws ObjectNotFoundException, DatabaseException {
560
561         Connection connection = null;
562         PreparedStatement statement = null;
563         ResultSet resultSet = null;
564         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
565         sql.append("SELECT CompanyID");
566         sql.append(" FROM " + TABLE_NAME);
567         sql.append(" WHERE CompanySpaceName = ?");
568         try {
569             connection = DBUtils.getConnection();
570             statement = connection.prepareStatement(sql.toString());
571             statement.setString(1, companySpaceName);
572             resultSet = statement.executeQuery();
573             if(!resultSet.next()) {
574                 throw new ObjectNotFoundException("Cannot find the row in table Company where alternate key [CompanySpaceName] = (" + companySpaceName + ").");
575             }
576
577             return resultSet.getInt("CompanyID");
578         } catch(SQLException sqle) {
579             log.error("Sql Execution Error!", sqle);
580             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getCompanyIDFromCompanySpaceName(ak).");
581         } finally {
582             DBUtils.closeResultSet(resultSet);
583             DBUtils.closeStatement(statement);
584             DBUtils.closeConnection(connection);
585         }
586     }
587
588     public int getCompanyIDFromCompanyCreationDate(java.util.Date JavaDoc companyCreationDate)
589         throws ObjectNotFoundException, DatabaseException {
590
591         int totalCompanies = 0;
592         int ret = 0;
593
594         try {
595             totalCompanies = getNumberOfCompanies();
596         } catch (Exception JavaDoc err) {}
597
598         Collection collectionCompany = getCompanies_withSortSupport_limit(0, totalCompanies, "CompanyCreationDate", "ASC");
599         Iterator iteratorCompany = collectionCompany.iterator();
600         while (iteratorCompany.hasNext()) {
601             CompanyBean companyBean = (CompanyBean) iteratorCompany.next();
602             java.util.Date JavaDoc companyCreationDateDB = new java.util.Date JavaDoc(companyBean.getCompanyCreationDate().getTime());
603             String JavaDoc dateFormat = DateUtil.getDateDDMMYYYY(companyCreationDate);
604             String JavaDoc dateFormatDB = DateUtil.getDateDDMMYYYY(companyCreationDateDB);
605             if (dateFormat.equals(dateFormatDB)) {
606                 ret = companyBean.getCompanyID();
607                 break;
608             }
609         }
610         if (ret == 0) {
611             throw new ObjectNotFoundException("Cannot get company ID from company date.");
612         }
613         return ret;
614     }
615
616     /*
617      * Included columns: CompanyID, GroupID, CompanyName, CompanyAddress, CompanyCity,
618      * CompanyCAP, CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax,
619      * CompanyWebsite, CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter,
620      * CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
621      * Excluded columns:
622      */

623     public CompanyBean getCompany(int companyID)
624         throws ObjectNotFoundException, DatabaseException {
625
626         Connection connection = null;
627         PreparedStatement statement = null;
628         ResultSet resultSet = null;
629         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
630         sql.append("SELECT CompanyID, GroupID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP, CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite, CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate");
631         sql.append(" FROM " + TABLE_NAME);
632         sql.append(" WHERE CompanyID = ?");
633         try {
634             connection = DBUtils.getConnection();
635             statement = connection.prepareStatement(sql.toString());
636             statement.setInt(1, companyID);
637             resultSet = statement.executeQuery();
638             if(!resultSet.next()) {
639                 throw new ObjectNotFoundException("Cannot find the row in table Company where primary key = (" + companyID + ").");
640             }
641
642             CompanyBean bean = new CompanyBean();
643             // @todo: uncomment the following line(s) as needed
644
//bean.setCompanyID(companyID);
645
bean.setCompanyID(resultSet.getInt("CompanyID"));
646             bean.setGroupID(resultSet.getInt("GroupID"));
647             bean.setCompanyName(resultSet.getString("CompanyName"));
648             bean.setCompanyAddress(resultSet.getString("CompanyAddress"));
649             bean.setCompanyCity(resultSet.getString("CompanyCity"));
650             bean.setCompanyCAP(resultSet.getString("CompanyCAP"));
651             bean.setCompanyProvince(resultSet.getString("CompanyProvince"));
652             bean.setCompanyRegion(resultSet.getString("CompanyRegion"));
653             bean.setCompanyPhone(resultSet.getString("CompanyPhone"));
654             bean.setCompanyFax(resultSet.getString("CompanyFax"));
655             bean.setCompanyWebsite(resultSet.getString("CompanyWebsite"));
656             bean.setCompanyEmail(resultSet.getString("CompanyEmail"));
657             bean.setCompanySpaceName(resultSet.getString("CompanySpaceName"));
658             bean.setCompanySpaceHeader(resultSet.getString("CompanySpaceHeader"));
659             bean.setCompanySpaceFooter(resultSet.getString("CompanySpaceFooter"));
660             bean.setCompanyVATNumber(resultSet.getString("CompanyVATNumber"));
661             bean.setCompanyLogo(resultSet.getString("CompanyLogo"));
662             bean.setCompanyCss(resultSet.getString("CompanyCss"));
663             bean.setCompanyCreationDate(resultSet.getTimestamp("CompanyCreationDate"));
664             bean.setCompanyModifiedDate(resultSet.getTimestamp("CompanyModifiedDate"));
665             return bean;
666         } catch(SQLException sqle) {
667             log.error("Sql Execution Error!", sqle);
668             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getCompany(pk).");
669         } finally {
670             DBUtils.closeResultSet(resultSet);
671             DBUtils.closeStatement(statement);
672             DBUtils.closeConnection(connection);
673         }
674     }
675
676     public Collection getCompanies_withSortSupport_limit(int offset, int rowsToReturn, String JavaDoc sort, String JavaDoc order)
677         throws IllegalArgumentException JavaDoc, DatabaseException {
678         if (DBUtils.getDatabaseType() == DBUtils.DATABASE_MYSQL) {
679             return getBeans_withSortSupport_limit_mysql(offset, rowsToReturn, sort, order);
680         } else if (DBUtils.getDatabaseType() == DBUtils.DATABASE_NOSCROLL) {
681             return getBeans_withSortSupport_limit_noscroll(offset, rowsToReturn, sort, order);
682         }
683         return getBeans_withSortSupport_limit_general(offset, rowsToReturn, sort, order);
684     }
685
686     /*
687      * Included columns: CompanyID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP,
688      * CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite,
689      * CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
690      * Excluded columns:
691      */

692     /**
693      * This method support sorting and for PUBLIC view
694      */

695     /* @todo fix bug that cannot prepare sort and order */
696     private Collection getBeans_withSortSupport_limit_mysql(int offset, int rowsToReturn, String JavaDoc sort, String JavaDoc order)
697         throws IllegalArgumentException JavaDoc, DatabaseException {
698         if (offset < 0) throw new IllegalArgumentException JavaDoc("The offset < 0 is not allowed.");
699         if (rowsToReturn <= 0) throw new IllegalArgumentException JavaDoc("The rowsToReturn <= 0 is not allowed.");
700         /*
701          * Sort by
702          * CompanyID or CompanyName or CompanyCreationDate
703          */

704         if ((!sort.equals("CompanyID")) &&
705            (!sort.equals("CompanyName")) &&
706            (!sort.equals("CompanyAddress")) &&
707            (!sort.equals("CompanyCreationDate"))) {
708            throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the criteria '" + sort + "'.");
709         }
710
711         if ((!order.equals("ASC")) &&
712            (!order.equals("DESC")) ) {
713            throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the order '" + order + "'.");
714         }
715
716         Connection connection = null;
717         PreparedStatement statement = null;
718         ResultSet resultSet = null;
719         Collection retValue = new ArrayList();
720         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
721         sql.append("SELECT *");
722         sql.append(" FROM " + TABLE_NAME);
723         sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
724
if (rowsToReturn != 1) {
725             sql.append(" LIMIT ?, ?");
726         }
727
728         try {
729             connection = DBUtils.getConnection();
730             statement = connection.prepareStatement(sql.toString());
731             if (rowsToReturn != 1) {
732                 statement.setInt(1, offset);
733                 statement.setInt(2, rowsToReturn);
734             }
735             resultSet = statement.executeQuery();
736             while (resultSet.next()) {
737                 CompanyBean bean = new CompanyBean();
738                 bean.setCompanyID(resultSet.getInt("CompanyID"));
739                 bean.setGroupID(resultSet.getInt("GroupID"));
740                 bean.setCompanyName(resultSet.getString("CompanyName"));
741                 bean.setCompanyAddress(resultSet.getString("CompanyAddress"));
742                 bean.setCompanyCity(resultSet.getString("CompanyCity"));
743                 bean.setCompanyCAP(resultSet.getString("CompanyCAP"));
744                 bean.setCompanyProvince(resultSet.getString("CompanyProvince"));
745                 bean.setCompanyRegion(resultSet.getString("CompanyRegion"));
746                 bean.setCompanyPhone(resultSet.getString("CompanyPhone"));
747                 bean.setCompanyFax(resultSet.getString("CompanyFax"));
748                 bean.setCompanyWebsite(resultSet.getString("CompanyWebsite"));
749                 bean.setCompanyEmail(resultSet.getString("CompanyEmail"));
750                 bean.setCompanySpaceName(resultSet.getString("CompanySpaceName"));
751                 bean.setCompanySpaceHeader(resultSet.getString("CompanySpaceHeader"));
752                 bean.setCompanySpaceFooter(resultSet.getString("CompanySpaceFooter"));
753                 bean.setCompanyVATNumber(resultSet.getString("CompanyVATNumber"));
754                 bean.setCompanyLogo(resultSet.getString("CompanyLogo"));
755                 bean.setCompanyCss(resultSet.getString("CompanyCss"));
756                 bean.setCompanyCreationDate(resultSet.getTimestamp("CompanyCreationDate"));
757                 bean.setCompanyModifiedDate(resultSet.getTimestamp("CompanyModifiedDate"));
758                 retValue.add(bean);
759             }
760             return retValue;
761         } catch(SQLException sqle) {
762             log.error("Sql Execution Error!", sqle);
763             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getBeans_withSortSupport_limit_mysql.");
764         } finally {
765             DBUtils.closeResultSet(resultSet);
766             DBUtils.closeStatement(statement);
767             DBUtils.closeConnection(connection);
768         }
769     }
770
771     /*
772      * Included columns: CompanyID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP,
773      * CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite,
774      * CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
775      * Excluded columns:
776      */

777     /**
778      * This method support sorting and for PUBLIC view
779      */

780     /* @todo fix bug that cannot prepare sort and order */
781     private Collection getBeans_withSortSupport_limit_noscroll(int offset, int rowsToReturn, String JavaDoc sort, String JavaDoc order)
782         throws IllegalArgumentException JavaDoc, DatabaseException {
783         if (offset < 0) throw new IllegalArgumentException JavaDoc("The offset < 0 is not allowed.");
784         if (rowsToReturn <= 0) throw new IllegalArgumentException JavaDoc("The rowsToReturn <= 0 is not allowed.");
785         /*
786          * Sort by
787          * CompanyID or CompanyName or CompanyCreationDate
788          */

789         if ((!sort.equals("CompanyID")) &&
790            (!sort.equals("CompanyName")) &&
791            (!sort.equals("CompanyAddress")) &&
792            (!sort.equals("CompanyCreationDate"))) {
793            throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the criteria '" + sort + "'.");
794         }
795
796         if ((!order.equals("ASC")) &&
797            (!order.equals("DESC")) ) {
798             throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the order '" + order + "'.");
799         }
800
801         Connection connection = null;
802         PreparedStatement statement = null;
803         ResultSet resultSet = null;
804         Collection retValue = new ArrayList();
805         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
806         sql.append("SELECT *");
807         sql.append(" FROM " + TABLE_NAME);
808         sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
809

810         try {
811             connection = DBUtils.getConnection();
812             statement = connection.prepareStatement(sql.toString());
813             if (rowsToReturn != 1) {
814                 statement.setMaxRows(offset + rowsToReturn);
815             }
816             resultSet = statement.executeQuery();
817             int rowIndex = -1;
818             while (resultSet.next()) {
819                 rowIndex++;
820                 if(rowsToReturn !=1) {
821                     if (rowIndex < offset) continue;
822                 }
823                 CompanyBean bean = new CompanyBean();
824                 bean.setCompanyID(resultSet.getInt("CompanyID"));
825                 bean.setGroupID(resultSet.getInt("GroupID"));
826                 bean.setCompanyName(resultSet.getString("CompanyName"));
827                 bean.setCompanyAddress(resultSet.getString("CompanyAddress"));
828                 bean.setCompanyCity(resultSet.getString("CompanyCity"));
829                 bean.setCompanyCAP(resultSet.getString("CompanyCAP"));
830                 bean.setCompanyProvince(resultSet.getString("CompanyProvince"));
831                 bean.setCompanyRegion(resultSet.getString("CompanyRegion"));
832                 bean.setCompanyPhone(resultSet.getString("CompanyPhone"));
833                 bean.setCompanyFax(resultSet.getString("CompanyFax"));
834                 bean.setCompanyWebsite(resultSet.getString("CompanyWebsite"));
835                 bean.setCompanyEmail(resultSet.getString("CompanyEmail"));
836                 bean.setCompanySpaceName(resultSet.getString("CompanySpaceName"));
837                 bean.setCompanySpaceHeader(resultSet.getString("CompanySpaceHeader"));
838                 bean.setCompanySpaceFooter(resultSet.getString("CompanySpaceFooter"));
839                 bean.setCompanyVATNumber(resultSet.getString("CompanyVATNumber"));
840                 bean.setCompanyLogo(resultSet.getString("CompanyLogo"));
841                 bean.setCompanyCss(resultSet.getString("CompanyCss"));
842                 bean.setCompanyCreationDate(resultSet.getTimestamp("CompanyCreationDate"));
843                 bean.setCompanyModifiedDate(resultSet.getTimestamp("CompanyModifiedDate"));
844                 retValue.add(bean);
845                 if (retValue.size() == rowsToReturn) break;// Fix the Sybase bug
846
}
847             return retValue;
848         } catch(SQLException sqle) {
849             log.error("Sql Execution Error!", sqle);
850             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getBeans_withSortSupport_limit_noscroll.");
851         } finally {
852             DBUtils.closeResultSet(resultSet);
853             DBUtils.resetStatement(statement);
854             DBUtils.closeStatement(statement);
855             DBUtils.closeConnection(connection);
856         }
857     }
858
859    /*
860     * Included columns: CompanyID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP,
861     * CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite,
862     * CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
863     * Excluded columns:
864     */

865    /**
866     * This method support sorting and for PUBLIC view
867     */

868    /* @todo fix bug that cannot prepare sort and order */
869
870     private Collection getBeans_withSortSupport_limit_general(int offset, int rowsToReturn, String JavaDoc sort, String JavaDoc order)
871         throws IllegalArgumentException JavaDoc, DatabaseException {
872         if (offset < 0) throw new IllegalArgumentException JavaDoc("The offset < 0 is not allowed.");
873         if (rowsToReturn <= 0) throw new IllegalArgumentException JavaDoc("The rowsToReturn <= 0 is not allowed.");
874         /*
875          * Sort by
876          * CompanyID or CompanyName or CompanyCreationDate
877          */

878         if ((!sort.equals("CompanyID")) &&
879             (!sort.equals("CompanyName")) &&
880             (!sort.equals("CompanyAddress")) &&
881             (!sort.equals("CompanyCreationDate"))) {
882             throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the criteria '" + sort + "'.");
883         }
884
885         if ((!order.equals("ASC")) &&
886             (!order.equals("DESC")) ) {
887             throw new IllegalArgumentException JavaDoc("Cannot sort, reason: don't understand the order '" + order + "'.");
888         }
889
890         Connection connection = null;
891         PreparedStatement statement = null;
892         ResultSet resultSet = null;
893         Collection retValue = new ArrayList();
894         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
895         sql.append("SELECT *");
896         sql.append(" FROM " + TABLE_NAME);
897         sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
898

899         try {
900             connection = DBUtils.getConnection();
901             statement = connection.prepareStatement(sql.toString(),ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
902             if (rowsToReturn != 1) {
903                 statement.setMaxRows(offset + rowsToReturn);
904             }
905             try {
906                 statement.setFetchSize(rowsToReturn);
907             } catch (SQLException sqle) {
908                 //do nothing, postgreSQL doesnt support this method
909
}
910             resultSet = statement.executeQuery();
911             boolean loop = resultSet.absolute(offset + 1);// the absolute method begin with 1 instead of 0 as in the LIMIT clause
912
while (loop) {
913                 CompanyBean bean = new CompanyBean();
914                 bean.setCompanyID(resultSet.getInt("CompanyID"));
915                 bean.setGroupID(resultSet.getInt("GroupID"));
916                 bean.setCompanyName(resultSet.getString("CompanyName"));
917                 bean.setCompanyAddress(resultSet.getString("CompanyAddress"));
918                 bean.setCompanyCity(resultSet.getString("CompanyCity"));
919                 bean.setCompanyCAP(resultSet.getString("CompanyCAP"));
920                 bean.setCompanyProvince(resultSet.getString("CompanyProvince"));
921                 bean.setCompanyRegion(resultSet.getString("CompanyRegion"));
922                 bean.setCompanyPhone(resultSet.getString("CompanyPhone"));
923                 bean.setCompanyFax(resultSet.getString("CompanyFax"));
924                 bean.setCompanyWebsite(resultSet.getString("CompanyWebsite"));
925                 bean.setCompanyEmail(resultSet.getString("CompanyEmail"));
926                 bean.setCompanySpaceName(resultSet.getString("CompanySpaceName"));
927                 bean.setCompanySpaceHeader(resultSet.getString("CompanySpaceHeader"));
928                 bean.setCompanySpaceFooter(resultSet.getString("CompanySpaceFooter"));
929                 bean.setCompanyVATNumber(resultSet.getString("CompanyVATNumber"));
930                 bean.setCompanyLogo(resultSet.getString("CompanyLogo"));
931                 bean.setCompanyCss(resultSet.getString("CompanyCss"));
932                 bean.setCompanyCreationDate(resultSet.getTimestamp("CompanyCreationDate"));
933                 bean.setCompanyModifiedDate(resultSet.getTimestamp("CompanyModifiedDate"));
934                 retValue.add(bean);
935                 if(rowsToReturn !=1) {
936                     if (retValue.size() == rowsToReturn) break; // Fix the Sybase bug
937
}
938                 loop = resultSet.next();
939             }
940             return retValue;
941         } catch(SQLException sqle) {
942             log.error("Sql Execution Error!", sqle);
943             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getBeans_withSortSupport_limit_general.");
944         } finally {
945             DBUtils.closeResultSet(resultSet);
946             DBUtils.resetStatement(statement);
947             DBUtils.closeStatement(statement);
948             DBUtils.closeConnection(connection);
949         }
950     }
951
952     public int getNumberOfCompanies()
953         throws AssertionException, DatabaseException {
954
955         Connection connection = null;
956         PreparedStatement statement = null;
957         ResultSet resultSet = null;
958         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
959         sql.append("SELECT Count(*)");
960         sql.append(" FROM " + TABLE_NAME);
961         //sql.append(" WHERE "); // @todo: uncomment as needed
962
try {
963             connection = DBUtils.getConnection();
964             statement = connection.prepareStatement(sql.toString());
965             resultSet = statement.executeQuery();
966             if (!resultSet.next()) {
967                 throw new AssertionException("Assertion in CompanyDAOImplJDBC.getNumberOfCompanies.");
968             }
969             return resultSet.getInt(1);
970         } catch(SQLException sqle) {
971             log.error("Sql Execution Error!", sqle);
972             throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getNumberOfCompanies.");
973         } finally {
974             DBUtils.closeResultSet(resultSet);
975             DBUtils.closeStatement(statement);
976             DBUtils.closeConnection(connection);
977         }
978     }
979
980     /*
981      * Included columns: CompanyID, GroupID, CompanyName, CompanyAddress, CompanyCity,
982      * CompanyCAP, CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax,
983      * CompanyWebsite, CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter,
984      * CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
985      * Excluded columns:
986      */

987     public Collection getCompanies()
988         throws DatabaseException {
989
990         Connection connection = null;
991         PreparedStatement statement = null;
992         ResultSet resultSet = null;
993         Collection retValue = new ArrayList();
994         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
995         sql.append("SELECT CompanyID, GroupID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP, CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite, CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber, CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate");
996         sql.append(" FROM " + TABLE_NAME);
997         //sql.append(" WHERE "); // @todo: uncomment as needed
998
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
999
try {
1000            connection = DBUtils.getConnection();
1001            statement = connection.prepareStatement(sql.toString());
1002            resultSet = statement.executeQuery();
1003            while (resultSet.next()) {
1004                CompanyBean bean = new CompanyBean();
1005                bean.setCompanyID(resultSet.getInt("CompanyID"));
1006                bean.setGroupID(resultSet.getInt("GroupID"));
1007                bean.setCompanyName(resultSet.getString("CompanyName"));
1008                bean.setCompanyAddress(resultSet.getString("CompanyAddress"));
1009                bean.setCompanyCity(resultSet.getString("CompanyCity"));
1010                bean.setCompanyCAP(resultSet.getString("CompanyCAP"));
1011                bean.setCompanyProvince(resultSet.getString("CompanyProvince"));
1012                bean.setCompanyRegion(resultSet.getString("CompanyRegion"));
1013                bean.setCompanyPhone(resultSet.getString("CompanyPhone"));
1014                bean.setCompanyFax(resultSet.getString("CompanyFax"));
1015                bean.setCompanyWebsite(resultSet.getString("CompanyWebsite"));
1016                bean.setCompanyEmail(resultSet.getString("CompanyEmail"));
1017                bean.setCompanySpaceName(resultSet.getString("CompanySpaceName"));
1018                bean.setCompanySpaceHeader(resultSet.getString("CompanySpaceHeader"));
1019                bean.setCompanySpaceFooter(resultSet.getString("CompanySpaceFooter"));
1020                bean.setCompanyVATNumber(resultSet.getString("CompanyVATNumber"));
1021                bean.setCompanyLogo(resultSet.getString("CompanyLogo"));
1022                bean.setCompanyCss(resultSet.getString("CompanyCss"));
1023                bean.setCompanyCreationDate(resultSet.getTimestamp("CompanyCreationDate"));
1024                bean.setCompanyModifiedDate(resultSet.getTimestamp("CompanyModifiedDate"));
1025                retValue.add(bean);
1026            }
1027            return retValue;
1028        } catch(SQLException sqle) {
1029            log.error("Sql Execution Error!", sqle);
1030            throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.getCompanies.");
1031        } finally {
1032            DBUtils.closeResultSet(resultSet);
1033            DBUtils.closeStatement(statement);
1034            DBUtils.closeConnection(connection);
1035        }
1036    }
1037
1038} // end of class CompanyDAOImplJDBC
1039
Popular Tags