Add secondary_index concerns
Add a way to create a secondary index with the space/type ID of the object rather than the compile-time type, which may not always be available. Also, add a way to delete a secondary index (whether by compile-time type or by object space/type ID).
This commit is contained in:
parent
a5a78dacf1
commit
8df442a65f
2 changed files with 28 additions and 0 deletions
|
|
@ -183,6 +183,13 @@ namespace graphene { namespace db {
|
|||
FC_THROW_EXCEPTION( fc::assert_exception, "invalid index type" );
|
||||
}
|
||||
|
||||
void delete_secondary_index(const secondary_index& secondary) {
|
||||
auto itr = std::find_if(_sindex.begin(), _sindex.end(),
|
||||
[&secondary](const auto& ptr) { return &secondary == ptr.get(); });
|
||||
FC_ASSERT(itr != _sindex.end(), "Cannot remove secondary index: secondary index not found");
|
||||
_sindex.erase(itr);
|
||||
}
|
||||
|
||||
protected:
|
||||
vector< shared_ptr<index_observer> > _observers;
|
||||
vector< unique_ptr<secondary_index> > _sindex;
|
||||
|
|
|
|||
|
|
@ -152,6 +152,27 @@ namespace graphene { namespace db {
|
|||
{
|
||||
return get_mutable_index_type<PrimaryIndexType>().template add_secondary_index<SecondaryIndexType>();
|
||||
}
|
||||
template<typename SecondaryIndexType>
|
||||
SecondaryIndexType* add_secondary_index(const uint8_t space_id, const uint8_t type_id)
|
||||
{
|
||||
auto* base_primary = dynamic_cast<base_primary_index*>(&get_mutable_index(space_id, type_id));
|
||||
FC_ASSERT(base_primary != nullptr,
|
||||
"Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.",
|
||||
("S", space_id)("T", type_id));
|
||||
return base_primary->template add_secondary_index<SecondaryIndexType>();
|
||||
}
|
||||
|
||||
template<typename PrimaryIndexType>
|
||||
void delete_secondary_index(const secondary_index& secondary) {
|
||||
get_mutable_index_type<PrimaryIndexType>().delete_secondary_index(secondary);
|
||||
}
|
||||
void delete_secondary_index(const uint8_t space_id, const uint8_t type_id, const secondary_index& secondary) {
|
||||
auto* base_primary = dynamic_cast<base_primary_index*>(&get_mutable_index(space_id, type_id));
|
||||
FC_ASSERT(base_primary != nullptr,
|
||||
"Cannot add secondary index: index for space ID ${S} and type ID ${T} does not support secondary indexes.",
|
||||
("S", space_id)("T", type_id));
|
||||
base_primary->delete_secondary_index(secondary);
|
||||
}
|
||||
|
||||
void pop_undo();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue