initialize method
Build a fully-initialised AtPersistenceBundle for atSign.
Calling this twice for the same atSign returns the same bundle — the factory owns the per-atSign lifecycle. Callers should not try to manage it themselves.
If a previous bundle for atSign has been closed (whether
directly via AtPersistenceBundle.close or via closeFor),
the stale entry is dropped and a fresh bundle is built.
Throws ArgumentError if config does not match
backendId.
Implementation
@override
Future<AtPersistenceBundle> initialize(
String atSign, AtPersistenceConfig config) async {
if (config is! SqlitePersistenceConfig) {
throw ArgumentError(
'SqliteAtPersistenceFactory expects SqlitePersistenceConfig, '
'got ${config.runtimeType}');
}
final existing = _bundles[atSign];
if (existing != null) {
if (!existing.isClosed) return existing;
_bundles.remove(atSign);
}
_logger.info('Initialising SQLite persistence for $atSign');
final db = SqliteDatabase.open(atSign, config.dbPathFor(atSign));
final commitLog = config.enableCommitLog ? SqliteAtCommitLog(db) : null;
final accessLog = config.enableAccessLog ? SqliteAtAccessLog(db) : null;
final notificationKeystore = config.enableNotificationKeystore
? SqliteAtNotificationKeystore(db)
: null;
final keyValueStore = SqliteAtKeyValueStore(db, atSign)
..commitLog = commitLog;
await keyValueStore.initialize();
final bundle = SqliteAtPersistenceBundle._(
atSign: atSign,
db: db,
keyValueStore: keyValueStore,
accessLog: accessLog,
notificationKeystore: notificationKeystore,
);
_bundles[atSign] = bundle;
return bundle;
}