merge latest object store changes
This commit is contained in:
commit
148abd4b7b
|
@ -304,6 +304,8 @@ public:
|
||||||
bool set_link(size_t col, size_t row, size_t, size_t) { return mark_dirty(row, col); }
|
bool set_link(size_t col, size_t row, size_t, size_t) { return mark_dirty(row, col); }
|
||||||
bool set_null(size_t col, size_t row) { return mark_dirty(row, col); }
|
bool set_null(size_t col, size_t row) { return mark_dirty(row, col); }
|
||||||
bool nullify_link(size_t col, size_t row, size_t) { return mark_dirty(row, col); }
|
bool nullify_link(size_t col, size_t row, size_t) { return mark_dirty(row, col); }
|
||||||
|
bool set_int_unique(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); }
|
||||||
|
bool set_string_unique(size_t col, size_t row, StringData) { return mark_dirty(row, col); }
|
||||||
|
|
||||||
// Doesn't change any data
|
// Doesn't change any data
|
||||||
bool optimize_table() { return true; }
|
bool optimize_table() { return true; }
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#ifndef REALM_INDEX_SET_HPP
|
#ifndef REALM_INDEX_SET_HPP
|
||||||
#define REALM_INDEX_SET_HPP
|
#define REALM_INDEX_SET_HPP
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "list.hpp"
|
#include "list.hpp"
|
||||||
#import <stdexcept>
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace realm;
|
using namespace realm;
|
||||||
|
|
||||||
|
@ -26,40 +27,40 @@ size_t List::size() {
|
||||||
return m_link_view->size();
|
return m_link_view->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Row List::get(size_t row_ndx) {
|
Row List::get(std::size_t row_ndx) {
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_valid_row(row_ndx);
|
verify_valid_row(row_ndx);
|
||||||
return m_link_view->get(row_ndx);
|
return m_link_view->get(row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::set(size_t row_ndx, size_t target_row_ndx) {
|
void List::set(std::size_t row_ndx, std::size_t target_row_ndx) {
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_in_tranaction();
|
verify_in_tranaction();
|
||||||
verify_valid_row(row_ndx);
|
verify_valid_row(row_ndx);
|
||||||
m_link_view->set(row_ndx, target_row_ndx);
|
m_link_view->set(row_ndx, target_row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::add(size_t target_row_ndx) {
|
void List::add(std::size_t target_row_ndx) {
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_in_tranaction();
|
verify_in_tranaction();
|
||||||
m_link_view->add(target_row_ndx);
|
m_link_view->add(target_row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::insert(size_t row_ndx, size_t target_row_ndx) {
|
void List::insert(std::size_t row_ndx, std::size_t target_row_ndx) {
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_in_tranaction();
|
verify_in_tranaction();
|
||||||
verify_valid_row(row_ndx, true);
|
verify_valid_row(row_ndx, true);
|
||||||
m_link_view->insert(row_ndx, target_row_ndx);
|
m_link_view->insert(row_ndx, target_row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::remove(size_t row_ndx) {
|
void List::remove(std::size_t row_ndx) {
|
||||||
verify_attached();
|
verify_attached();
|
||||||
verify_in_tranaction();
|
verify_in_tranaction();
|
||||||
verify_valid_row(row_ndx);
|
verify_valid_row(row_ndx);
|
||||||
m_link_view->remove(row_ndx);
|
m_link_view->remove(row_ndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::verify_valid_row(size_t row_ndx, bool insertion) {
|
void List::verify_valid_row(std::size_t row_ndx, bool insertion) {
|
||||||
size_t size = m_link_view->size();
|
size_t size = m_link_view->size();
|
||||||
if (row_ndx > size || (!insertion && row_ndx == size)) {
|
if (row_ndx > size || (!insertion && row_ndx == size)) {
|
||||||
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
|
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#ifndef REALM_LIST_HPP
|
#ifndef REALM_LIST_HPP
|
||||||
#define REALM_LIST_HPP
|
#define REALM_LIST_HPP
|
||||||
|
|
||||||
#import "shared_realm.hpp"
|
#include "shared_realm.hpp"
|
||||||
#import <realm/link_view.hpp>
|
#include <realm/link_view.hpp>
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
class List {
|
class List {
|
||||||
|
@ -31,8 +31,8 @@ namespace realm {
|
||||||
SharedRealm realm() { return m_realm; }
|
SharedRealm realm() { return m_realm; }
|
||||||
|
|
||||||
size_t size();
|
size_t size();
|
||||||
Row get(size_t row_ndx);
|
Row get(std::size_t row_ndx);
|
||||||
void set(size_t row_ndx, size_t target_row_ndx);
|
void set(std::size_t row_ndx, std::size_t target_row_ndx);
|
||||||
|
|
||||||
void add(size_t target_row_ndx);
|
void add(size_t target_row_ndx);
|
||||||
void remove(size_t list_ndx);
|
void remove(size_t list_ndx);
|
||||||
|
@ -47,7 +47,7 @@ namespace realm {
|
||||||
template<typename ValueType, typename ContextType>
|
template<typename ValueType, typename ContextType>
|
||||||
void set(ContextType ctx, ValueType value, size_t list_ndx);
|
void set(ContextType ctx, ValueType value, size_t list_ndx);
|
||||||
|
|
||||||
void verify_valid_row(size_t row_ndx, bool insertion = false);
|
void verify_valid_row(std::size_t row_ndx, bool insertion = false);
|
||||||
void verify_attached();
|
void verify_attached();
|
||||||
void verify_in_tranaction();
|
void verify_in_tranaction();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
/* Copyright 2015 Realm Inc - All Rights Reserved
|
////////////////////////////////////////////////////////////////////////////
|
||||||
* Proprietary and Confidential
|
//
|
||||||
*/
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "results.hpp"
|
#include "results.hpp"
|
||||||
|
|
||||||
|
@ -107,9 +121,8 @@ util::Optional<RowExpr> Results::first()
|
||||||
case Mode::Table:
|
case Mode::Table:
|
||||||
return m_table->size() == 0 ? util::none : util::make_optional(m_table->front());
|
return m_table->size() == 0 ? util::none : util::make_optional(m_table->front());
|
||||||
case Mode::Query:
|
case Mode::Query:
|
||||||
update_tableview();
|
|
||||||
REALM_FALLTHROUGH;
|
|
||||||
case Mode::TableView:
|
case Mode::TableView:
|
||||||
|
update_tableview();
|
||||||
return m_table_view.size() == 0 ? util::none : util::make_optional(m_table_view.front());
|
return m_table_view.size() == 0 ? util::none : util::make_optional(m_table_view.front());
|
||||||
}
|
}
|
||||||
REALM_UNREACHABLE();
|
REALM_UNREACHABLE();
|
||||||
|
@ -124,9 +137,8 @@ util::Optional<RowExpr> Results::last()
|
||||||
case Mode::Table:
|
case Mode::Table:
|
||||||
return m_table->size() == 0 ? util::none : util::make_optional(m_table->back());
|
return m_table->size() == 0 ? util::none : util::make_optional(m_table->back());
|
||||||
case Mode::Query:
|
case Mode::Query:
|
||||||
update_tableview();
|
|
||||||
REALM_FALLTHROUGH;
|
|
||||||
case Mode::TableView:
|
case Mode::TableView:
|
||||||
|
update_tableview();
|
||||||
return m_table_view.size() == 0 ? util::none : util::make_optional(m_table_view.back());
|
return m_table_view.size() == 0 ? util::none : util::make_optional(m_table_view.back());
|
||||||
}
|
}
|
||||||
REALM_UNREACHABLE();
|
REALM_UNREACHABLE();
|
||||||
|
@ -159,9 +171,9 @@ size_t Results::index_of(Row const& row)
|
||||||
throw DetatchedAccessorException{};
|
throw DetatchedAccessorException{};
|
||||||
}
|
}
|
||||||
if (m_table && row.get_table() != m_table) {
|
if (m_table && row.get_table() != m_table) {
|
||||||
throw IncorrectTableException(object_schema.name,
|
throw IncorrectTableException{
|
||||||
ObjectStore::object_type_for_table_name(row.get_table()->get_name()),
|
ObjectStore::object_type_for_table_name(m_table->get_name()),
|
||||||
"Attempting to get the index of a Row of the wrong type");
|
ObjectStore::object_type_for_table_name(row.get_table()->get_name())};
|
||||||
}
|
}
|
||||||
return index_of(row.get_index());
|
return index_of(row.get_index());
|
||||||
}
|
}
|
||||||
|
@ -276,7 +288,7 @@ void Results::clear()
|
||||||
case Mode::TableView:
|
case Mode::TableView:
|
||||||
validate_write();
|
validate_write();
|
||||||
update_tableview();
|
update_tableview();
|
||||||
m_table_view.clear();
|
m_table_view.clear(RemoveMode::unordered);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,6 +323,11 @@ TableView Results::get_tableview()
|
||||||
REALM_UNREACHABLE();
|
REALM_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringData Results::get_object_type() const noexcept
|
||||||
|
{
|
||||||
|
return ObjectStore::object_type_for_table_name(m_table->get_name());
|
||||||
|
}
|
||||||
|
|
||||||
Results Results::sort(realm::SortOrder&& sort) const
|
Results Results::sort(realm::SortOrder&& sort) const
|
||||||
{
|
{
|
||||||
return Results(m_realm, object_schema, get_query(), std::move(sort));
|
return Results(m_realm, object_schema, get_query(), std::move(sort));
|
||||||
|
@ -321,8 +338,8 @@ Results Results::filter(Query&& q) const
|
||||||
return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort());
|
return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort());
|
||||||
}
|
}
|
||||||
|
|
||||||
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) :
|
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) {
|
||||||
column_index(column), column_name(table->get_column_name(column)), column_type(table->get_column_type(column)),
|
column_index = column;
|
||||||
std::runtime_error((std::string)"Operation not supported on '" + table->get_column_name(column).data() + "' columns")
|
column_name = table->get_column_name(column);
|
||||||
{
|
column_type = table->get_column_type(column);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
/* Copyright 2015 Realm Inc - All Rights Reserved
|
////////////////////////////////////////////////////////////////////////////
|
||||||
* Proprietary and Confidential
|
//
|
||||||
*/
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef REALM_RESULTS_HPP
|
#ifndef REALM_RESULTS_HPP
|
||||||
#define REALM_RESULTS_HPP
|
#define REALM_RESULTS_HPP
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#ifndef REALM_SCHEMA_HPP
|
#ifndef REALM_SCHEMA_HPP
|
||||||
#define REALM_SCHEMA_HPP
|
#define REALM_SCHEMA_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
|
|
|
@ -38,6 +38,7 @@ Realm::Config::Config(const Config& c)
|
||||||
, read_only(c.read_only)
|
, read_only(c.read_only)
|
||||||
, in_memory(c.in_memory)
|
, in_memory(c.in_memory)
|
||||||
, cache(c.cache)
|
, cache(c.cache)
|
||||||
|
, disable_format_upgrade(c.disable_format_upgrade)
|
||||||
, encryption_key(c.encryption_key)
|
, encryption_key(c.encryption_key)
|
||||||
, schema_version(c.schema_version)
|
, schema_version(c.schema_version)
|
||||||
, migration_function(c.migration_function)
|
, migration_function(c.migration_function)
|
||||||
|
@ -71,7 +72,7 @@ Realm::Realm(Config config)
|
||||||
m_history = realm::make_client_history(m_config.path, m_config.encryption_key.data());
|
m_history = realm::make_client_history(m_config.path, m_config.encryption_key.data());
|
||||||
SharedGroup::DurabilityLevel durability = m_config.in_memory ? SharedGroup::durability_MemOnly :
|
SharedGroup::DurabilityLevel durability = m_config.in_memory ? SharedGroup::durability_MemOnly :
|
||||||
SharedGroup::durability_Full;
|
SharedGroup::durability_Full;
|
||||||
m_shared_group = std::make_unique<SharedGroup>(*m_history, durability, m_config.encryption_key.data());
|
m_shared_group = std::make_unique<SharedGroup>(*m_history, durability, m_config.encryption_key.data(), !m_config.disable_format_upgrade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (util::File::PermissionDenied const& ex) {
|
catch (util::File::PermissionDenied const& ex) {
|
||||||
|
@ -92,6 +93,11 @@ Realm::Realm(Config config)
|
||||||
"Realm file is currently open in another process "
|
"Realm file is currently open in another process "
|
||||||
"which cannot share access with this process. All processes sharing a single file must be the same architecture.");
|
"which cannot share access with this process. All processes sharing a single file must be the same architecture.");
|
||||||
}
|
}
|
||||||
|
catch (FileFormatUpgradeRequired const& ex) {
|
||||||
|
throw RealmFileException(RealmFileException::Kind::FormatUpgradeRequired, m_config.path,
|
||||||
|
"The Realm file format must be allowed to be upgraded "
|
||||||
|
"in order to proceed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Realm::~Realm() {
|
Realm::~Realm() {
|
||||||
|
@ -171,6 +177,13 @@ SharedRealm Realm::get_shared_realm(Config config)
|
||||||
else {
|
else {
|
||||||
realm->update_schema(std::move(target_schema), target_schema_version);
|
realm->update_schema(std::move(target_schema), target_schema_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!realm->m_config.read_only) {
|
||||||
|
// End the read transaction created to validation/update the
|
||||||
|
// schema to avoid pinning the version even if the user never
|
||||||
|
// actually reads data
|
||||||
|
realm->invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
#ifndef REALM_REALM_HPP
|
#ifndef REALM_REALM_HPP
|
||||||
#define REALM_REALM_HPP
|
#define REALM_REALM_HPP
|
||||||
|
|
||||||
|
#include "object_store.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "object_store.hpp"
|
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
class ClientHistory;
|
class ClientHistory;
|
||||||
class Realm;
|
class Realm;
|
||||||
|
@ -48,6 +49,7 @@ namespace realm {
|
||||||
bool read_only = false;
|
bool read_only = false;
|
||||||
bool in_memory = false;
|
bool in_memory = false;
|
||||||
bool cache = true;
|
bool cache = true;
|
||||||
|
bool disable_format_upgrade = false;
|
||||||
std::vector<char> encryption_key;
|
std::vector<char> encryption_key;
|
||||||
|
|
||||||
std::unique_ptr<const Schema> schema;
|
std::unique_ptr<const Schema> schema;
|
||||||
|
@ -88,6 +90,7 @@ namespace realm {
|
||||||
void commit_transaction();
|
void commit_transaction();
|
||||||
void cancel_transaction();
|
void cancel_transaction();
|
||||||
bool is_in_transaction() const { return m_in_transaction; }
|
bool is_in_transaction() const { return m_in_transaction; }
|
||||||
|
bool is_in_read_transaction() const { return !!m_group; }
|
||||||
|
|
||||||
bool refresh();
|
bool refresh();
|
||||||
void set_auto_refresh(bool auto_refresh) { m_auto_refresh = auto_refresh; }
|
void set_auto_refresh(bool auto_refresh) { m_auto_refresh = auto_refresh; }
|
||||||
|
@ -161,6 +164,8 @@ namespace realm {
|
||||||
process which cannot share with the current process due to an
|
process which cannot share with the current process due to an
|
||||||
architecture mismatch. */
|
architecture mismatch. */
|
||||||
IncompatibleLockFile,
|
IncompatibleLockFile,
|
||||||
|
/** Thrown if the file needs to be upgraded to a new format, but upgrades have been explicitly disabled. */
|
||||||
|
FormatUpgradeRequired,
|
||||||
};
|
};
|
||||||
RealmFileException(Kind kind, std::string path, std::string message) :
|
RealmFileException(Kind kind, std::string path, std::string message) :
|
||||||
std::runtime_error(std::move(message)), m_kind(kind), m_path(std::move(path)) {}
|
std::runtime_error(std::move(message)), m_kind(kind), m_path(std::move(path)) {}
|
||||||
|
|
Loading…
Reference in New Issue