FileDocCategorySizeDatePackage
ArrayType.javaAPI DocHibernate 3.2.53306Wed Jul 05 13:17:28 BST 2006org.hibernate.type

ArrayType

public class ArrayType extends CollectionType
A type for persistent arrays.
author
Gavin King

Fields Summary
private final Class
elementClass
private final Class
arrayClass
Constructors Summary
public ArrayType(String role, String propertyRef, Class elementClass, boolean isEmbeddedInXML)

		super(role, propertyRef, isEmbeddedInXML);
		this.elementClass = elementClass;
		arrayClass = Array.newInstance(elementClass, 0).getClass();
	
Methods Summary
public java.util.IteratorgetElementsIterator(java.lang.Object collection)
Not defined for collections of primitive type

		return Arrays.asList( (Object[]) collection ).iterator();
	
public java.lang.ClassgetReturnedClass()

		return arrayClass;
	
public booleanhasHolder(org.hibernate.EntityMode entityMode)

		return true;
	
public java.lang.ObjectindexOf(java.lang.Object array, java.lang.Object element)

		int length = Array.getLength(array);
		for ( int i=0; i<length; i++ ) {
			//TODO: proxies!
			if ( Array.get(array, i)==element ) return new Integer(i);
		}
		return null;
	
protected booleaninitializeImmediately(org.hibernate.EntityMode entityMode)

		return true;
	
public java.lang.Objectinstantiate(int anticipatedSize)

		throw new UnsupportedOperationException();
	
public org.hibernate.collection.PersistentCollectioninstantiate(org.hibernate.engine.SessionImplementor session, org.hibernate.persister.collection.CollectionPersister persister, java.io.Serializable key)

		return new PersistentArrayHolder(session, persister);
	
public java.lang.ObjectinstantiateResult(java.lang.Object original)

		return Array.newInstance( elementClass, Array.getLength(original) );
	
public booleanisArrayType()

		return true;
	
public java.lang.ObjectreplaceElements(java.lang.Object original, java.lang.Object target, java.lang.Object owner, java.util.Map copyCache, org.hibernate.engine.SessionImplementor session)

		
		int length = Array.getLength(original);
		if ( length!=Array.getLength(target) ) {
			//note: this affects the return value!
			target=instantiateResult(original);
		}
		
		Type elemType = getElementType( session.getFactory() );
		for ( int i=0; i<length; i++ ) {
			Array.set( target, i, elemType.replace( Array.get(original, i), null, session, owner, copyCache ) );
		}
		
		return target;
	
	
public java.lang.StringtoLoggableString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		if ( value == null ) {
			return "null";
		}
		int length = Array.getLength(value);
		List list = new ArrayList(length);
		Type elemType = getElementType(factory);
		for ( int i=0; i<length; i++ ) {
			list.add( elemType.toLoggableString( Array.get(value, i), factory ) );
		}
		return list.toString();
	
public org.hibernate.collection.PersistentCollectionwrap(org.hibernate.engine.SessionImplementor session, java.lang.Object array)

		return new PersistentArrayHolder(session, array);