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

changeset 158
4f912cd42876
parent 151
b3f14cd4f3ab
child 167
3f30adba1c63
equal deleted inserted replaced
157:1e6f16fad3a5 158:4f912cd42876
32 import javax.servlet.ServletContextEvent 32 import javax.servlet.ServletContextEvent
33 import javax.servlet.ServletContextListener 33 import javax.servlet.ServletContextListener
34 import javax.servlet.annotation.WebListener 34 import javax.servlet.annotation.WebListener
35 import javax.sql.DataSource 35 import javax.sql.DataSource
36 36
37 enum class DatabaseDialect {
38 Postgres
39 }
40
41 /** 37 /**
42 * Provides access to the database. 38 * Provides access to the database.
43 */ 39 */
44 @WebListener 40 @WebListener
45 class DataSourceProvider : ServletContextListener, LoggingTrait { 41 class DataSourceProvider : ServletContextListener, LoggingTrait {
42
43 enum class Dialect {
44 Postgres
45 }
46 46
47 /** 47 /**
48 * The database dialect to use. 48 * The database dialect to use.
49 * May be overridden by context parameter. 49 * May be overridden by context parameter.
50 * 50 *
51 * @see Constants.CTX_ATTR_DB_DIALECT 51 * @see Constants.CTX_ATTR_DB_DIALECT
52 */ 52 */
53 var dialect = DatabaseDialect.Postgres; private set 53 var dialect = Dialect.Postgres; private set
54 54
55 /** 55 /**
56 * The data source, if available. 56 * The data source, if available.
57 */ 57 */
58 var dataSource: DataSource? = null 58 var dataSource: DataSource? = null
128 val sc = sce!!.servletContext 128 val sc = sce!!.servletContext
129 129
130 val dbSchema = sc.getInitParameter(Constants.CTX_ATTR_DB_SCHEMA) ?: DB_DEFAULT_SCHEMA 130 val dbSchema = sc.getInitParameter(Constants.CTX_ATTR_DB_SCHEMA) ?: DB_DEFAULT_SCHEMA
131 sc.getInitParameter(Constants.CTX_ATTR_DB_DIALECT)?.let {dbDialect -> 131 sc.getInitParameter(Constants.CTX_ATTR_DB_DIALECT)?.let {dbDialect ->
132 try { 132 try {
133 dialect = DatabaseDialect.valueOf(dbDialect) 133 dialect = Dialect.valueOf(dbDialect)
134 } catch (ex: IllegalArgumentException) { 134 } catch (ex: IllegalArgumentException) {
135 logger().error( 135 logger().error(
136 "Unknown or unsupported database dialect {}. Defaulting to {}.", 136 "Unknown or unsupported database dialect {}. Defaulting to {}.",
137 dbDialect, 137 dbDialect,
138 dialect 138 dialect

mercurial