Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kspangsege committed Oct 29, 2014
1 parent 815058d commit 7243100
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/tightdb/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,15 @@ void Group::remove_table(size_t table_ndx)
// columns of other tables, however, to do that, we would have to
// automatically remove the "offending" link columns from those other
// tables. Such a behaviour is deemed too obscure, and we shall therefore
// require that a removed table does not contain foreigh origin backlink
// columns.
// require that a removed table does not contain any backlinks columns whose
// origin table is not the removed table.
typedef _impl::TableFriend tf;
if (tf::is_cross_table_link_target(*table))
throw CrossTableLinkTarget();

// There is no easy way for Group::TransactAdvancer to handle removal of
// tables that contain foreign target table link columns, because that
// involves removal of the corresponding backlink columns. For that reason,
// involves removal of the corresponding backlink columns. For this reason,
// we start by removing all columns, which will generate individual
// replication instructions for each column removal with sufficient
// information for Group::TransactAdvancer to handle them.
Expand Down
4 changes: 2 additions & 2 deletions src/tightdb/replication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ inline void Replication::erase_column(const Descriptor& desc, std::size_t col_nd
if (!tf::is_link_type(ColumnType(type))) {
simple_cmd(instr_EraseColumn, util::tuple(col_ndx)); // Throws
}
else { // it's a link column:

else {
// Link column
TIGHTDB_ASSERT(desc.is_root());
typedef _impl::DescriptorFriend df;
const Table& origin_table = df::get_root_table(desc);
Expand Down
6 changes: 3 additions & 3 deletions src/tightdb/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,9 @@ void Table::do_erase_column(Descriptor& desc, size_t col_ndx)
// the column removal to correctly reproduce the desired effect, namely that
// the table appears truncated after the removal of the last non-hidden
// column. The clear operation needs to be submitted to the replication
// handler as an individual operation, and precede the column removal
// operation in order to get the right behaviour in
// Group::advance_transact().
// handler as an individual operationin order to get the right behaviour in
// Group::advance_transact(). This ensures that origin tables for cleared
// backlink columns are marked dirty.
if (desc.is_root()) {
if (root_table.m_spec.get_public_column_count() == 1 && root_table.m_cols.size() > 1)
root_table.clear(); // Throws
Expand Down
35 changes: 33 additions & 2 deletions test/test_links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,37 @@ TEST(Links_CascadeRemove_ColumnLink)
target_row_1 = target->get(1);
origin_row_1.set_link(0,1); // origin[1].o_1 -> target[1]

// Break link by clearing table
// Break links by clearing table
CHECK(origin_row_0.get_link(0) == 0 && origin_row_1.get_link(0) == 1);
CHECK(target_row_0 && target_row_1);
origin->clear();
CHECK(!target_row_0 && !target_row_1);
CHECK(target->is_empty());
origin->add_empty_row(2);
target->add_empty_row(2);
origin_row_0 = origin->get(0);
origin_row_1 = origin->get(1);
target_row_0 = target->get(0);
target_row_1 = target->get(1);
origin_row_0.set_link(0,0); // origin[0].o_1 -> target[0]
origin_row_1.set_link(0,1); // origin[1].o_1 -> target[1]

// Break links by link column removal
CHECK(origin_row_0.get_link(0) == 0 && origin_row_1.get_link(0) == 1);
CHECK(target_row_0 && target_row_1);
origin->remove_column(0);
CHECK(!target_row_0 && !target_row_1);
CHECK(target->is_empty());
origin->add_column_link(type_Link, "o_1", *target, link_Strong);
origin_row_0.set_link(0,0); // origin[0].o_1 -> target[0]
origin_row_1.set_link(0,1); // origin[1].o_1 -> target[1]

// Break links by removal of origin table
CHECK(origin_row_0.get_link(0) == 0 && origin_row_1.get_link(0) == 1);
CHECK(target_row_0 && target_row_1);
group.remove_table("origin");
CHECK(!target_row_0 && !target_row_1);
CHECK(target->is_empty());
}


Expand Down Expand Up @@ -1057,7 +1083,7 @@ TEST(Links_CascadeRemove_ColumnLinkList)
link_list_1->add(0); // origin[1].o_1 -> [ target[0] ]
link_list_1->add(1); // origin[1].o_1 -> [ target[0], target[1] ]

// Break link by clearing table
// Break links by clearing table
CHECK(link_list_0->size() == 1 && link_list_0->get(0).get_index() == 0);
CHECK(link_list_1->size() == 2 && link_list_1->get(0).get_index() == 0 &&
link_list_1->get(1).get_index() == 1);
Expand All @@ -1072,6 +1098,11 @@ TEST(Links_CascadeRemove_MultiLevel)
}


TEST(Links_CascadeRemove_SameOriginAndTargetTable)
{
}


TEST(Links_CascadeRemove_Cycles)
{
}
Expand Down

0 comments on commit 7243100

Please sign in to comment.