ImagingTools Core SDK
Classes | Public Member Functions | List of all members
imtdb::IDependentMetaInfoControllerabstract

Manages cascading metadata updates when related objects are deleted. More...

#include <IDependentMetaInfoController.h>

Inherits istd::IPolymorphic.

Inherited by imtdb::CSqlDatabaseDocumentDelegateComp [virtual].

Classes

struct  DependentMetaInfo
 Information for updating dependent metadata fields. More...
 
struct  MetaFieldCleanupPlan
 Plan for cleaning up metadata fields when referenced objects are deleted. More...
 

Public Member Functions

virtual bool UpdateDependentMetaInfo (const DependentMetaInfo &metaInfo) const =0
 Updates dependent metadata fields to reflect changes in referenced objects.
 
virtual bool ClearDependentMetaInfo (const MetaFieldCleanupPlan &metaInfo) const =0
 Clears metadata fields that reference deleted objects.
 

Detailed Description

Manages cascading metadata updates when related objects are deleted.

IDependentMetaInfoController maintains referential integrity in JSON-based metadata when referenced objects are deleted. It identifies and cleans up dependent metadata fields that reference deleted objects, preventing stale references.

The Problem

Consider this scenario:

The Solution

The controller:

  1. Observes deletion events in source collections (Customers)
  2. Identifies dependent collections (Orders) with references
  3. Finds objects with metadata referencing deleted IDs
  4. Clears or nullifies the dependent metadata fields
  5. Updates timestamps and audit trails

Cleanup Workflow

* 1. Delete Customer "cust-123"
*    ↓
* 2. Controller identifies dependent metadata:
*    - Table: orders
*    - Key: CustomerId
*    - Dependent fields: CustomerName, CustomerEmail
*    ↓
* 3. Find orders with CustomerId = "cust-123"
*    ↓
* 4. Update metadata:
*    {
*      "CustomerId": null,         // Clear reference
*      "CustomerName": null,       // Clear dependent field
*      "CustomerEmail": null       // Clear dependent field
*    }
*    ↓
* 5. Update LastModified timestamp
* 

Usage Example

auto controller = acf::CreateComponent<CDependentTableMetaInfoControllerComp>();
// Configure which fields depend on which references
controller->AddDependentMapping("orders", "CustomerId",
QStringList{"CustomerName", "CustomerEmail"});
// When deleting customers
imtbase::ICollectionInfo::Ids deletedCustomerIds = {"cust-123", "cust-456"};
MetaFieldCleanupPlan plan;
plan.objectIds = deletedCustomerIds;
plan.dependentKey = "CustomerId";
plan.metaInfoIds = QStringList{"CustomerName", "CustomerEmail"};
controller->ClearDependentMetaInfo(plan);
// All orders referencing deleted customers now have cleaned metadata
Note
Cleanup is typically automatic via Observer pattern
Works with JSON/JSONB metadata columns
See also
CDependentTableMetaInfoControllerComp for implementation
CSqlDatabaseDocumentDelegateComp for integration

Definition at line 95 of file IDependentMetaInfoController.h.

Member Function Documentation

◆ ClearDependentMetaInfo()

virtual bool imtdb::IDependentMetaInfoController::ClearDependentMetaInfo ( const MetaFieldCleanupPlan metaInfo) const
pure virtual

Clears metadata fields that reference deleted objects.

When objects are deleted, this method finds all dependent objects that have metadata referencing the deleted IDs and clears the relevant fields.

Parameters
metaInfoDescribes which objects were deleted and what fields to clean
Returns
true if cleanup succeeded, false on error

Process:

  1. Find all objects where metadata[dependentKey] is in objectIds
  2. For each found object:
    • Set metadata[dependentKey] = null
    • For each field in metaInfoIds: set metadata[field] = null
    • Update LastModified timestamp
// Customers "cust-123" and "cust-456" were deleted
plan.objectIds = {"cust-123", "cust-456"};
plan.dependentKey = "CustomerId";
plan.metaInfoIds = {"CustomerName", "CustomerEmail"};
controller->ClearDependentMetaInfo(plan);
// All orders with CustomerId in deleted list now have cleared metadata
Plan for cleaning up metadata fields when referenced objects are deleted.
QString dependentKey
The metadata key that holds the reference to deleted objects.
imtbase::ICollectionInfo::Ids objectIds
List of IDs of deleted objects (e.g., Customer IDs)
QStringList metaInfoIds
List of metadata keys to clear when reference is deleted.
Note
This maintains referential integrity in JSON metadata
Typically called automatically when objects are deleted
See also
UpdateDependentMetaInfo()

◆ UpdateDependentMetaInfo()

virtual bool imtdb::IDependentMetaInfoController::UpdateDependentMetaInfo ( const DependentMetaInfo metaInfo) const
pure virtual

Updates dependent metadata fields to reflect changes in referenced objects.

When a referenced object changes (e.g., Customer renamed), this method updates all dependent metadata that includes derived fields from that object.

Parameters
metaInfoDescribes which object's metadata to update and what values to set
Returns
true if update succeeded, false on error

Example use case:

  • Customer "cust-123" renamed from "John Doe" to "John Smith"
  • Update all Order metadata where CustomerId = "cust-123"
  • Set CustomerName = "John Smith"
update.objectId = "order-789";
update.dependentKey = "CustomerId";
update.metaInfoIds = QStringList{"CustomerName"};
update.metaInfoValues = QStringList{"John Smith"};
controller->UpdateDependentMetaInfo(update);
Information for updating dependent metadata fields.
QString dependentKey
The metadata key that holds the reference to another object.
QStringList metaInfoIds
List of metadata field names to update.
QString objectId
ID of the object whose metadata should be updated.
QStringList metaInfoValues
New values for the metadata fields.
See also
ClearDependentMetaInfo()