Java Code Examples for org.hibernate.persister.collection.CollectionPersister#getIndexType()

The following examples show how to use org.hibernate.persister.collection.CollectionPersister#getIndexType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPersistentCollection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean needsRecreate(CollectionPersister persister) {
	// Workaround for situations like HHH-7072.  If the collection element is a component that consists entirely
	// of nullable properties, we currently have to forcefully recreate the entire collection.  See the use
	// of hasNotNullableColumns in the AbstractCollectionPersister constructor for more info.  In order to delete
	// row-by-row, that would require SQL like "WHERE ( COL = ? OR ( COL is null AND ? is null ) )", rather than
	// the current "WHERE COL = ?" (fails for null for most DBs).  Note that
	// the param would have to be bound twice.  Until we eventually add "parameter bind points" concepts to the
	// AST in ORM 5+, handling this type of condition is either extremely difficult or impossible.  Forcing
	// recreation isn't ideal, but not really any other option in ORM 4.
	// Selecting a type used in where part of update statement
	// (must match condidion in org.hibernate.persister.collection.BasicCollectionPersister.doUpdateRows).
	// See HHH-9474
	Type whereType;
	if ( persister.hasIndex() ) {
		whereType = persister.getIndexType();
	}
	else {
		whereType = persister.getElementType();
	}
	if ( whereType instanceof CompositeType ) {
		CompositeType componentIndexType = (CompositeType) whereType;
		return !componentIndexType.hasNotNullProperty();
	}
	return false;
}
 
Example 2
Source File: PersistentMapElementHolder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
throws HibernateException {
	
	Type elementType = persister.getElementType();
	Type indexType = persister.getIndexType();
	final String indexNodeName = getIndexAttributeName(persister);

	Serializable[] cached = (Serializable[]) disassembled;

	for ( int i=0; i<cached.length; ) {
		Object index = indexType.assemble( cached[i++], getSession(), owner );
		Object object = elementType.assemble( cached[i++], getSession(), owner );
		
		Element subelement = element.addElement( persister.getElementNodeName() );
		elementType.setToXMLNode( subelement, object, persister.getFactory() );
		
		String indexString = ( (NullableType) indexType ).toXMLString( index, persister.getFactory() );
		setIndex( subelement, indexNodeName, indexString );
	}
	
}
 
Example 3
Source File: PersistentMapElementHolder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
	
	Type elementType = persister.getElementType();
	Type indexType = persister.getIndexType();
	final String indexNodeName = getIndexAttributeName(persister);

	List elements =  element.elements( persister.getElementNodeName() );
	int length = elements.size();
	Serializable[] result = new Serializable[length*2];
	for ( int i=0; i<length*2; ) {
		Element elem = (Element) elements.get(i/2);
		Object object = elementType.fromXMLNode( elem, persister.getFactory() );
		final String indexString = getIndex(elem, indexNodeName, i);
		Object index = ( (NullableType) indexType ).fromXMLString( indexString, persister.getFactory() );
		result[i++] = indexType.disassemble( index, getSession(), null );
		result[i++] = elementType.disassemble( object, getSession(), null );
	}
	return result;
}
 
Example 4
Source File: PersistentIndexedElementHolder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
	Object object = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
	final Type elementType = persister.getElementType();
	final SessionFactoryImplementor factory = persister.getFactory();
	String indexNode = getIndexAttributeName(persister);

	Element elem = element.addElement( persister.getElementNodeName() );
	elementType.setToXMLNode( elem, object, factory ); 
	
	final Type indexType = persister.getIndexType();
	final Object indexValue = persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() );
	final String index = ( (NullableType) indexType ).toXMLString( indexValue, factory );
	setIndex(elem, indexNode, index);
	return object;
}
 
Example 5
Source File: PersistentIndexedElementHolder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) 
throws HibernateException {
	
	final Type indexType = persister.getIndexType();
	HashMap snapshot = (HashMap) getSnapshot();
	HashMap deletes = (HashMap) snapshot.clone();
	deletes.keySet().removeAll( ( (HashMap) getSnapshot(persister) ).keySet() );
	ArrayList deleteList = new ArrayList( deletes.size() );
	Iterator iter = deletes.entrySet().iterator();
	while ( iter.hasNext() ) {
		Map.Entry me = (Map.Entry) iter.next();
		final Object object = indexIsFormula ?
			me.getValue() :
			( (NullableType) indexType ).fromXMLString( (String) me.getKey(), persister.getFactory() );
		if (object!=null) deleteList.add(object);
	}
	
	return deleteList.iterator();
	
}
 
Example 6
Source File: AbstractCollectionReference.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private CollectionFetchableIndex buildIndexGraph() {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	if ( persister.hasIndex() ) {
		final Type type = persister.getIndexType();
		if ( type.isAssociationType() ) {
			if ( type.isEntityType() ) {
				final EntityPersister indexPersister = persister.getFactory().getEntityPersister(
						( (EntityType) type ).getAssociatedEntityName()
				);

				final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
						collectionQuerySpace,
						indexPersister,
						CollectionPropertyNames.COLLECTION_INDICES,
						(EntityType) persister.getIndexType(),
						collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
						collectionQuerySpace.canJoinsBeRequired(),
						allowIndexJoin
				);
				return new CollectionFetchableIndexEntityGraph( this, entityQuerySpace );
			}
			else if ( type.isAnyType() ) {
				return new CollectionFetchableIndexAnyGraph( this );
			}
		}
		else if ( type.isComponentType() ) {
			final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
					collectionQuerySpace,
					new CompositePropertyMapping(
							(CompositeType) persister.getIndexType(),
							(PropertyMapping) persister,
							""
					),
					CollectionPropertyNames.COLLECTION_INDICES,
					(CompositeType) persister.getIndexType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					allowIndexJoin
			);
			return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace );
		}
	}

	return null;
}
 
Example 7
Source File: PersistentIndexedElementHolder.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Object getIndex(Object entry, int i, CollectionPersister persister) {
	String index = ( (IndexedValue) entry ).index;
	final Type indexType = persister.getIndexType();
	return ( (NullableType) indexType ).fromXMLString( index, persister.getFactory() );
}