/** * CatalogueConfigStorage - Low-level storage for catalogue configuration * * Handles the 'catcfg:' prefix for storing catalogue configuration. * * Key format: catcfg: * Value: Serialized (string type_label, string expression) * * @version 0.1 * @since 0.1 */ namespace Implexus.Storage.LowLevel { /** * Configuration data for a Catalogue entity. */ public class CatalogueConfig : Object { /** * The type label for documents to catalogue. */ public string type_label { get; set; } /** * The expression used to extract the grouping key. */ public string expression { get; set; } /** * Creates a new CatalogueConfig. * * @param type_label The type label for documents * @param expression The expression to extract the grouping key */ public CatalogueConfig(string type_label, string expression) { this.type_label = type_label; this.expression = expression; } } /** * Low-level storage for catalogue configuration. * * This class provides type-safe operations for storing and retrieving * catalogue configuration using the 'catcfg:' key prefix. */ public class CatalogueConfigStorage : Object { /** * Key prefix for catalogue config entries. */ private const string PREFIX = "catcfg:"; /** * The underlying Dbm storage. */ private Dbm _dbm; /** * Creates a new CatalogueConfigStorage with the given Dbm backend. * * @param dbm The Dbm backend to use for storage */ public CatalogueConfigStorage(Dbm dbm) { _dbm = dbm; } /** * Stores catalogue configuration. * * @param path The catalogue path * @param type_label The type label for documents to catalogue * @param expression The expression to extract the grouping key * @throws StorageError if the operation fails */ public void store(Core.EntityPath path, string type_label, string expression) throws StorageError { string key = PREFIX + path.to_string(); var writer = new ElementWriter(); writer.write_element(new Invercargill.NativeElement(type_label)); writer.write_element(new Invercargill.NativeElement(expression)); _dbm.set(key, writer.to_binary_data()); } /** * Loads catalogue configuration. * * @param path The catalogue path * @return The configuration, or null if not found * @throws StorageError if the data is corrupt */ public CatalogueConfig? load(Core.EntityPath path) throws StorageError { string key = PREFIX + path.to_string(); var data = _dbm.get(key); if (data == null) { return null; } var reader = new ElementReader((!) data); try { var label_element = reader.read_element(); var expr_element = reader.read_element(); if (label_element.is_null() || expr_element.is_null()) { return null; } string type_label = label_element.as(); string expression = expr_element.as(); return new CatalogueConfig(type_label, expression); } catch (Invercargill.ElementError e) { throw new StorageError.CORRUPT_DATA("Failed to read catalogue config: %s".printf(e.message)); } } /** * Deletes catalogue configuration. * * @param path The catalogue path * @throws StorageError if the operation fails */ public void delete(Core.EntityPath path) throws StorageError { string key = PREFIX + path.to_string(); try { _dbm.delete(key); } catch (StorageError e) { // Key doesn't exist, that's fine } } } } // namespace Implexus.Storage.LowLevel