1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/* Copyright (c) 2015, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "sql/dd/cache/local_multi_map.h"
#include <assert.h>
#include "sql/dd/cache/multi_map_base.h"
#include "sql/dd/impl/cache/cache_element.h" // Cache_element
#include "sql/dd/impl/tables/character_sets.h"
#include "sql/dd/impl/tables/collations.h"
#include "sql/dd/impl/tables/column_statistics.h"
#include "sql/dd/impl/tables/events.h"
#include "sql/dd/impl/tables/resource_groups.h"
#include "sql/dd/impl/tables/routines.h"
#include "sql/dd/impl/tables/schemata.h"
#include "sql/dd/impl/tables/spatial_reference_systems.h"
#include "sql/dd/impl/tables/tables.h"
#include "sql/dd/impl/tables/tablespaces.h"
namespace dd {
class Abstract_table;
class Charset;
class Collation;
class Column_statistics;
class Event;
class Resource_group;
class Routine;
class Schema;
class Spatial_reference_system;
class Tablespace;
} // namespace dd
namespace dd {
namespace cache {
// Put a new element into the map.
template <typename T>
void Local_multi_map<T>::put(Cache_element<T> *element) {
#ifndef NDEBUG
// The new object instance may not be present in the map.
Cache_element<T> *e = nullptr;
m_map<const T *>()->get(element->object(), &e);
assert(!e);
// Get all keys that were created within the element.
const typename T::Id_key *id_key = element->id_key();
const typename T::Name_key *name_key = element->name_key();
const typename T::Aux_key *aux_key = element->aux_key();
// There must be at least one key.
assert(id_key || name_key || aux_key);
// None of the keys may exist.
assert((!id_key || !m_map<typename T::Id_key>()->is_present(*id_key)) &&
(!name_key || !m_map<typename T::Name_key>()->is_present(*name_key)) &&
(!aux_key || !m_map<typename T::Aux_key>()->is_present(*aux_key)));
#endif
// Add the keys and the element to the maps.
Multi_map_base<T>::add_single_element(element);
}
// Remove an element from the map.
template <typename T>
void Local_multi_map<T>::remove(Cache_element<T> *element) {
#ifndef NDEBUG
// The object must be present.
Cache_element<T> *e = nullptr;
m_map<const T *>()->get(element->object(), &e);
assert(e);
// Get all keys that were created within the element.
const typename T::Id_key *id_key = element->id_key();
const typename T::Name_key *name_key = element->name_key();
const typename T::Aux_key *aux_key = element->aux_key();
// All non-null keys must exist.
assert((!id_key || m_map<typename T::Id_key>()->is_present(*id_key)) &&
(!name_key || m_map<typename T::Name_key>()->is_present(*name_key)) &&
(!aux_key || m_map<typename T::Aux_key>()->is_present(*aux_key)));
#endif
// Remove the keys and the element from the maps.
Multi_map_base<T>::remove_single_element(element);
}
// Remove and delete all elements and objects from the map.
template <typename T>
void Local_multi_map<T>::erase() {
typename Multi_map_base<T>::Const_iterator it;
for (it = begin(); it != end();) {
assert(it->second);
assert(it->second->object());
// Make sure we handle iterator invalidation: Increment
// before erasing.
Cache_element<T> *element = it->second;
++it;
// Remove the element from the multi map, delete the wrapped object.
remove(element);
delete element->object();
delete element;
}
}
/* purecov: begin inspected */
template <typename T>
void Local_multi_map<T>::dump() const {
#ifndef NDEBUG
fprintf(stderr, " --------------------------------\n");
fprintf(stderr, " Local multi map for '%s'\n",
T::DD_table::instance().name().c_str());
Multi_map_base<T>::dump();
fprintf(stderr, " --------------------------------\n");
#endif
}
/* purecov: end */
// Explicitly instantiate the types for the various usages.
template class Local_multi_map<Abstract_table>;
template class Local_multi_map<Charset>;
template class Local_multi_map<Collation>;
template class Local_multi_map<Column_statistics>;
template class Local_multi_map<Event>;
template class Local_multi_map<Resource_group>;
template class Local_multi_map<Routine>;
template class Local_multi_map<Schema>;
template class Local_multi_map<Spatial_reference_system>;
template class Local_multi_map<Tablespace>;
} // namespace cache
} // namespace dd
|