01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.identity.hibernate;
23:
24: import java.sql.*;
25:
26: import org.apache.commons.logging.*;
27: import org.hibernate.*;
28: import org.hibernate.cfg.*;
29: import org.jbpm.identity.*;
30:
31: public class IdentitySessionFactory {
32:
33: protected Configuration configuration = null;
34: protected SessionFactory sessionFactory = null;
35:
36: public IdentitySessionFactory() {
37: this (createConfiguration());
38: }
39:
40: public IdentitySessionFactory(Configuration configuration) {
41: this (configuration, configuration.buildSessionFactory());
42: }
43:
44: public IdentitySessionFactory(Configuration configuration,
45: SessionFactory sessionFactory) {
46: this .configuration = configuration;
47: this .sessionFactory = sessionFactory;
48: }
49:
50: public static Configuration createConfiguration() {
51: return createConfiguration(null);
52: }
53:
54: public static Configuration createConfiguration(String resource) {
55: Configuration configuration = null;
56: // create the hibernate configuration
57: configuration = new Configuration();
58:
59: if (resource != null) {
60: log.debug("using '" + resource
61: + "' as hibernate configuration for jbpm");
62: configuration.configure(resource);
63: } else {
64: log
65: .debug("using the default hibernate configuration file: hibernate.cfg.xml");
66: configuration.configure();
67: }
68: return configuration;
69: }
70:
71: public IdentitySession openIdentitySession() {
72: return new IdentitySession(sessionFactory.openSession());
73: }
74:
75: public IdentitySession openIdentitySession(Connection connection) {
76: return new IdentitySession(sessionFactory
77: .openSession(connection));
78: }
79:
80: public void evictCachedIdentities() {
81: sessionFactory.evict(User.class);
82: sessionFactory.evict(Membership.class);
83: sessionFactory.evict(Group.class);
84: }
85:
86: public Configuration getConfiguration() {
87: return configuration;
88: }
89:
90: public SessionFactory getSessionFactory() {
91: return sessionFactory;
92: }
93:
94: private static final Log log = LogFactory
95: .getLog(IdentitySessionFactory.class);
96: }
|