KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > db > Database


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.db;
15
16 /**
17  * General Database Constants and Utilities
18  *
19  * @author Jorg Janke
20  * @version $Id: Database.java,v 1.9 2003/09/27 01:22:18 jjanke Exp $
21  */

22 public class Database
23 {
24     /** Oracle ID */
25     public static String JavaDoc DB_ORACLE = "Oracle";
26     /** PostgreSQL ID */
27     public static String JavaDoc DB_POSTGRESQL = "PostgreSQL";
28
29     /** Supported Databases */
30     public static String JavaDoc[] DB_NAMES = new String JavaDoc[] {
31         DB_ORACLE
32     // ,DB_POSTGRESQL
33
};
34
35     /** Database Classes */
36     protected static Class JavaDoc[] DB_CLASSES = new Class JavaDoc[] {
37         DB_Oracle.class
38     // ,DB_PostgreSQL.class
39
};
40
41     /** Connection Timeout in seconds */
42     public static int CONNECTION_TIMEOUT = 10;
43
44     /*************************************************************************/
45
46     /** The active Database */
47     private static CompiereDatabase s_db = null;
48
49     /**
50      * Set Database
51      * @param databaseName database name e.g. DB_ORACLE
52      * @throws Exception if databaseName is invalid or database calss cannot be instanciated
53      */

54     public static void setDatabase (String JavaDoc databaseName) throws Exception JavaDoc
55     {
56         for (int i = 0; i < DB_NAMES.length; i++)
57         {
58             if (DB_NAMES[i].equals(databaseName))
59             {
60                 s_db = (CompiereDatabase)DB_CLASSES[i].newInstance();
61                 return;
62             }
63         }
64         throw new IllegalArgumentException JavaDoc ("Database.setDatabase - Database invalid: " + databaseName);
65     } // setDatabase
66

67     /**
68      * Set Database
69      * @param database CompiereDatabase instance
70      * @throws Exception if databaseName is invalid or database calss cannot be instanciated
71      */

72     public static void setDatabase (CompiereDatabase database) throws Exception JavaDoc
73     {
74         if (database == null)
75             throw new IllegalArgumentException JavaDoc ("Database.setDatabase - Database is NULL");
76         s_db = database;
77     } // setDatabase
78

79     /**
80      * Get Database
81      * @return database
82      */

83     public static CompiereDatabase getDatabase()
84     {
85         return s_db;
86     } // getDatabase
87

88 } // Database
89
Popular Tags