mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Resolve trivial differences with realm-cocoa
This commit is contained in:
parent
bdc8dbc5b2
commit
aaa811306e
@ -22,6 +22,7 @@
|
|||||||
#include "impl/external_commit_helper.hpp"
|
#include "impl/external_commit_helper.hpp"
|
||||||
#include "impl/transact_log_handler.hpp"
|
#include "impl/transact_log_handler.hpp"
|
||||||
#include "impl/weak_realm_notifier.hpp"
|
#include "impl/weak_realm_notifier.hpp"
|
||||||
|
#include "object_schema.hpp"
|
||||||
#include "object_store.hpp"
|
#include "object_store.hpp"
|
||||||
#include "schema.hpp"
|
#include "schema.hpp"
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "object_store.hpp"
|
#include "object_store.hpp"
|
||||||
|
|
||||||
|
#include "object_schema.hpp"
|
||||||
#include "schema.hpp"
|
#include "schema.hpp"
|
||||||
#include "util/format.hpp"
|
#include "util/format.hpp"
|
||||||
|
|
||||||
@ -507,7 +508,7 @@ bool ObjectStore::is_empty(const Group *group) {
|
|||||||
InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) :
|
InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) :
|
||||||
m_old_version(old_version), m_new_version(new_version)
|
m_old_version(old_version), m_new_version(new_version)
|
||||||
{
|
{
|
||||||
m_what = util::format("Provided schema version %1 is less than last set version %2.", old_version, new_version);
|
m_what = util::format("Provided schema version %1 is less than last set version %2.", new_version, old_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
|
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
|
||||||
@ -527,16 +528,16 @@ DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string
|
|||||||
SchemaValidationException::SchemaValidationException(std::vector<ObjectSchemaValidationException> const& errors)
|
SchemaValidationException::SchemaValidationException(std::vector<ObjectSchemaValidationException> const& errors)
|
||||||
: m_validation_errors(errors)
|
: m_validation_errors(errors)
|
||||||
{
|
{
|
||||||
m_what = "Schema validation failed due to the following errors: ";
|
m_what = "Schema validation failed due to the following errors:";
|
||||||
for (auto const& error : errors) {
|
for (auto const& error : errors) {
|
||||||
m_what += std::string("\n- ") + error.what();
|
m_what += std::string("\n- ") + error.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaMismatchException::SchemaMismatchException(std::vector<ObjectSchemaValidationException> const& errors) :
|
SchemaMismatchException::SchemaMismatchException(std::vector<ObjectSchemaValidationException> const& errors) :
|
||||||
m_validation_errors(errors)
|
m_validation_errors(errors)
|
||||||
{
|
{
|
||||||
m_what = "Migration is required due to the following errors: ";
|
m_what = "Migration is required due to the following errors:";
|
||||||
for (auto const& error : errors) {
|
for (auto const& error : errors) {
|
||||||
m_what += std::string("\n- ") + error.what();
|
m_what += std::string("\n- ") + error.what();
|
||||||
}
|
}
|
||||||
@ -546,7 +547,7 @@ PropertyTypeNotIndexableException::PropertyTypeNotIndexableException(std::string
|
|||||||
Property const& property)
|
Property const& property)
|
||||||
: ObjectSchemaPropertyException(object_type, property)
|
: ObjectSchemaPropertyException(object_type, property)
|
||||||
{
|
{
|
||||||
m_what = util::format("Can't index property %1.%2: indexing a property of type '%3' is currently not supported",
|
m_what = util::format("Can't index property %1.%2: indexing a property of type '%3' is currently not supported.",
|
||||||
object_type, property.name, string_for_property_type(property.type));
|
object_type, property.name, string_for_property_type(property.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +573,7 @@ InvalidNullabilityException::InvalidNullabilityException(std::string const& obje
|
|||||||
case PropertyType::Any:
|
case PropertyType::Any:
|
||||||
case PropertyType::Array:
|
case PropertyType::Array:
|
||||||
case PropertyType::LinkingObjects:
|
case PropertyType::LinkingObjects:
|
||||||
m_what = util::format("Property '%1' of type '%2' cannoy be nullable",
|
m_what = util::format("Property '%1' of type '%2' cannot be nullable.",
|
||||||
property.name, string_for_property_type(property.type));
|
property.name, string_for_property_type(property.type));
|
||||||
break;
|
break;
|
||||||
case PropertyType::Int:
|
case PropertyType::Int:
|
||||||
@ -599,17 +600,17 @@ MismatchedPropertiesException::MismatchedPropertiesException(std::string const&
|
|||||||
ObjectSchemaValidationException(object_type), m_old_property(old_property), m_new_property(new_property)
|
ObjectSchemaValidationException(object_type), m_old_property(old_property), m_new_property(new_property)
|
||||||
{
|
{
|
||||||
if (new_property.type != old_property.type) {
|
if (new_property.type != old_property.type) {
|
||||||
m_what = util::format("Property types for '%1' property doe not match. Old type '%2', new type '%3'",
|
m_what = util::format("Property types for '%1' property do not match. Old type '%2', new type '%3'.",
|
||||||
old_property.name,
|
old_property.name,
|
||||||
string_for_property_type(old_property.type),
|
string_for_property_type(old_property.type),
|
||||||
string_for_property_type(new_property.type));
|
string_for_property_type(new_property.type));
|
||||||
}
|
}
|
||||||
else if (new_property.object_type != old_property.object_type) {
|
else if (new_property.object_type != old_property.object_type) {
|
||||||
m_what = util::format("Target object type for property '%1' do not match. Old type '%2', new type '%3'",
|
m_what = util::format("Target object type for property '%1' do not match. Old type '%2', new type '%3'.",
|
||||||
old_property.name, old_property.object_type, new_property.object_type);
|
old_property.name, old_property.object_type, new_property.object_type);
|
||||||
}
|
}
|
||||||
else if (new_property.is_nullable != old_property.is_nullable) {
|
else if (new_property.is_nullable != old_property.is_nullable) {
|
||||||
m_what = util::format("Nullability for property '%1' has been changed from %2 to %3",
|
m_what = util::format("Nullability for property '%1' has been changed from %2 to %3.",
|
||||||
old_property.name,
|
old_property.name,
|
||||||
old_property.is_nullable, new_property.is_nullable);
|
old_property.is_nullable, new_property.is_nullable);
|
||||||
}
|
}
|
||||||
@ -645,17 +646,17 @@ InvalidLinkingObjectsPropertyException::InvalidLinkingObjectsPropertyException(T
|
|||||||
{
|
{
|
||||||
switch (error_type) {
|
switch (error_type) {
|
||||||
case Type::OriginPropertyDoesNotExist:
|
case Type::OriginPropertyDoesNotExist:
|
||||||
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' does not exist",
|
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' does not exist.",
|
||||||
property.object_type, property.link_origin_property_name,
|
property.object_type, property.link_origin_property_name,
|
||||||
object_type, property.name);
|
object_type, property.name);
|
||||||
break;
|
break;
|
||||||
case Type::OriginPropertyIsNotALink:
|
case Type::OriginPropertyIsNotALink:
|
||||||
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' is not a link",
|
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' is not a link.",
|
||||||
property.object_type, property.link_origin_property_name,
|
property.object_type, property.link_origin_property_name,
|
||||||
object_type, property.name);
|
object_type, property.name);
|
||||||
break;
|
break;
|
||||||
case Type::OriginPropertyInvalidLinkTarget:
|
case Type::OriginPropertyInvalidLinkTarget:
|
||||||
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' links to a different class",
|
m_what = util::format("Property '%1.%2' declared as origin of linking objects property '%3.%4' links to a different class.",
|
||||||
property.object_type, property.link_origin_property_name,
|
property.object_type, property.link_origin_property_name,
|
||||||
object_type, property.name);
|
object_type, property.name);
|
||||||
break;
|
break;
|
||||||
|
@ -19,17 +19,20 @@
|
|||||||
#ifndef REALM_OBJECT_STORE_HPP
|
#ifndef REALM_OBJECT_STORE_HPP
|
||||||
#define REALM_OBJECT_STORE_HPP
|
#define REALM_OBJECT_STORE_HPP
|
||||||
|
|
||||||
#include "schema.hpp"
|
|
||||||
#include "property.hpp"
|
#include "property.hpp"
|
||||||
|
|
||||||
#include <realm/table_ref.hpp>
|
#include <realm/table_ref.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
class Group;
|
class Group;
|
||||||
|
class ObjectSchema;
|
||||||
class ObjectSchemaValidationException;
|
class ObjectSchemaValidationException;
|
||||||
class Schema;
|
class Schema;
|
||||||
|
class StringData;
|
||||||
|
|
||||||
class ObjectStore {
|
class ObjectStore {
|
||||||
public:
|
public:
|
||||||
|
@ -94,6 +94,8 @@ namespace realm {
|
|||||||
return "object";
|
return "object";
|
||||||
case PropertyType::Array:
|
case PropertyType::Array:
|
||||||
return "array";
|
return "array";
|
||||||
|
case PropertyType::LinkingObjects:
|
||||||
|
return "linking objects";
|
||||||
#if __GNUC__
|
#if __GNUC__
|
||||||
default:
|
default:
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "impl/realm_coordinator.hpp"
|
#include "impl/realm_coordinator.hpp"
|
||||||
#include "impl/results_notifier.hpp"
|
#include "impl/results_notifier.hpp"
|
||||||
|
#include "object_schema.hpp"
|
||||||
#include "object_store.hpp"
|
#include "object_store.hpp"
|
||||||
#include "util/format.hpp"
|
#include "util/format.hpp"
|
||||||
|
|
||||||
@ -130,18 +131,16 @@ bool Results::is_valid() const
|
|||||||
{
|
{
|
||||||
if (m_realm)
|
if (m_realm)
|
||||||
m_realm->verify_thread();
|
m_realm->verify_thread();
|
||||||
|
|
||||||
if (m_table && !m_table->is_attached())
|
if (m_table && !m_table->is_attached())
|
||||||
return false;
|
return false;
|
||||||
if (m_mode == Mode::TableView && (!m_table_view.is_attached() || (m_live && m_table_view.depends_on_deleted_object())))
|
|
||||||
return false;
|
|
||||||
if (m_mode == Mode::LinkView && !m_link_view->is_attached())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Results::validate_read() const
|
void Results::validate_read() const
|
||||||
{
|
{
|
||||||
|
// is_valid ensures that we're on the correct thread.
|
||||||
if (!is_valid())
|
if (!is_valid())
|
||||||
throw InvalidatedException();
|
throw InvalidatedException();
|
||||||
}
|
}
|
||||||
@ -199,8 +198,8 @@ RowExpr Results::get(size_t row_ndx)
|
|||||||
break;
|
break;
|
||||||
case Mode::LinkView:
|
case Mode::LinkView:
|
||||||
if (update_linkview()) {
|
if (update_linkview()) {
|
||||||
if (row_ndx < m_link_view->size())
|
if (row_ndx < m_link_view->size())
|
||||||
return m_link_view->get(row_ndx);
|
return m_link_view->get(row_ndx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
REALM_FALLTHROUGH;
|
REALM_FALLTHROUGH;
|
||||||
|
@ -135,6 +135,9 @@ public:
|
|||||||
// Ideally this would not be public but it's needed for some KVO stuff
|
// Ideally this would not be public but it's needed for some KVO stuff
|
||||||
Mode get_mode() const { return m_mode; }
|
Mode get_mode() const { return m_mode; }
|
||||||
|
|
||||||
|
// Is this Results associated with a Realm that has not been invalidated?
|
||||||
|
bool is_valid() const;
|
||||||
|
|
||||||
// The Results object has been invalidated (due to the Realm being invalidated)
|
// The Results object has been invalidated (due to the Realm being invalidated)
|
||||||
// All non-noexcept functions can throw this
|
// All non-noexcept functions can throw this
|
||||||
struct InvalidatedException : public std::runtime_error {
|
struct InvalidatedException : public std::runtime_error {
|
||||||
@ -187,9 +190,6 @@ public:
|
|||||||
friend class _impl::ResultsNotifier;
|
friend class _impl::ResultsNotifier;
|
||||||
static void set_table_view(Results& results, TableView&& tv);
|
static void set_table_view(Results& results, TableView&& tv);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns if this Results class is still valid
|
|
||||||
bool is_valid() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedRealm m_realm;
|
SharedRealm m_realm;
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
#include "schema.hpp"
|
#include "schema.hpp"
|
||||||
|
|
||||||
|
#include "object_schema.hpp"
|
||||||
#include "object_store.hpp"
|
#include "object_store.hpp"
|
||||||
#include "property.hpp"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -118,10 +118,8 @@ void Schema::validate() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check indexable
|
// check indexable
|
||||||
if (prop.is_indexed) {
|
if (prop.is_indexed && !prop.is_indexable()) {
|
||||||
if (!prop.is_indexable()) {
|
exceptions.emplace_back(PropertyTypeNotIndexableException(object.name, prop));
|
||||||
exceptions.emplace_back(PropertyTypeNotIndexableException(object.name, prop));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
#ifndef REALM_SCHEMA_HPP
|
#ifndef REALM_SCHEMA_HPP
|
||||||
#define REALM_SCHEMA_HPP
|
#define REALM_SCHEMA_HPP
|
||||||
|
|
||||||
#include "object_schema.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
|
class ObjectSchema;
|
||||||
|
|
||||||
class Schema : private std::vector<ObjectSchema> {
|
class Schema : private std::vector<ObjectSchema> {
|
||||||
private:
|
private:
|
||||||
using base = std::vector<ObjectSchema>;
|
using base = std::vector<ObjectSchema>;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "binding_context.hpp"
|
#include "binding_context.hpp"
|
||||||
#include "impl/realm_coordinator.hpp"
|
#include "impl/realm_coordinator.hpp"
|
||||||
#include "impl/transact_log_handler.hpp"
|
#include "impl/transact_log_handler.hpp"
|
||||||
|
#include "object_schema.hpp"
|
||||||
#include "object_store.hpp"
|
#include "object_store.hpp"
|
||||||
#include "schema.hpp"
|
#include "schema.hpp"
|
||||||
#include "util/format.hpp"
|
#include "util/format.hpp"
|
||||||
@ -82,12 +83,12 @@ REALM_NOINLINE static void translate_file_exception(StringData path, bool read_o
|
|||||||
}
|
}
|
||||||
catch (util::File::Exists const& ex) {
|
catch (util::File::Exists const& ex) {
|
||||||
throw RealmFileException(RealmFileException::Kind::Exists, ex.get_path(),
|
throw RealmFileException(RealmFileException::Kind::Exists, ex.get_path(),
|
||||||
util::format("File at path '%1' already exists", ex.get_path()),
|
util::format("File at path '%1' already exists.", ex.get_path()),
|
||||||
ex.what());
|
ex.what());
|
||||||
}
|
}
|
||||||
catch (util::File::NotFound const& ex) {
|
catch (util::File::NotFound const& ex) {
|
||||||
throw RealmFileException(RealmFileException::Kind::NotFound, ex.get_path(),
|
throw RealmFileException(RealmFileException::Kind::NotFound, ex.get_path(),
|
||||||
util::format("Directory at path '%1' does not exists", ex.get_path()), ex.what());
|
util::format("Directory at path '%1' does not exist.", ex.get_path()), ex.what());
|
||||||
}
|
}
|
||||||
catch (util::File::AccessError const& ex) {
|
catch (util::File::AccessError const& ex) {
|
||||||
// Errors for `open()` include the path, but other errors don't. We
|
// Errors for `open()` include the path, but other errors don't. We
|
||||||
@ -100,7 +101,7 @@ REALM_NOINLINE static void translate_file_exception(StringData path, bool read_o
|
|||||||
underlying.replace(pos - 1, ex.get_path().size() + 2, "");
|
underlying.replace(pos - 1, ex.get_path().size() + 2, "");
|
||||||
}
|
}
|
||||||
throw RealmFileException(RealmFileException::Kind::AccessError, ex.get_path(),
|
throw RealmFileException(RealmFileException::Kind::AccessError, ex.get_path(),
|
||||||
util::format("Unable to open a realm at path '%1': %2", ex.get_path(), underlying), ex.what());
|
util::format("Unable to open a realm at path '%1': %2.", ex.get_path(), underlying), ex.what());
|
||||||
}
|
}
|
||||||
catch (IncompatibleLockFile const& ex) {
|
catch (IncompatibleLockFile const& ex) {
|
||||||
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, path,
|
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, path,
|
||||||
@ -314,7 +315,7 @@ void Realm::verify_thread() const
|
|||||||
void Realm::verify_in_write() const
|
void Realm::verify_in_write() const
|
||||||
{
|
{
|
||||||
if (!is_in_transaction()) {
|
if (!is_in_transaction()) {
|
||||||
throw InvalidTransactionException("Cannot modify persisted objects outside of a write transaction.");
|
throw InvalidTransactionException("Cannot modify managed objects outside of a write transaction.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user