Remove classpath files and update ignore
[platform/upstream/iotivity.git] / cloud / resourcedirectory / src / main / java / org / iotivity / cloud / rdserver / db / DBManager.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2016 Samsung Electronics All Rights Reserved.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22 package org.iotivity.cloud.rdserver.db;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26
27 import org.iotivity.cloud.rdserver.Constants;
28 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresencePayload;
29
30 public class DBManager {
31
32     private static DBManager mDBManager = new DBManager();
33     private MongoDB          mMongoDB   = null;;
34
35     private DBManager() {
36         try {
37             mMongoDB = new MongoDB(Constants.RD_DB_NAME);
38             mMongoDB.createTable(Constants.RD_TABLE);
39             mMongoDB.createTable(Constants.PRESENCE_TABLE);
40         } catch (Exception e) {
41             // TODO Auto-generated catch block
42             e.printStackTrace();
43         }
44     }
45
46     public static DBManager getInstance() {
47         return mDBManager;
48     }
49
50     public ArrayList<ResPresencePayload> registerResource(
51             ArrayList<HashMap<Object, Object>> pubResourceList) {
52         return mMongoDB.createRDResource(pubResourceList, Constants.RD_TABLE);
53     }
54
55     public ArrayList<HashMap<Object, Object>> findResourceAboutDi(String di,
56             String key, String value) {
57         return mMongoDB.readResourceAboutDid(di, key, value,
58                 Constants.RD_TABLE);
59     }
60
61     public ArrayList<ResPresencePayload> deleteResourceAboutDi(String di) {
62         return mMongoDB.deleteResourceAboutDi(di, Constants.RD_TABLE);
63     }
64
65     public ArrayList<ResPresencePayload> deleteResourceAboutDiAandIns(String di,
66             String ins) {
67         return mMongoDB.deleteResourceAboutDiAndIns(di, ins,
68                 Constants.RD_TABLE);
69     }
70
71     public Object findInsAboutDi(String di, String href) {
72         return mMongoDB.readInsAboutDid(di, href, Constants.RD_TABLE);
73     }
74
75     public void updateDeviceState(HashMap<Object, Object> deviceState) {
76         mMongoDB.createDevicePresenceResource(deviceState,
77                 Constants.PRESENCE_TABLE);
78     }
79
80     public String findDeviceState(String deviceId) {
81         return mMongoDB.readDeviceState(deviceId, Constants.PRESENCE_TABLE);
82     }
83 }