Split out datastore implementation from aaa-shiro
[aaa.git] / aaa-idm-store-h2 / src / main / java / org / opendaylight / aaa / datastore / h2 / IdmLightSimpleConnectionProvider.java
1 /*
2  * Copyright (c) 2016, 2017 Red Hat, Inc. 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 package org.opendaylight.aaa.datastore.h2;
9
10 import java.sql.Connection;
11 import java.sql.DriverManager;
12 import java.sql.SQLException;
13
14 /**
15  * Simple Provider of JDBC Connections, based on an {@link IdmLightConfig} and
16  * {@link DriverManager}.
17  *
18  * @author Michael Vorburger
19  */
20 public class IdmLightSimpleConnectionProvider implements ConnectionProvider {
21     private final IdmLightConfig config;
22
23     public IdmLightSimpleConnectionProvider(IdmLightConfig config) {
24         new org.h2.Driver();
25         this.config = config;
26     }
27
28     @Override
29     public Connection getConnection() throws StoreException {
30         try {
31             return DriverManager.getConnection(config.getDbConnectionString(), config.getDbUser(), config.getDbPwd());
32         } catch (SQLException e) {
33             throw new StoreException("Cannot connect to database server", e);
34         }
35     }
36 }