Skip to content

Commit 07477f3

Browse files
gavinkingDavideD
authored andcommitted
#2042 add insertMultiple() and friends, with semantics aligned with ORM 7
see #2042
1 parent 87361ff commit 07477f3

File tree

4 files changed

+126
-4
lines changed

4 files changed

+126
-4
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/Mutiny.java

+44-4
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
17301730
*/
17311731
Uni<Void> insertAll(int batchSize, Object... entities);
17321732

1733+
/**
1734+
* Insert multiple rows, using the size of the
1735+
* given list as the batch size.
1736+
*
1737+
* @param entities new transient instances
1738+
*
1739+
* @see org.hibernate.StatelessSession#insert(Object)
1740+
*/
1741+
Uni<Void> insertMultiple(List<?> entities);
1742+
17331743
/**
17341744
* Delete a row.
17351745
*
@@ -1758,6 +1768,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
17581768
*/
17591769
Uni<Void> deleteAll(int batchSize, Object... entities);
17601770

1771+
/**
1772+
* Delete multiple rows, using the size of the
1773+
* given list as the batch size.
1774+
*
1775+
* @param entities detached entity instances
1776+
*
1777+
* @see org.hibernate.StatelessSession#delete(Object)
1778+
*/
1779+
Uni<Void> deleteMultiple(List<?> entities);
1780+
17611781
/**
17621782
* Update a row.
17631783
*
@@ -1787,13 +1807,14 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
17871807
Uni<Void> updateAll(int batchSize, Object... entities);
17881808

17891809
/**
1790-
* Refresh the entity instance state from the database.
1810+
* Update multiple rows, using the size of the
1811+
* given list as the batch size.
17911812
*
1792-
* @param entity The entity to be refreshed.
1813+
* @param entities detached entity instances
17931814
*
1794-
* @see org.hibernate.StatelessSession#refresh(Object)
1815+
* @see org.hibernate.StatelessSession#update(Object)
17951816
*/
1796-
Uni<Void> refresh(Object entity);
1817+
Uni<Void> updateMultiple(List<?> entities);
17971818

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

1841+
/**
1842+
* Refresh the entity instance state from the database.
1843+
*
1844+
* @param entity The entity to be refreshed.
1845+
*
1846+
* @see org.hibernate.StatelessSession#refresh(Object)
1847+
*/
1848+
Uni<Void> refresh(Object entity);
1849+
18201850
/**
18211851
* Refresh the entity instance state from the database.
18221852
*
@@ -1837,6 +1867,16 @@ default <T> Uni<T> get(Class<T> entityClass, Object id, LockModeType lockModeTyp
18371867
*/
18381868
Uni<Void> refreshAll(int batchSize, Object... entities);
18391869

1870+
/**
1871+
* Refresh the entity instance state from the database
1872+
* using the size of the given list as the batch size.
1873+
*
1874+
* @param entities The entities to be refreshed.
1875+
*
1876+
* @see org.hibernate.StatelessSession#refresh(Object)
1877+
*/
1878+
Uni<Void> refreshMultiple(List<?> entities);
1879+
18401880
/**
18411881
* Refresh the entity instance state from the database.
18421882
*

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinyStatelessSessionImpl.java

+21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hibernate.reactive.pool.ReactiveConnection;
1818
import org.hibernate.reactive.session.ReactiveStatelessSession;
1919

20+
import java.util.List;
2021
import java.util.concurrent.CompletableFuture;
2122
import java.util.concurrent.CompletionStage;
2223
import java.util.function.Function;
@@ -128,6 +129,11 @@ public Uni<Void> insertAll(int batchSize, Object... entities) {
128129
return uni( () -> delegate.reactiveInsertAll( batchSize, entities ) );
129130
}
130131

132+
@Override
133+
public Uni<Void> insertMultiple(List<?> entities) {
134+
return insertAll( entities.size(), entities.toArray() );
135+
}
136+
131137
@Override
132138
public Uni<Void> delete(Object entity) {
133139
return uni( () -> delegate.reactiveDelete( entity ) );
@@ -143,6 +149,11 @@ public Uni<Void> deleteAll(int batchSize, Object... entities) {
143149
return uni( () -> delegate.reactiveDeleteAll( entities ) );
144150
}
145151

152+
@Override
153+
public Uni<Void> deleteMultiple(List<?> entities) {
154+
return deleteAll( entities.size(), entities.toArray() );
155+
}
156+
146157
@Override
147158
public Uni<Void> update(Object entity) {
148159
return uni( () -> delegate.reactiveUpdate( entity ) );
@@ -158,6 +169,11 @@ public Uni<Void> updateAll(int batchSize, Object... entities) {
158169
return uni( () -> delegate.reactiveUpdateAll( batchSize, entities ) );
159170
}
160171

172+
@Override
173+
public Uni<Void> updateMultiple(List<?> entities) {
174+
return updateAll( entities.size(), entities.toArray() );
175+
}
176+
161177
@Override
162178
public Uni<Void> refresh(Object entity) {
163179
return uni( () -> delegate.reactiveRefresh( entity ) );
@@ -183,6 +199,11 @@ public Uni<Void> refreshAll(int batchSize, Object... entities) {
183199
return uni( () -> delegate.reactiveRefreshAll( batchSize, entities ) );
184200
}
185201

202+
@Override
203+
public Uni<Void> refreshMultiple(List<?> entities) {
204+
return refreshAll( entities.size(), entities.toArray() );
205+
}
206+
186207
@Override
187208
public Uni<Void> refresh(Object entity, LockMode lockMode) {
188209
return uni( () -> delegate.reactiveRefresh( entity, lockMode ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/Stage.java

+40
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
17751775
*/
17761776
CompletionStage<Void> insert(int batchSize, Object... entities);
17771777

1778+
/**
1779+
* Insert multiple rows, using the size of the
1780+
* given list as the batch size.
1781+
*
1782+
* @param entities new transient instances
1783+
*
1784+
* @see org.hibernate.StatelessSession#insert(Object)
1785+
*/
1786+
CompletionStage<Void> insertMultiple(List<?> entities);
1787+
17781788
/**
17791789
* Delete a row.
17801790
*
@@ -1803,6 +1813,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
18031813
*/
18041814
CompletionStage<Void> delete(int batchSize, Object... entities);
18051815

1816+
/**
1817+
* Delete multiple rows, using the size of the
1818+
* given list as the batch size.
1819+
*
1820+
* @param entities detached entity instances
1821+
*
1822+
* @see org.hibernate.StatelessSession#delete(Object)
1823+
*/
1824+
CompletionStage<Void> deleteMultiple(List<?> entities);
1825+
18061826
/**
18071827
* Update a row.
18081828
*
@@ -1831,6 +1851,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
18311851
*/
18321852
CompletionStage<Void> update(int batchSize, Object... entities);
18331853

1854+
/**
1855+
* Update multiple rows, using the size of the
1856+
* given list as the batch size.
1857+
*
1858+
* @param entities a detached entity instance
1859+
*
1860+
* @see org.hibernate.StatelessSession#update(Object)
1861+
*/
1862+
CompletionStage<Void> updateMultiple(List<?> entities);
1863+
18341864
/**
18351865
* Refresh the entity instance state from the database.
18361866
*
@@ -1859,6 +1889,16 @@ default <T> CompletionStage<T> get(Class<T> entityClass, Object id, LockModeType
18591889
*/
18601890
CompletionStage<Void> refresh(int batchSize, Object... entities);
18611891

1892+
/**
1893+
* Refresh the entity instance state from the database,
1894+
* using the size of the given list as the batch size.
1895+
*
1896+
* @param entities The entities to be refreshed.
1897+
*
1898+
* @see org.hibernate.StatelessSession#refresh(Object)
1899+
*/
1900+
CompletionStage<Void> refreshMultiple(List<?> entities);
1901+
18621902
/**
18631903
* Refresh the entity instance state from the database.
18641904
*

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageStatelessSessionImpl.java

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.reactive.stage.Stage.Query;
2020
import org.hibernate.reactive.stage.Stage.SelectionQuery;
2121

22+
import java.util.List;
2223
import java.util.concurrent.CompletableFuture;
2324
import java.util.concurrent.CompletionStage;
2425
import java.util.function.Function;
@@ -67,6 +68,11 @@ public CompletionStage<Void> insert(int batchSize, Object... entities) {
6768
return delegate.reactiveInsertAll( batchSize, entities );
6869
}
6970

71+
@Override
72+
public CompletionStage<Void> insertMultiple(List<?> entities) {
73+
return delegate.reactiveInsertAll( entities.size(), entities.toArray() );
74+
}
75+
7076
@Override
7177
public CompletionStage<Void> delete(Object entity) {
7278
return delegate.reactiveDelete( entity );
@@ -82,6 +88,11 @@ public CompletionStage<Void> delete(int batchSize, Object... entities) {
8288
return delegate.reactiveDeleteAll( batchSize, entities );
8389
}
8490

91+
@Override
92+
public CompletionStage<Void> deleteMultiple(List<?> entities) {
93+
return delegate.reactiveDeleteAll( entities.size(), entities.toArray() );
94+
}
95+
8596
@Override
8697
public CompletionStage<Void> update(Object entity) {
8798
return delegate.reactiveUpdate( entity );
@@ -97,6 +108,11 @@ public CompletionStage<Void> update(int batchSize, Object... entities) {
97108
return delegate.reactiveUpdateAll( batchSize, entities );
98109
}
99110

111+
@Override
112+
public CompletionStage<Void> updateMultiple(List<?> entities) {
113+
return delegate.reactiveUpdateAll( entities.size(), entities.toArray() );
114+
}
115+
100116
@Override
101117
public CompletionStage<Void> refresh(Object entity) {
102118
return delegate.reactiveRefresh( entity );
@@ -112,6 +128,11 @@ public CompletionStage<Void> refresh(int batchSize, Object... entities) {
112128
return delegate.reactiveRefreshAll( batchSize, entities );
113129
}
114130

131+
@Override
132+
public CompletionStage<Void> refreshMultiple(List<?> entities) {
133+
return delegate.reactiveRefreshAll( entities.size(), entities.toArray() );
134+
}
135+
115136
@Override
116137
public CompletionStage<Void> refresh(Object entity, LockMode lockMode) {
117138
return delegate.reactiveRefresh( entity, lockMode );

0 commit comments

Comments
 (0)