KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > setup > impl > sl > dbloader > hibernate > HibernateSchemaLoader


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

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 /**
23  * @author <a HREF="mailto:palber@novell.com">Polina Alber</a>
24  * Date: Apr 13, 2005; Time: 12:54:05 AM
25  * @since JBoss portal 2.0
26  * Class org.jboss.portal.setup.impl.sl.dbloader.hibernate.HibernateSchemaLoader
27  */

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    /**
36     * @see SchemaLoader#setSchemaLoaderConfig(org.jboss.portal.setup.sl.SchemaLoaderConfig)
37     */

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    /**
56     * @see org.jboss.portal.setup.sl.SchemaLoader#getSchemaLoaderConfig()
57     */

58    public SchemaLoaderConfig getSchemaLoaderConfig()
59    {
60       return m_config;
61    }
62
63    /**
64     * @see org.jboss.portal.setup.sl.SchemaLoader#loadSchema()
65     */

66    public boolean loadSchema() throws PortalSetupException
67    {
68       return m_pm.loadPersistenceSchema();
69
70    }
71
72    /**
73     * @see org.jboss.portal.setup.sl.SchemaLoader#isSchemaExists()
74     */

75    public boolean isSchemaExists() throws PortalSetupException
76    {
77       boolean result = false;
78       String JavaDoc 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    /**
94     * @see org.jboss.portal.setup.sl.SchemaLoader#destroySchema()
95     */

96    public boolean destroySchema() throws PortalSetupException
97    {
98       return m_pm.destroyPersistenceSchema();
99    }
100
101    /**
102     * destroy SchemaLoader and cleans all resources
103     *
104     * @throws PortalSetupException
105     */

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