diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index a53ed992a..a9acfec52 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -11,11 +11,13 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version === Added - Define Jakarta Data extensions +- Create BasicRepository +- Include insert and update methods in CrudRepository - Create Insert, Update, Delete and Save annotations === Changed -* Rename CrudRepository to BasicRepository +* Move the basic repository methods to the `BasicRepository` interface == [1.0.0-b3] - 2022-07-24 diff --git a/api/src/main/java/jakarta/data/repository/CrudRepository.java b/api/src/main/java/jakarta/data/repository/CrudRepository.java index 234fa73bc..14e22e4c8 100644 --- a/api/src/main/java/jakarta/data/repository/CrudRepository.java +++ b/api/src/main/java/jakarta/data/repository/CrudRepository.java @@ -38,37 +38,55 @@ public interface CrudRepository extends BasicRepository { /** *

Inserts an entity into the database. If an entity of this type with the same - * unique identifier already exists in the database, then this method raises - * {@link EntityExistsException}.

+ * unique identifier already exists in the database and the database supports ACID transactions, + * then this method raises {@link EntityExistsException}. In databases that follow the BASE model + * or use an append model to write data, this exception is not thrown.

+ * + *

The entity instance returned as a result of this method must include all values that were + * written to the database, including all automatically generated values and incremented values + * that changed due to the insert. After invoking this method, do not continue to use the instance + * that is supplied as a parameter. This method makes no guarantees about the state of the + * instance that is supplied as a parameter.

* * @param entity the entity to insert. Must not be {@code null}. - * @throws EntityExistsException if the entity is already present in the database. + * @param Type of the entity to insert. + * @return the inserted entity, which may or may not be a different instance depending on whether the insert caused values to be generated or automatically incremented. + * @throws EntityExistsException if the entity is already present in the database (in ACID-supported databases). * @throws NullPointerException if the entity is null. - * @throws UnsupportedOperationException for Key-Value and Wide-Column databases - * that use an append model to write data. */ - @Insert - void insert(T entity); + @Insert + S insert(S entity); /** - *

Inserts multiple entities into the database. If an entity of this type with the same - * unique identifier as any of the given entities already exists in the database, - * then this method raises {@link EntityExistsException}.

+ *

Inserts multiple entities into the database. If any entity of this type with the same + * unique identifier as any of the given entities already exists in the database and the database + * supports ACID transactions, then this method raises {@link EntityExistsException}. + * In databases that follow the BASE model or use an append model to write data, this exception + * is not thrown.

+ * + *

The entities within the returned {@link Iterable} must include all values that were + * written to the database, including all automatically generated values and incremented values + * that changed due to the insert. After invoking this method, do not continue to use + * the entity instances that are supplied in the parameter. This method makes no guarantees + * about the state of the entity instances that are supplied in the parameter. + * The position of entities within the {@code Iterable} return value must correspond to the + * position of entities in the parameter based on the unique identifier of the entity.

* * @param entities entities to insert. - * @throws EntityExistsException if any of the entities are already present in the database. - * @throws NullPointerException if either the iterable is null or any element is null. - * @throws UnsupportedOperationException for Key-Value and Wide-Column databases - * that use an append model to write data. + * @param Type of the entities to insert. + * @return an iterable containing the inserted entities, which may or may not be different instances depending + * on whether the insert caused values to be generated or automatically incremented. + * @throws EntityExistsException if any of the entities are already present in the database (in ACID-supported databases). + * @throws NullPointerException if the iterable is null or any element is null. */ @Insert - void insertAll(Iterable entities); - + Iterable insertAll(Iterable entities); /** *

Modifies an entity that already exists in the database.

* *

For an update to be made, a matching entity with the same unique identifier - * must be present in the database.

+ * must be present in the database. In databases that use an append model to write data or + * follow the BASE model, this method behaves the same as the {@link #insert} method.

* *

If the entity is versioned (for example, with {@code jakarta.persistence.Version} or by * another convention from the entity model such as having an attribute named {@code version}), @@ -77,7 +95,7 @@ public interface CrudRepository extends BasicRepository { * *

Non-matching entities are ignored and do not cause an error to be raised.

* - * @param entity the entity to update. + * @param entity the entity to update. Must not be {@code null}. * @return true if a matching entity was found in the database to update, otherwise false. * @throws NullPointerException if the entity is null. */ @@ -85,10 +103,11 @@ public interface CrudRepository extends BasicRepository { boolean update(T entity); /** - *

Modifies entities that already exists in the database.

+ *

Modifies entities that already exist in the database.

* *

For an update to be made to an entity, a matching entity with the same unique identifier - * must be present in the database.

+ * must be present in the database. In databases that use an append model to write data or + * follow the BASE model, this method behaves the same as the {@link #insertAll} method.

* *

If the entity is versioned (for example, with {@code jakarta.persistence.Version} or by * another convention from the entity model such as having an attribute named {@code version}), @@ -103,4 +122,5 @@ public interface CrudRepository extends BasicRepository { */ @Update int updateAll(Iterable entities); + }