Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/release 2 #122

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5ec827a
Add cascade delete on lazy entities
ulisse1996 Jan 8, 2023
1a6aaa5
Remove quarkus target
ulisse1996 Jan 8, 2023
2deaa52
Add merge
ulisse1996 Jan 30, 2023
145e7ca
Add codeql
ulisse1996 Jan 30, 2023
c1c2bba
Add distinct
ulisse1996 Feb 2, 2023
10de02c
Move version to rc3
ulisse1996 Feb 2, 2023
ee8c65a
Add user image path
ulisse1996 Feb 3, 2023
3feaf1c
Fix failing tests
ulisse1996 Feb 5, 2023
93053ab
Fix failing tests
ulisse1996 Feb 5, 2023
4b42803
Fix sonar complains, Add tests
ulisse1996 Feb 5, 2023
ac612eb
Fix check for custom fn in Query, Fix messages on mismatch
ulisse1996 Feb 19, 2023
4cb1b81
Add count, hasResults for DSL
ulisse1996 Feb 26, 2023
af51b52
Fix merge on copied entities
ulisse1996 Feb 27, 2023
498d9a0
Fix wrong insert on special merge with keys
ulisse1996 Mar 12, 2023
9a7aeb3
Add distinct for entity dsl
ulisse1996 Apr 12, 2023
e7669d1
Fix relationship autoset on indirect one to one
ulisse1996 May 26, 2023
11bd63f
Fix tests
ulisse1996 May 30, 2023
af3850c
Fix delete on one to one
ulisse1996 May 31, 2023
5dadc94
Add enum converter
ulisse1996 Jul 13, 2023
152fa85
Fix enum converter uppercase
ulisse1996 Jul 15, 2023
e3f537f
Add inline value with alias
ulisse1996 Aug 26, 2023
10ce064
Add Copy annotations on methods
ulisse1996 Dec 23, 2023
cd2cd1b
Fix duplicate Override on delegation
ulisse1996 Jan 2, 2024
eed3b61
Fix missing import
ulisse1996 Jan 2, 2024
e3b5c8e
Avoid sync blocks for virtual thread compatibility
ulisse1996 Mar 9, 2024
c32dc4c
Fix Lombok java21 compatibility
ulisse1996 Mar 10, 2024
beee6b0
Fix concurrent initalization for delegate fields
ulisse1996 Mar 10, 2024
2ce3f31
Add with support for query
ulisse1996 Mar 23, 2024
ff4cc61
Add with support for query
ulisse1996 Mar 23, 2024
bb50972
Add insert as permitted operation
ulisse1996 Jul 9, 2024
2440b3b
Fire Global Event Listener without checks
ulisse1996 Aug 22, 2024
b09a26a
Remove wrong spaces on queries validation
ulisse1996 Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "CodeQL"

on:
push:
branches: [ "master", "1.x.x" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "26 11 * * 3"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ java ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## 2.0.0
## 2.0.0-RC3
- Feature: Source Code move to Java 11
- Feature: Custom Converter without **@Converter** annotation using **@ConverterProvider**
- Feature: Custom SqlAccessor for Vendor Specific
Expand All @@ -9,17 +9,28 @@
- Feature: startsWith, contains, endsWith, notStartsWith, notContains and notEndsWith for like and notLike
- Feature: Group By for Simple DSL
- Feature: Having for Simple DSL
- Feature: Simple one type read for Simple DSL
- Feature: SQL Ansi Aggregation Functions (COUNT, SUM, MIN, MAX, AVG)
- Feature: Quarkus Extension module
- Feature: FrameworkIntegrationService for Integration with external framework like Quarkus or Micronaut
- Feature: Support for List args in @Query with named params
- Feature: Support for Metrics using MetricsTracker
- Feature: DB2 Sql Specifics
- Feature: Bean Provider for Bean Validation
- Feature: Cascade delete on not initialized lazy entities
- Feature: UUID SqlAccessor
- Feature: Merge for Entities
- Feature: Simple DSL distinct select
- Removal: Removed notLike and like
- Refactor: Refactor of IT Tests
- Bugfix: Fix missing upsert for entities with relationships
- Bugfix: Fix dev mode reloading issues for Quarkus
- Bugfix: Fix event dispatch on unsupported relationships
- Bugfix: Fix missing setEntity for projections with inherited classes
- Bugfix: Fix NPE on where checker for Simple DSL
- Bugfix: Fix IllegalArgumentException for invalid Vendor Function params
- Bugfix: Fix wrong exceptions on Update/Remove Event
- Bugfix: Removed useless update on Entities with a false modified flag

## 1.10.0
- Feature: BeanProvider for Dependency Injection Extensions
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ JAORM is divided in modules that are used from main module using **Java SPI**
- MySql
- MS SQL Server
- PostgreSQL
- DB2
- Validation
- Extensions
- ANSI SQL Build Extensions
- Dependency Injection Extensions
- Framework and Dependency Injection Extensions
- Micronaut Extension
- Jakarta CDI Extension
- Javax CDI Extension
- Spring DI Extension
- Quarkus Extension

## Features

Expand All @@ -48,7 +50,7 @@ JAORM is divided in modules that are used from main module using **Java SPI**
- Supports for most of famous RDBMS
- Supports for **@Getter**, **@Setter** and **@Data** Annotations of [Lombok](https://projectlombok.org/) on Entity
- Supports for [JSR 380](https://beanvalidation.org/2.0-jsr380/) Validation on Entity during Persist/Update
- Supports for DI with JavaEE, JakartaEE, Micronaut and Spring
- Supports for DI with JavaEE, JakartaEE, Micronaut, Quarkus and Spring

## Use

Expand Down
2 changes: 1 addition & 1 deletion jaorm-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jaorm-pom</artifactId>
<groupId>io.github.ulisse1996</groupId>
<version>2.0.0-RC2</version>
<version>2.0.0-RC3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion jaorm-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jaorm-pom</artifactId>
<groupId>io.github.ulisse1996</groupId>
<version>2.0.0-RC2</version>
<version>2.0.0-RC3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion jaorm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jaorm-pom</artifactId>
<groupId>io.github.ulisse1996</groupId>
<version>2.0.0-RC2</version>
<version>2.0.0-RC3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
85 changes: 61 additions & 24 deletions jaorm-core/src/main/java/io/github/ulisse1996/jaorm/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import io.github.ulisse1996.jaorm.entity.Page;
import io.github.ulisse1996.jaorm.entity.Result;
import io.github.ulisse1996.jaorm.entity.event.*;
import io.github.ulisse1996.jaorm.entity.relationship.EntityEvent;
import io.github.ulisse1996.jaorm.entity.relationship.EntityEventType;
import io.github.ulisse1996.jaorm.entity.relationship.Relationship;
import io.github.ulisse1996.jaorm.entity.relationship.UpdateEvent;
import io.github.ulisse1996.jaorm.entity.relationship.*;
import io.github.ulisse1996.jaorm.entity.sql.SqlAccessor;
import io.github.ulisse1996.jaorm.entity.sql.SqlParameter;
import io.github.ulisse1996.jaorm.entity.validation.ValidationResult;
Expand Down Expand Up @@ -74,28 +71,32 @@ default R update(R entity) {
.apply(entity);
checkUpsert(entity);
} else {
if (entity instanceof PreUpdate) {
try {
((PreUpdate<?>) entity).preUpdate();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
ListenersService.getInstance().fireEvent(entity, GlobalEventType.PRE_UPDATE);
UpdateEvent.updateEntity(entity);
checkUpsert(entity);
if (entity instanceof PostUpdate) {
try {
((PostUpdate<?>) entity).postUpdate();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
handleSimpleUpdate(entity);
}
ListenersService.getInstance().fireEvent(entity, GlobalEventType.POST_UPDATE);
return entity;
}

default void handleSimpleUpdate(R entity) {
if (entity instanceof PreUpdate) {
try {
((PreUpdate<?>) entity).preUpdate();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
ListenersService.getInstance().fireEvent(entity, GlobalEventType.PRE_UPDATE);
UpdateEvent.updateEntity(entity);
checkUpsert(entity);
if (entity instanceof PostUpdate) {
try {
((PostUpdate<?>) entity).postUpdate();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
}

default void checkUpsert(R entity) {
if (FeatureConfigurator.getInstance().isInsertAfterFailedUpdateEnabled()) {
// We check for updated row for upsert
Expand All @@ -106,6 +107,37 @@ default void checkUpsert(R entity) {
}
}

default R merge(R entity) {
Objects.requireNonNull(entity);
doValidation(entity);
RelationshipService relationshipService = RelationshipService.getInstance();
if (relationshipService.isEventActive(entity.getClass(), EntityEventType.MERGE)) {
ListenersService.getInstance().fireEvent(entity, GlobalEventType.PRE_MERGE);
EntityEvent.forType(EntityEventType.MERGE)
.apply(entity);
} else {
if (entity instanceof PreMerge) {
try {
((PreMerge<?>) entity).preMerge();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
ListenersService.getInstance().fireEvent(entity, GlobalEventType.PRE_MERGE);
MergeEvent.mergeEntity(entity);
checkUpsert(entity);
if (entity instanceof PostMerge) {
try {
((PostMerge<?>) entity).postMerge();
} catch (Exception ex) {
throw new UpdateEventException(ex);
}
}
}
ListenersService.getInstance().fireEvent(entity, GlobalEventType.POST_MERGE);
return entity;
}

default R insert(R entity) {
Objects.requireNonNull(entity);
doValidation(entity);
Expand Down Expand Up @@ -164,6 +196,11 @@ default void delete(List<R> entities) {
entities.forEach(this::delete);
}

default List<R> merge(List<R> entities) {
Objects.requireNonNull(entities);
return entities.stream().map(this::merge).collect(Collectors.toList());
}

default List<R> insert(List<R> entities) {
Objects.requireNonNull(entities);
return entities.stream()
Expand Down Expand Up @@ -223,19 +260,19 @@ default void applyRelationshipBatch(List<R> entities, Class<?> entityClass, Enti
if (node.isOpt()) {
results = entities.stream()
.map(EntityDelegate::unboxEntity)
.map(node::getAsOpt)
.map(i -> node.getAsOpt(i, eventType))
.filter(Result::isPresent)
.map(Result::get)
.collect(Collectors.toList());
} else if (node.isCollection()) {
results = entities.stream()
.map(EntityDelegate::unboxEntity)
.flatMap(e -> Optional.ofNullable(node.getAsCollection(e)).orElse(Collections.emptyList()).stream())
.flatMap(e -> Optional.ofNullable(node.getAsCollection(e, eventType)).orElse(Collections.emptyList()).stream())
.collect(Collectors.toList());
} else {
results = entities.stream()
.map(EntityDelegate::unboxEntity)
.map(node::get)
.map(i -> node.get(i, eventType))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.ulisse1996.jaorm.entity;

import java.util.ArrayList;
import java.util.List;

public class DirtinessTracker<T> {

private final EntityDelegate<T> delegate;
private final List<Object> removedElements;

public DirtinessTracker(EntityDelegate<T> delegate) {
this.delegate = delegate;
this.removedElements = new ArrayList<>();
}

public EntityDelegate<T> getDelegate() {
return delegate;
}

public void registerRemoved(Result<?> result) {
Fixed Show fixed Hide fixed
if (result != null && result.isPresent() && result.get() instanceof EntityDelegate) {
this.removedElements.add(result.get());
}
}

public void registerRemoved(Object element) {
if (element instanceof EntityDelegate) {
this.removedElements.add(element);
}
}

public List<Object> getRemovedElements() {
return removedElements;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.ulisse1996.jaorm.entity;

import io.github.ulisse1996.jaorm.entity.relationship.LazyEntityInfo;
import io.github.ulisse1996.jaorm.entity.relationship.RelationshipManager;
import io.github.ulisse1996.jaorm.schema.TableInfo;

import java.sql.ResultSet;
Expand All @@ -17,6 +19,15 @@ static <R> R unboxEntity(R e) {
return e;
}

@SuppressWarnings("unchecked")
static <R> EntityDelegate<R> unwrap(R e) {
if (e instanceof EntityDelegate<?>) {
return (EntityDelegate<R>) e;
} else {
throw new UnsupportedOperationException("Object is not an EntityDelegate");
}
}

EntityDelegate<T> generateDelegate();
Supplier<T> getEntityInstance();
EntityMapper<T> getEntityMapper();
Expand All @@ -36,6 +47,11 @@ static <R> R unboxEntity(R e) {
boolean isDefaultGeneration();
T initDefault(T entity);
TableInfo toTableInfo();
DirtinessTracker<T> getTracker();
boolean isLazyEntity();
LazyEntityInfo getLazyInfo();
void setLazyInfo(LazyEntityInfo info);
Dismissed Show dismissed Hide dismissed
RelationshipManager<T> getRelationshipManager();
default void setAutoGenerated(Map<String, Object> generated) {
if (!generated.isEmpty()) {
EntityMapper<T> mapper = getEntityMapper();
Expand Down
Loading