1 /*
2 * Copyright (C) 2017-2019 Centre National d'Etudes Spatiales (CNES).
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 package fr.cnes.doi.plugin.impl.db.service;
20
21 import fr.cnes.doi.plugin.impl.db.impl.DOIDbDataAccessServiceImpl;
22 import java.util.Map;
23
24 /**
25 * Database singleton for accessing to the DOI database.
26 *
27 * @author Jean-Christophe Malapert (jean-christophe.malapert@cnes.fr)
28 */
29 public final class DatabaseSingleton {
30
31 /**
32 * DOI db access.
33 */
34 private final DOIDbDataAccessService das;
35
36 /**
37 * Returns the instance
38 *
39 * @return the instance
40 */
41 public static DatabaseSingleton getInstance() {
42 return DatabaseSingletonHolder.INSTANCE;
43 }
44
45 /**
46 * Initialize the DOI singleton.
47 */
48 private DatabaseSingleton() {
49 this.das = new DOIDbDataAccessServiceImpl();
50 }
51
52 /**
53 * Initialize the DOI database.
54 *
55 * @param dbUrl database URL
56 * @param dbUser database user
57 * @param dbPwd database password
58 * @param options database options
59 */
60 public void init(final String dbUrl, final String dbUser, final String dbPwd,
61 final Map<String, Integer> options) {
62 ((DOIDbDataAccessServiceImpl) this.das).init(dbUrl, dbUser, dbPwd, options);
63 }
64
65 /**
66 * Returns the database access.
67 *
68 * @return the database access.
69 */
70 public DOIDbDataAccessService getDatabaseAccess() {
71 return this.das;
72 }
73
74 /**
75 * Holder
76 */
77 private static class DatabaseSingletonHolder {
78
79 /**
80 * Database singleton Unique Instance not pre-initiliaze
81 */
82 private static final DatabaseSingleton INSTANCE = new DatabaseSingleton();
83 }
84 }