KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > dao > DAO


1 /*
2  * $$Id: DAO.java,v 1.3 2005/06/07 12:32:30 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 07.05.2003
27  *
28  */

29 package org.jresearch.gossip.dao;
30
31 import java.sql.Connection JavaDoc;
32 import java.sql.PreparedStatement JavaDoc;
33 import java.sql.ResultSet JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.util.Date JavaDoc;
36
37 import javax.sql.DataSource JavaDoc;
38
39 import org.jresearch.gossip.dao.drivers.DbDriver;
40
41 /**
42  * DOCUMENT ME!
43  *
44  * @author Bel
45  */

46 public abstract class DAO {
47     protected DataSource JavaDoc dataSource;
48
49     /**
50      * DOCUMENT ME!
51      *
52      * @return
53      */

54     public DataSource JavaDoc getDataSource() {
55         return dataSource;
56     }
57
58     /**
59      * DOCUMENT ME!
60      *
61      * @param source
62      */

63     public void setDataSource(DataSource JavaDoc source) {
64         if (this.dataSource == null) {
65             dataSource = source;
66         }
67     }
68
69     /**
70      * DOCUMENT ME!
71      *
72      * @return DOCUMENT ME!
73      *
74      * @throws SQLException
75      * DOCUMENT ME!
76      */

77     public Date JavaDoc now() throws SQLException JavaDoc {
78         Connection JavaDoc connection = this.dataSource.getConnection();
79         PreparedStatement JavaDoc st = connection.prepareStatement(DbDriver
80                 .getInstance().getQueries().getSql_NOW());
81         ResultSet JavaDoc rs = null;
82         Date JavaDoc now = null;
83
84         try {
85             rs = st.executeQuery();
86
87             if (rs.next()) {
88                 now = rs.getTimestamp(1);
89             }
90         } finally {
91             if (rs != null) {
92                 rs.close();
93             }
94
95             st.close();
96             connection.close();
97         }
98
99         return now;
100     }
101 }
102
Popular Tags