Database Reference
In-Depth Information
We inject the test data collection /db/test-records into our function under test
as an argument.
We make assertions that the function should never return the id s of the
records in the test data collection.
Note that this is quite a brittle set of test assertions, as the id s are generated
randomly, so we may never hit the edge cases. Hopefully, though, it shows you
what is possible.
Our newly refactored function now accepts the path to the records collection as
a parameter, which allows us to use our test data collection when testing, and
the real collection otherwise.
We have really only scratched the surface of both the larger topic of testing and the
specifics of XQSuite here, but hopefully we've provided enough information to start
you thinking about testing and XQuery code quality. XQSuite provides several other
annotations that allow you to pass parameters in different ways and make different
types of assertions about the results of a function. For further information, consult
the XQSuite documentation .
Versioning
eXist provides two simple versioning mechanisms, which, while not applicable to all
use cases, can be useful to those who wish to track the revision history of certain
types of documents. Both mechanisms can be configured on a per-collection hierar‐
chy basis, which enables you to switch versioning on and off for various document
collections within your database.
Historical Archiving
The historical archival facility will make an archival copy of any document before it is
deleted or overwritten. The archival copy will be placed into a mirror of the collection
tree under the archival collection /db/history by default.
While this is not versioning in the strictest sense, it can be valid for many applica‐
tions. Arguably, you could also achieve basic versioning, if all updates to a document
are performed by the user as document replacements. However, the real purpose of
this facility is to effectively make documents immutable for archival purposes.
Historical archiving is implemented in a document trigger written in Java called
org.exist.collections.triggers.HistoryTrigger . For more information on data‐
base triggers and configuring them, see “Database Triggers” on page 449 . If you wish to
configure the HistoryTrigger for a collection in your database, you need to add the
Search WWH ::




Custom Search