2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.rdserver.db;
24 import java.util.ArrayList;
25 import java.util.HashMap;
27 import org.iotivity.cloud.rdserver.Constants;
28 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresencePayload;
30 public class DBManager {
32 private static DBManager mDBManager = new DBManager();
33 private MongoDB mMongoDB = null;;
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
46 public static DBManager getInstance() {
50 public ArrayList<ResPresencePayload> registerResource(
51 ArrayList<HashMap<Object, Object>> pubResourceList) {
52 return mMongoDB.createRDResource(pubResourceList, Constants.RD_TABLE);
55 public ArrayList<HashMap<Object, Object>> findResourceAboutDi(String di,
56 String key, String value) {
57 return mMongoDB.readResourceAboutDid(di, key, value,
61 public ArrayList<ResPresencePayload> deleteResourceAboutDi(String di) {
62 return mMongoDB.deleteResourceAboutDi(di, Constants.RD_TABLE);
65 public ArrayList<ResPresencePayload> deleteResourceAboutDiAandIns(String di,
67 return mMongoDB.deleteResourceAboutDiAndIns(di, ins,
71 public Object findInsAboutDi(String di, String href) {
72 return mMongoDB.readInsAboutDid(di, href, Constants.RD_TABLE);
75 public void updateDeviceState(HashMap<Object, Object> deviceState) {
76 mMongoDB.createDevicePresenceResource(deviceState,
77 Constants.PRESENCE_TABLE);
80 public String findDeviceState(String deviceId) {
81 return mMongoDB.readDeviceState(deviceId, Constants.PRESENCE_TABLE);