1 9 package org.jboss.portal.setup.impl.sl.dbloader.hibernate; 10 11 import org.jboss.portal.setup.sl.SchemaLoader; 12 import org.jboss.portal.setup.sl.SchemaLoaderConfig; 13 import org.jboss.portal.setup.sl.HibernateSchemaLoaderConfig; 14 import org.jboss.portal.setup.PortalSetupException; 15 import org.jboss.portal.setup.pm.PersistenceSession; 16 import org.jboss.portal.setup.impl.pm.HibernatePersistenceManager; 17 18 import org.apache.log4j.Logger; 19 20 21 22 28 public class HibernateSchemaLoader implements SchemaLoader 29 { 30 31 private final Logger m_log = Logger.getLogger(getClass()); 32 private HibernateSchemaLoaderConfig m_config = null; 33 private HibernatePersistenceManager m_pm = new HibernatePersistenceManager(); 34 35 38 public void setSchemaLoaderConfig(SchemaLoaderConfig config) throws PortalSetupException 39 { 40 if (m_log.isDebugEnabled()) 41 { 42 m_log.debug("Entering SchemaLoader#setSchemaLoaderConfig()"); 43 } 44 if (config != null && config.getConfiguration() instanceof HibernateSchemaLoaderConfig) 45 { 46 m_config = (HibernateSchemaLoaderConfig)config.getConfiguration(); 47 setUpHibernate(); 48 } 49 if (m_log.isDebugEnabled()) 50 { 51 m_log.debug("Exiting SchemaLoader#setSchemaLoaderConfig()"); 52 } 53 } 54 55 58 public SchemaLoaderConfig getSchemaLoaderConfig() 59 { 60 return m_config; 61 } 62 63 66 public boolean loadSchema() throws PortalSetupException 67 { 68 return m_pm.loadPersistenceSchema(); 69 70 } 71 72 75 public boolean isSchemaExists() throws PortalSetupException 76 { 77 boolean result = false; 78 String checkSchemaSql = m_config.getSchemaQueryString(); 79 PersistenceSession session = null; 80 try 81 { 82 session = m_pm.getSession(); 83 result = session.validate(checkSchemaSql, false); 84 } 85 finally 86 { 87 session.close(); 88 } 89 return result; 90 91 } 92 93 96 public boolean destroySchema() throws PortalSetupException 97 { 98 return m_pm.destroyPersistenceSchema(); 99 } 100 101 106 public void destroy() throws PortalSetupException 107 { 108 if (null != m_pm) 109 { 110 m_pm.destroy(); 111 m_pm = null; 112 } 113 } 114 115 116 private void setUpHibernate() throws PortalSetupException 117 { 118 119 m_pm.initialize(m_config.getHibernateConfig(), m_config.getSchemaLoadURIs()); 120 121 122 } 123 124 125 } 126 | Popular Tags |