Internals

Code design

OntoDB uses a small set of standard patterns, so a new method plugs in at a known place instead of growing a conditional.

Patterns

PatternWhere
Iterator (volcano)TripleIterator; every executor's Init / Next pulls one row at a time
RepositoryTripleStore and Dictionary hide where triples and terms live (MemStore, IndexedStore; MemDictionary, DiskDictionary)
FactoryExecutorFactory::Create maps a plan node to its executor; Database::Open; the LogRecord named constructors; MakeDamagePolicy
BuilderPlanner builds the plan tree from a bound query
Strategy, replace conditional with polymorphismLogDamagePolicy, one class per recovery mode; \set join selects the join operator; TraceSink implementations
Null objectNullTraceSink when tracing is off
DecoratorRecordingStore wraps any TripleStore and records its changes, so a statement can be logged as one transaction or undone
AdapterRdfLoader adapts raptor2's parser to Dictionary and TripleStore
CommandThe shell's command table, one entry per backslash command, read by both dispatch and \help; log records are replayable commands
RAIIReadPageGuard and WritePageGuard unpin on destruction
Dependency injectionExecutorContext carries the store, dictionary, config, and stats into every executor; LogManager, Durability, and the buffer pool take their collaborators as constructor arguments

Adding to OntoDB

To addWhere
A shell commandOne entry in tools/shell/commands.cpp: word, usage, summary, handler. \help picks it up
An executorA class with Init / Next, a plan node, and a case in ExecutorFactory::Create
A storage backendA TripleStore implementation; the engine sees only the interface
A recovery modeA LogDamagePolicy subclass and a case in MakeDamagePolicy
A verify checkA function returning a CheckResult (ok, report line), added to Durability::Verify

Deliberate exceptions

Further reading

Gamma, Helm, Johnson, and Vlissides, *Design Patterns*. Fowler, *Refactoring*, on replacing conditionals with polymorphism and extracting functions.