yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package net.onrc.onos.graph; |
| 6 | |
| 7 | import java.util.ArrayList; |
| 8 | import java.util.HashMap; |
| 9 | import java.util.List; |
| 10 | import java.util.Map; |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @author nickkaranatsios |
| 15 | */ |
| 16 | public class GraphDBManager { |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 17 | //private static ThreadLocal<HashMap<String, DBConnection>> connections = new ThreadLocal<HashMap<String, DBConnection>>(); |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 18 | private static DBOperation operation = null; |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 19 | /* |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 20 | static Map<String, DBConnection> getConnectionMap() { |
| 21 | if (connections.get() == null) { |
| 22 | connections.set(new HashMap<String, DBConnection>()); |
| 23 | } |
| 24 | return connections.get(); |
| 25 | } |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 26 | */ |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 27 | public static DBOperation getDBOperation(final String dbStore, final String dbConfigFile) { |
yoshi | d38cd31 | 2013-12-02 19:54:44 -0800 | [diff] [blame] | 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); |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 35 | } |
yoshi | 95ff5c2 | 2013-11-25 17:00:18 -0800 | [diff] [blame] | 36 | return operation; |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public static DBConnection getConnection(final String dbStore, final String dbConfigFile) { |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 40 | //DBConnection conn = getConnectionMap().get(dbStore); |
| 41 | DBConnection conn = null; |
| 42 | //if (conn == null) { |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 43 | if (dbStore.equals("ramcloud")) { |
| 44 | conn = new RamCloudDBConnection(dbConfigFile); |
| 45 | } else if (dbStore.equals("titan")) { |
| 46 | conn = new TitanDBConnection(dbConfigFile); |
| 47 | } |
| 48 | |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 49 | //GraphDBManager.getConnectionMap().put(dbStore, conn); |
| 50 | //} else { |
| 51 | // GraphDBManager.getConnectionMap().get(dbStore); |
| 52 | //} |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 53 | return conn; |
| 54 | } |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 55 | /* |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 56 | static List<DBConnection> getConnections() { |
| 57 | return new ArrayList<DBConnection>(getConnectionMap().values()); |
| 58 | } |
yoshi | 56b4eda | 2013-12-04 13:57:31 -0800 | [diff] [blame] | 59 | */ |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 60 | } |