~zorba-coders/zorba/bugs-912586-912593-912722

« back to all changes in this revision

Viewing changes to src/store/naive/pul_primitives.cpp

  • Committer: Cezar Andrei
  • Date: 2012-03-28 15:42:12 UTC
  • mfrom: (10606.1.129 zorba)
  • Revision ID: cezar.lp@cezarandrei.com-20120328154212-jh2heq49xcqjppce
Merge from trunck and resolve ChangeLog conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include <exception>
19
19
 
20
 
#include "store/naive/shared_types.h"
21
 
#include "store/naive/store_defs.h"
22
 
#include "store/naive/simple_store.h"
23
 
#include "store/naive/simple_pul.h"
24
 
#include "store/naive/pul_primitives.h"
25
 
#include "store/naive/node_items.h"
26
 
#include "store/naive/atomic_items.h"
27
 
#include "store/naive/simple_collection.h"
28
 
#include "store/naive/simple_item_factory.h"
29
 
#include "store/naive/node_factory.h"
30
 
#include "store/naive/simple_index.h"
31
 
#include "store/naive/simple_index_value.h"
 
20
#include "shared_types.h"
 
21
#include "store_defs.h"
 
22
#include "simple_store.h"
 
23
#include "simple_pul.h"
 
24
#include "pul_primitives.h"
 
25
#include "node_items.h"
 
26
#include "atomic_items.h"
 
27
#include "collection.h"
 
28
#include "simple_item_factory.h"
 
29
#include "node_factory.h"
 
30
#include "simple_index.h"
 
31
#include "simple_index_value.h"
32
32
 
33
33
#include "store/api/iterator.h"
34
34
#include "store/api/copymode.h"
793
793
********************************************************************************/
794
794
void UpdPut::apply()
795
795
{
796
 
  SimpleStore* store = &GET_STORE();
 
796
  Store* store = &GET_STORE();
797
797
 
798
798
  zstring targetUri;
799
799
  theTargetUri->getStringValue2(targetUri);
847
847
 
848
848
void UpdPut::undo()
849
849
{
850
 
  SimpleStore* store = &GET_STORE();
 
850
  Store* store = &GET_STORE();
851
851
 
852
852
  store->deleteDocument(theTargetUri->getStringValue());
853
853
 
948
948
  theCollection = GET_STORE().getCollection(theName, theDynamicCollection);
949
949
  if (theCollection == NULL)
950
950
    return;//If two delete collection are issued in the same snapshot is a noop
951
 
  SimpleCollection* collection = static_cast<SimpleCollection*>(theCollection.getp());
 
951
  Collection* collection = static_cast<Collection*>(theCollection.getp());
952
952
 
953
953
  std::vector<store::Index*> indexes;
954
954
  collection->getIndexes(indexes);
1012
1012
********************************************************************************/
1013
1013
void UpdInsertIntoCollection::apply()
1014
1014
{
1015
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1015
  Collection* lColl = static_cast<Collection*>
1016
1016
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1017
1017
  assert(lColl);
1018
1018
 
1029
1029
 
1030
1030
void UpdInsertIntoCollection::undo()
1031
1031
{
1032
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1032
  Collection* lColl = static_cast<Collection*>
1033
1033
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1034
1034
  assert(lColl);
1035
1035
 
1036
1036
  uint64_t lastPos;
1037
 
  try {
 
1037
  try 
 
1038
  {
1038
1039
    lastPos = to_xs_unsignedLong(lColl->size()) - 1;
1039
 
  } catch (std::range_error& e) {
 
1040
  }
 
1041
  catch (std::range_error& e)
 
1042
  {
1040
1043
    throw ZORBA_EXCEPTION(
1041
1044
        zerr::ZSTR0060_RANGE_EXCEPTION,
1042
1045
        ERROR_PARAMS(
1061
1064
********************************************************************************/
1062
1065
void UpdInsertFirstIntoCollection::apply()
1063
1066
{
1064
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1067
  Collection* lColl = static_cast<Collection*>
1065
1068
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1066
1069
  assert(lColl);
1067
1070
 
1080
1083
 
1081
1084
void UpdInsertFirstIntoCollection::undo()
1082
1085
{
1083
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1086
  Collection* lColl = static_cast<Collection*>
1084
1087
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1085
1088
  assert(lColl);
1086
1089
 
1098
1101
********************************************************************************/
1099
1102
void UpdInsertLastIntoCollection::apply()
1100
1103
{
1101
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1104
  Collection* lColl = static_cast<Collection*>
1102
1105
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1103
1106
  assert(lColl);
1104
1107
 
1114
1117
 
1115
1118
void UpdInsertLastIntoCollection::undo()
1116
1119
{
1117
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1120
  Collection* lColl = static_cast<Collection*>
1118
1121
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1119
1122
  assert(lColl);
1120
1123
 
1146
1149
********************************************************************************/
1147
1150
void UpdInsertBeforeIntoCollection::apply()
1148
1151
{
1149
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1152
  Collection* lColl = static_cast<Collection*>
1150
1153
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1151
1154
  assert(lColl);
1152
1155
 
1162
1165
 
1163
1166
void UpdInsertBeforeIntoCollection::undo()
1164
1167
{
1165
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1168
  Collection* lColl = static_cast<Collection*>
1166
1169
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1167
1170
  assert(lColl);
1168
1171
  ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
1176
1179
********************************************************************************/
1177
1180
void UpdInsertAfterIntoCollection::apply()
1178
1181
{
1179
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1182
  Collection* lColl = static_cast<Collection*>
1180
1183
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1181
1184
  assert(lColl);
1182
1185
 
1193
1196
 
1194
1197
void UpdInsertAfterIntoCollection::undo()
1195
1198
{
1196
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1199
  Collection* lColl = static_cast<Collection*>
1197
1200
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1198
1201
  assert(lColl);
1199
1202
  ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
1207
1210
********************************************************************************/
1208
1211
void UpdDeleteNodesFromCollection::apply()
1209
1212
{
1210
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1213
  Collection* lColl = static_cast<Collection*>
1211
1214
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1212
1215
  assert(lColl);
1213
1216
 
1262
1265
 
1263
1266
void UpdDeleteNodesFromCollection::undo()
1264
1267
{
1265
 
  SimpleCollection* lColl = static_cast<SimpleCollection*>
 
1268
  Collection* lColl = static_cast<Collection*>
1266
1269
                            (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1267
1270
  assert(lColl);
1268
1271
 
1276
1279
}
1277
1280
 
1278
1281
 
 
1282
/*******************************************************************************
 
1283
  UpdTruncateCollection
 
1284
********************************************************************************/
 
1285
void UpdTruncateCollection::apply()
 
1286
{
 
1287
  Collection* lColl = static_cast<Collection*>
 
1288
                      (GET_STORE().getCollection(theName, theDynamicCollection).getp());
 
1289
  assert(lColl);
 
1290
  
 
1291
  lColl->removeAll();
 
1292
  theIsApplied = true;
 
1293
 
 
1294
}
 
1295
 
 
1296
void UpdTruncateCollection::undo()
 
1297
{
 
1298
  if (!theIsApplied) return;
 
1299
 
 
1300
  throw ZORBA_EXCEPTION(
 
1301
    zerr::ZDDY0019_UNDO_NOT_POSSIBLE,
 
1302
    ERROR_PARAMS( theName->getStringValue(), "truncation" )
 
1303
  );
 
1304
 
 
1305
}
 
1306
 
1279
1307
 
1280
1308
/////////////////////////////////////////////////////////////////////////////////
1281
1309
//                                                                             //
1304
1332
 
1305
1333
void UpdCreateIndex::apply()
1306
1334
{
1307
 
  SimpleStore* store = &GET_STORE();
 
1335
  Store* store = &GET_STORE();
1308
1336
 
1309
1337
  try
1310
1338
  {
1330
1358
{
1331
1359
  if (theIsApplied)
1332
1360
  {
1333
 
    SimpleStore* store = &GET_STORE();
 
1361
    Store* store = &GET_STORE();
1334
1362
 
1335
1363
    store->deleteIndex(theQName);
1336
1364
  }
1350
1378
 
1351
1379
void UpdDeleteIndex::apply()
1352
1380
{
1353
 
  SimpleStore* store = &GET_STORE();
 
1381
  Store* store = &GET_STORE();
1354
1382
 
1355
1383
  if ((theIndex = store->getIndex(theQName)) == NULL)
1356
1384
  {
1370
1398
{
1371
1399
  if (theIsApplied)
1372
1400
  {
1373
 
    SimpleStore* store = &GET_STORE();
 
1401
    Store* store = &GET_STORE();
1374
1402
 
1375
1403
    store->addIndex(theIndex);
1376
1404
  }
1400
1428
 
1401
1429
void UpdRefreshIndex::apply()
1402
1430
{
1403
 
  SimpleStore& store = GET_STORE();
 
1431
  Store& store = GET_STORE();
1404
1432
 
1405
1433
  if ((theIndex = store.getIndex(theQName)) == NULL)
1406
1434
  {
1420
1448
{
1421
1449
  if (theIsApplied)
1422
1450
  {
1423
 
    SimpleStore* store = &GET_STORE();
 
1451
    Store* store = &GET_STORE();
1424
1452
    store->deleteIndex(theQName);
1425
1453
    store->addIndex(theIndex);
1426
1454
  }
1450
1478
 
1451
1479
void UpdActivateIC::apply()
1452
1480
{
1453
 
  SimpleStore* store = &GET_STORE();
 
1481
  Store* store = &GET_STORE();
1454
1482
  store->activateIC(theQName, theCollectionName,theIsApplied);
1455
1483
}
1456
1484
 
1459
1487
{
1460
1488
  if (theIsApplied)
1461
1489
  {
1462
 
    SimpleStore* store = &GET_STORE();
 
1490
    Store* store = &GET_STORE();
1463
1491
    bool isApplied;
1464
1492
    store->deactivateIC(theQName,isApplied);
1465
1493
    theIsApplied=false;
1492
1520
 
1493
1521
void UpdActivateForeignKeyIC::apply()
1494
1522
{
1495
 
  SimpleStore* store = &GET_STORE();
 
1523
  Store* store = &GET_STORE();
1496
1524
  store->activateForeignKeyIC(theQName, theFromCollectionName, theToCollectionName,theIsApplied);
1497
1525
}
1498
1526
 
1501
1529
{
1502
1530
  if (theIsApplied)
1503
1531
  {
1504
 
    SimpleStore* store = &GET_STORE();
 
1532
    Store* store = &GET_STORE();
1505
1533
    bool isApplied;
1506
1534
    store->deactivateIC(theQName,isApplied);
1507
1535
    theIsApplied=false;
1530
1558
 
1531
1559
void UpdDeActivateIC::apply()
1532
1560
{
1533
 
  SimpleStore* store = &GET_STORE();
 
1561
  Store* store = &GET_STORE();
1534
1562
  store::IC_t ic = store->deactivateIC(theQName,theIsApplied);
1535
1563
  if (theIsApplied)
1536
1564
  {
1554
1582
{
1555
1583
  if (theIsApplied)
1556
1584
  {
1557
 
    SimpleStore* store = &GET_STORE();
 
1585
    Store* store = &GET_STORE();
1558
1586
    bool isApplied;
1559
 
    switch (theICKind) {
 
1587
    switch (theICKind) 
 
1588
    {
1560
1589
      case store::IC::ic_collection:
1561
1590
        store->activateIC(theQName, theFromCollectionName,isApplied);
1562
1591
        break;
1592
1621
 
1593
1622
void UpdCreateDocument::apply()
1594
1623
{
1595
 
  SimpleStore* store = &GET_STORE();
 
1624
  Store* store = &GET_STORE();
1596
1625
 
1597
1626
  store->addNode(theUri->getStringValue(), theDoc);
1598
1627
 
1604
1633
{
1605
1634
  if (theIsApplied)
1606
1635
  {
1607
 
    SimpleStore* store = &GET_STORE();
 
1636
    Store* store = &GET_STORE();
1608
1637
 
1609
1638
    store->deleteDocument(theUri->getStringValue());
1610
1639
    theIsApplied = false;
1628
1657
 
1629
1658
void UpdDeleteDocument::apply()
1630
1659
{
1631
 
  SimpleStore* store = &GET_STORE();
 
1660
  Store* store = &GET_STORE();
1632
1661
 
1633
1662
  zstring lUri = theUri->getStringValue();
1634
1663
 
1646
1675
{
1647
1676
  if (theIsApplied)
1648
1677
  {
1649
 
    SimpleStore* store = &GET_STORE();
 
1678
    Store* store = &GET_STORE();
1650
1679
    store->addNode(theUri->getStringValue(), theDoc);
1651
1680
    theIsApplied = false;
1652
1681
  }