https://github.com/algoristic/simple-jpql
OOP-Wrapper for JPQL
https://github.com/algoristic/simple-jpql
java jpql
Last synced: 9 months ago
JSON representation
OOP-Wrapper for JPQL
- Host: GitHub
- URL: https://github.com/algoristic/simple-jpql
- Owner: algoristic
- Archived: true
- Created: 2019-11-05T14:39:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-10T00:17:15.000Z (almost 4 years ago)
- Last Synced: 2025-04-13T12:57:50.191Z (9 months ago)
- Topics: java, jpql
- Language: Java
- Homepage:
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-jpql
## Overview
**Simple-jpql** provides a wrapper around the JPQL query-syntax defined by JPA. **Simple-jpql** is designed to give you OOP-feeling when writing SQL queries, unlike "stringing" your queries together with plain JPQL, whilst providing an easier syntax than the Criteria API.
## Examples
### Example Data
Given is a very simple database with the tables:
```sql
CREATE TABLE Author (
id INT(11) NOT NULL,
name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id)
)
;
CREATE TABLE Book (
id INT(11) NOT NULL,
title VARCHAR(255) DEFAULT NULL,
year INT(11) DEFAULT NULL,
author_id INT(11) DEFAULT NULL,
PRIMARY KEY (id),
FOREIGN KEY (author_id) REFERENCES Author(id)
)
;
```
**Query all from a single table**
SQL
```sql
SELECT
*
FROM
Books b
;
```
Java
```java
Table books = Table.of(Books.class);
Select.all.from(books);
```
**Combined specific properties, using conditions**
SQL
```sql
SELECT
b.id,
b.year
FROM
Books b
WHERE
b.title LIKE 'Berserk%'
AND
b.year > 1990
;
```
Java
```java
Table books = Table.of(Book.class);
Select.properties(
books.property("id"),
books.property("year")))
.from(books)
.where(Condition.and(
books.property("title").like("Berserk%"),
books.property("year").greaterThan(1990)
));
```
### Queries with Non-Primitive Datatypes
SQL
```sql
SELECT
b
FROM
books b
WHERE
b.author_id = xyz
```
Java
```java
EntityManager em = ...;
Author author = ...;
Table books = Table.of(Book.class);
Query query = Select.properties(books)
.from(books)
.where(books.property("author").isEquals(author))
.query(em);
```
### Planing
- FUNCTIONS (others than simple aggregate-functions)
- JOINS
- GROUP BY and HAVING
- ORDER BY
- distinct date/time/datetime datatype