HHH-18492 add Hibernate.isEmpty() for pure convenience
HHH-18492 add Hibernate.isEmpty() for pure convenience Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
349b209deb
commit
04b8d80125
|
@ -190,6 +190,21 @@ public final class Hibernate {
|
|||
: collection.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine is the given persistent collection is {@linkplain Collection#isEmpty() empty},
|
||||
* without fetching its state from the database.
|
||||
*
|
||||
* @param collection a persistent collection associated with an open session
|
||||
* @return {@code true} if the collection is empty
|
||||
*
|
||||
* @since 7.0
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> collection) {
|
||||
return collection instanceof PersistentCollection
|
||||
? ((PersistentCollection<?>) collection).getSize() == 0
|
||||
: collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given persistent collection {@linkplain Collection#contains(Object) contains}
|
||||
* the given element, without fetching its state from the database.
|
||||
|
|
|
@ -179,6 +179,7 @@ public abstract class AbstractPersistentCollection<E> implements Serializable, P
|
|||
if ( cachedSize>=0 ) {
|
||||
return cachedSize;
|
||||
}
|
||||
else {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( this );
|
||||
if ( entry == null ) {
|
||||
throwLazyInitializationExceptionIfNotConnected();
|
||||
|
@ -193,6 +194,7 @@ public abstract class AbstractPersistentCollection<E> implements Serializable, P
|
|||
return cachedSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TBH not sure why this is public
|
||||
|
|
|
@ -1383,9 +1383,7 @@ public abstract class AbstractCollectionPersister
|
|||
public int getSize(Object key, SharedSessionContractImplementor session) {
|
||||
try {
|
||||
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
|
||||
PreparedStatement st = jdbcCoordinator
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( sqlSelectSizeString );
|
||||
final PreparedStatement st = jdbcCoordinator.getStatementPreparer().prepareStatement( sqlSelectSizeString );
|
||||
try {
|
||||
getKeyType().nullSafeSet( st, key, 1, session );
|
||||
ResultSet rs = jdbcCoordinator.getResultSetReturn().extract( st, sqlSelectSizeString );
|
||||
|
|
Loading…
Reference in New Issue