Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java @ 4400:e4985122e76c
conf.xml: Register the extreme_curve_export generator, a WaterlevelExporter.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 05 Nov 2012 12:25:39 +0100 |
parents | 69f06b83b3ec |
children | fb9dcc68b9c2 |
rev | line source |
---|---|
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.backend; |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
3 import java.lang.management.ManagementFactory; |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.Properties; |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
7 import javax.management.InstanceAlreadyExistsException; |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
8 import javax.management.MBeanRegistrationException; |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
9 import javax.management.MBeanServer; |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
10 import javax.management.MalformedObjectNameException; |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
11 import javax.management.NotCompliantMBeanException; |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
12 import javax.management.ObjectName; |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
13 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
14 import org.apache.log4j.Logger; |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
15 |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.hibernate.SessionFactory; |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
18 import org.hibernate.cfg.Configuration; |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
19 import org.hibernate.cfg.Environment; |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
20 |
2361
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
21 import org.hibernate.impl.SessionFactoryImpl; |
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
22 |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
23 import org.hibernate.jmx.StatisticsService; |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
24 |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 public final class SessionFactoryProvider |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 { |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 private static Logger log = Logger.getLogger(SessionFactoryProvider.class); |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
29 public static final boolean ENABLE_JMX = |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
30 Boolean.getBoolean("flys.backend.enablejmx"); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
31 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
32 private static SessionFactory flysSessionFactory; |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
33 private static SessionFactory sedDBSessionFactory; |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 private SessionFactoryProvider() { |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public static synchronized SessionFactory getSessionFactory() { |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
39 if (flysSessionFactory == null) { |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
40 flysSessionFactory = |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
41 createSessionFactory(FLYSCredentials.getInstance()); |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
43 return flysSessionFactory; |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
179
aaac9c291067
Default connection parameters are now overwritable with system properties.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
46 public static SessionFactory createSessionFactory() { |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
47 return createSessionFactory(FLYSCredentials.getDefault()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
48 } |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
49 |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
50 public static synchronized SessionFactory getSedDBSessionFactory() { |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
51 if (sedDBSessionFactory == null) { |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
52 sedDBSessionFactory = |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
53 createSessionFactory(SedDBCredentials.getInstance()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
54 } |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
55 return sedDBSessionFactory; |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
56 } |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
57 |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
58 public static SessionFactory createSedDBSessionFactory() { |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
59 return createSessionFactory(SedDBCredentials.getDefault()); |
179
aaac9c291067
Default connection parameters are now overwritable with system properties.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
60 } |
aaac9c291067
Default connection parameters are now overwritable with system properties.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
61 |
178
82bc55666a97
Expose the creation of the SessionFactory to the public to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
62 public static SessionFactory createSessionFactory( |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
63 Credentials credentials |
178
82bc55666a97
Expose the creation of the SessionFactory to the public to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
64 ) { |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
65 Configuration cfg = createConfiguration(credentials); |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
66 |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
67 SessionFactory factory = cfg.buildSessionFactory(); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
68 |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
69 if (ENABLE_JMX) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
70 registerAsMBean(factory); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
71 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
72 else { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
73 log.info("No JMX support for hibernate."); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
74 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
75 |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
76 return factory; |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
77 } |
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
78 |
2337
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
79 public static void registerAsMBean(SessionFactory factory) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
80 |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
81 StatisticsService statsMBean = new StatisticsService(); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
82 statsMBean.setSessionFactory(factory); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
83 statsMBean.setStatisticsEnabled(true); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
84 |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
85 try { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
86 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
87 mbs.registerMBean( |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
88 statsMBean, |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
89 new ObjectName("Hibernate:application=Statistics")); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
90 |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
91 log.info("Enabled JMX support for hibernate."); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
92 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
93 catch (MalformedObjectNameException mone) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
94 log.warn(mone, mone); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
95 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
96 catch (InstanceAlreadyExistsException iaee) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
97 log.warn(iaee, iaee); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
98 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
99 catch (MBeanRegistrationException mbre) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
100 log.warn(mbre, mbre); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
101 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
102 catch (NotCompliantMBeanException ncmbe) { |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
103 log.warn(ncmbe, ncmbe); |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
104 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
105 } |
52d712cd2384
Added code and a system property 'flys.backend.enablejmx=true' to enable JMX support for hibernate.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1237
diff
changeset
|
106 |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
107 public static Configuration createConfiguration() { |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
108 return createConfiguration(FLYSCredentials.getInstance()); |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
109 } |
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
110 |
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
111 public static Configuration createConfiguration( |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
112 Credentials credentials |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
113 ) { |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 Configuration cfg = new Configuration(); |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
116 for (Class clazz: credentials.getClasses()) { |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
117 cfg.addAnnotatedClass(clazz); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
118 } |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 if (log.isDebugEnabled()) { |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
121 log.debug("user: " + credentials.getUser()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
122 log.debug("dialect: " + credentials.getDialect()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
123 log.debug("driver: " + credentials.getDriver()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
124 log.debug("url: " + credentials.getUrl()); |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 Properties props = new Properties(); |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 // We rely on our own connection pool |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 props.setProperty( |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 "hibernate.connection.provider_class", |
3337
69f06b83b3ec
Set correct connection provider class which package had changed in the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3333
diff
changeset
|
132 "de.intevation.flys.utils.DBCPConnectionProvider"); |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
3333
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
134 props.setProperty(Environment.DIALECT, credentials.getDialect()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
135 props.setProperty(Environment.USER, credentials.getUser()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
136 props.setProperty(Environment.PASS, credentials.getPassword()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
137 props.setProperty(Environment.DRIVER, credentials.getDriver()); |
76c75c8b9ee0
SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
138 props.setProperty(Environment.URL, credentials.getUrl()); |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 cfg.mergeProperties(props); |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
1229
8b12b338a3f6
Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1210
diff
changeset
|
142 return cfg; |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
2361
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
144 |
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
145 |
2362
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
146 public static String getProperty(SessionFactoryImpl factory, String key) { |
2361
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
147 Properties props = factory.getProperties(); |
2362
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
148 return props.getProperty(key); |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
149 } |
2361
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
150 |
2362
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
151 public static String getUser(SessionFactoryImpl factory) { |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
152 return getProperty(factory, Environment.USER); |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
153 } |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
154 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
155 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
156 public static String getPass(SessionFactoryImpl factory) { |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
157 return getProperty(factory, Environment.PASS); |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
158 } |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
159 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
160 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
161 public static String getURL(SessionFactoryImpl factory) { |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
162 return getProperty(factory, Environment.URL); |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
163 } |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
164 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
165 |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
166 public static String getDriver(SessionFactoryImpl factory) { |
2649151c9500
Added some functions that return information about the db connection used by the current database session.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2361
diff
changeset
|
167 return getProperty(factory, Environment.DRIVER); |
2361
e9b0fd1de89d
Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2360
diff
changeset
|
168 } |
176
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
3035d861a576
SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |