KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > identity > hibernate > IdentitySessionFactory


1 package org.jbpm.identity.hibernate;
2
3 import java.sql.*;
4
5 import org.apache.commons.logging.*;
6 import org.hibernate.*;
7 import org.hibernate.cfg.*;
8 import org.jbpm.identity.*;
9
10 public class IdentitySessionFactory {
11   
12   protected Configuration configuration = null;
13   protected SessionFactory sessionFactory = null;
14   
15   public IdentitySessionFactory() {
16     this(createConfiguration());
17   }
18
19   public IdentitySessionFactory(Configuration configuration) {
20     this(configuration, configuration.buildSessionFactory());
21   }
22
23   public IdentitySessionFactory(Configuration configuration, SessionFactory sessionFactory) {
24     this.configuration = configuration;
25     this.sessionFactory = sessionFactory;
26   }
27
28   public static Configuration createConfiguration() {
29     return createConfiguration(null);
30   }
31
32   public static Configuration createConfiguration(String JavaDoc resource) {
33     Configuration configuration = null;
34     // create the hibernate configuration
35
configuration = new Configuration();
36     
37     if (resource!=null) {
38       log.debug("using '"+resource+"' as hibernate configuration for jbpm");
39       configuration.configure(resource);
40     } else {
41       log.debug("using the default hibernate configuration file: hibernate.cfg.xml");
42       configuration.configure();
43     }
44     return configuration;
45   }
46
47   public IdentitySession openIdentitySession() {
48     return new IdentitySession(sessionFactory.openSession());
49   }
50
51   public IdentitySession openIdentitySession(Connection connection) {
52     return new IdentitySession(sessionFactory.openSession(connection));
53   }
54
55   public void evictCachedIdentities() {
56     sessionFactory.evict(User.class);
57     sessionFactory.evict(Membership.class);
58     sessionFactory.evict(Group.class);
59   }
60
61   public Configuration getConfiguration() {
62     return configuration;
63   }
64   public SessionFactory getSessionFactory() {
65     return sessionFactory;
66   }
67
68   private static final Log log = LogFactory.getLog(IdentitySessionFactory.class);
69 }
70
Popular Tags