Java Code Examples for org.hibernate.type.CollectionType#getElementType()

The following examples show how to use org.hibernate.type.CollectionType#getElementType() . 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: HibernateTraversableResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {

		if ( type.isCollectionType() ) {
			CollectionType collType = (CollectionType) type;
			Type assocType = collType.getElementType( factory );
			addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
		}
		//ToOne association
		else if ( type.isEntityType() || type.isAnyType() ) {
			associations.add( prefix + name );
		}
		else if ( type.isComponentType() ) {
			CompositeType componentType = (CompositeType) type;
			addAssociationsToTheSetForAllProperties(
					componentType.getPropertyNames(),
					componentType.getSubtypes(),
					(prefix.equals( "" ) ? name : prefix + name) + ".",
					factory);
		}
	}
 
Example 2
Source File: Nullability.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * check sub elements-nullability. Returns property path that break
 * nullability or null if none
 *
 * @param propertyType type to check
 * @param value value to check
 *
 * @return property path
 * @throws HibernateException error while getting subcomponent values
 */
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
	if ( propertyType.isComponentType() ) {
		return checkComponentNullability( value, (CompositeType) propertyType );
	}

	if ( propertyType.isCollectionType() ) {
		// persistent collections may have components
		final CollectionType collectionType = (CollectionType) propertyType;
		final Type collectionElementType = collectionType.getElementType( session.getFactory() );

		if ( collectionElementType.isComponentType() ) {
			// check for all components values in the collection
			final CompositeType componentType = (CompositeType) collectionElementType;
			final Iterator itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
			while ( itr.hasNext() ) {
				final Object compositeElement = itr.next();
				if ( compositeElement != null ) {
					return checkComponentNullability( compositeElement, componentType );
				}
			}
		}
	}

	return null;
}
 
Example 3
Source File: Nullability.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * check sub elements-nullability. Returns property path that break
 * nullability or null if none
 *
 * @param propertyType type to check
 * @param value value to check
 *
 * @return property path
 * @throws HibernateException error while getting subcomponent values
 */
private String checkSubElementsNullability(final Type propertyType, final Object value) 
throws HibernateException {
	//for non null args, check for components and elements containing components
	if ( propertyType.isComponentType() ) {
		return checkComponentNullability( value, (AbstractComponentType) propertyType );
	}
	else if ( propertyType.isCollectionType() ) {

		//persistent collections may have components
		CollectionType collectionType = (CollectionType) propertyType;
		Type collectionElementType = collectionType.getElementType( session.getFactory() );
		if ( collectionElementType.isComponentType() ) {
			//check for all components values in the collection

			AbstractComponentType componentType = (AbstractComponentType) collectionElementType;
			Iterator iter = CascadingAction.getLoadedElementsIterator(session, collectionType, value);
			while ( iter.hasNext() ) {
				Object compValue = iter.next();
				if (compValue != null) {
					return checkComponentNullability(compValue, componentType);
				}
			}
		}
	}
	return null;
}
 
Example 4
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private CriteriaInfoProvider getPathInfo(String path) {
	StringTokenizer tokens = new StringTokenizer( path, "." );
	String componentPath = "";

	// start with the 'rootProvider'
	CriteriaInfoProvider provider = nameCriteriaInfoMap.get( rootEntityName );

	while ( tokens.hasMoreTokens() ) {
		componentPath += tokens.nextToken();
		final Type type = provider.getType( componentPath );
		if ( type.isAssociationType() ) {
			// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
			final AssociationType atype = (AssociationType) type;
			final CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null;
			final Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null;
			// is the association a collection of components or value-types? (i.e a colloction of valued types?)
			if ( ctype != null  && elementType.isComponentType() ) {
				provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) );
			}
			else if ( ctype != null && !elementType.isEntityType() ) {
				provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() );
			}
			else {
				provider = new EntityCriteriaInfoProvider(
						(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) )
				);
			}

			componentPath = "";
		}
		else if ( type.isComponentType() ) {
			if (!tokens.hasMoreTokens()) {
				throw new QueryException(
						"Criteria objects cannot be created directly on components.  Create a criteria on " +
								"owning entity and use a dotted property to access component property: " + path
				);
			}
			else {
				componentPath += '.';
			}
		}
		else {
			throw new QueryException( "not an association: " + componentPath );
		}
	}

	return provider;
}
 
Example 5
Source File: SessionFactoryHelper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Given a collection type, determine the Type representing elements
 * within instances of that collection.
 *
 * @param collectionType The collection type to be checked.
 *
 * @return The Type of the elements of the collection.
 */
private Type getElementType(CollectionType collectionType) {
	return collectionType.getElementType( sfi );
}
 
Example 6
Source File: SessionFactoryHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Given a collection type, determine the Type representing elements
 * within instances of that collection.
 *
 * @param collectionType The collection type to be checked.
 * @return The Type of the elements of the collection.
 */
private Type getElementType(CollectionType collectionType) {
	return collectionType.getElementType( sfi );
}