Skip to content

Commit

Permalink
Merge pull request #138 from xdev-software/develop
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
JohannesRabauer authored Aug 6, 2024
2 parents f7263f4 + c3d8396 commit 92932e8
Show file tree
Hide file tree
Showing 62 changed files with 3,616 additions and 622 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ hs_err_pid*
.tern-project

# EclipseStore
storage
storage-person
storage-invoice
storage-complex
storage-eclipsestore
spring-data-eclipse-store/storage
spring-data-eclipse-store-demo/storage
spring-data-eclipse-store-demo/storage-person
spring-data-eclipse-store-demo/storage-invoice
spring-data-eclipse-store-demo/storage-complex
spring-data-eclipse-store-jpa/storage-eclipsestore
spring-data-eclipse-store-jpa/storage-h2.mv.db
spring-data-eclipse-store-jpa/storage-h2.trace.db

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2.1.0

* Implemented auto-id-generation for UUIDs.
* Implemented composite primary keys.
* Keyword "ignoreCase" now available for queries.
* Implemented ``@Query`` annotation with simple SQL-Selects

# 2.0.1

* Fix for Issue [#131](https://github.com/xdev-software/spring-data-eclipse-store/issues/131)
Expand Down
6 changes: 3 additions & 3 deletions docs/antora.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: ROOT
title: Spring-Data-Eclipse-Store
version: master
display_version: '2.0.0'
display_version: '2.1.0'
start_page: index.adoc
nav:
- modules/ROOT/nav.adoc
asciidoc:
attributes:
product-name: 'Spring-Data-Eclipse-Store'
display-version: '2.0.0'
maven-version: '2.0.0'
display-version: '2.1.0'
maven-version: '2.1.0'
page-editable: false
page-out-of-support: false
4 changes: 3 additions & 1 deletion docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* xref:configuration.adoc[Configuration]
* xref:working-copies.adoc[Working Copies]
* xref:features/features.adoc[Features]
** xref:features/ids.adoc[IDs]
** xref:features/lazies.adoc[Lazy References]
** xref:features/queries.adoc[Queries]
** xref:features/transactions.adoc[Transactions]
** xref:features/versions.adoc[Versions]
* xref:migration.adoc[Migration]
* xref:migration.adoc[Migration from JPA]
* xref:known-issues.adoc[Known issues]
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/features/features.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= Features

* xref:features/ids.adoc[IDs]
* xref:features/lazies.adoc[Lazy References]
* xref:features/queries.adoc[Queries]
* xref:features/transactions.adoc[Transactions]
* xref:features/versions.adoc[Versions]
19 changes: 19 additions & 0 deletions docs/modules/ROOT/pages/features/ids.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
= IDs

{product-name} supports the following types with auto generating (``GenerationType.AUTO``) values:

* ``int`` / ``Integer``
* ``long`` / ``Long``
* ``String``
* ``UUID``
Other generation types are currently not supported.

== Composite keys

It is possible to use **any class as https://jakarta.ee/specifications/persistence/3.2/apidocs/jakarta.persistence/jakarta/persistence/id[``@Id``]** but without any auto generation.
Most importantly the used class **must have a valid ``hashCode``** since a ``HashMap`` is used to store and manage entities.

{product-name} can also handle https://jakarta.ee/specifications/persistence/3.2/apidocs/jakarta.persistence/jakarta/persistence/embeddedid[``@EmbeddedId``] which results in the same behavior as ``@Id`` but the id-class must then implement ``Serializable``.

Multiple Ids for a single entity and https://jakarta.ee/specifications/persistence/3.2/apidocs/jakarta.persistence/jakarta/persistence/idclass[``@IdClass``] are **not** supported.
73 changes: 73 additions & 0 deletions docs/modules/ROOT/pages/features/queries.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
= Queries

== Keywords

It is possible to use **most of the standard query keywords** for repositories defined in Spring Data JPA: https://docs.spring.io/spring-data/jpa/reference/repositories/query-keywords-reference.html[Spring Data JPA - Repository query keywords].

Here are a few examples:

[source,java]
----
@Repository
public interface UserRepository extends EclipseStoreRepository<User, Long>
{
List<User> findByFirstName(String firstName, String lastName);
List<User> findByFirstNameAndLastName(String firstName, String lastName);
List<User> findByDateOfBirthBefore(LocalDate date);
List<User> findByAgeIn(List<Integer> ages);
List<User> findByIsActiveFalse();
}
----

More examples are in the https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/query/by/string/UserRepository.java[test-cases].

== Query by Example

Developers can also use https://docs.spring.io/spring-data/jpa/reference/repositories/query-by-example.html[Query by Example] if preferred.

An example:

[source,java]
----
public List<User> findAllUsersNamedMick()
{
final User probe = new User(1, "Mick", BigDecimal.TEN);
return userRepository.findAll(Example.of(probe));
}
----

More examples are in the https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/query/by/example/QueryByExampleTest.java[test-cases].

== @Query annotation

The support for a ``@Query``-Annotation is currently quite limited, but useful nonetheless.

To keep parse and execute SQL-Queries we use the https://github.com/npgall/cqengine[cqengine] by https://github.com/npgall[Niall Gallagher].
It offers rudimentary support of some SQL-Queries, but not all.

[NOTE]
====
https://github.com/npgall/cqengine[cqengine] parses the SQL String as a SQLite-SQL-String and is therefore different from the https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html#jpa.query-methods.at-query[HQL or JPQL] of Spring Data JPA.
====

Here are some working examples:

[source,java]
----
public interface MyEntityRepository extends ListCrudRepository<MyEntity, Long>
{
@Query("SELECT * FROM MyEntity WHERE name = '?1'")
List<MyEntity> findByName(String name);
@Query("SELECT * FROM MyEntity WHERE (name = '?1' AND age > ?2)")
List<MyEntity> findByNameAndAgeGreaterThan(String name, int age);
@Query("SELECT * FROM MyEntity WHERE 'name' LIKE '%?1%'")
List<MyEntity> findByNameContaining(String keyword);
@Query("SELECT * FROM MyEntity WHERE otherEntity IS NOT NULL")
List<MyEntity> findWhereOtherEntityIsNotNull();
}
----

More examples are in the https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/query/hsql/MyEntityRepository.java[test-cases].
12 changes: 0 additions & 12 deletions docs/modules/ROOT/pages/known-issues.adoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
= Known issues

== Query annotations

In Spring-Data-JPA you can write a Query over methods of repositories like this:

[source,java,title="From https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java[spring-petclinic]"]
----
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
List<PetType> findPetTypes();
----

We created https://github.com/xdev-software/spring-data-eclipse-store/issues/32[an issue] for that but right now we *do not support Query annotations*.

== Data changes

There are two basic ways to keep your data up to date.
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/migration.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Migration
= Migration from JPA

Migrating from Spring Data JPA is very easy.
We implemented a https://github.com/xdev-software/spring-data-eclipse-store-migration[OpenRewrite recipe] for that.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-benchmark</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<inceptionYear>2023</inceptionYear>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-demo</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package software.xdev.spring.data.eclipse.store.demo.dual.storage;

import java.io.File;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import software.xdev.spring.data.eclipse.store.demo.TestUtil;
import software.xdev.spring.data.eclipse.store.demo.dual.storage.invoice.PersistenceInvoiceConfiguration;
import software.xdev.spring.data.eclipse.store.demo.dual.storage.person.PersistencePersonConfiguration;


@SpringBootTest(classes = DualStorageDemoApplication.class)
class DualStorageDemoApplicationTest
{
private final PersistenceInvoiceConfiguration invoiceConfiguration;
private final PersistencePersonConfiguration personConfiguration;

@Autowired
public DualStorageDemoApplicationTest(
final PersistenceInvoiceConfiguration invoiceConfiguration,
final PersistencePersonConfiguration personConfiguration)
{
this.invoiceConfiguration = invoiceConfiguration;
this.personConfiguration = personConfiguration;
}

@BeforeAll
static void clearPreviousData()
{
TestUtil.deleteDirectory(new File("./" + PersistenceInvoiceConfiguration.STORAGE_PATH));
TestUtil.deleteDirectory(new File("./" + PersistencePersonConfiguration.STORAGE_PATH));
}

@Test
void checkPossibilityToSimplyStartAndRestartApplication()
{
this.invoiceConfiguration.getStorageInstance().stop();
this.personConfiguration.getStorageInstance().stop();
DualStorageDemoApplication.main(new String[]{});
}
}
4 changes: 2 additions & 2 deletions spring-data-eclipse-store-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>spring-data-eclipse-store-jpa</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<inceptionYear>2023</inceptionYear>
Expand Down
23 changes: 22 additions & 1 deletion spring-data-eclipse-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>spring-data-eclipse-store</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-data-eclipse-store</name>
Expand Down Expand Up @@ -47,6 +47,7 @@
<maven.compiler.release>${javaVersion}</maven.compiler.release>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Should be in sync with org.eclipse.store:integrations-spring-boot3 -->
Expand Down Expand Up @@ -163,6 +164,26 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.googlecode.cqengine</groupId>
<artifactId>cqengine</artifactId>
<version>3.6.0</version>
<exclusions>
<exclusion>
<artifactId>kryo</artifactId>
<groupId>com.esotericsoftware</groupId>
</exclusion>
<exclusion>
<artifactId>kryo-serializers</artifactId>
<groupId>de.javakaffee</groupId>
</exclusion>
<exclusion>
<artifactId>sqlite-jdbc</artifactId>
<groupId>org.xerial</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package software.xdev.spring.data.eclipse.store.exceptions;

public class IdFieldFinalException extends RuntimeException
public class IdFieldException extends RuntimeException
{
public IdFieldFinalException(final String message)
public IdFieldException(final String message)
{
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
@QueryAnnotation
public @interface Query
{
@SuppressWarnings("unused") String value() default "";
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ private AbstractCriteriaNode<T> from(
{
Objects.requireNonNull(criteria);
final Part.Type type = Objects.requireNonNull(part).getType();
final Part.IgnoreCaseType ignoreCaseType = part.shouldIgnoreCase();
final boolean doIgnoreCase =
ignoreCaseType == Part.IgnoreCaseType.ALWAYS || ignoreCaseType == Part.IgnoreCaseType.WHEN_POSSIBLE;

switch(type)
{
Expand Down Expand Up @@ -169,27 +172,27 @@ private AbstractCriteriaNode<T> from(
}
case LIKE ->
{
return criteria.like((String)Objects.requireNonNull(parameters).next());
return criteria.like((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case STARTING_WITH ->
{
return criteria.startWith((String)Objects.requireNonNull(parameters).next());
return criteria.startWith((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case ENDING_WITH ->
{
return criteria.endWith((String)Objects.requireNonNull(parameters).next());
return criteria.endWith((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case CONTAINING ->
{
return criteria.containing((String)Objects.requireNonNull(parameters).next());
return criteria.containing((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case NOT_LIKE ->
{
return criteria.notLike((String)Objects.requireNonNull(parameters).next());
return criteria.notLike((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case NOT_CONTAINING ->
{
return criteria.notContaining((String)Objects.requireNonNull(parameters).next());
return criteria.notContaining((String)Objects.requireNonNull(parameters).next(), doIgnoreCase);
}
case EXISTS ->
{
Expand Down
Loading

0 comments on commit 92932e8

Please sign in to comment.