Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 1 | /** NDN-Atmos: Cataloging Service for distributed data originally developed |
| 2 | * for atmospheric science data |
| 3 | * Copyright (C) 2015 Colorado State University |
| 4 | * |
| 5 | * NDN-Atmos is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * NDN-Atmos is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with NDN-Atmos. If not, see <http://www.gnu.org/licenses/>. |
| 17 | **/ |
| 18 | |
| 19 | #ifndef ATMOS_QUERY_QUERY_ADAPTER_HPP |
| 20 | #define ATMOS_QUERY_QUERY_ADAPTER_HPP |
| 21 | |
| 22 | #include "util/catalog-adapter.hpp" |
| 23 | #include "util/mysql-util.hpp" |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 24 | #include "util/config-file.hpp" |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 25 | |
| 26 | #include <thread> |
| 27 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 28 | #include <json/reader.h> |
| 29 | #include <json/value.h> |
| 30 | #include <json/writer.h> |
| 31 | |
| 32 | #include <ndn-cxx/data.hpp> |
| 33 | #include <ndn-cxx/face.hpp> |
| 34 | #include <ndn-cxx/interest.hpp> |
| 35 | #include <ndn-cxx/interest-filter.hpp> |
| 36 | #include <ndn-cxx/name.hpp> |
| 37 | #include <ndn-cxx/security/key-chain.hpp> |
| 38 | #include <ndn-cxx/util/time.hpp> |
| 39 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 40 | #include <ndn-cxx/util/in-memory-storage-lru.hpp> |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 41 | #include <ndn-cxx/util/string-helper.hpp> |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 42 | #include <ChronoSync/socket.hpp> |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 43 | |
| 44 | #include "mysql/mysql.h" |
| 45 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 46 | #include <map> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 47 | #include <unordered_map> |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 48 | #include <memory> |
| 49 | #include <mutex> |
| 50 | #include <sstream> |
| 51 | #include <string> |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 52 | #include <array> |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 53 | #include <utility> |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 54 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 55 | #include "util/logger.hpp" |
| 56 | |
| 57 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 58 | namespace atmos { |
| 59 | namespace query { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 60 | #ifdef HAVE_LOG4CXX |
| 61 | INIT_LOGGER("QueryAdapter"); |
| 62 | #endif |
| 63 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 64 | // todo: calculate payload limit by get the size of a signed empty Data packet |
| 65 | static const size_t PAYLOAD_LIMIT = 7000; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * QueryAdapter handles the Query usecases for the catalog |
| 69 | */ |
| 70 | template <typename DatabaseHandler> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 71 | class QueryAdapter : public atmos::util::CatalogAdapter { |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 72 | public: |
| 73 | /** |
| 74 | * Constructor |
| 75 | * |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 76 | * @param face: Face that will be used for NDN communications |
| 77 | * @param keyChain: KeyChain that will be used for data signing |
| 78 | * @param syncSocket: ChronoSync socket |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 79 | */ |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 80 | QueryAdapter(const std::shared_ptr<ndn::Face>& face, |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 81 | const std::shared_ptr<ndn::KeyChain>& keyChain, |
| 82 | const std::shared_ptr<chronosync::Socket>& syncSocket); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 83 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 84 | virtual |
| 85 | ~QueryAdapter(); |
| 86 | |
| 87 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 88 | * Helper function to specify section handler |
| 89 | */ |
| 90 | void |
| 91 | setConfigFile(util::ConfigFile& config, |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 92 | const ndn::Name& prefix, |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 93 | const std::vector<std::string>& nameFields, |
| 94 | const std::string& databaseTable); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 95 | |
| 96 | protected: |
| 97 | /** |
| 98 | * Helper function for configuration parsing |
| 99 | */ |
| 100 | void |
| 101 | onConfig(const util::ConfigSection& section, |
| 102 | bool isDryDun, |
| 103 | const std::string& fileName, |
| 104 | const ndn::Name& prefix); |
| 105 | |
| 106 | /** |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 107 | * Handles incoming query requests by stripping the filter off the Interest to get the |
| 108 | * actual request out. This removes the need for a 2-step Interest-Data retrieval. |
| 109 | * |
| 110 | * @param filter: InterestFilter that caused this Interest to be routed |
| 111 | * @param interest: Interest that needs to be handled |
| 112 | */ |
| 113 | virtual void |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 114 | onIncomingQueryInterest(const ndn::InterestFilter& filter, const ndn::Interest& interest); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 115 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 116 | /** |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 117 | * Handles requests for responses to an filter initialization request |
| 118 | * |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 119 | * @param interest: Interest that needs to be handled |
| 120 | */ |
| 121 | virtual void |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 122 | onFiltersInitializationInterest(std::shared_ptr<const ndn::Interest> interest); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Helper function that generates query results from a Json query carried in the Interest |
| 126 | * |
| 127 | * @param interest: Interest that needs to be handled |
| 128 | */ |
| 129 | void |
| 130 | populateFiltersMenu(std::shared_ptr<const ndn::Interest> interest); |
| 131 | |
| 132 | void |
| 133 | getFiltersMenu(Json::Value& value); |
| 134 | |
| 135 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 136 | * Helper function that makes query-results data |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 137 | * |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 138 | * @param segmentPrefix: Name that identifies the Prefix for the Data |
| 139 | * @param value: Json::Value to be sent in the Data |
| 140 | * @param segmentNo: uint64_t the segment for this Data |
| 141 | * @param isFinalBlock: bool to indicate whether this needs to be flagged in the Data as the |
| 142 | * last entry |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 143 | * @param isAutocomplete: bool to indicate whether this is an autocomplete message |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 144 | * @param resultCount: the number of records in the query results |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 145 | * @param viewStart: the start index of the record in the query results payload |
| 146 | * @param viewEnd: the end index of the record in the query results payload |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 147 | * @param lastComponent: flag to indicate the content contains the last component for |
| 148 | autocompletion query |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 149 | */ |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 150 | std::shared_ptr<ndn::Data> |
| 151 | makeReplyData(const ndn::Name& segmentPrefix, |
| 152 | const Json::Value& value, |
| 153 | uint64_t segmentNo, |
| 154 | bool isFinalBlock, |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 155 | bool isAutocomplete, |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 156 | uint64_t resultCount, |
| 157 | uint64_t viewStart, |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 158 | uint64_t viewEnd, |
| 159 | bool lastComponent); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 160 | |
| 161 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 162 | * Helper function that generates query results from a Json query carried in the Interest |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 163 | * |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 164 | * @param interest: Interest that needs to be handled |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 165 | */ |
| 166 | void |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 167 | runJsonQuery(std::shared_ptr<const ndn::Interest> interest); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 168 | |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 169 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 170 | * Helper function that makes ACK data |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 171 | * |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 172 | * @param interest: Intersts that needs to be handled |
| 173 | * @param version: Version that needs to be in the data name |
| 174 | */ |
| 175 | std::shared_ptr<ndn::Data> |
| 176 | makeAckData(std::shared_ptr<const ndn::Interest> interest, |
| 177 | const ndn::Name::Component& version); |
| 178 | |
| 179 | /** |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 180 | * Helper function that sends NACK |
| 181 | * |
| 182 | * @param dataPrefix: prefix for the data packet |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 183 | */ |
| 184 | void |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 185 | sendNack(const ndn::Name& dataPrefix); |
| 186 | |
| 187 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 188 | * Helper function that signs the data |
| 189 | */ |
| 190 | void |
| 191 | signData(ndn::Data& data); |
| 192 | |
| 193 | /** |
| 194 | * Helper function that publishes query-results data segments |
| 195 | */ |
| 196 | virtual void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 197 | prepareSegmentsBySqlString(const ndn::Name& segmentPrefix, |
| 198 | const std::string& sqlString, |
| 199 | bool lastComponent, |
| 200 | const std::string& nameField); |
| 201 | |
| 202 | virtual void |
| 203 | prepareSegmentsByParams(std::vector<std::pair<std::string, std::string>>& queryParams, |
| 204 | const ndn::Name& segmentPrefix); |
| 205 | |
| 206 | void |
| 207 | generateSegments(ResultSet_T& res, |
| 208 | const ndn::Name& segmentPrefix, |
| 209 | int resultCount, |
| 210 | bool autocomplete, |
| 211 | bool lastComponent); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Helper function to set the DatabaseHandler |
| 215 | */ |
| 216 | void |
| 217 | setDatabaseHandler(const util::ConnectionDetails& databaseId); |
| 218 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 219 | void |
| 220 | closeDatabaseHandler(); |
| 221 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 222 | /** |
| 223 | * Helper function that set filters to make the adapter work |
| 224 | */ |
| 225 | void |
| 226 | setFilters(); |
| 227 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 228 | void |
| 229 | setCatalogId(); |
| 230 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 231 | /** |
| 232 | * Helper function that generates the sqlQuery string for autocomplete query |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 233 | * @param sqlQuery: stringstream to save the sqlQuery string |
| 234 | * @param jsonValue: Json value that contains the query information |
| 235 | * @param lastComponent: Flag to mark the last component query |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 236 | * @param nameField: stringstream to save the nameField string |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 237 | */ |
| 238 | bool |
| 239 | json2AutocompletionSql(std::stringstream& sqlQuery, |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 240 | Json::Value& jsonValue, |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 241 | bool& lastComponent, |
| 242 | std::stringstream& nameField); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 243 | |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 244 | bool |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 245 | doPrefixBasedSearch(Json::Value& jsonValue, |
| 246 | std::vector<std::pair<std::string, std::string>>& typedComponents); |
| 247 | |
| 248 | bool |
| 249 | doFilterBasedSearch(Json::Value& jsonValue, |
| 250 | std::vector<std::pair<std::string, std::string>>& typedComponents); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 251 | |
| 252 | ndn::Name |
| 253 | getQueryResultsName(std::shared_ptr<const ndn::Interest> interest, |
| 254 | const ndn::Name::Component& version); |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 255 | |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 256 | std::string |
| 257 | getChronoSyncDigest(); |
| 258 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 259 | protected: |
| 260 | typedef std::unordered_map<ndn::Name, const ndn::RegisteredPrefixId*> RegisteredPrefixList; |
| 261 | // Handle to the Catalog's database |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 262 | std::shared_ptr<DatabaseHandler> m_dbConnPool; |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 263 | const std::shared_ptr<chronosync::Socket>& m_socket; |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 264 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 265 | // mutex to control critical sections |
| 266 | std::mutex m_mutex; |
| 267 | // @{ needs m_mutex protection |
| 268 | // The Queries we are currently writing to |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 269 | ndn::util::InMemoryStorageLru m_activeQueryToFirstResponse; |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 270 | ndn::util::InMemoryStorageLru m_cache; |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 271 | std::string m_chronosyncDigest; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 272 | // @} |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 273 | RegisteredPrefixList m_registeredPrefixList; |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 274 | ndn::Name m_catalogId; // should be replaced with the PK digest |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 275 | std::vector<std::string> m_filterCategoryNames; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 276 | }; |
| 277 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 278 | template <typename DatabaseHandler> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 279 | QueryAdapter<DatabaseHandler>::QueryAdapter(const std::shared_ptr<ndn::Face>& face, |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 280 | const std::shared_ptr<ndn::KeyChain>& keyChain, |
| 281 | const std::shared_ptr<chronosync::Socket>& syncSocket) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 282 | : util::CatalogAdapter(face, keyChain) |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 283 | , m_socket(syncSocket) |
| 284 | , m_activeQueryToFirstResponse(100000) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 285 | , m_cache(250000) |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 286 | , m_chronosyncDigest("0") |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 287 | , m_catalogId("catalogIdPlaceHolder") // initialize for unitests |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 288 | { |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | template <typename DatabaseHandler> |
| 292 | void |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 293 | QueryAdapter<DatabaseHandler>::setFilters() |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 294 | { |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 295 | m_registeredPrefixList[m_prefix] = m_face->setInterestFilter(ndn::InterestFilter(m_prefix), |
| 296 | bind(&query::QueryAdapter<DatabaseHandler>::onIncomingQueryInterest, |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 297 | this, _1, _2), |
| 298 | bind(&query::QueryAdapter<DatabaseHandler>::onRegisterSuccess, |
| 299 | this, _1), |
| 300 | bind(&query::QueryAdapter<DatabaseHandler>::onRegisterFailure, |
| 301 | this, _1, _2)); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | template <typename DatabaseHandler> |
| 305 | void |
| 306 | QueryAdapter<DatabaseHandler>::setConfigFile(util::ConfigFile& config, |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 307 | const ndn::Name& prefix, |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 308 | const std::vector<std::string>& nameFields, |
| 309 | const std::string& databaseTable) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 310 | { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 311 | m_nameFields = nameFields; |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 312 | m_databaseTable = databaseTable; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 313 | config.addSectionHandler("queryAdapter", bind(&QueryAdapter<DatabaseHandler>::onConfig, this, |
| 314 | _1, _2, _3, prefix)); |
| 315 | } |
| 316 | |
| 317 | template <typename DatabaseHandler> |
| 318 | void |
| 319 | QueryAdapter<DatabaseHandler>::onConfig(const util::ConfigSection& section, |
| 320 | bool isDryRun, |
| 321 | const std::string& filename, |
| 322 | const ndn::Name& prefix) |
| 323 | { |
| 324 | using namespace util; |
| 325 | if (isDryRun) { |
| 326 | return; |
| 327 | } |
| 328 | std::string signingId, dbServer, dbName, dbUser, dbPasswd; |
| 329 | for (auto item = section.begin(); |
| 330 | item != section.end(); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 331 | ++item) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 332 | { |
| 333 | if (item->first == "signingId") { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 334 | signingId = item->second.get_value<std::string>(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 335 | if (signingId.empty()) { |
| 336 | throw Error("Empty value for \"signingId\"" |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 337 | " in \"query\" section"); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 338 | } |
| 339 | } |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 340 | if (item->first == "filterCategoryNames") { |
| 341 | std::istringstream ss(item->second.get_value<std::string>()); |
| 342 | std::string token; |
| 343 | while(std::getline(ss, token, ',')) { |
| 344 | m_filterCategoryNames.push_back(token); |
| 345 | } |
| 346 | } |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 347 | if (item->first == "database") { |
| 348 | const util::ConfigSection& dataSection = item->second; |
| 349 | for (auto subItem = dataSection.begin(); |
| 350 | subItem != dataSection.end(); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 351 | ++subItem) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 352 | { |
| 353 | if (subItem->first == "dbServer") { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 354 | dbServer = subItem->second.get_value<std::string>(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 355 | } |
| 356 | if (subItem->first == "dbName") { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 357 | dbName = subItem->second.get_value<std::string>(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 358 | } |
| 359 | if (subItem->first == "dbUser") { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 360 | dbUser = subItem->second.get_value<std::string>(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 361 | } |
| 362 | if (subItem->first == "dbPasswd") { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 363 | dbPasswd = subItem->second.get_value<std::string>(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 364 | } |
| 365 | } |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 366 | |
| 367 | if (dbServer.empty()){ |
| 368 | throw Error("Invalid value for \"dbServer\"" |
| 369 | " in \"query\" section"); |
| 370 | } |
| 371 | if (dbName.empty()){ |
| 372 | throw Error("Invalid value for \"dbName\"" |
| 373 | " in \"query\" section"); |
| 374 | } |
| 375 | if (dbUser.empty()){ |
| 376 | throw Error("Invalid value for \"dbUser\"" |
| 377 | " in \"query\" section"); |
| 378 | } |
| 379 | if (dbPasswd.empty()){ |
| 380 | throw Error("Invalid value for \"dbPasswd\"" |
| 381 | " in \"query\" section"); |
| 382 | } |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 386 | if (m_filterCategoryNames.empty()) { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 387 | throw Error("Empty value for \"filterCategoryNames\" in \"query\" section"); |
| 388 | } |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 389 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 390 | m_prefix = prefix; |
| 391 | |
| 392 | m_signingId = ndn::Name(signingId); |
| 393 | setCatalogId(); |
| 394 | |
| 395 | util::ConnectionDetails mysqlId(dbServer, dbUser, dbPasswd, dbName); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 396 | setDatabaseHandler(mysqlId); |
| 397 | setFilters(); |
| 398 | } |
| 399 | |
| 400 | template <typename DatabaseHandler> |
| 401 | void |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 402 | QueryAdapter<DatabaseHandler>::setCatalogId() |
| 403 | { |
| 404 | //empty |
| 405 | } |
| 406 | |
| 407 | template <> |
| 408 | void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 409 | QueryAdapter<ConnectionPool_T>::setCatalogId() |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 410 | { |
| 411 | // use public key digest as the catalog ID |
| 412 | ndn::Name keyId; |
| 413 | if (m_signingId.empty()) { |
| 414 | keyId = m_keyChain->getDefaultKeyNameForIdentity(m_keyChain->getDefaultIdentity()); |
| 415 | } else { |
| 416 | keyId = m_keyChain->getDefaultKeyNameForIdentity(m_signingId); |
| 417 | } |
| 418 | |
| 419 | std::shared_ptr<ndn::PublicKey> pKey = m_keyChain->getPib().getPublicKey(keyId); |
| 420 | ndn::Block keyDigest = pKey->computeDigest(); |
| 421 | m_catalogId.clear(); |
| 422 | m_catalogId.append(ndn::toHex(*keyDigest.getBuffer())); |
| 423 | } |
| 424 | |
| 425 | template <typename DatabaseHandler> |
| 426 | void |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 427 | QueryAdapter<DatabaseHandler>::setDatabaseHandler(const util::ConnectionDetails& databaseId) |
| 428 | { |
| 429 | //empty |
| 430 | } |
| 431 | |
| 432 | template <> |
| 433 | void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 434 | QueryAdapter<ConnectionPool_T>::setDatabaseHandler(const util::ConnectionDetails& databaseId) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 435 | { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 436 | m_dbConnPool = zdbConnectionSetup(databaseId); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | template <typename DatabaseHandler> |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 440 | void |
| 441 | QueryAdapter<DatabaseHandler>::closeDatabaseHandler() |
| 442 | { |
| 443 | } |
| 444 | |
| 445 | template <> |
| 446 | void |
| 447 | QueryAdapter<ConnectionPool_T>::closeDatabaseHandler() |
| 448 | { |
| 449 | ConnectionPool_stop(*m_dbConnPool); |
| 450 | } |
| 451 | |
| 452 | |
| 453 | template <typename DatabaseHandler> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 454 | QueryAdapter<DatabaseHandler>::~QueryAdapter() |
| 455 | { |
| 456 | for (const auto& itr : m_registeredPrefixList) { |
| 457 | if (static_cast<bool>(itr.second)) |
| 458 | m_face->unsetInterestFilter(itr.second); |
| 459 | } |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 460 | |
| 461 | closeDatabaseHandler(); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | template <typename DatabaseHandler> |
| 465 | void |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 466 | QueryAdapter<DatabaseHandler>::onIncomingQueryInterest(const ndn::InterestFilter& filter, |
| 467 | const ndn::Interest& interest) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 468 | { |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 469 | _LOG_DEBUG(">> QueryAdapter::onIncomingQueryInterest"); |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 470 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 471 | // Interest must carry component "initialization" or "query" |
| 472 | if (interest.getName().size() < filter.getPrefix().size()) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 473 | // must NACK incorrect interest |
| 474 | sendNack(interest.getName()); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 475 | return; |
| 476 | } |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 477 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 478 | _LOG_DEBUG("Interest : " << interest.getName()); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 479 | std::shared_ptr<const ndn::Interest> interestPtr = interest.shared_from_this(); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 480 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 481 | if (interest.getName()[filter.getPrefix().size()] == ndn::Name::Component("filters-initialization")) { |
| 482 | std::thread queryThread(&QueryAdapter<DatabaseHandler>::onFiltersInitializationInterest, |
| 483 | this, |
| 484 | interestPtr); |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 485 | queryThread.detach(); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 486 | } |
| 487 | else if (interest.getName()[filter.getPrefix().size()] == ndn::Name::Component("query")) { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 488 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 489 | auto data = m_cache.find(interest); |
| 490 | if (data) { |
| 491 | m_face->put(*data); |
| 492 | return; |
| 493 | } |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 494 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 495 | // catalog must strip sequence number in an Interest for further process |
| 496 | if (interest.getName().size() > (filter.getPrefix().size() + 2)) { |
| 497 | // Interest carries sequence number, only grip the main part |
| 498 | // e.g., /hep/query/<query-params>/<version>/#seq |
| 499 | ndn::Interest queryInterest(interest.getName().getPrefix(filter.getPrefix().size() + 2)); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 500 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 501 | auto data = m_cache.find(queryInterest); |
| 502 | if (data) { |
| 503 | // catalog has generated some data, but still working on it |
| 504 | return; |
| 505 | } |
Chengyu Fan | 69279bf | 2016-02-18 16:05:00 -0700 | [diff] [blame] | 506 | interestPtr = std::make_shared<ndn::Interest>(queryInterest); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 507 | } |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 508 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 509 | std::thread queryThread(&QueryAdapter<DatabaseHandler>::runJsonQuery, |
| 510 | this, |
| 511 | interestPtr); |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 512 | queryThread.detach(); |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 513 | } |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 514 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 515 | // ignore other Interests |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | template <typename DatabaseHandler> |
| 519 | void |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 520 | QueryAdapter<DatabaseHandler>::onFiltersInitializationInterest(std::shared_ptr<const ndn::Interest> interest) |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 521 | { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 522 | _LOG_DEBUG(">> QueryAdapter::onFiltersInitializationInterest"); |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 523 | |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 524 | if(m_socket != nullptr) { |
| 525 | const ndn::ConstBufferPtr digestPtr = m_socket->getRootDigest(); |
| 526 | std::string digestStr = ndn::toHex(digestPtr->buf(), digestPtr->size()); |
| 527 | _LOG_DEBUG("Original digest :" << m_chronosyncDigest); |
| 528 | _LOG_DEBUG("New digest : " << digestStr); |
| 529 | // if the m_chronosyncDigest and the rootdigest are not equal |
| 530 | if (digestStr != m_chronosyncDigest) { |
| 531 | // (1) update chronosyncDigest |
| 532 | // (2) clear all staled ACK data |
| 533 | m_mutex.lock(); |
| 534 | m_chronosyncDigest = digestStr; |
| 535 | m_activeQueryToFirstResponse.erase(ndn::Name("/")); |
| 536 | m_mutex.unlock(); |
| 537 | _LOG_DEBUG("Change digest to " << m_chronosyncDigest); |
| 538 | } |
| 539 | } |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 540 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 541 | auto data = m_activeQueryToFirstResponse.find(*interest); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 542 | if (data) { |
| 543 | m_face->put(*data); |
| 544 | } |
| 545 | else { |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 546 | populateFiltersMenu(interest); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 547 | } |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 548 | |
| 549 | _LOG_DEBUG("<< QueryAdapter::onFiltersInitializationInterest"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | template <typename DatabaseHandler> |
| 553 | void |
| 554 | QueryAdapter<DatabaseHandler>::populateFiltersMenu(std::shared_ptr<const ndn::Interest> interest) |
| 555 | { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 556 | _LOG_DEBUG(">> QueryAdapter::populateFiltersMenu"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 557 | Json::Value filters; |
| 558 | Json::FastWriter fastWriter; |
| 559 | getFiltersMenu(filters); |
| 560 | |
| 561 | const std::string filterValue = fastWriter.write(filters); |
| 562 | |
| 563 | if (!filters.empty()) { |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 564 | // use /<prefix>/filters-initialization/<seg> as data name |
| 565 | ndn::Name filterDataName(interest->getName().getPrefix(-1)); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 566 | |
| 567 | const char* payload = filterValue.c_str(); |
| 568 | size_t payloadLength = filterValue.size(); |
| 569 | size_t startIndex = 0, seqNo = 0; |
| 570 | |
| 571 | if (filterValue.length() > PAYLOAD_LIMIT) { |
| 572 | payloadLength = PAYLOAD_LIMIT; |
| 573 | ndn::Name segmentName = ndn::Name(filterDataName).appendSegment(seqNo); |
| 574 | std::shared_ptr<ndn::Data> filterData = std::make_shared<ndn::Data>(segmentName); |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 575 | // freshnessPeriod 0 means permanent? |
| 576 | filterData->setFreshnessPeriod(ndn::time::milliseconds(10)); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 577 | filterData->setContent(reinterpret_cast<const uint8_t*>(payload + startIndex), payloadLength); |
| 578 | |
| 579 | signData(*filterData); |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 580 | |
| 581 | _LOG_DEBUG("Populate Filter Data :" << segmentName); |
| 582 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 583 | m_mutex.lock(); |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 584 | // save the filter results in the activeQueryToFirstResponse structure |
| 585 | // when version changes, the activeQueryToFirstResponse should be cleaned |
| 586 | m_activeQueryToFirstResponse.insert(*filterData); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 587 | try { |
| 588 | m_face->put(*filterData); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 589 | } |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 590 | catch (std::exception& e) { |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 591 | _LOG_ERROR(e.what()); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 592 | } |
| 593 | m_mutex.unlock(); |
| 594 | |
| 595 | seqNo++; |
| 596 | startIndex = payloadLength * seqNo + 1; |
| 597 | } |
| 598 | payloadLength = filterValue.size() - PAYLOAD_LIMIT * seqNo; |
| 599 | |
| 600 | ndn::Name lastSegment = ndn::Name(filterDataName).appendSegment(seqNo); |
| 601 | std::shared_ptr<ndn::Data> filterData = std::make_shared<ndn::Data>(lastSegment); |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 602 | filterData->setFreshnessPeriod(ndn::time::milliseconds(10)); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 603 | filterData->setContent(reinterpret_cast<const uint8_t*>(payload + startIndex), payloadLength); |
| 604 | filterData->setFinalBlockId(ndn::Name::Component::fromSegment(seqNo)); |
| 605 | |
| 606 | signData(*filterData); |
| 607 | m_mutex.lock(); |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 608 | m_activeQueryToFirstResponse.insert(*filterData); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 609 | m_face->put(*filterData); |
| 610 | m_mutex.unlock(); |
| 611 | } |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 612 | _LOG_DEBUG("<< QueryAdapter::populateFiltersMenu"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | template <typename DatabaseHandler> |
| 616 | void |
| 617 | QueryAdapter<DatabaseHandler>::getFiltersMenu(Json::Value& value) |
| 618 | { |
| 619 | // empty |
| 620 | } |
| 621 | |
| 622 | // get distinct value of each column |
| 623 | template <> |
| 624 | void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 625 | QueryAdapter<ConnectionPool_T>::getFiltersMenu(Json::Value& value) |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 626 | { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 627 | _LOG_DEBUG(">> QueryAdapter::getFiltersMenu"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 628 | Json::Value tmp; |
| 629 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 630 | Connection_T conn = ConnectionPool_getConnection(*m_dbConnPool); |
| 631 | if (!conn) { |
| 632 | _LOG_DEBUG("No available database connections"); |
| 633 | return; |
| 634 | } |
| 635 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 636 | for (size_t i = 0; i < m_filterCategoryNames.size(); i++) { |
| 637 | std::string columnName = m_filterCategoryNames[i]; |
| 638 | std::string getFilterSql("SELECT DISTINCT " + columnName + |
| 639 | " FROM " + m_databaseTable + ";"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 640 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 641 | ResultSet_T res4ColumnName; |
| 642 | TRY { |
| 643 | res4ColumnName = Connection_executeQuery(conn, reinterpret_cast<const char*>(getFilterSql.c_str()), getFilterSql.size()); |
| 644 | } |
| 645 | CATCH(SQLException) { |
| 646 | _LOG_ERROR(Connection_getLastError(conn)); |
| 647 | } |
| 648 | END_TRY; |
| 649 | |
| 650 | while (ResultSet_next(res4ColumnName)) { |
| 651 | tmp[columnName].append(ResultSet_getString(res4ColumnName, 1)); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 652 | } |
| 653 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 654 | value.append(tmp); |
| 655 | tmp.clear(); |
| 656 | } |
| 657 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 658 | _LOG_DEBUG("<< QueryAdapter::getFiltersMenu"); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | template <typename DatabaseHandler> |
| 662 | void |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 663 | QueryAdapter<DatabaseHandler>::signData(ndn::Data& data) |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 664 | { |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 665 | if (m_signingId.empty()) |
| 666 | m_keyChain->sign(data); |
| 667 | else { |
| 668 | ndn::Name keyName = m_keyChain->getDefaultKeyNameForIdentity(m_signingId); |
| 669 | ndn::Name certName = m_keyChain->getDefaultCertificateNameForKey(keyName); |
| 670 | m_keyChain->sign(data, certName); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 671 | } |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | template <typename DatabaseHandler> |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 675 | ndn::Name |
| 676 | QueryAdapter<DatabaseHandler>::getQueryResultsName(std::shared_ptr<const ndn::Interest> interest, |
| 677 | const ndn::Name::Component& version) |
| 678 | { |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 679 | // use generic name, instead of specific one |
| 680 | ndn::Name queryResultName = interest->getName(); |
| 681 | queryResultName.append(version); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 682 | return queryResultName; |
| 683 | } |
| 684 | |
| 685 | template <typename DatabaseHandler> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 686 | std::shared_ptr<ndn::Data> |
| 687 | QueryAdapter<DatabaseHandler>::makeAckData(std::shared_ptr<const ndn::Interest> interest, |
| 688 | const ndn::Name::Component& version) |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 689 | { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 690 | std::string queryResultNameStr(getQueryResultsName(interest, version).toUri()); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 691 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 692 | std::shared_ptr<ndn::Data> ack = std::make_shared<ndn::Data>(interest->getName()); |
| 693 | ack->setContent(reinterpret_cast<const uint8_t*>(queryResultNameStr.c_str()), |
| 694 | queryResultNameStr.length()); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 695 | ack->setFreshnessPeriod(ndn::time::milliseconds(10000)); |
| 696 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 697 | signData(*ack); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 698 | |
| 699 | _LOG_DEBUG("Make ACK : " << queryResultNameStr); |
| 700 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 701 | return ack; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | template <typename DatabaseHandler> |
| 705 | void |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 706 | QueryAdapter<DatabaseHandler>::sendNack(const ndn::Name& dataPrefix) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 707 | { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 708 | uint64_t segmentNo = 0; |
| 709 | |
| 710 | std::shared_ptr<ndn::Data> nack = |
| 711 | std::make_shared<ndn::Data>(ndn::Name(dataPrefix).appendSegment(segmentNo)); |
| 712 | nack->setFreshnessPeriod(ndn::time::milliseconds(10000)); |
| 713 | nack->setFinalBlockId(ndn::Name::Component::fromSegment(segmentNo)); |
| 714 | |
| 715 | signData(*nack); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 716 | |
| 717 | _LOG_DEBUG("Send Nack: " << ndn::Name(dataPrefix).appendSegment(segmentNo)); |
| 718 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 719 | m_mutex.lock(); |
| 720 | m_cache.insert(*nack); |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 721 | m_face->put(*nack); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 722 | m_mutex.unlock(); |
| 723 | } |
| 724 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 725 | template <typename DatabaseHandler> |
| 726 | bool |
| 727 | QueryAdapter<DatabaseHandler>::json2AutocompletionSql(std::stringstream& sqlQuery, |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 728 | Json::Value& jsonValue, |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 729 | bool& lastComponent, |
| 730 | std::stringstream& fieldName) |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 731 | { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 732 | _LOG_DEBUG(">> QueryAdapter::json2AutocompletionSql"); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 733 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 734 | _LOG_DEBUG(jsonValue.toStyledString()); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 735 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 736 | if (jsonValue.type() != Json::objectValue) { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 737 | return false; |
| 738 | } |
| 739 | |
| 740 | std::string typedString; |
| 741 | // get the string in the jsonValue |
| 742 | for (Json::Value::iterator iter = jsonValue.begin(); iter != jsonValue.end(); ++iter) |
| 743 | { |
| 744 | Json::Value key = iter.key(); |
| 745 | Json::Value value = (*iter); |
| 746 | |
| 747 | if (key == Json::nullValue || value == Json::nullValue) { |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 748 | _LOG_ERROR("Null key or value in JsonValue"); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 749 | return false; |
| 750 | } |
| 751 | |
| 752 | // cannot convert to string |
| 753 | if (!key.isConvertibleTo(Json::stringValue) || !value.isConvertibleTo(Json::stringValue)) { |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 754 | _LOG_ERROR("Malformed JsonQuery string"); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 755 | return false; |
| 756 | } |
| 757 | |
| 758 | if (key.asString().compare("?") == 0) { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 759 | typedString = value.asString(); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 760 | // since the front end triggers the autocompletion when users typed '/', |
| 761 | // there must be a '/' at the end, and the first char must be '/' |
| 762 | if (typedString.at(typedString.length() - 1) != '/' || typedString.find("/") != 0) |
| 763 | return false; |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | // 1. get the expected column number by parsing the typedString, so we can get the filed name |
| 769 | size_t pos = 0; |
| 770 | size_t start = 1; // start from the 1st char which is not '/' |
| 771 | size_t count = 0; // also the name to query for |
| 772 | std::string token; |
| 773 | std::string delimiter = "/"; |
| 774 | std::map<std::string, std::string> typedComponents; |
| 775 | while ((pos = typedString.find(delimiter, start)) != std::string::npos) { |
| 776 | token = typedString.substr(start, pos - start); |
| 777 | if (count >= m_nameFields.size() - 1) { |
| 778 | return false; |
| 779 | } |
| 780 | |
| 781 | // add column name and value (token) into map |
| 782 | typedComponents.insert(std::pair<std::string, std::string>(m_nameFields[count], token)); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 783 | count++; |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 784 | start = pos + 1; |
| 785 | } |
| 786 | |
| 787 | // 2. generate the sql string (append what appears in the typed string, like activity='xxx'), |
| 788 | // return true |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 789 | if (count == m_nameFields.size() - 1) |
| 790 | lastComponent = true; // indicate this query is to query the last component |
| 791 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 792 | bool more = false; |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 793 | |
| 794 | fieldName << m_nameFields[count]; |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 795 | for (std::map<std::string, std::string>::iterator it = typedComponents.begin(); |
| 796 | it != typedComponents.end(); ++it) { |
| 797 | if (more) |
| 798 | sqlQuery << " AND"; |
| 799 | else |
| 800 | sqlQuery << " WHERE"; |
| 801 | |
| 802 | sqlQuery << " " << it->first << "='" << it->second << "'"; |
| 803 | |
| 804 | more = true; |
| 805 | } |
| 806 | sqlQuery << ";"; |
| 807 | return true; |
| 808 | } |
| 809 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 810 | template <typename databasehandler> |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 811 | bool |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 812 | QueryAdapter<databasehandler>::doPrefixBasedSearch(Json::Value& jsonValue, |
| 813 | std::vector<std::pair<std::string, std::string>>& typedComponents) |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 814 | { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 815 | _LOG_DEBUG(">> QueryAdapter::doPrefixBasedSearch"); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 816 | |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 817 | if (jsonValue.type() != Json::objectValue) { |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 818 | return false; |
| 819 | } |
| 820 | |
| 821 | std::string typedString; |
| 822 | // get the string in the jsonValue |
| 823 | for (Json::Value::iterator iter = jsonValue.begin(); iter != jsonValue.end(); ++iter) |
| 824 | { |
| 825 | Json::Value key = iter.key(); |
| 826 | Json::Value value = (*iter); |
| 827 | |
| 828 | if (key == Json::nullValue || value == Json::nullValue) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 829 | _LOG_ERROR("null key or value in jsonValue"); |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 830 | return false; |
| 831 | } |
| 832 | |
| 833 | // cannot convert to string |
| 834 | if (!key.isConvertibleTo(Json::stringValue) || !value.isConvertibleTo(Json::stringValue)) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 835 | _LOG_ERROR("malformed jsonquery string"); |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 836 | return false; |
| 837 | } |
| 838 | |
| 839 | if (key.asString().compare("??") == 0) { |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 840 | typedString = value.asString(); |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 841 | if (typedString.empty() || typedString.find("/") != 0) |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 842 | return false; |
| 843 | break; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | // 1. get the expected column number by parsing the typedString, so we can get the filed name |
| 848 | size_t pos = 0; |
| 849 | size_t start = 1; // start from the 1st char which is not '/' |
| 850 | size_t count = 0; // also the name to query for |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 851 | size_t typedStringlen = typedString.length(); |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 852 | std::string token; |
| 853 | std::string delimiter = "/"; |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 854 | |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 855 | while ((pos = typedString.find(delimiter, start)) != std::string::npos) { |
| 856 | token = typedString.substr(start, pos - start); |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 857 | if (count >= m_nameFields.size()) { |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 858 | return false; |
| 859 | } |
| 860 | |
| 861 | // add column name and value (token) into map |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 862 | typedComponents.push_back(std::make_pair(m_nameFields[count], token)); |
| 863 | |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 864 | count++; |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 865 | start = pos + 1; |
| 866 | } |
| 867 | |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 868 | // we may have a component after the last "/" |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 869 | if (start < typedStringlen) { |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 870 | typedComponents.push_back(std::make_pair(m_nameFields[count], |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 871 | typedString.substr(start, typedStringlen - start))); |
Chengyu Fan | 4d5fbd2 | 2015-09-18 14:34:08 -0600 | [diff] [blame] | 872 | } |
| 873 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 874 | return true; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 875 | } |
| 876 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 877 | |
| 878 | template <typename databasehandler> |
| 879 | bool |
| 880 | QueryAdapter<databasehandler>::doFilterBasedSearch(Json::Value& jsonValue, |
| 881 | std::vector<std::pair<std::string, std::string>>& typedComponents) |
| 882 | { |
| 883 | _LOG_DEBUG(">> QueryAdapter::doFilterBasedSearch"); |
| 884 | |
| 885 | if (jsonValue.type() != Json::objectValue) { |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | for (Json::Value::iterator iter = jsonValue.begin(); iter != jsonValue.end(); ++iter) |
| 890 | { |
| 891 | Json::Value key = iter.key(); |
| 892 | Json::Value value = (*iter); |
| 893 | |
| 894 | if (key == Json::nullValue || value == Json::nullValue) { |
| 895 | _LOG_ERROR("null key or value in jsonValue"); |
| 896 | return false; |
| 897 | } |
| 898 | |
| 899 | // cannot convert to string |
| 900 | if (!key.isConvertibleTo(Json::stringValue) || !value.isConvertibleTo(Json::stringValue)) { |
| 901 | _LOG_ERROR("malformed jsonQuery string"); |
| 902 | return false; |
| 903 | } |
| 904 | |
| 905 | if (key.asString().compare("?") == 0 || key.asString().compare("??") == 0) { |
| 906 | continue; |
| 907 | } |
| 908 | |
| 909 | _LOG_DEBUG(key.asString() << " " << value.asString()); |
| 910 | typedComponents.push_back(std::make_pair(key.asString(), value.asString())); |
| 911 | } |
| 912 | |
| 913 | return true; |
| 914 | } |
| 915 | |
| 916 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 917 | template <typename DatabaseHandler> |
| 918 | void |
| 919 | QueryAdapter<DatabaseHandler>::runJsonQuery(std::shared_ptr<const ndn::Interest> interest) |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 920 | { |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 921 | _LOG_DEBUG(">> QueryAdapter::runJsonQuery"); |
| 922 | |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 923 | // 1) Strip the prefix off the ndn::Interest's ndn::Name |
| 924 | // +1 to grab JSON component after "query" component |
Alison Craig | 1aced7d | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 925 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 926 | ndn::Name::Component jsonStr = interest->getName()[m_prefix.size()+1]; |
| 927 | // This one cannot parse the JsonQuery correctly, and should be moved to runJsonQuery |
| 928 | const std::string jsonQuery(reinterpret_cast<const char*>(jsonStr.value()), jsonStr.value_size()); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 929 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 930 | if (jsonQuery.length() <= 0) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 931 | // no JSON query, send Nack |
| 932 | sendNack(interest->getName()); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 933 | return; |
| 934 | } |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 935 | |
| 936 | // the version should be replaced with ChronoSync state digest |
| 937 | ndn::name::Component version; |
| 938 | |
| 939 | if(m_socket != nullptr) { |
| 940 | const ndn::ConstBufferPtr digestPtr = m_socket->getRootDigest(); |
| 941 | std::string digestStr = ndn::toHex(digestPtr->buf(), digestPtr->size()); |
Chengyu Fan | 36dae3a | 2015-11-02 22:39:24 -0700 | [diff] [blame] | 942 | _LOG_DEBUG("Original digest " << m_chronosyncDigest); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 943 | _LOG_DEBUG("New digest : " << digestStr); |
| 944 | // if the m_chronosyncDigest and the rootdigest are not equal |
| 945 | if (digestStr != m_chronosyncDigest) { |
| 946 | // (1) update chronosyncDigest |
| 947 | // (2) clear all staled ACK data |
| 948 | m_mutex.lock(); |
| 949 | m_chronosyncDigest = digestStr; |
| 950 | m_activeQueryToFirstResponse.erase(ndn::Name("/")); |
| 951 | m_mutex.unlock(); |
| 952 | _LOG_DEBUG("Change digest to " << m_chronosyncDigest); |
| 953 | } |
| 954 | version = ndn::name::Component::fromEscapedString(digestStr); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 955 | } |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 956 | else { |
| 957 | version = ndn::name::Component::fromEscapedString(m_chronosyncDigest); |
| 958 | } |
| 959 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 960 | // 2) From the remainder of the ndn::Interest's ndn::Name, get the JSON out |
| 961 | Json::Value parsedFromString; |
| 962 | Json::Reader reader; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 963 | if (!reader.parse(jsonQuery, parsedFromString)) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 964 | // json object is broken |
| 965 | sendNack(interest->getName()); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 966 | _LOG_ERROR("Cannot parse the JsonQuery"); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 967 | return; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 968 | } |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 969 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 970 | // 3) Convert the JSON Query into a MySQL one |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 971 | ndn::Name segmentPrefix(getQueryResultsName(interest, version)); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 972 | _LOG_DEBUG("segmentPrefix :" << segmentPrefix); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 973 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 974 | Json::Value tmp; |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 975 | std::vector<std::pair<std::string, std::string>> typedComponents; |
| 976 | |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 977 | // expect the autocomplete and the component-based query are separate |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 978 | // if Json::Value contains ? as key, is autocompletion |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 979 | if (parsedFromString.get("?", tmp) != tmp) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 980 | bool lastComponent = false; |
| 981 | std::stringstream sqlQuery, fieldName; |
| 982 | |
| 983 | // must generate the sql string for autocomple, the selected column is changing |
| 984 | if (!json2AutocompletionSql(sqlQuery, parsedFromString, lastComponent, fieldName)) { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 985 | sendNack(segmentPrefix); |
| 986 | return; |
| 987 | } |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 988 | prepareSegmentsBySqlString(segmentPrefix, sqlQuery.str(), lastComponent, fieldName.str()); |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 989 | } |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 990 | else if (parsedFromString.get("??", tmp) != tmp) { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 991 | if (!doPrefixBasedSearch(parsedFromString, typedComponents)) { |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 992 | sendNack(segmentPrefix); |
| 993 | return; |
| 994 | } |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 995 | prepareSegmentsByParams(typedComponents, segmentPrefix); |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 996 | } |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 997 | else { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 998 | if (!doFilterBasedSearch(parsedFromString, typedComponents)) { |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 999 | sendNack(segmentPrefix); |
| 1000 | return; |
| 1001 | } |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1002 | prepareSegmentsByParams(typedComponents, segmentPrefix); |
| 1003 | } |
| 1004 | |
| 1005 | } |
| 1006 | |
| 1007 | template <typename databasehandler> |
| 1008 | void |
| 1009 | QueryAdapter<databasehandler>:: |
| 1010 | prepareSegmentsByParams(std::vector<std::pair<std::string, std::string>>& queryParams, |
| 1011 | const ndn::Name& segmentprefix) |
| 1012 | { |
| 1013 | } |
| 1014 | |
| 1015 | template <> |
| 1016 | void |
| 1017 | QueryAdapter<ConnectionPool_T>:: |
| 1018 | prepareSegmentsByParams(std::vector<std::pair<std::string, std::string>>& queryParams, |
| 1019 | const ndn::Name& segmentPrefix) |
| 1020 | { |
| 1021 | _LOG_DEBUG(">> QueryAdapter::prepareSegmentsByParams"); |
| 1022 | |
| 1023 | // the prepared_statement cannot improve the performance, but can simplify the code |
| 1024 | Connection_T conn = ConnectionPool_getConnection(*m_dbConnPool); |
| 1025 | if (!conn) { |
| 1026 | // do not answer for this request due to lack of connections, request will come back later |
| 1027 | _LOG_DEBUG("No available database connections"); |
| 1028 | return; |
| 1029 | } |
| 1030 | std::string getRecordNumSqlStr("SELECT count(name) FROM "); |
| 1031 | getRecordNumSqlStr += m_databaseTable; |
| 1032 | getRecordNumSqlStr += " WHERE "; |
| 1033 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1034 | getRecordNumSqlStr += m_nameFields[i]; |
| 1035 | getRecordNumSqlStr += " LIKE ?"; |
| 1036 | if (i != m_nameFields.size() - 1) { |
| 1037 | getRecordNumSqlStr += " AND "; |
| 1038 | } |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 1039 | } |
| 1040 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1041 | PreparedStatement_T ps4RecordNum = |
| 1042 | Connection_prepareStatement(conn, reinterpret_cast<const char*>(getRecordNumSqlStr.c_str()), getRecordNumSqlStr.size()); |
| 1043 | |
| 1044 | // before query, initialize all params for statement |
| 1045 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1046 | PreparedStatement_setString(ps4RecordNum, i + 1, "%"); |
| 1047 | } |
| 1048 | |
| 1049 | // reset params based on the query |
| 1050 | for (std::vector<std::pair<std::string, std::string>>::iterator it = queryParams.begin(); |
| 1051 | it != queryParams.end(); ++it) { |
| 1052 | // dictionary is faster |
| 1053 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1054 | if (it->first == m_nameFields[i]) { |
| 1055 | PreparedStatement_setString(ps4RecordNum, i + 1, it->second.c_str()); |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | ResultSet_T res4RecordNum; |
| 1061 | TRY { |
| 1062 | res4RecordNum = PreparedStatement_executeQuery(ps4RecordNum); |
| 1063 | } |
| 1064 | CATCH(SQLException) { |
| 1065 | _LOG_ERROR(Connection_getLastError(conn)); |
| 1066 | } |
| 1067 | END_TRY; |
| 1068 | |
| 1069 | uint64_t resultCount = 0; // use count sql to get |
| 1070 | |
| 1071 | // result for record number |
| 1072 | while (ResultSet_next(res4RecordNum)) { |
| 1073 | resultCount = ResultSet_getInt(res4RecordNum, 1); |
| 1074 | } |
| 1075 | |
| 1076 | // get name list statement |
| 1077 | std::string getNameListSqlStr("SELECT name FROM "); |
| 1078 | getNameListSqlStr += m_databaseTable; |
| 1079 | getNameListSqlStr += " WHERE "; |
| 1080 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1081 | getNameListSqlStr += m_nameFields[i]; |
| 1082 | getNameListSqlStr += " LIKE ?"; |
| 1083 | if (i != m_nameFields.size() - 1) { |
| 1084 | getNameListSqlStr += " AND "; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | PreparedStatement_T ps4Name = |
| 1089 | Connection_prepareStatement(conn, reinterpret_cast<const char*>(getNameListSqlStr.c_str()), getNameListSqlStr.size()); |
| 1090 | |
| 1091 | // before query, initialize all params for statement |
| 1092 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1093 | PreparedStatement_setString(ps4Name, i + 1, "%"); |
| 1094 | } |
| 1095 | |
| 1096 | // reset params based on the query |
| 1097 | for (std::vector<std::pair<std::string, std::string>>::iterator it = queryParams.begin(); |
| 1098 | it != queryParams.end(); ++it) { |
| 1099 | // dictionary is faster |
| 1100 | for (size_t i = 0; i < m_nameFields.size(); i++) { |
| 1101 | if (it->first == m_nameFields[i]) { |
| 1102 | PreparedStatement_setString(ps4Name, i + 1, it->second.c_str()); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | ResultSet_T res4Name; |
| 1108 | TRY { |
| 1109 | res4Name = PreparedStatement_executeQuery(ps4Name); |
| 1110 | } |
| 1111 | CATCH(SQLException) { |
| 1112 | _LOG_ERROR(Connection_getLastError(conn)); |
| 1113 | } |
| 1114 | END_TRY; |
| 1115 | |
| 1116 | generateSegments(res4Name, segmentPrefix, resultCount, false, false); |
| 1117 | |
| 1118 | Connection_close(conn); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | template <typename DatabaseHandler> |
| 1122 | void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1123 | QueryAdapter<DatabaseHandler>::generateSegments(ResultSet_T& res, |
| 1124 | const ndn::Name& segmentPrefix, |
| 1125 | int resultCount, |
| 1126 | bool autocomplete, |
| 1127 | bool lastComponent) |
| 1128 | { |
| 1129 | uint64_t segmentno = 0; |
| 1130 | Json::Value tmp; |
| 1131 | Json::Value resultjson; |
| 1132 | Json::FastWriter fastWriter; |
| 1133 | |
| 1134 | uint64_t viewstart = 0, viewend = 0; |
| 1135 | while (ResultSet_next(res)) { |
| 1136 | const char *name = ResultSet_getString(res, 1); |
| 1137 | tmp.append(name); |
| 1138 | const std::string tmpString = fastWriter.write(tmp); |
| 1139 | if (tmpString.length() > PAYLOAD_LIMIT) { |
| 1140 | std::shared_ptr<ndn::Data> data |
| 1141 | = makeReplyData(segmentPrefix, resultjson, segmentno, false, |
| 1142 | autocomplete, resultCount, viewstart, viewend, lastComponent); |
| 1143 | m_mutex.lock(); |
| 1144 | m_cache.insert(*data); |
| 1145 | m_face->put(*data); |
| 1146 | m_mutex.unlock(); |
| 1147 | tmp.clear(); |
| 1148 | resultjson.clear(); |
| 1149 | segmentno++; |
| 1150 | viewstart = viewend + 1; |
| 1151 | } |
| 1152 | resultjson.append(name); |
| 1153 | viewend++; |
| 1154 | } |
| 1155 | std::shared_ptr<ndn::Data> data |
| 1156 | = makeReplyData(segmentPrefix, resultjson, segmentno, true, |
| 1157 | autocomplete, resultCount, viewstart, viewend, lastComponent); |
| 1158 | m_mutex.lock(); |
| 1159 | m_cache.insert(*data); |
| 1160 | m_face->put(*data); |
| 1161 | m_mutex.unlock(); |
| 1162 | } |
| 1163 | |
| 1164 | template <typename DatabaseHandler> |
| 1165 | void |
| 1166 | QueryAdapter<DatabaseHandler>::prepareSegmentsBySqlString(const ndn::Name& segmentPrefix, |
| 1167 | const std::string& sqlString, |
| 1168 | bool lastComponent, |
| 1169 | const std::string& nameField) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1170 | { |
| 1171 | // empty |
| 1172 | } |
| 1173 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1174 | |
| 1175 | template <> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1176 | void |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1177 | QueryAdapter<ConnectionPool_T>::prepareSegmentsBySqlString(const ndn::Name& segmentPrefix, |
| 1178 | const std::string& sqlString, |
| 1179 | bool lastComponent, |
| 1180 | const std::string& nameField) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1181 | { |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1182 | _LOG_DEBUG(">> QueryAdapter::prepareSegmentsBySqlString"); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 1183 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 1184 | _LOG_DEBUG(sqlString); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 1185 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1186 | Connection_T conn = ConnectionPool_getConnection(*m_dbConnPool); |
| 1187 | if (!conn) { |
| 1188 | _LOG_DEBUG("No available database connections"); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1189 | return; |
| 1190 | } |
| 1191 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1192 | //// just for get the rwo count ... |
| 1193 | std::string getRecordNumSqlStr("SELECT COUNT( DISTINCT "); |
| 1194 | getRecordNumSqlStr += nameField; |
| 1195 | getRecordNumSqlStr += ") FROM "; |
| 1196 | getRecordNumSqlStr += m_databaseTable; |
| 1197 | getRecordNumSqlStr += sqlString; |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 1198 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1199 | ResultSet_T res4RecordNum; |
| 1200 | TRY { |
| 1201 | res4RecordNum = Connection_executeQuery(conn, reinterpret_cast<const char*>(getRecordNumSqlStr.c_str()), getRecordNumSqlStr.size()); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1202 | } |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1203 | CATCH(SQLException) { |
| 1204 | _LOG_ERROR(Connection_getLastError(conn)); |
| 1205 | } |
| 1206 | END_TRY; |
Chengyu Fan | 4639821 | 2015-08-11 11:23:13 -0600 | [diff] [blame] | 1207 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1208 | uint64_t resultCount = 0; |
| 1209 | while (ResultSet_next(res4RecordNum)) { |
| 1210 | resultCount = ResultSet_getInt(res4RecordNum, 1); |
| 1211 | } |
| 1212 | //// |
| 1213 | |
| 1214 | std::string getNextFieldsSqlStr("SELECT DISTINCT "); |
| 1215 | getNextFieldsSqlStr += nameField; |
| 1216 | getNextFieldsSqlStr += " FROM "; |
| 1217 | getNextFieldsSqlStr += m_databaseTable; |
| 1218 | getNextFieldsSqlStr += sqlString; |
| 1219 | |
| 1220 | ResultSet_T res4NextFields; |
| 1221 | TRY { |
| 1222 | res4NextFields = Connection_executeQuery(conn, reinterpret_cast<const char*>(getNextFieldsSqlStr.c_str()), getNextFieldsSqlStr.size()); |
| 1223 | } |
| 1224 | CATCH(SQLException) { |
| 1225 | _LOG_ERROR(Connection_getLastError(conn)); |
| 1226 | } |
| 1227 | END_TRY; |
| 1228 | |
| 1229 | generateSegments(res4NextFields, segmentPrefix, resultCount, true, lastComponent); |
| 1230 | |
| 1231 | Connection_close(conn); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | template <typename DatabaseHandler> |
| 1235 | std::shared_ptr<ndn::Data> |
| 1236 | QueryAdapter<DatabaseHandler>::makeReplyData(const ndn::Name& segmentPrefix, |
| 1237 | const Json::Value& value, |
| 1238 | uint64_t segmentNo, |
| 1239 | bool isFinalBlock, |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame] | 1240 | bool isAutocomplete, |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 1241 | uint64_t resultCount, |
| 1242 | uint64_t viewStart, |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 1243 | uint64_t viewEnd, |
| 1244 | bool lastComponent) |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1245 | { |
| 1246 | Json::Value entry; |
| 1247 | Json::FastWriter fastWriter; |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 1248 | |
| 1249 | entry["resultCount"] = Json::UInt64(resultCount);; |
| 1250 | entry["viewStart"] = Json::UInt64(viewStart); |
| 1251 | entry["viewEnd"] = Json::UInt64(viewEnd); |
| 1252 | |
Chengyu Fan | 3b9bb34 | 2015-09-21 10:53:37 -0600 | [diff] [blame] | 1253 | if (lastComponent) |
| 1254 | entry["lastComponent"] = Json::Value(true); |
| 1255 | |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame] | 1256 | _LOG_DEBUG("resultCount " << resultCount << "; " |
| 1257 | << "viewStart " << viewStart << "; " |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 1258 | << "viewEnd " << viewEnd); |
Chengyu Fan | f4c747a | 2015-08-18 13:56:01 -0600 | [diff] [blame] | 1259 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1260 | if (isAutocomplete) { |
| 1261 | entry["next"] = value; |
| 1262 | } else { |
| 1263 | entry["results"] = value; |
| 1264 | } |
| 1265 | const std::string jsonMessage = fastWriter.write(entry); |
| 1266 | const char* payload = jsonMessage.c_str(); |
| 1267 | size_t payloadLength = jsonMessage.size() + 1; |
| 1268 | ndn::Name segmentName(segmentPrefix); |
| 1269 | segmentName.appendSegment(segmentNo); |
| 1270 | |
| 1271 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(segmentName); |
| 1272 | data->setContent(reinterpret_cast<const uint8_t*>(payload), payloadLength); |
| 1273 | data->setFreshnessPeriod(ndn::time::milliseconds(10000)); |
| 1274 | |
| 1275 | if (isFinalBlock) { |
| 1276 | data->setFinalBlockId(ndn::Name::Component::fromSegment(segmentNo)); |
| 1277 | } |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 1278 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 1279 | _LOG_DEBUG(segmentName); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 1280 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 1281 | signData(*data); |
| 1282 | return data; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 1283 | } |
| 1284 | |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 1285 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 1286 | } // namespace query |
| 1287 | } // namespace atmos |
| 1288 | #endif //ATMOS_QUERY_QUERY_ADAPTER_HPP |