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

Sat, 26 Dec 2020 20:19:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 26 Dec 2020 20:19:09 +0100
changeset 168
1c3694ae224c
parent 167
3f30adba1c63
child 180
009700915269
permissions
-rw-r--r--

adds "Create another" checkbox to issue form - fixes #110

151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * Copyright 2020 Mike Becker. All rights reserved.
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
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 import java.sql.SQLException
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 import javax.naming.Context
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 import javax.naming.InitialContext
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 import javax.naming.NamingException
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 import javax.servlet.ServletContextEvent
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 import javax.servlet.ServletContextListener
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import javax.servlet.annotation.WebListener
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
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 class DataSourceProvider : ServletContextListener, LoggingTrait {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
43 enum class Dialect {
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
44 Postgres
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
45 }
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
46
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 * The database dialect to use.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 * May be overridden by context parameter.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 * @see Constants.CTX_ATTR_DB_DIALECT
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 */
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
53 var dialect = Dialect.Postgres; private set
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 * The data source, if available.
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 var dataSource: DataSource? = null
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 companion object {
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 * 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
63 */
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 val SC_ATTR_NAME = "lightpit.service.DataSourceProvider"
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 * Timeout in seconds for the validation test.
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 private val DB_TEST_TIMEOUT = 10
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 * The default schema to test against when validating the connection.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 * May be overridden by context parameter.
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 *
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 * @see Constants.CTX_ATTR_DB_SCHEMA
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 private val DB_DEFAULT_SCHEMA = "lightpit"
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 /**
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 * The JNDI resource name for the data source.
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 private val DS_JNDI_NAME = "jdbc/lightpit/app"
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 private fun checkConnection(ds: DataSource, testSchema: String) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 try {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 ds.connection.use { conn ->
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 if (!conn.isValid(DB_TEST_TIMEOUT)) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 throw SQLException("Validation check failed.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 if (conn.isReadOnly) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 throw SQLException("Connection is read-only and thus unusable.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 if (conn.schema != testSchema) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 throw SQLException(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 String.format(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 "Connection is not configured to use the schema %s.",
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 testSchema
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 )
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 val metaData = conn.metaData
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 logger().info(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 "Connections as {} to {}/{} ready to go.",
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 metaData.userName,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 metaData.url,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 conn.schema
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 } catch (ex: SQLException) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 logger().error("Checking database connection failed", ex)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 }
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 private fun retrieveDataSource(ctx: Context): DataSource? {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 return try {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 val ret = ctx.lookup(DS_JNDI_NAME) as DataSource
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 logger().info("Data source retrieved.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 ret
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 } catch (ex: NamingException) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 logger().error("Data source {} not available.", DS_JNDI_NAME)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 logger().error("Reason for the missing data source: ", ex)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 }
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 override fun contextInitialized(sce: ServletContextEvent?) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 val sc = sce!!.servletContext
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 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
131 sc.getInitParameter(Constants.CTX_ATTR_DB_DIALECT)?.let { dbDialect ->
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 try {
158
4f912cd42876 migrates constants and removes global functions
Mike Becker <universe@uap-core.de>
parents: 151
diff changeset
133 dialect = Dialect.valueOf(dbDialect)
151
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 } catch (ex: IllegalArgumentException) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 logger().error(
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 "Unknown or unsupported database dialect {}. Defaulting to {}.",
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 dbDialect,
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 dialect
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 )
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 }
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 dataSource = try {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 logger().debug("Trying to access JNDI context ...")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 val initialCtx: Context = InitialContext()
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 val ctx = initialCtx.lookup("java:comp/env") as Context
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 retrieveDataSource(ctx)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 } catch (ex: NamingException) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 logger().error("Cannot access JNDI resources.", ex)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 } catch (ex: ClassCastException) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 logger().error("Cannot access JNDI resources.", ex)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 dataSource?.let { checkConnection(it, dbSchema) }
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 sc.setAttribute(SC_ATTR_NAME, this)
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 logger().info("Database facade injected into ServletContext.")
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 override fun contextDestroyed(sce: ServletContextEvent?) {
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 dataSource = null
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 }
b3f14cd4f3ab migrate DataSourceProvider
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 }

mercurial