27 #include "../../common/STLUtils.h" 
   28 #include "../../common/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> 
   69   m_dependentFkIdx.clear();
 
   74   dataset_idx_type::const_iterator it = m_datasets.find(name);
 
   76   return (it != m_datasets.end());
 
   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!"));
 
   87   if(datasetExists(dt->getName()))
 
   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() != 0)
 
   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());
 
   93   checkFKsDependency(dt.get());
 
   95   m_datasets.insert(dt);
 
  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!"));
 
  111   assert(datasetExists(dt->
getName()));
 
  112   assert(m_datasets.find(dt->
getName()) != m_datasets.end());
 
  113   assert((*m_datasets.find(dt->
getName())).get() == dt);
 
  117     dropDependentSequences(dt);
 
  118     dropDependentFKs(dt);
 
  122     m_seqFTIdx.erase(dt);
 
  123     m_dependentFkIdx.erase(dt);
 
  126   m_datasets.erase(dt->
getName());
 
  132     throw Exception(
TE_TR(
"Can not rename a NULL dataset schema!"));
 
  134   if(datasetExists(newName))
 
  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!"));
 
  140   dataset_idx_type::iterator it = m_datasets.find(dt->
getName());
 
  142   if(it == m_datasets.end())
 
  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!"));
 
  150   m_datasets.erase(it);
 
  152   aux->setName(newName);
 
  154   m_datasets.insert(aux);
 
  159   assert(i < m_datasets.size());
 
  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);
 
  172   if(it != m_datasets.end())
 
  181     throw Exception(
TE_TR(
"Could not add Sequence because there is already another Sequence with the same name in the catalog!"));
 
  183   checkSequenceDependency(s);
 
  184   m_sequences.insert(s);
 
  186   indexSequenceDependency(s);
 
  197   m_sequences.erase(s->
getName());
 
  198   dropDependentSequenceEntry(s);
 
  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);
 
  212   if(it != m_sequences.end())
 
  222   if((refFT == 0) || (getDataSetType(refFT->
getName()).
get() != refFT))
 
  223     throw Exception(
TE_TR(
"Could not find the DataSetType referenced in foreign key!"));
 
  225   m_dependentFkIdx.insert(std::pair<DataSetType*, ForeignKey*>(refFT, fk));
 
  232   if((refFT == 0) || (getDataSetType(refFT->
getName()).
get() != refFT))
 
  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; 
 
  247       m_dependentFkIdx.erase(it);
 
  252   throw Exception(
TE_TR(
"Something went wrong when removing the association of a foreign key and a DataSetType in the DataSourceCatalog!"));
 
  265        (getDataSetType(parent->
getName()).
get() == parent))
 
  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;
 
  283           m_sequences.erase(it->second);
 
  285           m_seqFTIdx.erase(it);
 
  308        (getDataSetType(parent->
getName()).
get() == parent))
 
  312   throw Exception(
TE_TR(
"Could not find in the catalog the DataSetType that owns the given sequence!"));
 
  322   sequence_idx_type::iterator it = m_sequences.find(s->
getName());
 
  331        (getDataSetType(parent->
getName()).
get() == parent))
 
  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;
 
  355     m_sequences.erase(it->second);
 
  357     m_seqFTIdx.erase(it);
 
  368   sequence_idx_type::iterator itpos = m_sequences.find(s->
getName());
 
  377        (getDataSetType(parent->
getName()).
get() == parent))
 
  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)
 
  391             m_seqFTIdx.erase(it);
 
  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)
 
  410     if((refFT == 0) || (getDataSetType(refFT->
getName()).
get() != refFT))
 
  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)
 
  424     assert(getDataSetType(refFT->
getName()).
get() == refFT);
 
  426     m_dependentFkIdx.insert(std::pair<DataSetType*, ForeignKey*>(refFT, fk));
 
  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. 
 
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. ...
 
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. 
 
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. 
 
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. 
 
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...
 
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.