public:
~ContextStoreSideGate();
- int insert(const std::string& columns, std::vector<Tuple*>& tuples);
+ int insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& tuples);
static ContextStoreSideGate getUserStore(const std::string& uri);
static ContextStoreSideGate getSystemStore(const std::string& uri);
{
}
-int ContextStore::insert(const std::string& columns, Tuple* record)
+int ContextStore::insert(const std::string& columns, std::shared_ptr<Tuple> record)
{
return E_SUPPORT;
}
-int ContextStore::insert(const std::string& columns, std::vector<Tuple*>& records)
+int ContextStore::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records)
{
return E_SUPPORT;
}
-int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records)
+int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records)
{
return E_SUPPORT;
}
public:
virtual ~ContextStore();
- virtual int insert(const std::string& columns, Tuple* record);
- virtual int insert(const std::string& columns, std::vector<Tuple*>& records);
- virtual int retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records);
+ virtual int insert(const std::string& columns, std::shared_ptr<Tuple> record);
+ virtual int insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records);
+ virtual int retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records);
virtual int remove(const std::string& selection);
DataType getColumnType(const std::string& columnName);
return E_NONE;
}
-int PlatformManagedStore::insert(const std::string& columns, Tuple* record)
+int PlatformManagedStore::insert(const std::string& columns, std::shared_ptr<Tuple> record)
{
if (columns.empty() || record == NULL) {
- delete record;
return E_PARAM;
}
return __proxy->call(METHOD_INSERT, param);
}
-int PlatformManagedStore::insert(const std::string& columns, std::vector<Tuple*>& records)
+int PlatformManagedStore::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records)
{
if (columns.empty() || records.empty()) {
- for (auto& tuple : records) {
- delete tuple;
- }
records.clear();
return E_PARAM;
}
return __proxy->call(METHOD_INSERT, param);
}
-int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records)
+int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records)
{
- IF_FAIL_RETURN(!query.projection.empty(), E_PARAM);
+ IF_FAIL_RETURN(!query.projection.empty() && records, E_PARAM);
GVariant* param = g_variant_new("(ssssu)", __uri.c_str(),
query.projection.c_str(), query.selection.c_str(),
GVariant* vals = NULL;
g_variant_get(outParam, "(v)", &vals);
- records = Tuple::buildFrom(vals);
+ try {
+ *records = Tuple::buildFrom(vals);
+ } catch (std::exception& e) {
+ _E("Exception: %s", e.what());
+ error = E_FAILED;
+ }
g_variant_unref(outParam);
- return E_NONE;
+ return error;
}
int PlatformManagedStore::remove(const std::string& selection)
int init(const std::string& uri);
- int insert(const std::string& columns, Tuple* record);
- int insert(const std::string& columns, std::vector<Tuple*>& records);
- int retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records);
+ int insert(const std::string& columns, std::shared_ptr<Tuple> record);
+ int insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records);
+ int retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records);
int remove(const std::string& selection);
private:
typedef struct _ctx_store_cursor_s {
size_t index;
std::vector<std::string> keys;
- std::vector<Tuple*> tuples;
+ std::vector<std::shared_ptr<Tuple>> tuples;
} ctx_store_cursor_s;
static ContextStoreManager __storeManager;
IF_FAIL_RETURN(!columns.empty(), E_PARAM);
columns.pop_back();
- Tuple* tuple = builder.build();
- IF_FAIL_RETURN(tuple, E_FAILED);
-
- return store->proxy->insert(columns, tuple);
+ try {
+ auto tuple = builder.build();
+ return store->proxy->insert(columns, tuple);
+ } catch (std::exception& e) {
+ return E_FAILED;
+ }
}
EXPORT_API int ctx_store_lazy_insert(ctx_store_h store, ctx_store_record_h record)
ctx_store_cursor_s* csr = new(std::nothrow) ctx_store_cursor_s;
IF_FAIL_RETURN(csr, E_NO_MEM);
- std::vector<Tuple*> tuples;
+ std::vector<std::shared_ptr<Tuple>> tuples;
ContextStoreSearchQuery query(projection, selection, sort_order, limit);
- int error = store->proxy->retrieve(query, tuples);
+ int error = store->proxy->retrieve(query, &tuples);
if (error != E_NONE) {
delete csr;
return error;
{
IF_FAIL_RETURN(cursor, E_NONE);
- for (auto& tuple : cursor->tuples) {
- delete tuple;
- }
-
+ cursor->tuples.clear();
delete cursor;
return E_NONE;
{
}
-int ContextStoreSideGate::insert(const std::string& columns, std::vector<Tuple*>& tuples)
+int ContextStoreSideGate::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& tuples)
{
return E_SUPPORT;
}
if (!__queryChecker.validateProjection(cols))
throw static_cast<int>(E_PARAM);
- std::vector<Tuple*> tuples = Tuple::buildFrom(vals);
+ std::vector<std::shared_ptr<Tuple>> tuples = Tuple::buildFrom(vals);
if (tuples.empty()) {
throw static_cast<int>(E_PARAM);
}
if (!__queryChecker.validateSortOrder(sortOrder))
throw static_cast<int>(E_PARAM);
- std::vector<Tuple*> tuples;
+ std::vector<std::shared_ptr<Tuple>> tuples;
int error = store.retrieve(*this, projection, selection, sortOrder, limit, &tuples);
if (error != E_NONE)
throw error;
{
}
-int ContextStoreSideGate::insert(const std::string& columns, std::vector<Tuple*>& tuples)
+int ContextStoreSideGate::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& tuples)
{
//TODO: Switch to the thread-default mainloop, get the Store object, and insert.
return E_SUPPORT;
return metadata.columns;
}
-int Store::insert(ContextStoreClient& client, const std::string& columns, std::vector<Tuple*>& tuples)
+int Store::insert(ContextStoreClient& client, const std::string& columns, std::vector<std::shared_ptr<Tuple>>& tuples)
{
//TODO: handling owner's ID
//TODO: delete expired data
_D("Inserting %u tuples of (%s) to %s", tuples.size(), columns.c_str(), metadata.uri.c_str());
int error = __getDatabase().insert(metadata.uri, columns, tuples) ? E_NONE : E_PARAM;
- for (auto& tuple : tuples) {
- delete tuple;
- }
tuples.clear();
return error;
}
int Store::retrieve(ContextStoreClient& client,
const std::string& projection, const std::string& selection,
- const std::string& sortOrder, unsigned int limit, std::vector<Tuple*>* tuples)
+ const std::string& sortOrder, unsigned int limit, std::vector<std::shared_ptr<Tuple>>* tuples)
{
if (!__readable(client))
return E_ACCESS;
const std::string& getColumns();
- int insert(ContextStoreClient& client, const std::string& columns, std::vector<Tuple*>& tuples);
+ int insert(ContextStoreClient& client, const std::string& columns, std::vector<std::shared_ptr<Tuple>>& tuples);
int retrieve(ContextStoreClient& client,
const std::string& projection, const std::string& selection,
const std::string& sortOrder, unsigned int limit,
- std::vector<Tuple*>* tuples);
+ std::vector<std::shared_ptr<Tuple>>* tuples);
int remove(ContextStoreClient& client, const std::string selection);
" FROM ContextStoreSchema"
" WHERE uri='" + uri + "'";
- std::vector<Tuple*> tuples;
+ std::vector<std::shared_ptr<Tuple>> tuples;
if (!database.execute(query, COL_STRING COL_INT64 COL_INT64 COL_STRING COL_STRING, NULL, &tuples)) {
_E("DB search failed");
return NULL;
tuples[0]->getAt(3, &readPrivil);
tuples[0]->getAt(4, &writePrivil);
- delete tuples[0];
-
_D("URI: %s, Retention: %u, Limit: %u", uri.c_str(), static_cast<unsigned int>(retention), static_cast<unsigned int>(limit));
_D("Columns: %s", columns.c_str());
_D("Read: %s", readPrivil.c_str());