HHH-17948 make getAll(), findAll() accept List instead of varargs
This commit is contained in:
parent
7e36768c65
commit
62e1b0470e
|
@ -706,15 +706,12 @@ public interface Session extends SharedSessionContract, EntityManager {
|
||||||
*
|
*
|
||||||
* @param entityType the entity type
|
* @param entityType the entity type
|
||||||
* @param ids the identifiers
|
* @param ids the identifiers
|
||||||
*
|
|
||||||
* @return an ordered list of persistent instances, with null elements representing missing
|
* @return an ordered list of persistent instances, with null elements representing missing
|
||||||
* entities
|
* entities
|
||||||
*
|
|
||||||
* @since 7.0
|
|
||||||
*
|
|
||||||
* @see #byMultipleIds(Class)
|
* @see #byMultipleIds(Class)
|
||||||
|
* @since 7.0
|
||||||
*/
|
*/
|
||||||
<E> List<E> findAll(Class<E> entityType, Object... ids);
|
<E> List<E> findAll(Class<E> entityType, List<Object> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the persistent instance of the given entity class with the given identifier,
|
* Return the persistent instance of the given entity class with the given identifier,
|
||||||
|
@ -925,7 +922,7 @@ public interface Session extends SharedSessionContract, EntityManager {
|
||||||
*
|
*
|
||||||
* @throws HibernateException If the given class does not resolve as a mapped entity
|
* @throws HibernateException If the given class does not resolve as a mapped entity
|
||||||
*
|
*
|
||||||
* @see #findAll(Class, Object...)
|
* @see #findAll(Class, List)
|
||||||
*/
|
*/
|
||||||
<T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass);
|
<T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass);
|
||||||
|
|
||||||
|
|
|
@ -261,13 +261,11 @@ public interface StatelessSession extends SharedSessionContract {
|
||||||
*
|
*
|
||||||
* @param entityClass The class of the entity to retrieve
|
* @param entityClass The class of the entity to retrieve
|
||||||
* @param ids The ids of the entities to retrieve
|
* @param ids The ids of the entities to retrieve
|
||||||
*
|
|
||||||
* @return an ordered list of detached entity instances, with
|
* @return an ordered list of detached entity instances, with
|
||||||
* null elements representing missing entities
|
* null elements representing missing entities
|
||||||
*
|
|
||||||
* @since 7.0
|
* @since 7.0
|
||||||
*/
|
*/
|
||||||
<T> List<T> getAll(Class<T> entityClass, Object... ids);
|
<T> List<T> getAll(Class<T> entityClass, List<Object> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh the entity instance state from the database.
|
* Refresh the entity instance state from the database.
|
||||||
|
|
|
@ -954,7 +954,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
|
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
|
||||||
return delegate.findAll( entityType, ids );
|
return delegate.findAll( entityType, ids );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,7 @@ public class SessionLazyDelegator implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
|
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
|
||||||
return this.lazySession.get().findAll( entityType, ids );
|
return this.lazySession.get().findAll( entityType, ids );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -948,7 +948,7 @@ public class SessionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
|
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
|
||||||
return this.byMultipleIds( entityType ).multiLoad( ids );
|
return this.byMultipleIds( entityType ).multiLoad( ids );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -513,7 +513,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> List<T> getAll(Class<T> entityClass, Object... ids) {
|
public <T> List<T> getAll(Class<T> entityClass, List<Object> ids) {
|
||||||
for (Object id : ids) {
|
for (Object id : ids) {
|
||||||
if ( id == null ) {
|
if ( id == null ) {
|
||||||
throw new IllegalArgumentException("Null id");
|
throw new IllegalArgumentException("Null id");
|
||||||
|
@ -522,13 +522,13 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
|
||||||
final EntityPersister persister = getEntityPersister( entityClass.getName() );
|
final EntityPersister persister = getEntityPersister( entityClass.getName() );
|
||||||
final JpaCriteriaQuery<T> query = getCriteriaBuilder().createQuery(entityClass);
|
final JpaCriteriaQuery<T> query = getCriteriaBuilder().createQuery(entityClass);
|
||||||
final JpaRoot<T> from = query.from(entityClass);
|
final JpaRoot<T> from = query.from(entityClass);
|
||||||
query.where( from.get(persister.getIdentifierPropertyName()).in(ids) );
|
query.where( from.get( persister.getIdentifierPropertyName() ).in(ids) );
|
||||||
final List<T> resultList = createSelectionQuery(query).getResultList();
|
final List<T> resultList = createSelectionQuery(query).getResultList();
|
||||||
final List<Object> idList = new ArrayList<>(resultList.size());
|
final List<Object> idList = new ArrayList<>( resultList.size() );
|
||||||
for (T entity : resultList) {
|
for (T entity : resultList) {
|
||||||
idList.add( persister.getIdentifier(entity, this) );
|
idList.add( persister.getIdentifier(entity, this) );
|
||||||
}
|
}
|
||||||
final List<T> list = new ArrayList<>(ids.length);
|
final List<T> list = new ArrayList<>( ids.size() );
|
||||||
for (Object id : ids) {
|
for (Object id : ids) {
|
||||||
final int pos = idList.indexOf(id);
|
final int pos = idList.indexOf(id);
|
||||||
list.add( pos < 0 ? null : resultList.get(pos) );
|
list.add( pos < 0 ? null : resultList.get(pos) );
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class FindAllTest {
|
||||||
s.persist(new Record(456L,"hello mars"));
|
s.persist(new Record(456L,"hello mars"));
|
||||||
});
|
});
|
||||||
scope.inTransaction(s-> {
|
scope.inTransaction(s-> {
|
||||||
List<Record> all = s.findAll(Record.class, 456L, 123L, 2L);
|
List<Record> all = s.findAll(Record.class, List.of(456L, 123L, 2L));
|
||||||
assertEquals("hello mars",all.get(0).message);
|
assertEquals("hello mars",all.get(0).message);
|
||||||
assertEquals("hello earth",all.get(1).message);
|
assertEquals("hello earth",all.get(1).message);
|
||||||
assertNull(all.get(2));
|
assertNull(all.get(2));
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class GetAllTest {
|
||||||
s.insert(new Record(456L,"hello mars"));
|
s.insert(new Record(456L,"hello mars"));
|
||||||
});
|
});
|
||||||
scope.inStatelessTransaction(s-> {
|
scope.inStatelessTransaction(s-> {
|
||||||
List<Record> all = s.getAll(Record.class, 456L, 123L, 2L);
|
List<Record> all = s.getAll(Record.class, List.of(456L, 123L, 2L));
|
||||||
assertEquals("hello mars",all.get(0).message);
|
assertEquals("hello mars",all.get(0).message);
|
||||||
assertEquals("hello earth",all.get(1).message);
|
assertEquals("hello earth",all.get(1).message);
|
||||||
assertNull(all.get(2));
|
assertNull(all.get(2));
|
||||||
|
|
Loading…
Reference in New Issue