a35ca48fdcbb4f66338fd083229c3257ef71a7f9
[moon.git] /
1 /*
2  * Copyright (c) 2014, 2015 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.h2.config;
10
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 /**
15  * Responsible for providing configuration properties for the IDMLight/H2
16  * data store implementation.
17  *
18  * @author peter.mellquist@hp.com
19  *
20  */
21 public class IdmLightConfig {
22
23     private static final Logger LOG = LoggerFactory.getLogger(IdmLightConfig.class);
24
25     /**
26      * The default timeout for db connections in seconds.
27      */
28     private static final int DEFAULT_DB_TIMEOUT = 3;
29
30     /**
31      * The default password for the database
32      */
33     private static final String DEFAULT_PASSWORD = "bar";
34
35     /**
36      * The default username for the database
37      */
38     private static final String DEFAULT_USERNAME = "foo";
39
40     /**
41      * The default driver for the databse is H2;  a pure-java implementation
42      * of JDBC.
43      */
44     private static final String DEFAULT_JDBC_DRIVER = "org.h2.Driver";
45
46     /**
47      * The default connection string includes the intention to use h2 as
48      * the JDBC driver, and the path for the file is located relative to
49      * KARAF_HOME.
50      */
51     private static final String DEFAULT_CONNECTION_STRING = "jdbc:h2:./";
52
53     /**
54      * The default filename for the database file.
55      */
56     private static final String DEFAULT_IDMLIGHT_DB_FILENAME = "idmlight.db";
57
58     /**
59      * The database filename
60      */
61     private String dbName;
62
63     /**
64      * the database connection string
65      */
66     private String dbPath;
67
68     /**
69      * The database driver (i.e., H2)
70      */
71     private String dbDriver;
72
73     /**
74      * The database password.  This is not the same as AAA credentials!
75      */
76     private String dbUser;
77
78     /**
79      * The database username.  This is not the same as AAA credentials!
80      */
81     private String dbPwd;
82
83     /**
84      * Timeout for database connections in seconds
85      */
86     private int dbValidTimeOut;
87
88     /**
89      * Creates an valid database configuration using default values.
90      */
91     public IdmLightConfig() {
92         // TODO make this configurable
93         dbName = DEFAULT_IDMLIGHT_DB_FILENAME;
94         dbPath = DEFAULT_CONNECTION_STRING + dbName;
95         dbDriver = DEFAULT_JDBC_DRIVER;
96         dbUser = DEFAULT_USERNAME;
97         dbPwd = DEFAULT_PASSWORD;
98         dbValidTimeOut = DEFAULT_DB_TIMEOUT;
99     }
100
101     /**
102      * Outputs some debugging information surrounding idmlight config
103      */
104     public void log() {
105         LOG.info("DB Path                 : {}", dbPath);
106         LOG.info("DB Driver               : {}", dbDriver);
107         LOG.info("DB Valid Time Out       : {}", dbValidTimeOut);
108     }
109
110     public String getDbName() {
111         return this.dbName;
112     }
113
114     public String getDbPath() {
115         return this.dbPath;
116     }
117
118     public String getDbDriver() {
119         return this.dbDriver;
120     }
121
122     public String getDbUser() {
123         return this.dbUser;
124     }
125
126     public String getDbPwd() {
127         return this.dbPwd;
128     }
129
130     public int getDbValidTimeOut() {
131         return this.dbValidTimeOut;
132     }
133 }