Resolve trivial differences with realm-cocoa

This commit is contained in:
Thomas Goyne 2016-06-21 16:23:38 -07:00
parent bdc8dbc5b2
commit aaa811306e
9 changed files with 39 additions and 34 deletions

View File

@ -22,6 +22,7 @@
#include "impl/external_commit_helper.hpp"
#include "impl/transact_log_handler.hpp"
#include "impl/weak_realm_notifier.hpp"
#include "object_schema.hpp"
#include "object_store.hpp"
#include "schema.hpp"

View File

@ -18,6 +18,7 @@
#include "object_store.hpp"
#include "object_schema.hpp"
#include "schema.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) :
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) :
@ -527,16 +528,16 @@ DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string
SchemaValidationException::SchemaValidationException(std::vector<ObjectSchemaValidationException> const& 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) {
m_what += std::string("\n- ") + error.what();
}
}
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) {
m_what += std::string("\n- ") + error.what();
}
@ -546,7 +547,7 @@ PropertyTypeNotIndexableException::PropertyTypeNotIndexableException(std::string
Property const& 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));
}
@ -572,7 +573,7 @@ InvalidNullabilityException::InvalidNullabilityException(std::string const& obje
case PropertyType::Any:
case PropertyType::Array:
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));
break;
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)
{
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,
string_for_property_type(old_property.type),
string_for_property_type(new_property.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);
}
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.is_nullable, new_property.is_nullable);
}
@ -645,17 +646,17 @@ InvalidLinkingObjectsPropertyException::InvalidLinkingObjectsPropertyException(T
{
switch (error_type) {
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,
object_type, property.name);
break;
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,
object_type, property.name);
break;
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,
object_type, property.name);
break;

View File

@ -19,17 +19,20 @@
#ifndef REALM_OBJECT_STORE_HPP
#define REALM_OBJECT_STORE_HPP
#include "schema.hpp"
#include "property.hpp"
#include <realm/table_ref.hpp>
#include <functional>
#include <string>
#include <vector>
namespace realm {
class Group;
class ObjectSchema;
class ObjectSchemaValidationException;
class Schema;
class StringData;
class ObjectStore {
public:

View File

@ -94,6 +94,8 @@ namespace realm {
return "object";
case PropertyType::Array:
return "array";
case PropertyType::LinkingObjects:
return "linking objects";
#if __GNUC__
default:
__builtin_unreachable();

View File

@ -20,6 +20,7 @@
#include "impl/realm_coordinator.hpp"
#include "impl/results_notifier.hpp"
#include "object_schema.hpp"
#include "object_store.hpp"
#include "util/format.hpp"
@ -130,18 +131,16 @@ bool Results::is_valid() const
{
if (m_realm)
m_realm->verify_thread();
if (m_table && !m_table->is_attached())
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;
}
void Results::validate_read() const
{
// is_valid ensures that we're on the correct thread.
if (!is_valid())
throw InvalidatedException();
}
@ -199,8 +198,8 @@ RowExpr Results::get(size_t row_ndx)
break;
case Mode::LinkView:
if (update_linkview()) {
if (row_ndx < m_link_view->size())
return m_link_view->get(row_ndx);
if (row_ndx < m_link_view->size())
return m_link_view->get(row_ndx);
break;
}
REALM_FALLTHROUGH;

View File

@ -135,6 +135,9 @@ public:
// Ideally this would not be public but it's needed for some KVO stuff
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)
// All non-noexcept functions can throw this
struct InvalidatedException : public std::runtime_error {
@ -187,9 +190,6 @@ public:
friend class _impl::ResultsNotifier;
static void set_table_view(Results& results, TableView&& tv);
};
// Returns if this Results class is still valid
bool is_valid() const;
private:
SharedRealm m_realm;

View File

@ -18,8 +18,8 @@
#include "schema.hpp"
#include "object_schema.hpp"
#include "object_store.hpp"
#include "property.hpp"
#include <algorithm>
@ -118,10 +118,8 @@ void Schema::validate() const
}
// check indexable
if (prop.is_indexed) {
if (!prop.is_indexable()) {
exceptions.emplace_back(PropertyTypeNotIndexableException(object.name, prop));
}
if (prop.is_indexed && !prop.is_indexable()) {
exceptions.emplace_back(PropertyTypeNotIndexableException(object.name, prop));
}
}
}

View File

@ -19,12 +19,12 @@
#ifndef REALM_SCHEMA_HPP
#define REALM_SCHEMA_HPP
#include "object_schema.hpp"
#include <string>
#include <vector>
namespace realm {
class ObjectSchema;
class Schema : private std::vector<ObjectSchema> {
private:
using base = std::vector<ObjectSchema>;

View File

@ -21,6 +21,7 @@
#include "binding_context.hpp"
#include "impl/realm_coordinator.hpp"
#include "impl/transact_log_handler.hpp"
#include "object_schema.hpp"
#include "object_store.hpp"
#include "schema.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) {
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());
}
catch (util::File::NotFound const& ex) {
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) {
// 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, "");
}
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) {
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, path,
@ -314,7 +315,7 @@ void Realm::verify_thread() const
void Realm::verify_in_write() const
{
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.");
}
}