00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #include <table_delta.h>
00028 #include <annotation_delta.h>
00029
00030 bool table_delta::apply(work_node& _x, undelta_base*& _u) const
00031 {
00032 std::cerr << "Cannot directly apply a table_delta: convert missing!" <<
00033 std::endl;
00034 return false;
00035 }
00036
00037 void table_delta::convert(work_node& _x, delta_base*& _d)
00038 {
00039 std::vector<annotation> t_add;
00040 for(t_ctr::const_iterator _tl = t_new.begin(); _tl != t_new.end(); ++_tl)
00041 {
00042 const t_line& tl(*_tl);
00043 vdbl::standard_table* ptb = (vdbl::standard_table*)
00044 _x.get_database_ptr()->get_table(tl.first, _x.get_dbuserid());
00045 if(ptb == NULL)
00046 {
00047 _x.get_database_ptr()->create_table(tl.first, _x.get_dbuserid());
00048 ptb = (vdbl::standard_table*)
00049 _x.get_database_ptr()->get_table(tl.first, _x.get_dbuserid());
00050 if(ptb == NULL)
00051 throw "Database inconsistency: Programming Error!";
00052 this->create_table(_x, ptb, tl.first);
00053 if(ptb == NULL)
00054 throw "Create table failed: Programming Error!";
00055 }
00056 vdbl::tableid tbi =
00057 _x.get_database_ptr()->get_tableid(tl.first, _x.get_dbuserid());
00058 vdbl::rowid _ri;
00059 if(!ptb->insert_row(tl.second, _ri))
00060 throw "Database inconsistency: Programming error!";
00061 t_add.push_back(annotation(tbi,_ri));
00062 }
00063 _x.keep(t_add);
00064 _d = (delta_base*) new annotation_delta(get_action(), t_add, t_rm);
00065 }
00066