1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.io.File ; 27 import java.util.Map ; 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 { 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.setDatabaseName("INFOGLUE_CMS"); 54 55 jdo.setConfiguration(CastorDatabaseService.class.getResource("/database.xml").toString()); 58 jdo.setClassLoader(CastorDatabaseService.class.getClassLoader()); 59 jdo.setCallbackInterceptor(new CmsJDOCallback()); 60 } 61 catch(Exception 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 76 83 logger.info("Getting new databaseobject...."); 84 return getJDO().getDatabase(); 86 } 87 catch(Exception 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 |