annotate backend/src/main/java/org/dive4elements/river/backend/SessionFactoryProvider.java @ 5844:4dd33b86dc61

Added header to river backend.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 26 Apr 2013 08:25:41 +0200
parents 5aa05a7a34b7
children 4c3ccf2b0304
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.backend;
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.util.Properties;
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
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
13 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
14
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import org.hibernate.SessionFactory;
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
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
17 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
18 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
19
2361
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
20 import org.hibernate.impl.SessionFactoryImpl;
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
21
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public final class SessionFactoryProvider
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 {
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 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
25
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
26 //public static final boolean ENABLE_JMX =
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
27 // Boolean.getBoolean("flys.backend.enablejmx");
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
28
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
29 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
30 private static SessionFactory sedDBSessionFactory;
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 private SessionFactoryProvider() {
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
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 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
36 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
37 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
38 createSessionFactory(FLYSCredentials.getInstance());
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
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
40 return flysSessionFactory;
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
179
aaac9c291067 Default connection parameters are now overwritable with system properties.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 178
diff changeset
43 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
44 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
45 }
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
46
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 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
48 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
49 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
50 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
51 }
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 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
53 }
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 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
56 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
57 }
aaac9c291067 Default connection parameters are now overwritable with system properties.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 178
diff changeset
58
178
82bc55666a97 Expose the creation of the SessionFactory to the public to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 176
diff changeset
59 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
60 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
61 ) {
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
62 Configuration cfg = createConfiguration(credentials);
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
63
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
64 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
65
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
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 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
68 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
69 }
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 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
71 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
72 }
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
73 */
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
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 return factory;
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
76 }
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
77
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
78 /** XXX: Commented out till it is configured correctly.
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
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
81 //
5557
fd7285e3829b FLYS backend: Commented out the Hibernate Management Bean statistic because they are not configured corrctly.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5193
diff changeset
82
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
83 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
84 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
85 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
86
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 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
88 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
89 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
90 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
91 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
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 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
94 }
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 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
96 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
97 }
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 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
99 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
100 }
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 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
102 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
103 }
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 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
105 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
106 }
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
107 }
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
108 */
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
109
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
110 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
111 return createConfiguration(FLYSCredentials.getInstance());
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
112 }
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
113
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
114 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
115 Credentials credentials
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
116 ) {
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 Configuration cfg = new Configuration();
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118
5564
a2da78fdbec0 Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5557
diff changeset
119 for (Class<?> clazz: credentials.getClasses()) {
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
120 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
121 }
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 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
124 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
125 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
126 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
127 log.debug("url: " + credentials.getUrl());
176
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
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 Properties props = new Properties();
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 // We rely on our own connection pool
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 props.setProperty(
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 "hibernate.connection.provider_class",
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
135 "org.dive4elements.river.utils.DBCPConnectionProvider");
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136
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
137 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
138 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
139 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
140 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
141 props.setProperty(Environment.URL, credentials.getUrl());
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142
5193
fb9dcc68b9c2 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3337
diff changeset
143 String connectionInitSqls = credentials.getConnectionInitSqls();
fb9dcc68b9c2 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3337
diff changeset
144 if (connectionInitSqls != null) {
fb9dcc68b9c2 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3337
diff changeset
145 props.setProperty("connectionInitSqls", connectionInitSqls);
fb9dcc68b9c2 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3337
diff changeset
146 }
fb9dcc68b9c2 Possible fix for flys/1202. Initial SQL statements can now be issued at connection creation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3337
diff changeset
147
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 cfg.mergeProperties(props);
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149
1229
8b12b338a3f6 Re-enabled Hibernate schema dumps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1210
diff changeset
150 return cfg;
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 }
2361
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
152
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
153
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
154 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
155 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
156 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
157 }
2361
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
158
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
159 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
160 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
161 }
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
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 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
165 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
166 }
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
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
168
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
169 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
170 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
171 }
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
172
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
173
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
174 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
175 return getProperty(factory, Environment.DRIVER);
2361
e9b0fd1de89d Made flys-backend compatible with oracle spatial.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2360
diff changeset
176 }
176
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 }
3035d861a576 SessionFactoryProvider for access to the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org