ade3e70fbe66e942766f745ee9ce3f776617db17
[aaa.git] / aaa-idm-store-h2 / src / main / java / org / opendaylight / aaa / 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.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(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     public abstract String getDbUser();
71
72     /**
73      * The database password. This is not the same as AAA credentials!
74      *
75      * @return data base password
76      */
77     public abstract String getDbPwd();
78
79     /**
80      * Timeout for database connections in seconds.
81      *
82      * @return data base valid time out
83      */
84     @Default
85     public int getDbValidTimeOut() {
86         return 3;
87     }
88
89     /**
90      * The JDBC default connection string.
91      *
92      * @return data base connection prefix
93      */
94     @Default
95     public String getDbConnectionStringPrefix() {
96         return "jdbc:h2:";
97     }
98
99     /**
100      * The JDBC database connection string.
101      *
102      * @return data base connection
103      */
104     @Default
105     public String getDbConnectionString() {
106         return getDbConnectionStringPrefix() + getDbDirectory() + File.separatorChar + getDbName();
107     }
108
109     public void log() {
110         LOG.info("DB Path                 : {}", getDbConnectionString());
111         LOG.info("DB Driver               : {}", getDbDriver());
112         LOG.info("DB Valid Time Out       : {}", getDbValidTimeOut());
113     }
114 }