KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > dao > drivers > DbDriver


1 /*
2  * $Id: DbDriver.java,v 1.4 2005/06/14 09:35:44 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;
26
27 import java.util.ResourceBundle JavaDoc;
28
29 /**
30  * DbDriver
31  *
32  * @author <a HREF="alexnet@sourceforge.net">A. Pavlov</a>
33  * @version $version$ 21.03.2004
34  */

35 public abstract class DbDriver {
36
37     static {
38         String JavaDoc dataBaseVendor = null;
39         try {
40             ResourceBundle JavaDoc dbconf = ResourceBundle
41                     .getBundle("org/jresearch/gossip/resources/db");
42             dataBaseVendor = dbconf.getString("dataBaseVendor");
43             Class JavaDoc clazz = DbDriverRegistry.getInstance().getDriverClass(
44                     dataBaseVendor);
45             if (null == clazz)
46                 throw new RuntimeException JavaDoc("Database driver [" + dataBaseVendor
47                         + "] not supported.");
48             DbDriver.instance = (DbDriver) clazz.newInstance();
49         } catch (InstantiationException JavaDoc e) {
50             e.printStackTrace(System.err);
51             throw new RuntimeException JavaDoc("Database driver [" + dataBaseVendor
52                     + "] can not be initialized.");
53         } catch (IllegalAccessException JavaDoc e) {
54             e.printStackTrace(System.err);
55             throw new RuntimeException JavaDoc("Database driver [" + dataBaseVendor
56                     + "] can not be initialized.");
57         }
58     }
59
60     private static DbDriver instance;
61
62     public static DbDriver getInstance() {
63         return instance;
64     }
65
66     protected Queries queries;
67
68     /**
69      * @return
70      */

71     public Queries getQueries() {
72         return this.queries;
73     }
74
75     /**
76      * Map data type of object from resultset to internal type. Database data
77      * type NUMBER mapped to java.math.BigDecimal according to JDBCv2. This is
78      * not a case for MySql.
79      *
80      * @param object
81      * Object from resultset.
82      * @return Boject of mapped data type
83      * @throws ClassCastException
84      */

85     public abstract Object JavaDoc mapObjectType(Object JavaDoc object)
86             throws ClassCastException JavaDoc;
87
88     /**
89      * Generic: Create value of last row number for expression BETWEEN
90      * ROW_IDX_START AND (ROW_IDX_START+LENGTH AS ROW_IDX_END). MySQL: Returns
91      * length for expression LIMIT ROW_IDX_START, LENGTH MSSQL: Returns length.
92      *
93      * @param startIdx
94      * @param length
95      * @return
96      */

97     public abstract int getLastRowIdx(int startIdx, int length);
98
99 }
100
Popular Tags