Commit c0c4be78 by maarten

remove dummies

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@505 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent 513dbb6b
...@@ -535,6 +535,8 @@ class Row ...@@ -535,6 +535,8 @@ class Row
return detail::getRowResult<C...>(*this, std::move(cix)); return detail::getRowResult<C...>(*this, std::move(cix));
} }
void assign(const std::vector<Item>& values);
bool operator==(const Row& rhs) const bool operator==(const Row& rhs) const
{ {
return mData == rhs.mData; return mData == rhs.mData;
...@@ -551,9 +553,9 @@ class Row ...@@ -551,9 +553,9 @@ class Row
private: private:
void assign(const string& name, const string& value, bool emplacing); void assign(const string& name, const string& value, bool updateLinked);
void assign(size_t column, const string& value, bool emplacing); void assign(size_t column, const string& value, bool updateLinked);
void assign(const Item& i, bool emplacing); void assign(const Item& i, bool updateLinked);
static void swap(size_t column, ItemRow* a, ItemRow* b); static void swap(size_t column, ItemRow* a, ItemRow* b);
...@@ -1226,6 +1228,8 @@ class Category ...@@ -1226,6 +1228,8 @@ class Category
bool isOrphan(Row r); bool isOrphan(Row r);
bool hasParent(Row r, const Category& parentCat, const ValidateLink& link) const; bool hasParent(Row r, const Category& parentCat, const ValidateLink& link) const;
bool hasChildren(Row r) const;
bool isValid(); bool isValid();
void validateLinks() const; void validateLinks() const;
......
...@@ -1724,6 +1724,37 @@ bool Category::isOrphan(Row r) ...@@ -1724,6 +1724,37 @@ bool Category::isOrphan(Row r)
return isOrphan; return isOrphan;
} }
bool Category::hasChildren(Row r) const
{
assert(mValidator != nullptr);
assert(mCatValidator != nullptr);
bool result = false;
for (auto& link: mValidator->getLinksForParent(mName))
{
auto childCat = mDb.get(link->mChildCategory);
if (childCat == nullptr)
continue;
Condition cond;
for (size_t ix = 0; ix < link->mParentKeys.size(); ++ix)
{
const char* value = r[link->mParentKeys[ix]].c_str();
cond = move(cond) && (Key(link->mChildKeys[ix]) == value);
}
result = not childCat->find(std::move(cond)).empty();
if (result)
break;
}
return result;
}
bool Category::isValid() bool Category::isValid()
{ {
bool result = true; bool result = true;
...@@ -2173,21 +2204,89 @@ Row& Row::operator=(const Row& rhs) ...@@ -2173,21 +2204,89 @@ Row& Row::operator=(const Row& rhs)
return *this; return *this;
} }
void Row::assign(const string& name, const string& value, bool emplacing) void Row::assign(const std::vector<Item>& values)
{
auto cat = mData->mCategory;
map<string,tuple<int,string,string>> changed;
for (auto& value: values)
{
auto columnIx = cat->addColumn(value.name());
auto& col = cat->mColumns[columnIx];
string tag = col.mValidator ? col.mValidator->mTag : to_string(columnIx);
changed[tag] = make_tuple(columnIx, operator[](columnIx).c_str(), value.value());
assign(columnIx, value.value(), true);
}
// see if we need to update any child categories that depend on these values
// auto iv = col.mValidator;
if (mCascadeUpdate)
{
auto& validator = cat->getValidator();
auto& db = cat->db();
for (auto linked: validator.getLinksForParent(cat->mName))
{
auto childCat = db.get(linked->mChildCategory);
if (childCat == nullptr)
continue;
// if (find(linked->mParentKeys.begin(), linked->mParentKeys.end(), iv->mTag) == linked->mParentKeys.end())
// continue;
Condition cond;
string childTag;
vector<Item> newValues;
for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
{
string pk = linked->mParentKeys[ix];
string ck = linked->mChildKeys[ix];
if (changed.count(pk) > 0)
{
childTag = ck;
cond = move(cond) && (Key(ck) == std::get<1>(changed[pk]));
newValues.emplace_back(ck, std::get<2>(changed[pk]));
}
else
{
const char* value = (*this)[pk].c_str();
cond = move(cond) && (Key(ck) == value);
}
}
auto rows = childCat->find(move(cond));
for (auto& cr: rows)
cr.assign(newValues);
}
}
}
void Row::assign(const Item& value, bool skipUpdateLinked)
{
assign(value.name(), value.value(), skipUpdateLinked);
}
void Row::assign(const string& name, const string& value, bool skipUpdateLinked)
{ {
try try
{ {
auto cat = mData->mCategory; auto cat = mData->mCategory;
assign(cat->addColumn(name), value, emplacing); assign(cat->addColumn(name), value, skipUpdateLinked);
} }
catch (const exception& ex) catch (const exception& ex)
{ {
cerr << "Could not assigning value '" << value << "' to column " << name << endl; cerr << "Could not assign value '" << value << "' to column _" << mData->mCategory->name() << '.' << name << endl;
throw; throw;
} }
} }
void Row::assign(size_t column, const string& value, bool emplacing) void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
{ {
if (mData == nullptr) if (mData == nullptr)
throw logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + to_string(column)); throw logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + to_string(column));
...@@ -2221,7 +2320,7 @@ void Row::assign(size_t column, const string& value, bool emplacing) ...@@ -2221,7 +2320,7 @@ void Row::assign(size_t column, const string& value, bool emplacing)
bool reinsert = false; bool reinsert = false;
if (not emplacing and // an update of an Item's value if (not skipUpdateLinked and // an update of an Item's value
cat->mIndex != nullptr and cat->keyFieldsByIndex().count(column)) cat->mIndex != nullptr and cat->keyFieldsByIndex().count(column))
{ {
reinsert = cat->mIndex->find(mData); reinsert = cat->mIndex->find(mData);
...@@ -2276,7 +2375,7 @@ void Row::assign(size_t column, const string& value, bool emplacing) ...@@ -2276,7 +2375,7 @@ void Row::assign(size_t column, const string& value, bool emplacing)
// see if we need to update any child categories that depend on this value // see if we need to update any child categories that depend on this value
auto iv = col.mValidator; auto iv = col.mValidator;
if (not emplacing and iv != nullptr and mCascadeUpdate) if (not skipUpdateLinked and iv != nullptr and mCascadeUpdate)
{ {
auto& validator = cat->getValidator(); auto& validator = cat->getValidator();
auto& db = cat->db(); auto& db = cat->db();
...@@ -2530,11 +2629,6 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b) ...@@ -2530,11 +2629,6 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
} }
} }
void Row::assign(const Item& value, bool emplacing)
{
assign(value.name(), value.value(), emplacing);
}
size_t Row::ColumnForItemTag(const char* itemTag) const size_t Row::ColumnForItemTag(const char* itemTag) const
{ {
size_t result = 0; size_t result = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment