comparison Framework/Plugins/IndexBackend.cpp @ 256:e184dcadf163

handling of revisions in metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Apr 2021 17:13:33 +0200
parents d663d9e44f8d
children 34e2b93a7ac1
comparison
equal deleted inserted replaced
255:d663d9e44f8d 256:e184dcadf163
444 } 444 }
445 445
446 SignalDeletedFiles(output, manager); 446 SignalDeletedFiles(output, manager);
447 } 447 }
448 448
449 449
450 void IndexBackend::DeleteMetadata(DatabaseManager& manager, 450 void IndexBackend::DeleteMetadata(DatabaseManager& manager,
451 int64_t id, 451 int64_t id,
452 int32_t metadataType) 452 int32_t metadataType)
453 { 453 {
454 DatabaseManager::CachedStatement statement( 454 DatabaseManager::CachedStatement statement(
463 args.SetIntegerValue("type", static_cast<int>(metadataType)); 463 args.SetIntegerValue("type", static_cast<int>(metadataType));
464 464
465 statement.Execute(args); 465 statement.Execute(args);
466 } 466 }
467 467
468 468
469 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output, 469 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output,
470 DatabaseManager& manager, 470 DatabaseManager& manager,
471 int64_t id) 471 int64_t id)
472 { 472 {
473 assert(manager.GetDialect() != Dialect_MySQL); 473 assert(manager.GetDialect() != Dialect_MySQL);
1254 } 1254 }
1255 } 1255 }
1256 1256
1257 1257
1258 bool IndexBackend::LookupMetadata(std::string& target /*out*/, 1258 bool IndexBackend::LookupMetadata(std::string& target /*out*/,
1259 int64_t& revision /*out*/,
1259 DatabaseManager& manager, 1260 DatabaseManager& manager,
1260 int64_t id, 1261 int64_t id,
1261 int32_t metadataType) 1262 int32_t metadataType)
1262 { 1263 {
1263 DatabaseManager::CachedStatement statement( 1264 std::unique_ptr<DatabaseManager::CachedStatement> statement;
1264 STATEMENT_FROM_HERE, manager, 1265
1265 "SELECT value FROM Metadata WHERE id=${id} and type=${type}"); 1266 switch (manager.GetDialect())
1266 1267 {
1267 statement.SetReadOnly(true); 1268 case Dialect_MySQL:
1268 statement.SetParameterType("id", ValueType_Integer64); 1269 case Dialect_PostgreSQL:
1269 statement.SetParameterType("type", ValueType_Integer64); 1270 statement.reset(new DatabaseManager::CachedStatement(
1271 STATEMENT_FROM_HERE, manager,
1272 "SELECT value FROM Metadata WHERE id=${id} and type=${type}"));
1273 break;
1274
1275 case Dialect_SQLite:
1276 statement.reset(new DatabaseManager::CachedStatement(
1277 STATEMENT_FROM_HERE, manager,
1278 "SELECT value, revision FROM Metadata WHERE id=${id} and type=${type}"));
1279 break;
1280
1281 default:
1282 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
1283 }
1284
1285
1286 statement->SetReadOnly(true);
1287 statement->SetParameterType("id", ValueType_Integer64);
1288 statement->SetParameterType("type", ValueType_Integer64);
1270 1289
1271 Dictionary args; 1290 Dictionary args;
1272 args.SetIntegerValue("id", id); 1291 args.SetIntegerValue("id", id);
1273 args.SetIntegerValue("type", metadataType); 1292 args.SetIntegerValue("type", metadataType);
1274 1293
1275 statement.Execute(args); 1294 statement->Execute(args);
1276 1295
1277 if (statement.IsDone()) 1296 if (statement->IsDone())
1278 { 1297 {
1279 return false; 1298 return false;
1280 } 1299 }
1281 else 1300 else
1282 { 1301 {
1283 target = ReadString(statement, 0); 1302 target = ReadString(*statement, 0);
1303
1304 if (manager.GetDialect() == Dialect_SQLite)
1305 {
1306 revision = ReadInteger64(*statement, 1);
1307 }
1308 else
1309 {
1310 revision = 0; // TODO - REVISIONS
1311 }
1312
1284 return true; 1313 return true;
1285 } 1314 }
1286 } 1315 }
1287 1316
1288 1317
1558 1587
1559 1588
1560 void IndexBackend::SetMetadata(DatabaseManager& manager, 1589 void IndexBackend::SetMetadata(DatabaseManager& manager,
1561 int64_t id, 1590 int64_t id,
1562 int32_t metadataType, 1591 int32_t metadataType,
1563 const char* value) 1592 const char* value,
1593 int64_t revision)
1564 { 1594 {
1565 if (manager.GetDialect() == Dialect_SQLite) 1595 if (manager.GetDialect() == Dialect_SQLite)
1566 { 1596 {
1567 DatabaseManager::CachedStatement statement( 1597 DatabaseManager::CachedStatement statement(
1568 STATEMENT_FROM_HERE, manager, 1598 STATEMENT_FROM_HERE, manager,
1569 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value})"); 1599 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value}, ${revision})");
1570 1600
1571 statement.SetParameterType("id", ValueType_Integer64); 1601 statement.SetParameterType("id", ValueType_Integer64);
1572 statement.SetParameterType("type", ValueType_Integer64); 1602 statement.SetParameterType("type", ValueType_Integer64);
1573 statement.SetParameterType("value", ValueType_Utf8String); 1603 statement.SetParameterType("value", ValueType_Utf8String);
1604 statement.SetParameterType("revision", ValueType_Integer64);
1574 1605
1575 Dictionary args; 1606 Dictionary args;
1576 args.SetIntegerValue("id", id); 1607 args.SetIntegerValue("id", id);
1577 args.SetIntegerValue("type", metadataType); 1608 args.SetIntegerValue("type", metadataType);
1578 args.SetUtf8Value("value", value); 1609 args.SetUtf8Value("value", value);
1610 args.SetIntegerValue("revision", revision);
1579 1611
1580 statement.Execute(args); 1612 statement.Execute(args);
1581 } 1613 }
1582 else 1614 else
1583 { 1615 {
1616 // TODO - REVISIONS
1584 { 1617 {
1585 DatabaseManager::CachedStatement statement( 1618 DatabaseManager::CachedStatement statement(
1586 STATEMENT_FROM_HERE, manager, 1619 STATEMENT_FROM_HERE, manager,
1587 "DELETE FROM Metadata WHERE id=${id} AND type=${type}"); 1620 "DELETE FROM Metadata WHERE id=${id} AND type=${type}");
1588 1621
2046 for (uint32_t i = 0; i < count; i++) 2079 for (uint32_t i = 0; i < count; i++)
2047 { 2080 {
2048 std::string name = "m" + boost::lexical_cast<std::string>(i); 2081 std::string name = "m" + boost::lexical_cast<std::string>(i);
2049 2082
2050 args.SetUtf8Value(name, metadata[i].value); 2083 args.SetUtf8Value(name, metadata[i].value);
2084
2085 std::string revisionSuffix;
2086 if (manager.GetDialect() == Dialect_SQLite)
2087 {
2088 revisionSuffix = ", 0"; // TODO - REVISIONS
2089 }
2051 2090
2052 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + 2091 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " +
2053 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + 2092 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " +
2054 "${" + name + "})"); 2093 "${" + name + "}" + revisionSuffix + ")");
2055 2094
2056 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + 2095 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) +
2057 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) 2096 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata)
2058 + ")"); 2097 + ")");
2059 2098
2119 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i", 2158 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i",
2120 countIdentifierTags, identifierTags); 2159 countIdentifierTags, identifierTags);
2121 2160
2122 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t", 2161 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t",
2123 countMainDicomTags, mainDicomTags); 2162 countMainDicomTags, mainDicomTags);
2124 2163
2125 ExecuteSetResourcesContentMetadata(manager, countMetadata, metadata); 2164 ExecuteSetResourcesContentMetadata(manager, countMetadata, metadata);
2126 } 2165 }
2127 #endif 2166 #endif
2128 2167
2129 2168