Example #1
0
uint64_t ObjectStore::get_schema_version(const Group *group) {
    ConstTableRef table = group->get_table(c_metadataTableName);
    if (!table || table->get_column_count() == 0) {
        return ObjectStore::NotVersioned;
    }
    return table->get_int(c_versionColumnIndex, c_zeroRowIndex);
}
Example #2
0
StringData ObjectStore::get_primary_key_for_object(const Group *group, StringData object_type) {
    ConstTableRef table = group->get_table(c_primaryKeyTableName);
    if (!table) {
        return "";
    }
    size_t row = table->find_first_string(c_primaryKeyObjectClassColumnIndex, object_type);
    if (row == not_found) {
        return "";
    }
    return table->get_string(c_primaryKeyPropertyNameColumnIndex, row);
}
Example #3
0
bool ObjectStore::is_empty(const Group *group) {
    for (size_t i = 0; i < group->size(); i++) {
        ConstTableRef table = group->get_table(i);
        std::string object_type = object_type_for_table_name(table->get_name());
        if (!object_type.length()) {
            continue;
        }
        if (!table->is_empty()) {
            return false;
        }
    }
    return true;
}
Example #4
0
void ObjectStore::validate_primary_column_uniqueness(const Group *group, Schema const& schema) {
    for (auto& object_schema : schema) {
        auto primary_prop = object_schema.primary_key_property();
        if (!primary_prop) {
            continue;
        }

        ConstTableRef table = table_for_object_type(group, object_schema.name);
        if (table->get_distinct_view(primary_prop->table_column).size() != table->size()) {
            throw DuplicatePrimaryKeyValueException(object_schema.name, *primary_prop);
        }
    }
}
Example #5
0
util::Optional<Property> ObjectStore::property_for_column_index(ConstTableRef& table, size_t column_index)
{
    StringData column_name = table->get_column_name(column_index);

#if REALM_ENABLE_SYNC
    // The object ID column is an implementation detail, and is omitted from the schema.
    // FIXME: Consider filtering out all column names starting with `!`.
    if (column_name == sync::object_id_column_name)
        return util::none;
#endif

    if (table->get_column_type(column_index) == type_Table) {
        auto subdesc = table->get_subdescriptor(column_index);
        if (subdesc->get_column_count() != 1 || subdesc->get_column_name(0) != ObjectStore::ArrayColumnName)
            return util::none;
    }

    Property property;
    property.name = column_name;
    property.type = ObjectSchema::from_core_type(*table->get_descriptor(), column_index);
    property.is_indexed = table->has_search_index(column_index);
    property.table_column = column_index;

    if (property.type == PropertyType::Object) {
        // set link type for objects and arrays
        ConstTableRef linkTable = table->get_link_target(column_index);
        property.object_type = ObjectStore::object_type_for_table_name(linkTable->get_name().data());
    }
    return property;
}
Example #6
0
ObjectSchema::ObjectSchema(Group const& group, StringData name, size_t index) : name(name) {
    ConstTableRef table;
    if (index < group.size()) {
        table = group.get_table(index);
    }
    else {
        table = ObjectStore::table_for_object_type(group, name);
    }

    size_t count = table->get_column_count();
    persisted_properties.reserve(count);
    for (size_t col = 0; col < count; col++) {
        if (auto property = ObjectStore::property_for_column_index(table, col)) {
            persisted_properties.push_back(std::move(property.value()));
        }
    }

    primary_key = realm::ObjectStore::get_primary_key_for_object(group, name);
    set_primary_key_property();
}
Example #7
0
ObjectSchema::ObjectSchema(const Group *group, const std::string &name) : name(name) {
    ConstTableRef table = ObjectStore::table_for_object_type(group, name);

    size_t count = table->get_column_count();
    properties.reserve(count);
    for (size_t col = 0; col < count; col++) {
        Property property;
        property.name = table->get_column_name(col).data();
        property.type = (PropertyType)table->get_column_type(col);
        property.is_indexed = table->has_search_index(col);
        property.is_primary = false;
        property.is_nullable = table->is_nullable(col) || property.type == PropertyType::Object;
        property.table_column = col;
        if (property.type == PropertyType::Object || property.type == PropertyType::Array) {
            // set link type for objects and arrays
            ConstTableRef linkTable = table->get_link_target(col);
            property.object_type = ObjectStore::object_type_for_table_name(linkTable->get_name().data());
        }
        properties.push_back(std::move(property));
    }

    primary_key = realm::ObjectStore::get_primary_key_for_object(group, name);
    set_primary_key_property();
}
Example #8
0
 int64_t operator()(ConstTableRef v) const
 {
     return v->size();
 }