src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt

Mon, 05 Aug 2024 19:38:47 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 05 Aug 2024 19:38:47 +0200
changeset 313
7cfe88b8e219
parent 310
bbf4eb9a71f8
permissions
-rw-r--r--

fix removing filter not working

fixes #407

151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
180
009700915269 merge resource bundles
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
2 * Copyright 2021 Mike Becker. All rights reserved.
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 * modification, are permitted provided that the following conditions are met:
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * 1. Redistributions of source code must retain the above copyright
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 * notice, this list of conditions and the following disclaimer.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 */
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 package de.uapcore.lightpit
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27
254
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
28 import jakarta.servlet.ServletContextEvent
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
29 import jakarta.servlet.ServletContextListener
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
30 import jakarta.servlet.annotation.WebListener
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 import java.sql.SQLException
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 import javax.naming.Context
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 import javax.naming.InitialContext
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import javax.naming.NamingException
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 import javax.sql.DataSource
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 * Provides access to the database.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 */
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 @WebListener
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
41 class DataSourceProvider : ServletContextListener {
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
42
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
43 private val logger = MyLogger()
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
45 enum class Dialect {
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
46 Postgres
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
47 }
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
48
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 * The database dialect to use.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 * May be overridden by context parameter.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 * @see Constants.CTX_ATTR_DB_DIALECT
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 */
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
55 var dialect = Dialect.Postgres; private set
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 * The data source, if available.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 */
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 var dataSource: DataSource? = null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 companion object {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 * The attribute name in the Servlet context under which an instance of this class can be found.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 */
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 180
diff changeset
66 const val SC_ATTR_NAME = "lightpit.service.DataSourceProvider"
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 * Timeout in seconds for the validation test.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 */
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 180
diff changeset
71 private const val DB_TEST_TIMEOUT = 10
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 * The default schema to test against when validating the connection.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 * May be overridden by context parameter.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 * @see Constants.CTX_ATTR_DB_SCHEMA
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 */
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 180
diff changeset
79 private const val DB_DEFAULT_SCHEMA = "lightpit"
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 * The JNDI resource name for the data source.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 */
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 180
diff changeset
84 private const val DS_JNDI_NAME = "jdbc/lightpit/app"
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 private fun checkConnection(ds: DataSource, testSchema: String) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 try {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 ds.connection.use { conn ->
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 if (!conn.isValid(DB_TEST_TIMEOUT)) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 throw SQLException("Validation check failed.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 if (conn.isReadOnly) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 throw SQLException("Connection is read-only and thus unusable.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 if (conn.schema != testSchema) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 throw SQLException(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 String.format(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 "Connection is not configured to use the schema %s.",
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 testSchema
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 val metaData = conn.metaData
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
105 logger.info(
310
bbf4eb9a71f8 fix regression after log string format change
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
106 "Connections as {0} to {1}/{2} ready to go.",
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 metaData.userName,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 metaData.url,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 conn.schema
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 } catch (ex: SQLException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
113 logger.error("Checking database connection failed", ex)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 private fun retrieveDataSource(ctx: Context): DataSource? {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 return try {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 val ret = ctx.lookup(DS_JNDI_NAME) as DataSource
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
120 logger.info("Data source retrieved.")
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 ret
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 } catch (ex: NamingException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
123 logger.error("Data source {0} not available.", DS_JNDI_NAME)
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
124 logger.error("Reason for the missing data source: ", ex)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 override fun contextInitialized(sce: ServletContextEvent?) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 val sc = sce!!.servletContext
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 val dbSchema = sc.getInitParameter(Constants.CTX_ATTR_DB_SCHEMA) ?: DB_DEFAULT_SCHEMA
167
3f30adba1c63 major refactoring of DAO architecture - also fixes #114
Mike Becker <universe@uap-core.de>
parents: 158
diff changeset
133 sc.getInitParameter(Constants.CTX_ATTR_DB_DIALECT)?.let { dbDialect ->
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 try {
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
135 dialect = Dialect.valueOf(dbDialect)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 } catch (ex: IllegalArgumentException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
137 logger.error(
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
138 "Unknown or unsupported database dialect {0}. Defaulting to {1}.",
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 dbDialect,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 dialect
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 dataSource = try {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
146 logger.debug("Trying to access JNDI context ...")
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 val initialCtx: Context = InitialContext()
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 val ctx = initialCtx.lookup("java:comp/env") as Context
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 retrieveDataSource(ctx)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 } catch (ex: NamingException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
151 logger.error("Cannot access JNDI resources.", ex)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 } catch (ex: ClassCastException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
154 logger.error("Cannot access JNDI resources.", ex)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 dataSource?.let { checkConnection(it, dbSchema) }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 sc.setAttribute(SC_ATTR_NAME, this)
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
161 logger.info("Database facade injected into ServletContext.")
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 override fun contextDestroyed(sce: ServletContextEvent?) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 dataSource = null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 }

mercurial