List of usage examples for org.hibernate.persister.collection CollectionPersister getElementByIndex
Object getElementByIndex(Serializable key, Object index, SharedSessionContractImplementor session, Object owner);
From source file:com.amalto.core.storage.hibernate.TypeMapping.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) protected static <T> List<T> getFullList(List valueList) { if (valueList == null) { return null; }//from w w w.ja va 2 s .co m if (!(valueList instanceof PersistentList)) { return valueList; } PersistentList list = (PersistentList) valueList; List<T> fullList = new LinkedList<T>(); SessionImplementor session = list.getSession(); if (!session.isConnected()) { throw new IllegalStateException("Session is not connected: impossible to read values from database."); //$NON-NLS-1$ } CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(list); CollectionPersister persister = entry.getLoadedPersister(); if (persister != null) { int databaseSize = persister.getSize(entry.getKey(), session); if (list.size() == databaseSize && !list.contains(null)) { // No need to reload a list (no omission in list and size() corresponds to size read from database). return list; } for (int i = 0; i < databaseSize; i++) { T wrapper = (T) persister.getElementByIndex(entry.getLoadedKey(), i, session, list.getOwner()); fullList.add(wrapper); } } // Returns a unmodifiable list -> returned list is *not* a persistent list so change tracking is not possible, // returning a unmodifiable list is a safety for code using returned list. return Collections.unmodifiableList(fullList); }