27 #include "../../common/STLUtils.h" 28 #include "../../core/translator/Translator.h" 29 #include "../../datatype/Enums.h" 30 #include "../../datatype/Property.h" 31 #include "../dataset/DataSetType.h" 32 #include "../dataset/Sequence.h" 33 #include "../dataset/ForeignKey.h" 34 #include "../Exception.h" 42 #include <boost/format.hpp> 74 dataset_idx_type::const_iterator it =
m_datasets.find(name);
81 if(dt.get() ==
nullptr)
82 throw Exception(
TE_TR(
"Can not add a NULL dataset schema to the catalog!"));
84 if(dt->getName().empty())
85 throw Exception(
TE_TR(
"Can not add a dataset schema with an empty name to the catalog!"));
88 throw Exception((boost::format(
TE_TR(
"Can not add dataset schema %1% to the catalog. There is already another one with this name!")) % dt->getName()).str());
90 if(dt->getCatalog() !=
nullptr)
91 throw Exception((boost::format(
TE_TR(
"Can not add dataset schema %1% to the catalog. It is already attached to one!")) % dt->getName()).str());
103 throw Exception(
TE_TR(
"Can not remove a NULL dataset schema from the catalog!"));
106 throw Exception(
TE_TR(
"Can not remove a dataset schema with an empty name from the catalog!"));
109 throw Exception(
TE_TR(
"Can not remove a dataset from another catalog!"));
135 throw Exception(
TE_TR(
"Could not rename DataSetType because the new name already exist in the catalog!"));
138 throw Exception(
TE_TR(
"Could not rename a dataset from another catalog!"));
143 throw Exception(
TE_TR(
"Could not find dataset schema in the catalog!"));
145 if((*it).get() !=
dt)
146 throw Exception(
TE_TR(
"The dataset schema is not registered in this catalog!"));
152 aux->setName(newName);
161 const dataset_idx_type::nth_index<1>::type& pos_idx =
m_datasets.get<1>();
168 assert(!name.empty());
170 dataset_idx_type::const_iterator it =
m_datasets.find(name);
181 throw Exception(
TE_TR(
"Could not add Sequence because there is already another Sequence with the same name in the catalog!"));
203 const sequence_idx_type::nth_index<1>::type& pos_idx =
m_sequences.get<1>();
210 sequence_idx_type::const_iterator it =
m_sequences.find(name);
223 throw Exception(
TE_TR(
"Could not find the DataSetType referenced in foreign key!"));
233 throw Exception(
TE_TR(
"Could not find the DataSetType referenced in foreign key!"));
235 std::pair<std::multimap<DataSetType*, ForeignKey*>::iterator,
236 std::multimap<DataSetType*, ForeignKey*>::iterator> range =
m_dependentFkIdx.equal_range(refFT);
238 while(range.first != range.second)
240 std::multimap<DataSetType*, ForeignKey*>::iterator it = range.first;
252 throw Exception(
TE_TR(
"Something went wrong when removing the association of a foreign key and a DataSetType in the DataSourceCatalog!"));
270 std::pair<std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator,
271 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator> range =
m_seqFTIdx.equal_range(dt);
273 while(range.first != range.second)
275 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator it = range.first;
312 throw Exception(
TE_TR(
"Could not find in the catalog the DataSetType that owns the given sequence!"));
334 m_seqFTIdx.insert(std::pair<DataSetType*, sequence_idx_type::iterator>(dt, it));
339 throw Exception(
TE_TR(
"Could not find in the catalog the DataSetType that owns the given sequence!"));
344 std::pair<std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator,
345 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator> range =
m_seqFTIdx.equal_range(dt);
347 while(range.first != range.second)
349 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator it = range.first;
381 std::pair<std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator,
382 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator> range =
m_seqFTIdx.equal_range(dt);
384 while(range.first != range.second)
386 std::multimap<DataSetType*, sequence_idx_type::iterator>::iterator it = range.first;
389 if(*(it->second) == *itpos)
398 throw Exception(
TE_TR(
"Could not find in the catalog the DataSetType that owns the given sequence in order to remove the sequence entry!"));
405 for(std::size_t i = 0; i < size; ++i)
411 throw Exception(
TE_TR(
"There is a foreign key in the DataSetType referencing another DataSetType that is not in the catalog!"));
419 for(std::size_t i = 0; i < size; ++i)
432 std::pair<std::multimap<DataSetType*, ForeignKey*>::iterator,
433 std::multimap<DataSetType*, ForeignKey*>::iterator> range =
m_dependentFkIdx.equal_range(dt);
435 while(range.first != range.second)
437 std::multimap<DataSetType*, ForeignKey*>::iterator it = range.first;
450 return dt->getName();
DataSourceCatalog * getCatalog() const
It returns the catalog that owns the DataSetType.
std::multimap< DataSetType *, ForeignKey * > m_dependentFkIdx
A multimap : datasettype -> fk. It tells for a DataSetType the list of fk referencing it...
boost::shared_ptr< DataSetType > DataSetTypePtr
result_type operator()(const Sequence *const s) const
te::dt::Property * getOwner() const
It returns the property type associated to the sequence.
result_type operator()(const DataSetTypePtr &dt) const
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Base exception class for plugin module.
A class that models the description of a dataset.
void remove(DataSetType *dt, const bool cascade=false)
It removes the dataset schema from the catalog.
It describes a sequence (a number generator).
bool datasetExists(const std::string &name) const
It checks if a dataset schema with the given name is in the catalog.
#define TE_TR(message)
It marks a string in order to get translated.
~DataSourceCatalog()
Destructor.
void detach(Sequence *s)
It will detaches the Sequence from the catalog.
It models a property definition.
void removeRef(ForeignKey *fk)
It drops the reference between the foreign key and its referenced DataSetType.
const DataSetTypePtr & getDataSetType(std::size_t i) const
It returns the i-th dataset schema.
void checkSequenceDependency(Sequence *s) const
It checks if the Sequence is owned by a DataSetType property and if that DataSetType is in the catalo...
void clear()
It clears the catalog, releasing all the resources used by it.
void remove(Constraint *c)
It removes the constraint.
std::size_t getNumberOfForeignKeys() const
It returns the number of foreign keys defined for the dataset type.
std::multimap< DataSetType *, sequence_idx_type::iterator > m_seqFTIdx
A multimap : owner-dt -> sequence-it.
void dropDependentSequences(te::dt::Property *p)
It drops Sequences that depends on the property.
void add(const DataSetTypePtr &dt)
It adds a new dataset schema to the catalog.
void addRef(ForeignKey *fk)
It checks if the referenced DataSetType is in the catalog and associate the fk to it...
Sequence * getSequence(std::size_t i) const
It returns the i-th Sequence.
static te::dt::TimeDuration dt(20, 30, 50, 11)
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
It models a foreign key constraint for a DataSetType.
It represents the system catalog of a DataSource.
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn't have one.
int getType() const
It returns the property data type.
dataset_idx_type m_datasets
void rename(DataSetType *dt, const std::string &newName)
It renames the dataset schema in the catalog.
ForeignKey * getForeignKey(std::size_t i) const
It returns the i-th foreign key associated to the dataset type.
void checkFKsDependency(DataSetType *dt) const
It checks if the DataSetTypes referenced by dt's foreign keys are in the catalog. ...
void dropDependentSequenceEntry(Sequence *s)
It drops the Sequence entry in the DataSetType sequence dependency list.
static DataSetTypePtr sm_nullds
virtual DataSetType * getDataSetType() const
It returns the DataSetType associated to the constraint.
DataSourceCatalog()
It creates a new DataSourceCatalog.
void dropDependentFKs(DataSetType *dt)
It drops foreign keys from other DataSetTypes that depends on the attributes in the given DataSetType...
sequence_idx_type m_sequences
const std::string & getName() const
It returns the sequence name.
void indexFKs(DataSetType *dt)
It looks for foreign keys in the DataSetType dt and try to index then with respect to referenced Data...
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
void setCatalog(DataSourceCatalog *catalog)
It sets the catalog associated to the sequence.
void indexSequenceDependency(Sequence *s)
It looks if the sequence is owned by a given DataSetType property and insert this information into th...
const std::string & getName() const
It returns the property name.