1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.web.config;
24
25 import java.net.URL;
26 import java.util.Map;
27 import java.util.TreeMap;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.hibernate.SessionFactory;
31 import org.hibernate.cfg.Configuration;
32 import net.smartlab.web.BusinessObjectFactory;
33 import net.smartlab.web.Domain;
34
35
36
37
38
39
40
41
42
43 public class TomcatConfigurationStrategy implements FactoryConfigurationStrategy {
44
45
46
47
48 private Map factories = new TreeMap();
49
50
51
52
53 protected final Log logger = LogFactory.getLog(TomcatConfigurationStrategy.class);
54
55
56
57
58
59 public SessionFactory getSessionFactory(BusinessObjectFactory bof) {
60 synchronized (BusinessObjectFactory.class) {
61 String archive = Domain.getLastArchiveName(bof.getClass());
62 URL file = Domain.getResource(bof.getClass(), new String[] {"/META-INF/" + archive + ".hcf",
63 "/META-INF/smartweb.jar.hcf", "/META-INF/hibernate.conf.xml"});
64 try {
65 if (!factories.containsKey(file.toString())) {
66
67 logger.warn("getSessionFactory() - configure hibernate without JNDI");
68 SessionFactory factory = new Configuration().configure(file).buildSessionFactory();
69 factories.put(file.toString(), factory);
70 }
71 return (SessionFactory)factories.get(file.toString());
72 } catch (Exception e) {
73 logger.error("getSessionFactory() - error", e);
74 return null;
75 }
76 }
77 }
78 }