ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model

Related tags

ORM orm16
Overview

About ORM16

ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model.

Example

Input Java model

package com.example.model;

@Serialized(context = PERSISTENCE, as = "accounts") // generate JDBC mapping
@Serialized(context = INTEGRATION, format = JSON)   // generate JSON mapping
public record Account(@Id UUID uuid,                // primary key
                      Instant created,              // use standard mapping to TIMESTAMP
                      String username,
                      @Value Locale locale,         // serialize as string value
                      @Mapping(                       // unwrap object (only in database)
                              context = PERSISTENCE, 
                              serializeAs = EMBEDDED,
                              overrides = {
                                      @AttributeOverride(map = "currencyCode", to = "currency")
                              }) 
                      @Mapping(context = INTEGRATION, serializeAs = VALUE) // serialize to string e.g. "100 EUR" 
                      Money balance             
                     ) {
}

public record Money(BigDecimal amount,
                    String currencyCode) {
    public static Money fromString(String value) {
        // parse string representation 
    }
    public String toString() {
        // build string representation of this object
    }
}

Database table in PostgreSQL

CREATE TABLE accounts (
    uuid             UUID NOT NULL PRIMARY KEY,  // account.uuid()
    created          TIMESTAMP NOT NULL,         // java.sql.Timestamp.from(account.created())
    username         VARCHAR(64) NOT NULL,       // account.username()
    locale           VARCHAR(5) NOT NULL,        // account.locale().toString()
    balance_amount   NUMERIC(10,2) DEFAULT NULL, // account.balance().amount()
    balance_currency CHAR(3) DEFAULT NULL        // account.balance().currencyCode()
)

JSON model

{
  "uuid"      : "92147655-226e-415e-8976-1844a8367ec6",
  "created"   : "2022-01-01T14:30:23.341Z",
  "username"  : "mustermann", 
  "locale"    : "en-US",
  "balance"   : "200 EUR"
}

Generated code

package com.example.model.jdbc;

public class AccountRepository implements Repository<Account, UUID> {
    
    public AccountRepository(JdbcDatabase jdbc) {
        // Inject connection pool / database wrapper
    }
    
    public void add(Account account) {
        // ...
    }
    
    public void update(Account account) {
        // ...
    }
    
    public Optional<Account> findById(UUID uuid) { 
        // ...
    }
    // other applicable methods
}

Planned v1 features

  1. Zero use of reflection at runtime
  2. Flexible mapping of records with customizable table and column names
  3. Separate mapping for persistence (JDBC/Postgres) and integration (JSON) contexts
  4. Variety of standard Java type mappings (primitives, Java Time API, UUIDs, URLs, enums)
  5. Arbitrary type conversions via factory methods or custom converter classes
  6. Unwrapping embedded entities
  7. Sensible defaults to reduce verbosity
  8. Micronaut microservice demo

Current open questions and challenges

  1. How to inject repository in the user code? ServiceLoader, Guice, Spring?
  2. Custom finders: findByXXX vs Criteria API convention, how to declare interface?
  3. Object tree traversal: how to model foreign keys and corresponding relationships? How to fetch this data?
  4. Plugin architecture: How to support different database dialects?
  5. Caching: does it make sense in microservice architectures? Should it be part of the solution?
You might also like...

ReDoSHunter: A Combined Static and Dynamic Approach for Regular Expression DoS Detection

ReDoSHunter ReDoSHunter is a combined static and dynamic approach for regular expression DoS detection. LATEST NOTE (updated at 2021.09.13): ReDoSHunt

Dec 23, 2022

Exploring Spring and Sprinboot by building projects

Explore-Spring-Springboot Exploring Spring and Sprinboot by building projects Requirements Java-JDK: 17 IDE supporting Maven Integration: Intellij IDE

Sep 19, 2022

A big, fast and persistent queue based on memory mapped file.

A big, fast and persistent queue based on memory mapped file.

Big Queue A big, fast and persistent queue based on memory mapped file. Notice, bigqueue is just a standalone library, for a high-throughput, persiste

Dec 30, 2022

JavaWeb MemoryShell Inject/Scan/Killer/Protect Research & Exploring

JavaWeb MemoryShell Inject/Scan/Killer/Protect Research & Exploring

Memory Shell JavaWeb MemoryShell Inject/Scan/Killer/Protect Research & Exploring 文章:JavaWeb 内存马一周目通关攻略 项目介绍 本项目用来学习和研究 JavaWeb 内存马添加和防御模式,共包含以下几个模块。 m

Dec 30, 2022

Exploring JSI

react-native-jsi-trial Exploring JSI This repo got a minimal example of JSI of creating a multiply function in CPP and using it from JS How to run the

Mar 22, 2022

Car-Sequencing-Problem - Car-Sequencing Problem solved with Constraint Programming approach

Car-Sequencing-Problem - Car-Sequencing Problem solved with Constraint Programming approach

Car-Sequencing problem solved with Constraint Programming : Problem Description : Cars in a production line can be configured with various options. A

Sep 7, 2022

Efficient lazy load approach for entities containing clob in hibernate

Lazy loading clob fields of Entites using Hibernate This is an efficient approach to load clob fields lazily of an Entity. Using this approach, distin

Jan 22, 2022

Dataflow template which read data from Kafka (Support SSL), transform, and outputs the resulting records to BigQuery

Kafka to BigQuery Dataflow Template The pipeline template read data from Kafka (Support SSL), transform the data and outputs the resulting records to

Jun 1, 2021

A Persistent Java Collections Library

PCollections A Persistent Java Collections Library Overview PCollections serves as a persistent and immutable analogue of the Java Collections Framewo

Dec 28, 2022

A Persistent Java Collections Library

PCollections A Persistent Java Collections Library Overview PCollections serves as a persistent and immutable analogue of the Java Collections Framewo

Dec 28, 2022

An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage.

Spring Boot + JPA — Clear Tests An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage. Check out the article

Nov 24, 2022

Representational State Transfer + Structured Query Language(RSQL): Demo application using RSQL parser to filter records based on provided condition(s)

Representational State Transfer + Structured Query Language: RSQL Demo application using RSQL parser to filter records based on provided condition(s)

Nov 23, 2022

Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based system

FRC 2022 Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based s

Oct 4, 2022

Firehose is an extensible, no-code, and cloud-native service to load real-time streaming data from Kafka to data stores, data lakes, and analytical storage systems.

Firehose - Firehose is an extensible, no-code, and cloud-native service to load real-time streaming data from Kafka to data stores, data lakes, and analytical storage systems.

Dec 22, 2022

A distributed data integration framework that simplifies common aspects of big data integration such as data ingestion, replication, organization and lifecycle management for both streaming and batch data ecosystems.

Apache Gobblin Apache Gobblin is a highly scalable data management solution for structured and byte-oriented data in heterogeneous data ecosystems. Ca

Jan 4, 2023

An extremely easy way to perform background processing in Java. Backed by persistent storage. Open and free for commercial use.

An extremely easy way to perform background processing in Java. Backed by persistent storage. Open and free for commercial use.

The ultimate library to perform background processing on the JVM. Dead simple API. Extensible. Reliable. Distributed and backed by persistent storage.

Jan 6, 2023

Persistent (immutable) collections for Java and Kotlin

Persistent (immutable) collections for Java and Kotlin

What are Dexx Collections? Dexx Collections are a port of Scala's immutable, persistent collection classes to pure Java. Persistent in the context of

Sep 30, 2022
Comments
  • Implement Criteria API prototype

    Implement Criteria API prototype

    Simple criteria API can be a reasonable alternative to Spring Data-like finder methods, if it enables at least filtering and ordering of the results. Possible solution may look like following:

    Java model

    public record Account(String firstName, LocalDate birthDate) {}
    

    Generated code

    public class AccountRepository implements Finder<AccountCriteria, Account> {
    
        public static class AccountCriteria implements Criteria<AccountCriteria, Account> {}
    
        public static StringCriteriaBuilder<AccountCriteria> firstName() {}
        public static TemporalCriteriaBuilder<AccountCriteria> birthDate() {}
    
        // restrict to specific types of conditions
       @Override
        public List<Account> findAll(AccountCriteria criteria) {
             var rs = jdbc.query("SELECT firstName, birthDate FROM Account WHERE " + criteria.toSQLTemplate(), criteria.params())
        }
    }
    

    User code

    AccountRepository accounts;
    
    @Get("/search-accounts")
    public List<Accounts> find(LocalDate givenDate, String searchString) {
          return accounts.findAll(birthDate().before(givenDate)
                                               .and(firstName().containsIgnoreCase(searchString)));
    }
    
    opened by ivan-gammel 0
  • Implement embedding / conversion model

    Implement embedding / conversion model

    As first PoC has shown viability of this approach, next step will be to implement the model for embedding entities and data type conversions. The model must support reasonably deep embedding hierarchies and chaining of custom and built-in conversions, e.g.:

    Embedding Given following structure:

    record A(@Embed B b) {}
    record B(@Embed C c) {}
    record C(@Embed D d) {}
    record D(String value) {}
    

    The following table could be mapped:

    CREATE TABLE A (
      b_c_d_value VARCHAR(255)
    );
    

    Conversion Given the following record:

    record A(@Map(using = MyTimestampToInstant.class) MyTimestamp value) {}
    

    The following table could be mapped, assuming conversion path from MyTimestamp to Instant and further to javax.sql.Timestamp.

    CREATE TABLE A (
      value TIMESTAMP NOT NULL
    );
    
    opened by ivan-gammel 0
Owner
Ivan Gammel
Ivan Gammel
Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper

Simple Flat Mapper Release Notes Getting Started Docs Building it The build is using Maven. git clone https://github.com/arnaudroger/SimpleFlatMapper.

Arnaud Roger 418 Dec 17, 2022
Storm - a fast, easy to use, no-bullshit opinionated Java ORM inspired by Doctrine

A stupidly simple Java/MySQL ORM with native Hikaricp and Redis cache support supporting MariaDB and Sqlite

Mats 18 Dec 1, 2022
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.

Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation

Markus Junginger 12.6k Jan 5, 2023
Ebean ORM

Ebean ORM

Ebean ORM 1.3k Jan 5, 2023
DAO oriented database mapping framework for Java 8+

Doma Doma 2 is a database access framework for Java 8+. Doma has various strengths: Verifies and generates source code at compile time using annotatio

domaframework 353 Dec 28, 2022
MyBatis SQL mapper framework for Java

MyBatis SQL Mapper Framework for Java The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented applications.

MyBatis 18k Jan 2, 2023
Language-Natural Persistence Layer for Java

Permazen is a better persistence layer for Java Persistence is central to most applications. But there are many challenges involved in persistence pro

Permazen 322 Dec 12, 2022
cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Code Generation Library 4.5k Jan 8, 2023
sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.

sql2o Sql2o is a small java library, with the purpose of making database interaction easy. When fetching data from the database, the ResultSet will au

Lars Aaberg 1.1k Dec 28, 2022
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

OpenAPI Generator Master (5.4.x): 6.0.x (6.0.x): ⭐ ⭐ ⭐ If you would like to contribute, please refer to guidelines and a list of open tasks. ⭐ ⭐ ⭐ ‼️

OpenAPI Tools 14.8k Dec 30, 2022