Enhancing Java Developer Experience with ArcadeDB - A Fluent API Proposal (Ref: Discussion #46) #2194
ivan-velikanov
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Subject: Enhancing Java Developer Experience with ArcadeDB - A Fluent API Proposal (Ref: Discussion #46)
Hi Luca (@lvca),
Hope you're doing well.
You might probably recall a discussion we had back in 2021 (ArcadeDB Discussion #46) regarding improving the Java development experience with ArcadeDB, perhaps drawing inspiration from libraries like Nitrite DB or Scala's Quill.
Since then, I've continued using ArcadeDB (appreciating its pure Java nature, multi-model capabilities, and the excellent Studio!) and have developed a set of helper libraries and patterns in Java to bridge some gaps and achieve a more fluent, type-safe, and less boilerplate-heavy coding style when working with embedded ArcadeDB instances.
I wanted to share this approach with you and the ArcadeDB team. I've put together a detailed explanation and a complete working example project (
xyz-jphil-gdrive_cache
- code attached/referenced below) showcasing these concepts.The core ideas revolve around:
My hope is that this makes mapping Java objects to ArcadeDB documents more elegant and less error-prone, somewhat akin to the experience with other database libraries.
I understand that maintaining such libraries is a significant effort, especially for a solo developer not working on this full-time. Therefore, I wanted to ask:
I've attached a detailed breakdown of the approach and key code snippets from the example project below. I believe incorporating such features could significantly enhance the developer experience for Java users adopting ArcadeDB.
Thanks for your time and consideration, and for the fantastic work on ArcadeDB!
Best regards.
PS: I didn't have something already written up, so I generated some documentation. I do not these libraries and tools in github at the moment, I will push them when I have time. As you might have noticed, our discussion is having a 4 year gap. Coding is not my core work actually. I have attached some AI generated documentation below. I hope this is not too wordy and serves the purpose. Thanks again.
ArcadeDB Fluent Java API Proposal - Detailed Example
This document outlines a proposed approach and provides examples for enhancing the Java developer experience when using ArcadeDB in an embedded mode. It leverages a few small helper libraries to achieve a more fluent and type-safe interaction pattern.
Motivation:
While ArcadeDB offers powerful features and a solid Java core, the standard API for schema definition and CRUD operations can sometimes involve string literals for type and field names, which can be error-prone. Inspired by libraries like Nitrite DB and Scala's Quill, this approach aims to:
Core Components:
org.projectlombok:lombok
) Standard library to reduce boilerplate (getters, setters, constructors, etc.).io.github.xyz-jphil.annotation_processor:xyz-jphil-annotation_processor-generate_symbols_from_fields
) An annotation processor that generates aSymbols
class containing staticString
constants for the fields of an annotated model class. It also generates helper methods likemap()
(object to Map) andmapAllFieldValues()
(Map to object).io.github.xyz-jphil.arcadedb:xyz-jphil-arcadedb-initialize_document_schema
) A small library providing aSchemaBuilder
to define ArcadeDB document types and indexes fluently, using the generated symbols.io.github.xyz-jphil.arcadedb:xyz-jphil-arcadedb-document_crud_helper
) Provides utilities like a fluentUpdate
builder for performing upsert operations easily.Example Implementation (
xyz-jphil-gdrive_cache
project):Let's look at how these components are used in the provided
xyz-jphil-gdrive_cache
project, which indexes Google Drive file metadata.1. Dependencies (pom.xml):
2. Model Class (
DriveFile.java
):This class represents the data stored in the database.
3. Generated Symbols (
DriveFileSymbols.java
- generated code):This file is automatically generated by the annotation processor during compilation.
4. Database Service (
ArcadeDbServiceImpl.java
):This service class manages the ArcadeDB lifecycle and uses the helper libraries.
Key Benefits Demonstrated:
$id
,$name
is cleaner than using"id"
,"name"
.DriveFile
class, recompiling will:DriveFileSymbols
class.map()
andmapAllFieldValues()
helpers generated by the symbol processor reduce manual mapping code.DriveFile.schema()
andinitDocTypes
is declarative and co-located with the model definition.Update.use(db)...
pattern simplifies common upsert logic.Potential Next Steps / Areas for Discussion:
SchemaBuilder
orUpdate
helper logic be incorporated directly into the core ArcadeDB Java API?This approach represents one way to enhance the Java development workflow with ArcadeDB. We hope this detailed example is useful and look forward to any feedback or insights from the ArcadeDB team regarding future plans in this area.
Beta Was this translation helpful? Give feedback.
All reactions