Create Queries using only POJO classes.

Overview

Fluent Query

Create Queries, Inserts, Updates e Deletes using only POJO classes.

Features

  • Configuration over code: independence business code of the infrastructure code;
  • Intrusive-less: zero or less changes for your code;
  • Glue code: it’s only a small and simple classes set;
  • Fluent Builder: code complete is your friend!
  • Check compiler: Refactory ? No problem. Do the compiler to work to you.
  • Performance-based: if you are paranoid by performance, use binder parameters to create Queries, Insert, Update and Deletes.

Mapping

Kotlin Support

See examples in:

Spring Sample

See examples in:

Examples


@Test
public void testSelect() {
	String expected = "select e0.* from Customer e0";
	
	String actual = new QueryBuilder()
		.from(Customer.class)
		.to(new NativeSQL())
		.sql()
		;
	
	Assert.assertEquals(expected, actual);
}

@Test
public void testOrderBy() {
	String expected = "select e0.* from Customer e0 order by e0.id, e0.name desc";
	
	String actual = new QueryBuilder()
		.from(Customer.class)
		.orderBy(x -> x.getId()).asc()
		.orderBy(x -> x.getName()).desc()
		.to(new NativeSQL())
		.sql()
		;
	
	Assert.assertEquals(expected, actual);
}

@Test
public void testCompleteLongString() {
	String expected = 
		"select e0.id, e0.name "
		+ "from Customer e0 "
		+ "where e0.id = :p0 and e0.name like :p1";
	
	NativeSQLResult result = new QueryBuilder()
		.from(Customer.class)
		.where(i -> i.getId()).eq(1L)
			.and(i -> i.getName()).like("r%")
		.select(i -> i.getId())
		.select(i -> i.getName())
		.to(new NativeSQL())
		;
	String actual = result.sql();
	
	Assert.assertEquals(expected, actual);
	Assert.assertEquals(result.params().get("p0"), 1L);
	Assert.assertEquals(result.params().get("p1"), "r%");
}

@Test
public void testTwoEntities() {
	String expected = 
		"select e0.name, e1.balance from Customer e0, Account e1" +
		" where e0.name like :p0" +
		" and e1.balance > :p1" +
		" and e1.customer_id = e0.id" +
		" and e1.customer_regionCode = e0.regionCode" +
		" and e1.balance < e0.minBalance"
		;
	
	NativeSQLResult result = new QueryBuilder()
		.from(Customer.class)
			.where(i -> i.getName()).like("r%")
			.select(i -> i.getName())
		.from(Account.class, (query, parent) -> {
			
			query
				.where(i -> i.getBalance()).gt(0.0)
					.and(i -> i.getCustomer().getId()).eq(parent.getId())
					.and(i -> i.getCustomer().getRegionCode()).eq(parent.getRegionCode())
					.and(i -> i.getBalance()).lt(parent.getMinBalance())
				.select(i -> i.getBalance());
			
		})
		.to(new NativeSQL())
		;
	String actual = result.sql();
	
	Assert.assertEquals(expected, actual);
	Assert.assertEquals(result.params().get("p0"), "r%");
	Assert.assertEquals(result.params().get("p1"), 0.0);
}

Insert, Update and Delete

@Test
public void testInsert() {
	String expected = "insert into Customer (id, name, minBalance) values (:p0, :p1, :p2)";
	
	NativeSQLResult result = new InsertBuilder()
		.into(Customer.class)
			.value(i -> i.getId()).set(1L)
			.value(i -> i.getName()).set("teste")
			.value(i -> i.getMinBalance()).set(10.2)
		.to(new NativeSQLInsertInto());
	
	String actual = result.sql();
	
	Assert.assertEquals(expected, actual);
	
	Assert.assertEquals(result.params().get("p0"), 1L);
	Assert.assertEquals(result.params().get("p1"), "teste");
	Assert.assertEquals(result.params().get("p2"), 10.2);
}

@Test
public void testUpdate() {
	String expected = "update Customer e0 set e0.name = :p0, e0.minBalance = :p1 where e0.id = :p2";
	
	NativeSQLResult result = new UpdateBuilder()
		.entity(Customer.class)
			.value(i -> i.getName()).set("teste")
			.value(i -> i.getMinBalance()).set(10.2)
		.where(i -> i.getId()).eq(1L)
		.to(new NativeSQLUpdate());
	
	String actual = result.sql();
	
	Assert.assertEquals(expected, actual);
	Assert.assertEquals(result.params().get("p0"), "teste");
	Assert.assertEquals(result.params().get("p1"), 10.2);
	Assert.assertEquals(result.params().get("p2"), 1L);
}

@Test
public void testDelete() {
	String expected = "delete from Customer e0 where e0.id = :p0";
	
	NativeSQLResult result = new DeleteBuilder()
		.entity(Customer.class)
		.where(i -> i.getId()).eq(1L)
		.to(new NativeSQLDelete());
	
	String actual = result.sql();
	
	Assert.assertEquals(expected, actual);	
	Assert.assertEquals(result.params().get("p0"), 1L);
}

Binder Parameters


@Test
public void testMultipleInsert() {
	String expected = "insert into Customer (name) values (:p0)";
	
	BinderSQL<Customer> binder = binderBuilder
			.from(Customer.class);
	
	binder.configure(new InsertBuilder()
		.into(Customer.class)
			.value(i -> i.getName()).set(binder.get(i -> i.getName()))
		.to(new NativeSQLInsertInto())
	);
	
	Customer customer1 = new Customer();
	customer1.setName("teste");
	
	Customer customer2 = new Customer();
	customer2.setName("rafael");
	
	NativeSQLResult result1 = binder.bind(customer1);
	NativeSQLResult result2 = binder.bind(customer2);
	
	String actual1 = result1.sql();
	String actual2 = result2.sql();
	
	Assert.assertEquals(expected, actual1);
	Assert.assertEquals(expected, actual2);
	Assert.assertEquals(result1.params().get("p0"), customer1.getName());
	Assert.assertEquals(result2.params().get("p0"), customer2.getName());
}
	 

Usage with Maven

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
	<repository>
	    <id>gitlab-maven</id>
	    <url>https://gitlab.com/api/v4/projects/23719062/packages/maven</url>
	</repository>
</repositories>

<dependency>
    <groupId>com.github.naskarlab</groupId>
    <artifactId>fluent-query</artifactId>
    <version>0.3.3</version>
</dependency>

Releases

0.3.3

Sync packages on jitpack and gitlab.

0.3.2

Github actions for publish on gitlab packages maven repository
[GitLab Packages](https://gitlab.com/naskarlab/maven-repository/-/packages/2311139)

0.3.1

- Included IN/NOT IN
- Included FOR UPDATE for SELECTs
- Included JPA Metamodel support, ie, now it support any JPA provider, beyond the JDBC and MongoDB.

0.3.0

- MappingValueProvider included for fill entities using unstructured datas.

0.2.0

- Use Binder parameters to create caches for queries, inserts, updates and delete sqls.

0.1.0

- Insert, Update and Delete included.

0.0.1

- Simple Queries
You might also like...

A tool which enhances your pojo, powered by java-agent.

A tool which enhances your pojo, powered by java-agent.

Oct 8, 2022

Old and archived; More recent development is in https://github.com/Create-Fabric/Create-Refabricated.

NOW ARCHIVED Go here for the continuation of this project. Old README Create Fabric A Fabric port of Create. Create Discord: https://discord.gg/AjRTh6

Dec 7, 2022

There are two challenges one is to create a backend api the other is to create a frontend application to consume the public data api devall.

There are two challenges one is to create a backend api the other is to create a frontend application to consume the public data api devall.

Sobre | Desafio | Resolução | Tecnologias | Execução | Itexto desafio tecnico Sobre os Desafios existem dois desafios um é criar uma api backend o out

Oct 18, 2021

Golden Axe (1989) game implemented in java using only standard libraries (Java 2D, Swing, AWT & Java Sound API)

Golden Axe (1989) game implemented in java using only standard libraries (Java 2D, Swing, AWT & Java Sound API)

Golden Axe (1989) game implemented in java using only standard libraries (Java 2D, Swing, AWT & Java Sound API), so no external libraries required. Video: https://youtu.be/uevIVLNhQqs

Jul 21, 2022

Yet another very simple java 3D software renderer using only standard 2D libraries (Java2D, AWT & Swing). Video: https://youtu.be/hWUX1t9f6zE

Yet another very simple java 3D software renderer using only standard 2D libraries (Java2D, AWT & Swing). Video: https://youtu.be/hWUX1t9f6zE

Another very simple 3D software renderer Another very simple 3D software renderer implemented in java using only standard libraries (java 2D, AWT & Sw

Oct 17, 2022

First experiments to try to render the Doom WAD maps using only standard libraries. Test 004 - https://youtu.be/-6mePgg7gXE

JavaDoomWADMapRendererTests Test 001 (07/set/2022) - https://youtu.be/MpY0PICdcwM First experiments to try to render the Doom WAD maps using only stan

Oct 17, 2022

LINQ-style queries for Java 8

JINQ: Easy Database Queries for Java 8 Jinq provides developers an easy and natural way to write database queries in Java. You can treat database data

Dec 28, 2022

Unified Queries for Java

Querydsl Querydsl is a framework which enables the construction of type-safe SQL-like queries for multiple backends including JPA, MongoDB and SQL in

Dec 31, 2022

Ultra-fast SQL-like queries on Java collections

Ultra-fast SQL-like queries on Java collections

CQEngine - Collection Query Engine CQEngine – Collection Query Engine – is a high-performance Java collection which can be searched with SQL-like quer

Dec 30, 2022

jdbi is designed to provide convenient tabular data access in Java; including templated SQL, parameterized and strongly typed queries, and Streams integration

The Jdbi library provides convenient, idiomatic access to relational databases in Java. Jdbi is built on top of JDBC. If your database has a JDBC driv

Dec 27, 2022

RTree2D is a 2D immutable R-tree with STR (Sort-Tile-Recursive) packing for ultra-fast nearest and intersection queries

RTree2D is a 2D immutable R-tree with STR (Sort-Tile-Recursive) packing for ultra-fast nearest and intersection queries

RTree2D RTree2D is a 2D immutable R-tree with STR (Sort-Tile-Recursive) packing for ultra-fast nearest and intersection queries. Goals Main our requir

Dec 14, 2022

A simple fast search engine written in java with the help of the Collection API which takes in multiple queries and outputs results accordingly.

A simple fast search engine written in java with the help of the Collection API which takes in multiple queries and outputs results accordingly.

Oct 24, 2022

Log4j CVE-2021-44228 examples: Remote Code Execution (through LDAP, RMI, ...), Forced DNS queries, ...

Log4j CVE-2021-44228 and CVE-2021-45046 Requisites Use a vulnerable JDK, for instance JDK 1.8.0_181 Usage Malicious server The malicious server deploy

Feb 7, 2022

🪖 A library for counting queries for Spring Data JPA application

🪖 Query-Counter Query-Counter is a library for counting queries for Spring Data JPA application, currently supporting Hibernate only. It aims to help

Dec 12, 2021

Beagle helps you identify keywords, phrases, regexes, and complex search queries of interest in streams of text documents.

Beagle helps you identify keywords, phrases, regexes, and complex search queries of interest in streams of text documents.

Beagle Beagle is a detector of interesting things in text. Its intended use is in-stream search applications. Suppose you need to monitor a stream of

Dec 3, 2022

TheRandomAPI is an API that is responsible for generating random responses to different queries.

TheRandomAPI is an API that is responsible for generating random responses to different queries.

Apr 2, 2022

Applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, Paging & Sorting, various Relationships, Transactions

Applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, Paging & Sorting, various Relationships, Transactions

University Management In this project, I practiced & applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, P

Sep 5, 2022

An open source, modular alternative of sketchware. Create your own app in android using block programming like scratch!

An open source, modular alternative of sketchware. Create your own app in android using block programming like scratch!

OpenBlocks An open source, modular alternative of sketchware. Create your own app in android using block programming like scratch! What is OpenBlocks?

Dec 16, 2022

This is simple project to show how to create a basic API using Java 11 + Maven + Spring Boot + PostgrSQL + Flyway.

This is simple project to show how to create a basic API using Java 11 + Maven + Spring Boot + PostgrSQL + Flyway.

Dec 10, 2022
Comments
  • Bump junit from 4.12 to 4.13.1

    Bump junit from 4.12 to 4.13.1

    Bumps junit from 4.12 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
Releases(0.3.3)
Owner
naskarlab
http://www.naskar.com.br http://biocloud.naskar.com.br
naskarlab
Rest.li is a REST+JSON framework for building robust, scalable service architectures using dynamic discovery and simple asynchronous APIs.

Rest.li is an open source REST framework for building robust, scalable RESTful architectures using type-safe bindings and asynchronous, non-blocking I

LinkedIn 2.3k Dec 29, 2022
Create: Liftoff is a create addon that hopes to empower the player even more with the industrial age of the create mod and space rockets!

Create: Liftoff Welcome to Create: Liftoff, a mod that hopes to empower the player even more with the industrial age of the create mod and space rocke

Tazer 9 Jun 6, 2022
Stops double clicks from impacting a player's knockback by only allowing the attack packet to be processed only once per tick per player

Stops double clicks from impacting a player's knockback by only allowing the attack packet to be processed only once per tick per player. It also moves the damage tick check to execute as soon as possible.

Jaiden 2 Oct 28, 2022
Querystream - Build JPA Criteria queries using a Stream-like API

QueryStream QueryStream allows you to perform JPA queries using a Stream-like API. Just like a Java 8 Stream, a QueryStream is built up in a pipeline,

null 11 Sep 24, 2022
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
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
Simple Java/POJO config library written with love and Lombok

Okaeri Configs Supported platforms (general use) General implementations based on standard format libraries directly. HJSON ?? hjson-java: Human JSON

Okaeri 51 Jan 7, 2023
Simple, efficient Excel to POJO library for Java

ZeroCell ZeroCell provides a simple API for loading data from Excel sheets into Plain Old Java Objects (POJOs) using annotations to map columns from a

Credit Data CRB 68 Dec 8, 2022
Java testing framework for testing pojo methods

Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;)

Piotr Joński 48 Aug 23, 2022