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