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 javax.naming.InitialContext; |
27 |
|
import javax.naming.NamingException; |
28 |
|
import javax.rmi.PortableRemoteObject; |
29 |
|
import org.apache.commons.logging.Log; |
30 |
|
import org.apache.commons.logging.LogFactory; |
31 |
|
import org.hibernate.SessionFactory; |
32 |
|
import org.hibernate.cfg.Configuration; |
33 |
|
import net.smartlab.config.Element; |
34 |
|
import net.smartlab.config.XMLConfiguration; |
35 |
|
import net.smartlab.web.BusinessObjectFactory; |
36 |
|
import net.smartlab.web.Domain; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@author |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0,3 |
|
46 |
|
public class JNDIConfigurationStrategy implements FactoryConfigurationStrategy { |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
protected final Log logger = LogFactory.getLog(JNDIConfigurationStrategy.class); |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@see |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0,3 |
|
57 |
0
|
public SessionFactory getSessionFactory(BusinessObjectFactory factory) {... |
58 |
0
|
synchronized (BusinessObjectFactory.class) { |
59 |
0
|
String archive = Domain.getLastArchiveName(factory.getClass()); |
60 |
0
|
URL file = Domain.getResource(factory.getClass(), new String[] {"/META-INF/" + archive + ".hcf", |
61 |
|
"/META-INF/smartweb.jar.hcf"}); |
62 |
0
|
try { |
63 |
0
|
XMLConfiguration config = new XMLConfiguration(file); |
64 |
0
|
Element sessionFactory = config.getElement("session-factory"); |
65 |
0
|
String jndi = sessionFactory.getAttribute("name"); |
66 |
0
|
try { |
67 |
0
|
return (SessionFactory)PortableRemoteObject.narrow(new InitialContext().lookup(jndi), |
68 |
|
SessionFactory.class); |
69 |
|
} catch (NamingException ne) { |
70 |
|
logger.info("getSessionFactory() - configure hibernate"); |
71 |
|
try { |
72 |
|
|
73 |
|
Configuration hibernate = new Configuration().configure(file); |
74 |
|
hibernate.buildSessionFactory(); |
75 |
|
return (SessionFactory)PortableRemoteObject.narrow(new InitialContext().lookup(jndi), |
76 |
|
SessionFactory.class); |
77 |
|
} catch (Exception e) { |
78 |
|
logger.error("getSessionFactory() - error", e); |
79 |
|
} |
80 |
|
} |
81 |
|
} catch (Exception e) { |
82 |
|
logger.error("getSessionFactory() - error", e); |
83 |
|
} |
84 |
0
|
return null; |
85 |
|
} |
86 |
|
} |
87 |
|
} |