blob: 6b06fd27c53a5d698778f90f273075a9cb072a0d [file] [log] [blame]
yoshi0451f282013-11-22 15:48:55 -08001/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package net.onrc.onos.graph;
6
7import java.util.ArrayList;
8import java.util.HashMap;
9import java.util.List;
10import java.util.Map;
11
12/**
13 *
14 * @author nickkaranatsios
15 */
16public class GraphDBManager {
17 private static ThreadLocal<HashMap<String, DBConnection>> connections = new ThreadLocal<HashMap<String, DBConnection>>();
18
19 static Map<String, DBConnection> getConnectionMap() {
20 if (connections.get() == null) {
21 connections.set(new HashMap<String, DBConnection>());
22 }
23 return connections.get();
24 }
25
26 public static DBOperation getDBOperation(final String dbStore, final String dbConfigFile) {
27 DBOperation operation = null;
28 if (dbStore.equals("ramcloud")) {
29 operation = new RamCloudDBOperation();
30 } else if (dbStore.equals("titan")) {
31 operation = new TitanDBOperation();
32 }
33 if (operation != null) {
34 operation.conn = GraphDBManager.getConnection(dbStore, dbConfigFile);
35 }
36 return null;
37 }
38
39 public static DBConnection getConnection(final String dbStore, final String dbConfigFile) {
40 DBConnection conn = getConnectionMap().get(dbStore);
41 if (conn == null) {
42 if (dbStore.equals("ramcloud")) {
43 conn = new RamCloudDBConnection(dbConfigFile);
44 } else if (dbStore.equals("titan")) {
45 conn = new TitanDBConnection(dbConfigFile);
46 }
47
48 GraphDBManager.getConnectionMap().put(dbStore, conn);
49 } else {
50 GraphDBManager.getConnectionMap().get(dbStore);
51 }
52 return conn;
53 }
54
55 static List<DBConnection> getConnections() {
56 return new ArrayList<DBConnection>(getConnectionMap().values());
57 }
58}