1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.objectledge.hibernate;
29
30 import java.net.MalformedURLException;
31
32 import org.hibernate.HibernateException;
33 import org.jcontainer.dna.ConfigurationException;
34 import org.jcontainer.dna.Logger;
35 import org.objectledge.filesystem.FileSystem;
36
37 /***
38 * The hibernate session factory component.
39 *
40 * <p>
41 * An example configuration follows:
42 * </p>
43 * <pre>
44 * <?xml version='1.0' encoding='utf-8'?>
45 * <!DOCTYPE hibernate-configuration PUBLIC
46 * "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
47 * "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
48 * <hibernate-configuration>
49 * <session-factory>
50 * <!-- Database connection settings -->
51 * <property name="connection.driver_class">org.postgresql.Driver</property>
52 * <property name="connection.url">jdbc:postgresql://localhost/test_db</property>
53 * <property name="connection.username">test</property>
54 * <property name="connection.password">test</property>
55 *
56 * <!-- JDBC connection pool (use the built-in) -->
57 * <property name="connection.pool_size">1</property>
58 *
59 * <!-- SQL dialect -->
60 * <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
61 *
62 * <!-- Echo all executed SQL to stdout -->
63 * <property name="show_sql">true</property>
64 *
65 * <property name="query.substitutions">true 1, false 0</property>
66 *
67 * <!-- Hibernate Security Service -->
68 * <mapping class="org.objectledge.security.hibernate.HibernatePermission"
69 * resource="org/objectledge/security/hibernate/HibernatePermission.hbm.xml"/>
70 * <mapping class="org.objectledge.security.hibernate.HibernateResourceGroup"
71 * resource="org/objectledge/security/hibernate/HibernateResourceGroup.hbm.xml"/>
72 * <mapping class="org.objectledge.security.hibernate.HibernateRole"
73 * resource="org/objectledge/security/hibernate/HibernateRole.hbm.xml"/>
74 * <mapping class="org.objectledge.security.hibernate.HibernateRolePermission"
75 * resource="org/objectledge/security/hibernate/HibernateRolePermission.hbm.xml"/>
76 * <mapping class="org.objectledge.security.hibernate.HibernateUser"
77 * resource="org/objectledge/security/hibernate/HibernateUser.hbm.xml"/>
78 * <mapping class="org.objectledge.security.hibernate.HibernateUserGroupRole"
79 * resource="org/objectledge/security/hibernate/HibernateUserGroupRole.hbm.xml"/>
80 * <mapping class="org.objectledge.security.hibernate.HibernateUserResourceGroupRo"
81 * resource="org/objectledge/security/hibernate/HibernateUserResourceGroupRo.hbm.xml"/>
82 * </session-factory>
83 * </hibernate-configuration>
84 *</pre>
85 * @author <a href="mailto:mgolebsk@elka.pw.edu.pl">Marcin Golebski</a>
86 * @version $Id: BasicHibernateSessionFactory.java,v 1.1 2006/01/17 13:40:27 zwierzem Exp $
87 */
88 public class BasicHibernateSessionFactory
89 extends AbstractHibernateSessionFactory
90 {
91 public BasicHibernateSessionFactory(Logger logger, final FileSystem fs,
92 InterceptorFactory interceptorFactory)
93 throws ConfigurationException
94 {
95 super(logger, fs, new HibernateConfigurator()
96 {
97 public void configure(org.hibernate.cfg.Configuration cfg) throws ConfigurationException
98 {
99 String xmlPath = "/config/org.objectledge.hibernate.HibernateSessionFactory.xml";
100 try
101 {
102 cfg.configure(fs.getResource(xmlPath));
103 }
104 catch(HibernateException e)
105 {
106 throw new ConfigurationException("cannot configure hibernate", e);
107 }
108 catch(MalformedURLException e)
109 {
110 throw new ConfigurationException("cannot access hibernate configuration file", e);
111 }
112 }
113 },
114 interceptorFactory);
115 }
116
117 public BasicHibernateSessionFactory(Logger logger, final FileSystem fs)
118 throws ConfigurationException
119 {
120 this(logger, fs, null);
121 }
122 }