Java Code Examples for org.hibernate.type.Type.fromXMLNode()

The following are Jave code examples for showing how to use fromXMLNode() of the org.hibernate.type.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: PersistentMapElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("unchecked")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
	final Type elementType = persister.getElementType();
	final Type indexType = persister.getIndexType();
	final String indexNodeName = getIndexAttributeName( persister );

	final List elements =  element.elements( persister.getElementNodeName() );
	final int length = elements.size();
	final Serializable[] result = new Serializable[length*2];
	int i = 0;
	while ( i < length*2 ) {
		final Element elem = (Element) elements.get( i/2 );
		final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
		final String indexString = getIndex( elem, indexNodeName, i );
		final Object index = ( (XmlRepresentableType) indexType ).fromXMLString( indexString, persister.getFactory() );
		result[i++] = indexType.disassemble( index, getSession(), null );
		result[i++] = elementType.disassemble( object, getSession(), null );
	}
	return result;
}
 
Example 2
Project: lams   File: PersistentListElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("deprecation")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
	final Type elementType = persister.getElementType();
	final String indexNodeName = getIndexAttributeName( persister );
	final List elements =  element.elements( persister.getElementNodeName() );
	final int length = elements.size();
	final Serializable[] result = new Serializable[length];
	for ( int i=0; i<length; i++ ) {
		final Element elem = (Element) elements.get( i );
		final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
		final Integer index = IntegerType.INSTANCE.fromString( getIndex( elem, indexNodeName, i ) );
		result[index] = elementType.disassemble( object, getSession(), null );
	}
	return result;
}
 
Example 3
Project: lams   File: PersistentElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("deprecation")
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
	final Type elementType = persister.getElementType();
	final ArrayList snapshot = (ArrayList) getSnapshot();
	final List elements = element.elements( persister.getElementNodeName() );
	if ( snapshot.size() != elements.size() ) {
		return false;
	}
	for ( int i=0; i<snapshot.size(); i++ ) {
		final Object old = snapshot.get( i );
		final Element elem = (Element) elements.get( i );
		final Object current = elementType.fromXMLNode( elem, persister.getFactory() );
		if ( elementType.isDirty( old, current, getSession() ) ) {
			return false;
		}
	}
	return true;
}
 
Example 4
Project: lams   File: PersistentElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
	final Type elementType = persister.getElementType();
	final ArrayList snapshot = (ArrayList) getSnapshot();
	final List elements = element.elements( persister.getElementNodeName() );
	final ArrayList result = new ArrayList();
	for ( int i=0; i<snapshot.size(); i++ ) {
		final Object old = snapshot.get( i );
		if ( i >= elements.size() ) {
			result.add( old );
		}
		else {
			final Element elem = (Element) elements.get( i );
			final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
			if ( elementType.isDirty( old, object, getSession() ) ) {
				result.add( old );
			}
		}
	}
	return result.iterator();
}
 
Example 5
Project: lams   File: PersistentIndexedElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
	final Type elementType = persister.getElementType();
	final String indexNode = getIndexAttributeName( persister );
	final List elements = element.elements( persister.getElementNodeName() );
	final HashMap snapshot = new HashMap( elements.size() );
	for ( int i=0; i<elements.size(); i++ ) {
		final Element elem = (Element) elements.get( i );
		final Object value = elementType.fromXMLNode( elem, persister.getFactory() );
		final Object copy = elementType.deepCopy( value, persister.getFactory() );
		snapshot.put( getIndex( elem, indexNode, i ), copy );
	}
	return snapshot;
	
}
 
Example 6
Project: lams   File: PersistentIndexedElementHolder.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("deprecation")
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
	final Type elementType = persister.getElementType();
	final String indexNode = getIndexAttributeName( persister );
	final HashMap snapshot = (HashMap) getSnapshot();
	final List elements = element.elements( persister.getElementNodeName() );

	if ( snapshot.size() !=  elements.size() ) {
		return false;
	}

	for ( int i=0; i<snapshot.size(); i++ ) {
		final Element elem = (Element) elements.get( i );
		final Object old = snapshot.get( getIndex( elem, indexNode, i ) );
		final Object current = elementType.fromXMLNode( elem, persister.getFactory() );
		if ( elementType.isDirty( old, current, getSession() ) ) {
			return false;
		}
	}
	return true;
}
 
Example 7
Project: lams   File: PersistentElementHolder.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator entries(CollectionPersister persister) {
	final Type elementType = persister.getElementType();
	final List subElements =  element.elements( persister.getElementNodeName() );
	final int length = subElements.size();
	final List result = new ArrayList(length);
	for ( Object subElementO : subElements ) {
		final Element subElement = (Element) subElementO;
		final Object object = elementType.fromXMLNode( subElement, persister.getFactory() );
		result.add( object );
	}
	return result.iterator();
}
 
Example 8
Project: lams   File: PersistentElementHolder.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("deprecation")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
	final Type collectionElementType = persister.getElementType();
	final List elements =  element.elements( persister.getElementNodeName() );
	final int length = elements.size();
	final Serializable[] result = new Serializable[length];
	for ( int i=0; i<length; i++ ) {
		final Element elem = (Element) elements.get( i );
		final Object object = collectionElementType.fromXMLNode( elem, persister.getFactory() );
		result[i] = collectionElementType.disassemble( object, getSession(), null );
	}
	return result;
}
 
Example 9
Project: lams   File: PersistentIndexedElementHolder.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator entries(CollectionPersister persister) {
	final Type elementType = persister.getElementType();
	final String indexNode = getIndexAttributeName( persister );
	final List elements =  element.elements( persister.getElementNodeName() );
	final int length = elements.size();
	final List result = new ArrayList( length );
	for ( int i=0; i<length; i++ ) {
		final Element elem = (Element) elements.get( i );
		final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
		result.add( new IndexedValue( getIndex( elem, indexNode, i ), object ) );
	}
	return result.iterator();
}