List of usage examples for org.hibernate.persister.collection QueryableCollection getSize
int getSize(Serializable key, SharedSessionContractImplementor session);
From source file:org.eclipse.emf.teneo.hibernate.LazyCollectionUtils.java
License:Open Source License
/** * Reads the size of a collection in a lazy manner, i.e. will try to not * load the collection from the database. The size is cached in the object, * so subsequent calls to this method will not result in additional database * queries. This until the collection changes then the cache is cleared. * //from w ww.java 2 s .c o m * Note if the collection can not be lazy loaded (see the * {@link #isLazyLoadableCollection(Collection)}) then the size method is * called on the collection. This method call is probably not lazy. * * @param coll * the collection to get the size from * @return the size of the collection */ public static int size(Collection<?> coll) { if (!isLazyLoadableCollection(coll)) { return coll.size(); } final PersistableDelegateList<?> persistableList = (PersistableDelegateList<?>) coll; final AbstractPersistentCollection persistentCollection = (AbstractPersistentCollection) persistableList .getDelegate(); final SessionImplementor session = persistentCollection.getSession(); final QueryableCollection persister = new SessionFactoryHelper(session.getFactory()) .getCollectionPersister(persistentCollection.getRole()); return persister.getSize(persistentCollection.getKey(), session); }