|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| BasicHibernateSessionFactory.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 | // | |
| 2 | // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. | |
| 3 | // All rights reserved. | |
| 4 | // | |
| 5 | // Redistribution and use in source and binary forms, with or without modification, | |
| 6 | // are permitted provided that the following conditions are met: | |
| 7 | // | |
| 8 | // * Redistributions of source code must retain the above copyright notice, | |
| 9 | // this list of conditions and the following disclaimer. | |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, | |
| 11 | // this list of conditions and the following disclaimer in the documentation | |
| 12 | // and/or other materials provided with the distribution. | |
| 13 | // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. | |
| 14 | // nor the names of its contributors may be used to endorse or promote products | |
| 15 | // derived from this software without specific prior written permission. | |
| 16 | // | |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
| 20 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 21 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 22 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 23 | // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 24 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | // POSSIBILITY OF SUCH DAMAGE. | |
| 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 | 0 | public BasicHibernateSessionFactory(Logger logger, final FileSystem fs, |
| 92 | InterceptorFactory interceptorFactory) | |
| 93 | throws ConfigurationException | |
| 94 | { | |
| 95 | 0 | super(logger, fs, new HibernateConfigurator() |
| 96 | { | |
| 97 | 0 | public void configure(org.hibernate.cfg.Configuration cfg) throws ConfigurationException |
| 98 | { | |
| 99 | 0 | String xmlPath = "/config/org.objectledge.hibernate.HibernateSessionFactory.xml"; |
| 100 | 0 | try |
| 101 | { | |
| 102 | 0 | cfg.configure(fs.getResource(xmlPath)); |
| 103 | } | |
| 104 | catch(HibernateException e) | |
| 105 | { | |
| 106 | 0 | throw new ConfigurationException("cannot configure hibernate", e); |
| 107 | } | |
| 108 | catch(MalformedURLException e) | |
| 109 | { | |
| 110 | 0 | throw new ConfigurationException("cannot access hibernate configuration file", e); |
| 111 | } | |
| 112 | } | |
| 113 | }, | |
| 114 | interceptorFactory); | |
| 115 | } | |
| 116 | ||
| 117 | 0 | public BasicHibernateSessionFactory(Logger logger, final FileSystem fs) |
| 118 | throws ConfigurationException | |
| 119 | { | |
| 120 | 0 | this(logger, fs, null); |
| 121 | } | |
| 122 | } |
|
||||||||||