comparison Framework/Plugins/DatabaseBackendAdapterV2.cpp @ 207:d9ef3f16e6a2

wrapping transactions in API v3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 Mar 2021 15:11:45 +0100
parents 873e37048f96
children 13a3863df7fa
comparison
equal deleted inserted replaced
206:6dcf57074dd4 207:d9ef3f16e6a2
1107 { 1107 {
1108 IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); 1108 IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
1109 1109
1110 try 1110 try
1111 { 1111 {
1112 backend->StartTransaction(); 1112 backend->StartTransaction(TransactionType_ReadWrite);
1113 return OrthancPluginErrorCode_Success; 1113 return OrthancPluginErrorCode_Success;
1114 } 1114 }
1115 ORTHANC_PLUGINS_DATABASE_CATCH; 1115 ORTHANC_PLUGINS_DATABASE_CATCH;
1116 } 1116 }
1117 1117
1424 { 1424 {
1425 return new Output(context_, database_); 1425 return new Output(context_, database_);
1426 } 1426 }
1427 1427
1428 1428
1429 void DatabaseBackendAdapterV2::Register(OrthancPluginContext* context, 1429 void DatabaseBackendAdapterV2::Register(IDatabaseBackend& backend)
1430 IDatabaseBackend& backend)
1431 { 1430 {
1432 OrthancPluginDatabaseBackend params; 1431 OrthancPluginDatabaseBackend params;
1433 memset(&params, 0, sizeof(params)); 1432 memset(&params, 0, sizeof(params));
1434 1433
1435 OrthancPluginDatabaseExtensions extensions; 1434 OrthancPluginDatabaseExtensions extensions;
1518 extensions.getAllMetadata = GetAllMetadata; 1517 extensions.getAllMetadata = GetAllMetadata;
1519 performanceWarning = false; 1518 performanceWarning = false;
1520 # endif 1519 # endif
1521 #endif 1520 #endif
1522 1521
1522 OrthancPluginContext* context = backend.GetContext();
1523
1523 if (performanceWarning) 1524 if (performanceWarning)
1524 { 1525 {
1525 char info[1024]; 1526 char info[1024];
1526 sprintf(info, 1527 sprintf(info,
1527 "Performance warning: The database index plugin was compiled " 1528 "Performance warning: The database index plugin was compiled "
1537 OrthancPluginLogWarning(context, info); 1538 OrthancPluginLogWarning(context, info);
1538 } 1539 }
1539 1540
1540 OrthancPluginDatabaseContext* database = 1541 OrthancPluginDatabaseContext* database =
1541 OrthancPluginRegisterDatabaseBackendV2(context, &params, &extensions, &backend); 1542 OrthancPluginRegisterDatabaseBackendV2(context, &params, &extensions, &backend);
1542 if (!context) 1543 if (database == NULL)
1543 { 1544 {
1544 throw std::runtime_error("Unable to register the database backend"); 1545 throw std::runtime_error("Unable to register the database backend");
1545 } 1546 }
1546 1547
1547 backend.SetOutputFactory(new Factory(context, database)); 1548 backend.SetOutputFactory(new Factory(context, database));