KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > dao > drivers > generic > GenericSqlDriver


1 /*
2  * $Id: GenericSqlDriver.java,v 1.4 2005/06/14 09:35:47 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  * Alexey Pavlov <alexnet@users.sourceforge.net>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 package org.jresearch.gossip.dao.drivers.generic;
26
27 import java.math.BigDecimal JavaDoc;
28 import java.sql.SQLException JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import org.jresearch.gossip.dao.drivers.DbDriver;
32
33 /**
34  * Generic SQL Driver
35  *
36  * @author <a HREF="alexnet@sourceforge.net">A. Pavlov</a>
37  * @version $version$ 21.03.2004
38  */

39 public class GenericSqlDriver extends DbDriver {
40
41     /**
42      * Create instance of dictionary of Generic SQL statetements.
43      */

44     public GenericSqlDriver() {
45         this.queries = new GenericSqlQueries();
46     }
47
48     /**
49      * @see org.jresearch.gossip.dao.drivers.DbDriver#mapObjectType(java.lang.Object)
50      */

51     public Object JavaDoc mapObjectType(Object JavaDoc object) throws ClassCastException JavaDoc {
52         if (null == object)
53             return null;
54         // remap BigDecimal type to Integer.
55
if (object instanceof BigDecimal JavaDoc) {
56             return new Integer JavaDoc(((BigDecimal JavaDoc) object).intValue());
57         }
58         if (object instanceof oracle.sql.TIMESTAMP) {
59             try {
60                 return new Date JavaDoc(((oracle.sql.TIMESTAMP) object)
61                         .timestampValue().getTime());
62             } catch (SQLException JavaDoc sqle) {
63                 throw new ClassCastException JavaDoc(
64                         "Can't convert oracle.sql.TIMESTAMP to java.util.Date"
65                                 + sqle.getLocalizedMessage());
66             }
67         }
68         // rest of datatypes.
69
return object;
70     }
71
72     public static final String JavaDoc VENDOR_ORACLE = "oracle";
73
74     /**
75      * Create value of last row for expression BETWEEN ROW_IDX_START AND
76      * ROW_IDX_END.
77      *
78      * @see org.jresearch.gossip.dao.drivers.DbDriver#getLastRowIdx(int, int)
79      */

80     public int getLastRowIdx(int startIdx, int length) {
81         return startIdx + length;
82     }
83 }
84
Popular Tags