Skip to content

Commit

Permalink
feat: include NoSQL repository capability of insert and update
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Mar 22, 2024
1 parent 07beed6 commit 3a8adec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
package org.eclipse.jnosql.mapping;

import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.CrudRepository;
import jakarta.data.repository.Delete;

import java.util.stream.Stream;

/**
* Interface for NoSQL repositories, providing additional operations beyond basic {@link BasicRepository}.
*
* @param <T> the type of the entity managed by this repository
* @param <K> the type of the entity's primary key
*/
public interface NoSQLRepository<T, K> extends BasicRepository<T, K> {
public interface NoSQLRepository<T, K> extends BasicRepository<T, K>, CrudRepository<T, K>{

/**
* Deletes all persistent entities of the primary entity type that are managed by the repository.
Expand All @@ -40,4 +43,38 @@ public interface NoSQLRepository<T, K> extends BasicRepository<T, K> {
* @throws UnsupportedOperationException for Key-Value and Wide-Column databases that are not capable of the {@code count} operation.
*/
long countBy();

/**
* Returns whether an entity with the given Id exists.
*
* @param id must not be {@code null}.
* @return {@code true} if an entity with the given Id exists, {@code false} otherwise.
* @throws NullPointerException when the Id is {@code null}.
*/
boolean existsById(K id);

/**
* Returns all instances of the type {@code T} with the given Ids.
* <p>
* If some or all Ids are not found, no entities are returned for these Ids.
* <p>
* Note that the order of elements in the result is not guaranteed.
*
* @param ids must not be {@code null} nor contain any {@code null} values.
* @return guaranteed to be not {@code null}. The size can be equal or less than the number of given
* ids.
* @throws NullPointerException in case the given {@link Iterable ids} or one of its items is {@code null}.
*/
Stream<T> findByIdIn(Iterable<K> ids);


/**
* Deletes all instances of the type {@code T} with the given Ids.
* <p>
* Entities that are not found in the persistent store are silently ignored.
*
* @param ids must not be {@code null}. Must not contain {@code null} elements.
* @throws NullPointerException when the iterable is {@code null} or contains {@code null} elements.
*/
void deleteByIdIn(Iterable<K> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ private static Object executeSingleEntity(Operation operation, Object param, Ret
if (returnType.isVoid()) {
return Void.TYPE;
} else if (returnType.isBoolean()) {
return result;
return true;
} else if (returnType.isInt()) {
return 1;
} else if (returnType.isLong()) {
return 1L;
} else {
return param;
return result;
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.data.repository.Query;
import jakarta.data.Sort;
import jakarta.inject.Inject;
import org.eclipse.jnosql.mapping.NoSQLRepository;
import org.eclipse.jnosql.mapping.PreparedStatement;
import org.assertj.core.api.Assertions;
import org.eclipse.jnosql.communication.Condition;
Expand Down Expand Up @@ -741,7 +742,7 @@ void shouldConvertMapAddressRepositoryOrder() {
}


interface PersonRepository extends CrudRepository<Person, Long> {
interface PersonRepository extends NoSQLRepository<Person, Long> {

List<Person> findBySalary_Currency(String currency);

Expand Down

0 comments on commit 3a8adec

Please sign in to comment.