Skip to content

Commit

Permalink
#2042 add insertMultiple() and friends, with semantics aligned with O…
Browse files Browse the repository at this point in the history
…RM 7

see #2042
  • Loading branch information
gavinking authored and DavideD committed Dec 20, 2024
1 parent 965b517 commit b7f9585
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
*/
Uni<Void> insertAll(int batchSize, Object... entities);

/**
* Insert multiple rows, using the size of the
* given list as the batch size.
*
* @param entities new transient instances
*
* @see org.hibernate.StatelessSession#insert(Object)
*/
Uni<Void> insertMultiple(List<?> entities);

/**
* Delete a row.
*
Expand Down Expand Up @@ -1758,6 +1768,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
*/
Uni<Void> deleteAll(int batchSize, Object... entities);

/**
* Delete multiple rows, using the size of the
* given list as the batch size.
*
* @param entities detached entity instances
*
* @see org.hibernate.StatelessSession#delete(Object)
*/
Uni<Void> deleteMultiple(List<?> entities);

/**
* Update a row.
*
Expand Down Expand Up @@ -1787,13 +1807,14 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
Uni<Void> updateAll(int batchSize, Object... entities);

/**
* Refresh the entity instance state from the database.
* Update multiple rows, using the size of the
* given list as the batch size.
*
* @param entity The entity to be refreshed.
* @param entities detached entity instances
*
* @see org.hibernate.StatelessSession#refresh(Object)
* @see org.hibernate.StatelessSession#update(Object)
*/
Uni<Void> refresh(Object entity);
Uni<Void> updateMultiple(List<?> entities);

/**
* Use a SQL {@code merge into} statement to perform an upsert.
Expand All @@ -1817,6 +1838,15 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
@Incubating
Uni<Void> upsert(String entityName, Object entity);

/**
* Refresh the entity instance state from the database.
*
* @param entity The entity to be refreshed.
*
* @see org.hibernate.StatelessSession#refresh(Object)
*/
Uni<Void> refresh(Object entity);

/**
* Refresh the entity instance state from the database.
*
Expand All @@ -1837,6 +1867,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
*/
Uni<Void> refreshAll(int batchSize, Object... entities);

/**
* Refresh the entity instance state from the database
* using the size of the given list as the batch size.
*
* @param entities The entities to be refreshed.
*
* @see org.hibernate.StatelessSession#refresh(Object)
*/
Uni<Void> refreshMultiple(List<?> entities);

/**
* Refresh the entity instance state from the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.reactive.pool.ReactiveConnection;
import org.hibernate.reactive.session.ReactiveStatelessSession;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
Expand Down Expand Up @@ -128,6 +129,11 @@ public Uni<Void> insertAll(int batchSize, Object... entities) {
return uni( () -> delegate.reactiveInsertAll( batchSize, entities ) );
}

@Override
public Uni<Void> insertMultiple(List<?> entities) {
return insertAll( entities.size(), entities.toArray() );
}

@Override
public Uni<Void> delete(Object entity) {
return uni( () -> delegate.reactiveDelete( entity ) );
Expand All @@ -143,6 +149,11 @@ public Uni<Void> deleteAll(int batchSize, Object... entities) {
return uni( () -> delegate.reactiveDeleteAll( entities ) );
}

@Override
public Uni<Void> deleteMultiple(List<?> entities) {
return deleteAll( entities.size(), entities.toArray() );
}

@Override
public Uni<Void> update(Object entity) {
return uni( () -> delegate.reactiveUpdate( entity ) );
Expand All @@ -158,6 +169,11 @@ public Uni<Void> updateAll(int batchSize, Object... entities) {
return uni( () -> delegate.reactiveUpdateAll( batchSize, entities ) );
}

@Override
public Uni<Void> updateMultiple(List<?> entities) {
return updateAll( entities.size(), entities.toArray() );
}

@Override
public Uni<Void> refresh(Object entity) {
return uni( () -> delegate.reactiveRefresh( entity ) );
Expand All @@ -183,6 +199,11 @@ public Uni<Void> refreshAll(int batchSize, Object... entities) {
return uni( () -> delegate.reactiveRefreshAll( batchSize, entities ) );
}

@Override
public Uni<Void> refreshMultiple(List<?> entities) {
return refreshAll( entities.size(), entities.toArray() );
}

@Override
public Uni<Void> refresh(Object entity, LockMode lockMode) {
return uni( () -> delegate.reactiveRefresh( entity, lockMode ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
*/
CompletionStage<Void> insert(int batchSize, Object... entities);

/**
* Insert multiple rows, using the size of the
* given list as the batch size.
*
* @param entities new transient instances
*
* @see org.hibernate.StatelessSession#insert(Object)
*/
CompletionStage<Void> insertMultiple(List<?> entities);

/**
* Delete a row.
*
Expand Down Expand Up @@ -1803,6 +1813,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
*/
CompletionStage<Void> delete(int batchSize, Object... entities);

/**
* Delete multiple rows, using the size of the
* given list as the batch size.
*
* @param entities detached entity instances
*
* @see org.hibernate.StatelessSession#delete(Object)
*/
CompletionStage<Void> deleteMultiple(List<?> entities);

/**
* Update a row.
*
Expand Down Expand Up @@ -1831,6 +1851,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
*/
CompletionStage<Void> update(int batchSize, Object... entities);

/**
* Update multiple rows, using the size of the
* given list as the batch size.
*
* @param entities a detached entity instance
*
* @see org.hibernate.StatelessSession#update(Object)
*/
CompletionStage<Void> updateMultiple(List<?> entities);

/**
* Refresh the entity instance state from the database.
*
Expand Down Expand Up @@ -1859,6 +1889,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
*/
CompletionStage<Void> refresh(int batchSize, Object... entities);

/**
* Refresh the entity instance state from the database,
* using the size of the given list as the batch size.
*
* @param entities The entities to be refreshed.
*
* @see org.hibernate.StatelessSession#refresh(Object)
*/
CompletionStage<Void> refreshMultiple(List<?> entities);

/**
* Refresh the entity instance state from the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.reactive.stage.Stage.Query;
import org.hibernate.reactive.stage.Stage.SelectionQuery;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
Expand Down Expand Up @@ -67,6 +68,11 @@ public CompletionStage<Void> insert(int batchSize, Object... entities) {
return delegate.reactiveInsertAll( batchSize, entities );
}

@Override
public CompletionStage<Void> insertMultiple(List<?> entities) {
return delegate.reactiveInsertAll( entities.size(), entities.toArray() );
}

@Override
public CompletionStage<Void> delete(Object entity) {
return delegate.reactiveDelete( entity );
Expand All @@ -82,6 +88,11 @@ public CompletionStage<Void> delete(int batchSize, Object... entities) {
return delegate.reactiveDeleteAll( batchSize, entities );
}

@Override
public CompletionStage<Void> deleteMultiple(List<?> entities) {
return delegate.reactiveDeleteAll( entities.size(), entities.toArray() );
}

@Override
public CompletionStage<Void> update(Object entity) {
return delegate.reactiveUpdate( entity );
Expand All @@ -97,6 +108,11 @@ public CompletionStage<Void> update(int batchSize, Object... entities) {
return delegate.reactiveUpdateAll( batchSize, entities );
}

@Override
public CompletionStage<Void> updateMultiple(List<?> entities) {
return delegate.reactiveUpdateAll( entities.size(), entities.toArray() );
}

@Override
public CompletionStage<Void> refresh(Object entity) {
return delegate.reactiveRefresh( entity );
Expand All @@ -112,6 +128,11 @@ public CompletionStage<Void> refresh(int batchSize, Object... entities) {
return delegate.reactiveRefreshAll( batchSize, entities );
}

@Override
public CompletionStage<Void> refreshMultiple(List<?> entities) {
return delegate.reactiveRefreshAll( entities.size(), entities.toArray() );
}

@Override
public CompletionStage<Void> refresh(Object entity, LockMode lockMode) {
return delegate.reactiveRefresh( entity, lockMode );
Expand Down

0 comments on commit b7f9585

Please sign in to comment.