YouTrack
Powerful project management for all your teams
Xodus-DNQ: What is it?
Some time ago, JetBrains released and open-sourced the Xodus-DNQ project. Xodus-DNQ is a Kotlin library that contains a data definition language and queries for Xodus. Xodus is a transactional, schema-less, embedded database that is written in Java and is also developed by JetBrains. Its first release was in July, 2016.
Xodus development started many years ago when YouTrack needed an embedded database that would meet its product performance requirements. Originally, it was implemented as an efficient Berkeley DB replacement, and today the benchmarks show that this goal was definitely achieved.
At present, both YouTrack and Hub use Xodus as a database. While this database doesn’t require a schema, the data tables are mimicked using entity types (like “Issue”, “Project”, and “User”). One entity is similar to a single table record in a schema-driven database. To represent these types, YouTrack and Hub both use Xodus-DNQ for persistent layer definition.
To give you some real-world performance examples, have a look at our own YouTrack and Hub installations. These contain nearly 1,6 million entities of the “Issue” type, about 1,6 million records of the “AuditEvent” type, more than 21 million entries of various issue history “Event”s, not to mention the numerous entities of other types. In short, it’s a lot of data that relies on Xodus for persistence and Xodus-DNQ for data definition.
If you have already used Xodus, you know that it provides a very simple API that is based on operating generic “Entity” instances:
final Entity user = txn.newEntity("User"); user.setProperty("login", loginName); user.setProperty("fullName", fullName); user.setProperty("email", email);
Xodus-DNQ significantly improves your experience by letting you define a persistent meta-model using Kotlin classes, including various properties types, parameters, constraints and triggers.
class XdUser(entity: Entity) : XdEntity(entity) { companion object : XdNaturalEntityType() var login by xdRequiredStringProp(unique = true, trimmed = true) var banned by xdBooleanProp() var created by xdRequiredDateTimeProp() val groups by xdLink0_N(XdGroup::users) } class XdGroup(entity: Entity) : XdEntity(entity) { companion object : XdNaturalEntityType() var name by xdRequiredStringProp(unique = true) { containsNone("<>/") } val users by xdLink0_N(XdUser::groups, onDelete = CLEAR, onTargetDelete = CLEAR) }
Also, Xodus-DNQ lets you build efficient database queries using a variety of operations like filtering, sorting, and mapping. Here’s a few examples:
// find users whose logins start with "max" XdUser.query(XdUser::login startsWith "max") XdUser.filter { it.login startsWith "max" } // find all groups users belong to XdUser.all().flatMapDistinct(XdUser::groups) // add groups to mutable collection user.groups.addAll(sequenceOf(group1, group2))
Xodus and Xodus-DNQ are available in Maven. You are very welcome to give them a try right away!
If you have any questions, don’t hesitate to contact us in GitHub or Stack Overflow.