apply method
Future<ApplyIncomingResult>
apply(
- List<OplogEntry> incoming,
- String incomingOrigin
)
Implementation
@visibleForTesting
Future<ApplyIncomingResult> apply(
List<OplogEntry> incoming,
String incomingOrigin,
) async {
final local = await getEntries();
final merged = mergeEntries(
authState!.clientId,
local,
incomingOrigin,
incoming,
relations,
);
final List<Statement> stmts = [];
for (final entry in merged.entries) {
final tablenameStr = entry.key;
final qualifiedTableName = QualifiedTablename.parse(tablenameStr);
final mapping = entry.value;
for (final entryChanges in mapping.values) {
final ShadowEntry shadowEntry = ShadowEntry(
namespace: entryChanges.namespace,
tablename: entryChanges.tablename,
primaryKey: getShadowPrimaryKey(entryChanges),
tags: encodeTags(entryChanges.tags),
);
switch (entryChanges.optype) {
case ChangesOpType.gone:
case ChangesOpType.delete:
stmts.add(_applyDeleteOperation(entryChanges, qualifiedTableName));
stmts.add(_deleteShadowTagsStatement(shadowEntry));
default:
stmts.add(
_applyNonDeleteOperation(entryChanges, qualifiedTableName),
);
stmts.add(_updateShadowTagsStatement(shadowEntry));
}
}
}
final tablenames = merged.keys.toList();
return ApplyIncomingResult(
tableNames: tablenames,
statements: stmts,
);
}