27 #include "../../common/STLUtils.h" 
   28 #include "../../common/Translator.h" 
   29 #include "../../datatype/Enums.h" 
   30 #include "../../geometry/GeometryProperty.h" 
   31 #include "../../raster/RasterProperty.h" 
   32 #include "../datasource/DataSourceCatalog.h" 
   33 #include "../Exception.h" 
   46   : CompositeProperty(name, name, te::dt::
DATASET_TYPE, id, 0),
 
   54  : CompositeProperty(rhs),
 
   58    m_category(rhs.m_category)
 
   60   if(rhs.
m_idxs.empty() == 
false)
 
   64     for(std::size_t i = 0; i < 
size; ++i)
 
   71       const std::vector<te::dt::Property*>& idxProperties = rhsIdx->
getProperties();
 
   73       std::vector<te::dt::Property*> properties;
 
   75       const std::size_t idxSize = idxProperties.size();
 
   77       for(std::size_t j = 0; j < idxSize; ++j)
 
   95     const std::size_t 
size = pkProperties.size();
 
   97     for(std::size_t i = 0; i < 
size; ++i)
 
  107       std::size_t s = 
m_idxs.size();
 
  108       for(std::size_t i = 0; i<s; ++i)
 
  123     for(std::size_t i = 0; i < 
size; ++i)
 
  129       const std::vector<te::dt::Property*>& ukProperties = rhsUk->
getProperties();
 
  131       const std::size_t ukSize = ukProperties.size();
 
  133       for(std::size_t j = 0; j < ukSize; ++j)
 
  143         std::size_t s = 
m_idxs.size();
 
  144         for(std::size_t i = 0; i<s; ++i)
 
  161     for(std::size_t i = 0; i < 
size; ++i)
 
  176     for(std::size_t i = 0; i < 
size; ++i)
 
  191       const std::vector<te::dt::Property*>& fkProperties = rhsFk->
getProperties();
 
  192       const std::size_t fkSize = fkProperties.size();
 
  194       for(std::size_t j = 0; j < fkSize; ++j)
 
  217     throw Exception(
TE_TR(
"Not implemented yet!"));
 
  243       setPrimaryKey(static_cast<PrimaryKey*>(c));
 
  247       add(static_cast<ForeignKey*>(c));
 
  252       m_uniqueKeys.push_back(static_cast<UniqueKey*>(c));
 
  257       m_checkConstraints.push_back(static_cast<CheckConstraint*>(c));
 
  294   std::size_t size = uks.size();
 
  296   for(std::size_t i = 0; i < size; ++i)
 
  302   std::size_t size = m_uniqueKeys.size();
 
  304   for(std::size_t i = 0; i < size; ++i)
 
  306     if(m_uniqueKeys[i]->getName() == name)
 
  307       return m_uniqueKeys[i];
 
  315   std::size_t size = m_uniqueKeys.size();
 
  317   for(std::size_t i = 0; i < size; ++i)
 
  319     if(m_uniqueKeys[i] == uk)
 
  321       m_uniqueKeys.erase(m_uniqueKeys.begin() + i);
 
  331   m_uniqueKeys.clear();
 
  336   std::size_t size = ccs.size();
 
  338   for(std::size_t i = 0; i < size; ++i)
 
  344   std::size_t size = m_checkConstraints.size();
 
  346   for(std::size_t i = 0; i < size; ++i)
 
  348     if(m_checkConstraints[i]->getName() == name)
 
  349       return m_checkConstraints[i];
 
  357   std::size_t size = m_checkConstraints.size();
 
  359   for(std::size_t i = 0; i < size; ++i)
 
  361     if(m_checkConstraints[i] == cc)
 
  363       m_checkConstraints.erase(m_checkConstraints.begin() + i);
 
  373   m_checkConstraints.clear();  
 
  380   m_idxs.push_back(idx);
 
  385   std::size_t size = idxs.size();
 
  387   for(std::size_t i = 0; i < size; ++i)
 
  393   std::size_t size = m_idxs.size();
 
  395   for(std::size_t i = 0; i < size; ++i)
 
  396     if(m_idxs[i]->getName() == name)
 
  405   if(m_pk && m_pk->getAssociatedIndex() == idx)
 
  413     std::size_t size = m_uniqueKeys.size();
 
  415     for(std::size_t i = 0; i < size; ++i)
 
  417       if(m_uniqueKeys[i]->getAssociatedIndex() == idx)
 
  419         delete m_uniqueKeys[i];
 
  420         m_uniqueKeys.erase(m_uniqueKeys.begin() + i);
 
  428     std::size_t size = m_idxs.size();
 
  430     for(std::size_t i = 0; i < size; ++i)
 
  434         m_idxs.erase(m_idxs.begin() + i);
 
  444   std::size_t size = m_idxs.size();
 
  446   for(std::size_t i = 0; i < size; ++i)
 
  449     if(m_pk && m_pk->getAssociatedIndex() == m_idxs[i])
 
  450       m_pk->setAssociatedIndex(0);
 
  453     std::size_t ssize = m_uniqueKeys.size();
 
  455     for(std::size_t j = 0; j < ssize; ++j)
 
  457       if(m_uniqueKeys[j]->getAssociatedIndex() == m_idxs[i])
 
  458         m_uniqueKeys[j]->setAssociatedIndex(0);
 
  469   std::size_t size = m_foreignKeys.size();
 
  471   for(std::size_t i = 0; i < size; ++i)
 
  473     if(m_foreignKeys[i]->getName() == name)
 
  474       return m_foreignKeys[i];
 
  485     m_catalog->addRef(fk);
 
  488   m_foreignKeys.push_back(fk);
 
  496     throw Exception(
TE_TR(
"The foreign key is not associated to this DataSetType!"));
 
  499     m_catalog->removeRef(fk);
 
  501   std::size_t size = m_foreignKeys.size();
 
  503   for(std::size_t i = 0; i < size; ++i)
 
  505     if(m_foreignKeys[i] == fk)
 
  507       m_foreignKeys.erase(m_foreignKeys.begin() + i);
 
  519   if(m_pk && m_pk->has(p))
 
  529   removeForeignKeys(p);
 
  533     m_catalog->dropDependentSequences(p);
 
  536   CompositeProperty::remove(p);
 
  547     m_pk->replace(p, pp);
 
  551     std::size_t size = m_uniqueKeys.size();
 
  553     for(std::size_t i = 0; i < size; ++i)
 
  554       m_uniqueKeys[i]->replace(p, pp);
 
  559     std::size_t size = m_idxs.size();
 
  561     for(std::size_t i = 0; i < size; ++i)
 
  562       m_idxs[i]->replace(p, pp);
 
  571       std::size_t size = m_catalog->getNumberOfSequences();
 
  573       for(std::size_t i = 0; i < size; ++i)
 
  574         if(m_catalog->getSequence(i)->getOwner() == p)
 
  575           m_catalog->getSequence(i)->setOwner(pp);
 
  581       std::size_t size = m_catalog->getNumberOfDataSets();
 
  583       for(std::size_t i = 0; i < size; ++i)
 
  587         std::size_t ssize = dt->getNumberOfForeignKeys();
 
  589         for(std::size_t j = 0; j < ssize; ++j)
 
  590           dt->getForeignKey(j)->replace(p, pp);
 
  597     std::size_t size = m_foreignKeys.size();
 
  599     for(std::size_t i = 0; i < size; ++i)
 
  600       m_foreignKeys[i]->replace(p, pp);
 
  605     std::size_t size = m_properties.size();
 
  607     for(std::size_t i = 0; i < size; ++i)
 
  608       if(m_properties[i] == p)
 
  610         m_properties[i] = pp;
 
  623   std::size_t size = m_uniqueKeys.size();
 
  628     if(m_uniqueKeys[i]->has(p))
 
  630       delete m_uniqueKeys[i];
 
  631       m_uniqueKeys.erase(m_uniqueKeys.begin() + i);
 
  641   std::size_t size = m_idxs.size();
 
  646     if(m_idxs[i]->has(p))
 
  649       m_idxs.erase(m_idxs.begin() + i);
 
  662     std::size_t size = m_foreignKeys.size();
 
  667       if(m_foreignKeys[i]->has(p))
 
  670           m_catalog->removeRef(m_foreignKeys[i]);
 
  672         delete m_foreignKeys[i];
 
  673         m_foreignKeys.erase(m_foreignKeys.begin() + i);
 
  686     std::pair<std::multimap<DataSetType*, ForeignKey*>::const_iterator,
 
  687               std::multimap<DataSetType*, ForeignKey*>::const_iterator> range = m_catalog->getRefFK(
this);
 
  689     while(range.first != range.second)
 
  691       std::multimap<DataSetType*, ForeignKey*>::const_iterator it = range.first; 
 
  694       if(it->second->isReferenced(p))
 
void add(te::dt::Property *p)
It adds the property to the list of properties that participates in the unique key. 
 
DataSetType & operator=(const DataSetType &rhs)
Assignment operator not allowed. 
 
virtual void setDataSetType(DataSetType *dt)
It sets the DataSetType associated to the constraint. 
 
void setDataSetType(DataSetType *dt)
It sets the DataSetType associated to the index. 
 
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key. 
 
Index * getAssociatedIndex() const 
It returns the associated index if one exists. 
 
It describes a primary key (pk) constraint. 
 
boost::shared_ptr< DataSetType > DataSetTypePtr
 
Property * clone() const 
It returns a clone of the object. 
 
PrimaryKey * m_pk
The DataSetType primary key. 
 
A class that models the description of a dataset. 
 
CheckConstraint * getCheckConstraint(std::size_t i) const 
It returns the i-th check-constraint associated to the dataset type. 
 
void removeIndexes(Property *p)
It removes all indexes related to the given Property. 
 
std::vector< Property * > m_properties
The list of property types that make the CompositeProperty. 
 
A class that describes a check constraint. 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
void clear()
It clears the DataSetType definition. 
 
std::vector< ForeignKey * > m_foreignKeys
A vector of foreign key constraints. 
 
void replace(Property *p, Property *pp)
It replaces the property p by pp and adjust all pointers inclusive in the catalog. 
 
It models a property definition. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the primary key. 
 
Index * getIndex(std::size_t i) const 
It returns the i-th index associated to the dataset type. 
 
void setReferencedProperties(const std::vector< te::dt::Property * > &properties)
It sets the referenced properties (on the referenced DataSetType) of this foreign key constraint...
 
It describes an index associated to a DataSetType. 
 
virtual ConstraintType getType() const =0
It returns the constraint type. 
 
void remove(Constraint *c)
It removes the constraint. 
 
void setOnDeleteAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
 
void add(te::dt::Property *p)
It adds a property to the foreign key constraint. 
 
Index * getAssociatedIndex() const 
It returns the associated index if one exists. 
 
It describes a unique key (uk) constraint. 
 
DataSetType * getReferencedDataSetType() const 
It returns the referenced DataSetType of this foreign key constraint. 
 
void removeForeignKeys(Property *p)
It removes all foreign keys that p takes part and all foreign keys that references p...
 
It models a foreign key constraint for a DataSetType. 
 
DataSetType(const std::string &name, unsigned int id=0)
It creates a new DataSetType not associated to any DataSetType or Catalog. 
 
It describes a unique key (uk) constraint. 
 
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that take part of the index. 
 
void setAssociatedIndex(Index *idx)
It sets the associated index. 
 
std::size_t size() const 
It returns the number of properties of the CompositeProperty. 
 
It describes a sequence (a number generator). 
 
A class that describes a check constraint. 
 
It models a foreign key constraint for a DataSetType. 
 
void add(Constraint *c)
It adds a new constraint. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that form the unique key. 
 
void removeUniqueKeys(Property *p)
It removes all unique keys related to the given Property. 
 
void setAssociatedIndex(Index *idx)
It sets the associated index. 
 
void clearUniqueKeys()
It removes all unique keys from the dataset type. 
 
ForeignKey * getForeignKey(std::size_t i) const 
It returns the i-th foreign key associated to the dataset type. 
 
void setOnUpdateAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the index. 
 
A class that models the description of a dataset. 
 
It describes a primary key (pk) constraint. 
 
std::vector< CheckConstraint * > m_checkConstraints
A vector of check constraints. 
 
virtual DataSetType * getDataSetType() const 
It returns the DataSetType associated to the constraint. 
 
std::size_t getPropertyPosition(const std::string &name) const 
It returns the property position based on its name. 
 
std::vector< UniqueKey * > m_uniqueKeys
A vector of unique key constraints. 
 
FKActionType getOnUpdateAction() const 
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
 
void setReferencedDataSetType(DataSetType *refDt)
It sets the referenced DataSetType of this foreign key constraint. 
 
void clearIndexes()
It removes all indexes from the dataset type. 
 
virtual const std::string & getName() const 
It returns the constraint name. 
 
std::vector< Index * > m_idxs
A vector of indexes. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the foreign key constraint. 
 
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...
 
const std::vector< te::dt::Property * > & getReferencedProperties() const 
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint...
 
It describes an index associated to a DataSetType. 
 
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint. 
 
UniqueKey * getUniqueKey(std::size_t i) const 
It returns the i-th unique key. 
 
void clearCheckConstraints()
It removes all check constraints. 
 
FKActionType getOnDeleteAction() const 
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
 
const std::string & getName() const 
It returns the property name. 
 
const std::string & getName() const 
It returns the index name.