org.hibernate.collection.PersistentIndexedElementHolder Maven / Gradle / Ivy
//$Id: PersistentIndexedElementHolder.java 10086 2006-07-05 18:17:27Z [email protected] $
package org.hibernate.collection;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Element;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.loader.CollectionAliases;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.NullableType;
import org.hibernate.type.Type;
import org.hibernate.util.CollectionHelper;
/**
* A persistent wrapper for an XML element
*
* @author Gavin King
*/
public abstract class PersistentIndexedElementHolder extends AbstractPersistentCollection {
protected Element element;
public PersistentIndexedElementHolder(SessionImplementor session, Element element) {
super(session);
this.element = element;
setInitialized();
}
public static final class IndexedValue {
String index;
Object value;
IndexedValue(String index, Object value) {
this.index = index;
this.value = value;
}
}
protected static String getIndex(Element element, String indexNodeName, int i) {
if (indexNodeName!=null) {
return element.attributeValue(indexNodeName);
}
else {
return Integer.toString(i);
}
}
protected static void setIndex(Element element, String indexNodeName, String index) {
if (indexNodeName!=null) element.addAttribute(indexNodeName, index);
}
protected static String getIndexAttributeName(CollectionPersister persister) {
String node = persister.getIndexNodeName();
return node==null ? null : node.substring(1);
}
public Serializable getSnapshot(CollectionPersister persister)
throws HibernateException {
final Type elementType = persister.getElementType();
String indexNode = getIndexAttributeName(persister);
List elements = element.elements( persister.getElementNodeName() );
HashMap snapshot = new HashMap( elements.size() );
for ( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy