Drop explicit jetty-servlets dependency
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / impl / datastore / h2 / IdmLightConfig.java
1 /*
2  * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.aaa.impl.datastore.h2;
10
11 import java.io.File;
12 import org.immutables.value.Value;
13 import org.immutables.value.Value.Default;
14 import org.immutables.value.Value.Immutable;
15 import org.immutables.value.Value.Style.ImplementationVisibility;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Responsible for providing configuration properties for the IDMLight/H2 data
21  * store implementation.
22  *
23  * @author peter.mellquist@hp.com - Initial contribution
24  * @author Michael Vorburger.ch - Made it configurable, as Immutable with
25  *         Builder
26  */
27 @Immutable
28 @Value.Style(stagedBuilder = true, strictBuilder = true, builder = "new",
29     typeImmutable = "*Impl", visibility = ImplementationVisibility.PRIVATE)
30 public abstract class IdmLightConfig {
31
32     private static final Logger LOG = LoggerFactory.getLogger(IdmLightConfig.class);
33
34     /**
35      * The filename for the H2 database file.
36      *
37      * @return data base name
38      */
39     @Default
40     public String getDbName() {
41         return "idmlight.db";
42     }
43
44     /**
45      * The database directory for the h2 database file. Either absolute or
46      * relative to KARAF_HOME.
47      *
48      * @return data base dir
49      */
50     @Default
51     public String getDbDirectory() {
52         return "./data";
53     }
54
55     /**
56      * The database JDBC driver, default is H2; a pure-java implementation.
57      *
58      * @return data base driver
59      */
60     @Default
61     public String getDbDriver() {
62         return "org.h2.Driver";
63     }
64
65     /**
66      * The database username. This is not the same as AAA credentials!
67      *
68      * @return data base user
69      */
70     @Default
71     public String getDbUser() {
72         return "foo";
73     }
74
75     /**
76      * The database password. This is not the same as AAA credentials!
77      *
78      * @return data base password
79      */
80     @Default
81     public String getDbPwd() {
82         return "bar";
83     }
84
85     /**
86      * Timeout for database connections in seconds.
87      *
88      * @return data base valid time out
89      */
90     @Default
91     public int getDbValidTimeOut() {
92         return 3;
93     }
94
95     /**
96      * The JDBC default connection string.
97      *
98      * @return data base connection prefix
99      */
100     @Default
101     public String getDbConnectionStringPrefix() {
102         return "jdbc:h2:";
103     }
104
105     /**
106      * The JDBC database connection string.
107      *
108      * @return data base connection
109      */
110     @Default
111     public String getDbConnectionString() {
112         return getDbConnectionStringPrefix() + getDbDirectory() + File.separatorChar + getDbName();
113     }
114
115     public void log() {
116         LOG.info("DB Path                 : {}", getDbConnectionString());
117         LOG.info("DB Driver               : {}", getDbDriver());
118         LOG.info("DB Valid Time Out       : {}", getDbValidTimeOut());
119     }
120
121     /**
122      * Get database connection string.
123      *
124      * @deprecated use {@link #getDbConnectionString()}
125      * @return data base connection string
126      */
127     @Deprecated
128     public String getDbPath() {
129         return getDbConnectionString();
130     }
131 }