KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > CastorDatabaseService


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.controllers.kernel.impl.simple;
25
26 import java.io.File JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.exolab.castor.jdo.Database;
31 import org.exolab.castor.jdo.JDO;
32 import org.exolab.castor.jdo.conf.JdoConf;
33 import org.exolab.castor.util.JdoConfFactory;
34 import org.infoglue.cms.exception.SystemException;
35 import org.infoglue.cms.util.CmsPropertyHandler;
36
37 public class CastorDatabaseService //extends DatabaseService
38
{
39     public final static Logger logger = Logger.getLogger(CastorDatabaseService.class.getName());
40
41     private static JDO jdo = null;
42     private static boolean block = false;
43     
44     public synchronized static JDO getJDO() throws SystemException
45     {
46         if(jdo != null)
47             return jdo;
48         
49         try
50         {
51             jdo = new JDO();
52             //jdo.setLogWriter(new Logger( System.out ).setPrefix( "INFOGLUE_CMS" ));
53
jdo.setDatabaseName("INFOGLUE_CMS");
54             
55             //DatabaseDefinitionsController.getController().getCastorDatabaseDefinitionFile("default");
56
//jdo.setConfiguration(CastorDatabaseService.class.getResource("/currentDatabase.xml").toString());
57
jdo.setConfiguration(CastorDatabaseService.class.getResource("/database.xml").toString());
58             jdo.setClassLoader(CastorDatabaseService.class.getClassLoader());
59             jdo.setCallbackInterceptor(new CmsJDOCallback());
60         }
61         catch(Exception JavaDoc e)
62         {
63             throw new SystemException("An error occurred while trying to get a JDO object. Castor message:" + e, e);
64         }
65         
66         return jdo;
67     }
68     
69     public synchronized static Database getDatabase() throws SystemException
70     {
71         try
72         {
73             //if(block)
74
// throw new SystemException("The database was blocked for recache - try again in 1 second..");
75

76             /*
77             while(block)
78             {
79                 logger.info("Waiting on block on database to release....");
80                 Thread.sleep(5);
81             }
82             */

83             logger.info("Getting new databaseobject....");
84             //try {throw new Exception("SHIT....");} catch(Exception e){e.printStackTrace();}
85
return getJDO().getDatabase();
86         }
87         catch(Exception JavaDoc e)
88         {
89             throw new SystemException("An error occurred while trying to get a Database object. Castor message:" + e, e);
90         }
91     }
92     
93     public static synchronized void setBlock(boolean block)
94     {
95         CastorDatabaseService.block = block;
96     }
97 }
Popular Tags