Java Code Examples for org.hibernate.engine.SessionFactoryImplementor#getCollectionPersister()

The following examples show how to use org.hibernate.engine.SessionFactoryImplementor#getCollectionPersister() . 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: AbstractEmptinessExpression.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
	PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
	Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
		        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	String role = ( ( CollectionType ) type ).getRole();
	try {
		return ( QueryableCollection ) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
Example 2
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Get an iterator over the element set of the collection, which may not yet be wrapped
 *
 * @param collection The collection to be iterated
 * @param session The session from which the request is originating.
 * @return The iterator.
 */
public Iterator getElementsIterator(Object collection, SessionImplementor session) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		final SessionFactoryImplementor factory = session.getFactory();
		final CollectionPersister persister = factory.getCollectionPersister( getRole() );
		final Type elementType = persister.getElementType();
		
		List elements = ( (Element) collection ).elements( persister.getElementNodeName() );
		ArrayList results = new ArrayList();
		for ( int i=0; i<elements.size(); i++ ) {
			Element value = (Element) elements.get(i);
			results.add( elementType.fromXMLNode( value, factory ) );
		}
		return results.iterator();
	}
	else {
		return getElementsIterator(collection);
	}
}
 
Example 3
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String getAssociatedEntityName(SessionFactoryImplementor factory)
		throws MappingException {
	try {
		
		QueryableCollection collectionPersister = (QueryableCollection) factory
				.getCollectionPersister( role );
		
		if ( !collectionPersister.getElementType().isEntityType() ) {
			throw new MappingException( 
					"collection was not an association: " + 
					collectionPersister.getRole() 
				);
		}
		
		return collectionPersister.getElementPersister().getEntityName();
		
	}
	catch (ClassCastException cce) {
		throw new MappingException( "collection role is not queryable " + role );
	}
}
 
Example 4
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
		throws MappingException {
	return (Joinable) factory.getCollectionPersister( role );
}