KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > ejb > odmg > ODMGHelper


1 package org.apache.ojb.ejb.odmg;
2
3 import org.apache.ojb.odmg.OJB;
4 import org.odmg.Database;
5 import org.odmg.Implementation;
6 import org.odmg.ODMGException;
7
8 /* Copyright 2002-2005 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22
23 /**
24  * Helper class that provide access to the OJB main/access classes.
25  * Nevertheless it is recommended to bind OJB main classes to JNDI and to
26  * lookup the {@link org.odmg.Implementation} instance via JNDI.
27  *
28  * @author <a HREF="mailto:arminw@apache.org">Armin Waibel</a>
29  * @version $Id: ODMGHelper.java,v 1.1.2.2 2005/12/21 22:21:39 tomdz Exp $
30  */

31 public class ODMGHelper
32 {
33     public static final String JavaDoc DEF_DATABASE_NAME = "default";
34     private static Implementation odmg;
35     private static Database db;
36
37     static
38     {
39         odmg = OJB.getInstance();
40         db = odmg.newDatabase();
41         try
42         {
43             System.out.println("[ODMG] Open new database " + db + " using databaseName name " + DEF_DATABASE_NAME);
44             db.open(DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
45         }
46         catch (ODMGException e)
47         {
48             e.printStackTrace();
49         }
50     }
51
52     public static Implementation getODMG()
53     {
54         return odmg;
55     }
56
57     static Database getDatabase()
58     {
59         return db;
60     }
61 }
62
Popular Tags