DataFactory is a library for Jetbrains Xodus database that provides compute abstraction layer through Actions and Conditions with a fluent API. It allows a managed access to the underlying database through consistent Java API that works both in an embedded or in a remote context through Java RMI.
Requirements: JDK 8, Maven
- It's a drop-in library for any Java project
- Does not require any server setup or administration
- Extendable managed database access through interfaces
$mvn clean install
<dependency>
<groupId>com.divroll</groupId>
<artifactId>datafactory</artifactId>
<version>0-SNAPSHOT</version>
</dependency>
EntityStore entityStore
= isClientMode ? DataFactoryClient.getInstance().getEntityStore()
: DataFactory.getInstance().getEntityStore();
The basic operation for the EntityStore
are:
- Save which is used both for saving a single entity or multiple entities
- Get which is used for getting a single entity or multiple entities
- Delete which is used for deleting a single or multiple entities
All operation, single or multiple entities operates in a transaction. Thus, it follows the concept of all-or-nothing.
DataFactoryEntity entity = new DataFactoryEntityBuilder()
.environment(PROD_ENVIRONMENT)
.entityType("Room")
.putPropertyMap("address", "Room 123, 456 Street, 789 Avenue")
.build();
entity = entityStore.saveEntity(entity).get();
Actions execute as part of the save operation. There as built-in actions which are listed here, but custom actions can also be used. An example implementation can be found here
entityStore.saveEntity(new DataFactoryEntityBuilder()
.environment(PROD_ENVIRONMENT)
.entityId(entity.entityId())
.addActions(new IncrementLikesAction(100))
.build());
Conditions provides the facility to save (or most usually, to update) an entity based on specific conditions. Throwing exception when condition is not satisfied. There are built-in conditions that can be used off-the-shelf which can be found here however it also possible to create custom conditions as such:
entity = entityStore.saveEntity(new DataFactoryEntityBuilder()
.environment(PROD_ENVIRONMENT)
.entityId(entity.entityId())
.addConditions(new HasBeenLikedThisWeekCondition())
.addActions(new IncrementLikesAction(100))
.build()).get();
The above example shows that the save operation will only succeed if the condition
HasBeenLikedThisWeekCondition
, and will execute the action accordingly if satisfied.
Both the condition and the action here are self-explanatory but you can check the
details here.
Jetbrains Xodus is fast and low-footprint, an embedded database by design, accessing it remotely can only be achieved by creating custom endpoints through remote access methods.
DataFactory provides a generic and fluent API for accessing the Xodus database without hand-coding these custom endpoints and just using Java RMI.
Furthermore, the lack of ability to scale horizontally across multiple JVM's makes it hard to be used in a distributed manner.
With DataFactory, a Xodus database instance running on a vertically-scaled server can be used in along with horizontally scaling application servers.