Example #1
0
Results List::filter(Query q) const
{
    verify_attached();
    if (m_link_view)
        return Results(m_realm, m_link_view, get_query().and_query(std::move(q)));
    return Results(m_realm, get_query().and_query(std::move(q)));
}
ValueType Object::get_property_value_impl(ContextType& ctx, const Property &property)
{
    verify_attached();

    size_t column = property.table_column;
    if (is_nullable(property.type) && m_row.is_null(column))
        return ctx.null_value();
    if (is_array(property.type) && property.type != PropertyType::LinkingObjects)
        return ctx.box(List(m_realm, *m_row.get_table(), column, m_row.get_index()));

    switch (property.type & ~PropertyType::Flags) {
        case PropertyType::Bool:   return ctx.box(m_row.get_bool(column));
        case PropertyType::Int:    return ctx.box(m_row.get_int(column));
        case PropertyType::Float:  return ctx.box(m_row.get_float(column));
        case PropertyType::Double: return ctx.box(m_row.get_double(column));
        case PropertyType::String: return ctx.box(m_row.get_string(column));
        case PropertyType::Data:   return ctx.box(m_row.get_binary(column));
        case PropertyType::Date:   return ctx.box(m_row.get_timestamp(column));
        case PropertyType::Any:    return ctx.box(m_row.get_mixed(column));
        case PropertyType::Object: {
            auto linkObjectSchema = m_realm->schema().find(property.object_type);
            TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), property.object_type);
            return ctx.box(Object(m_realm, *linkObjectSchema, table->get(m_row.get_link(column))));
        }
        case PropertyType::LinkingObjects: {
            auto target_object_schema = m_realm->schema().find(property.object_type);
            auto link_property = target_object_schema->property_for_name(property.link_origin_property_name);
            TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), target_object_schema->name);
            auto tv = m_row.get_table()->get_backlink_view(m_row.get_index(), table.get(), link_property->table_column);
            return ctx.box(Results(m_realm, std::move(tv)));
        }
        default: REALM_UNREACHABLE();
    }
}
Example #3
0
size_t List::find(Query&& q) const
{
    verify_attached();
    if (m_link_view) {
        size_t index = get_query().and_query(std::move(q)).find();
        return index == not_found ? index : m_link_view->find(index);
    }
    return q.find();
}
Example #4
0
size_t List::find(RowExpr const& row) const
{
    verify_attached();
    if (!row.is_attached())
        return not_found;
    validate(row);

    return m_link_view ? m_link_view->find(row.get_index()) : row.get_index();
}
Example #5
0
Results List::sort(SortDescriptor order) const
{
    verify_attached();
    if (m_link_view)
        return Results(m_realm, m_link_view, util::none, std::move(order));

    DescriptorOrdering new_order;
    new_order.append_sort(std::move(order));
    return Results(m_realm, get_query(), std::move(new_order));
}
Example #6
0
void Object::set_property_value(ContextType& ctx, StringData prop_name, ValueType value, bool try_update)
{
    verify_attached();
    m_realm->verify_in_write();
    auto& property = property_for_name(prop_name);

    // Modifying primary keys is allowed in migrations to make it possible to
    // add a new primary key to a type (or change the property type), but it
    // is otherwise considered the immutable identity of the row
    if (property.is_primary && !m_realm->is_in_migration())
        throw std::logic_error("Cannot modify primary key after creation");

    set_property_value_impl(ctx, property, value, try_update);
}
Example #7
0
NotificationToken List::add_notification_callback(CollectionChangeCallback cb) &
{
    verify_attached();
    // Adding a new callback to a notifier which had all of its callbacks
    // removed does not properly reinitialize the notifier. Work around this by
    // recreating it instead.
    // FIXME: The notifier lifecycle here is dumb (when all callbacks are removed
    // from a notifier a zombie is left sitting around uselessly) and should be
    // cleaned up.
    if (m_notifier && !m_notifier->have_callbacks())
        m_notifier.reset();
    if (!m_notifier) {
        if (get_type() == PropertyType::Object)
            m_notifier = std::static_pointer_cast<_impl::CollectionNotifier>(std::make_shared<ListNotifier>(m_link_view, m_realm));
        else
            m_notifier = std::static_pointer_cast<_impl::CollectionNotifier>(std::make_shared<PrimitiveListNotifier>(m_table, m_realm));
        RealmCoordinator::register_notifier(m_notifier);
    }
    return {m_notifier, m_notifier->add_callback(std::move(cb))};
}
Example #8
0
size_t List::get_origin_row_index() const
{
    verify_attached();
    return m_link_view ? m_link_view->get_origin_row_index() : m_table->get_parent_row_index();
}
Example #9
0
Query List::get_query() const
{
    verify_attached();
    return m_link_view ? m_table->where(m_link_view) : m_table->where();
}
Example #10
0
Results List::as_results() const
{
    verify_attached();
    return m_link_view ? Results(m_realm, m_link_view) : Results(m_realm, *m_table);
}
Example #11
0
size_t List::find(T const& value) const
{
    verify_attached();
    return m_table->find_first(0, value);
}
Example #12
0
PropertyType List::get_type() const
{
    verify_attached();
    return m_link_view ? PropertyType::Object
                       : ObjectSchema::from_core_type(*m_table->get_descriptor(), 0);
}
Example #13
0
size_t List::size() const
{
    verify_attached();
    return m_link_view ? m_link_view->size() : m_table->size();
}
Example #14
0
void List::verify_in_transaction() const
{
    verify_attached();
    m_realm->verify_in_write();
}