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

The following are Jave code examples for showing how to use isEntityType() 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: HibernateTraversableResolver.java   View Source Code Vote up 6 votes
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
Project: lams   File: AbstractVisitor.java   View Source Code Vote up 6 votes
/**
 * Visit a property value. Dispatch to the
 * correct handler for the property type.
 * @param value
 * @param type
 * @throws HibernateException
 */
final Object processValue(Object value, Type type) throws HibernateException {

	if ( type.isCollectionType() ) {
		//even process null collections
		return processCollection( value, (CollectionType) type );
	}
	else if ( type.isEntityType() ) {
		return processEntity( value, (EntityType) type );
	}
	else if ( type.isComponentType() ) {
		return processComponent( value, (CompositeType) type );
	}
	else {
		return null;
	}
}
 
Example 3
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 6 votes
@Override
public void finishingCollectionIndex(CollectionIndexDefinition indexDefinition) {
	final Type indexType = indexDefinition.getType();

	if ( indexType.isAnyType() ) {
		// nothing to do because the index graph was not pushed in #startingCollectionIndex.
	}
	else if ( indexType.isEntityType() || indexType.isComponentType() ) {
		// todo : validate the stack?
		final ExpandingFetchSource fetchSource = popFromStack();
		if ( !CollectionFetchableIndex.class.isInstance( fetchSource ) ) {
			throw new WalkingException(
					"CollectionReference did not return an expected index graph : " +
							indexDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
	}

	log.tracef(
			"%s Finished collection index graph : %s",
			StringHelper.repeat( "<<", fetchSourceStack.size() ),
			indexDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);
}
 
Example 4
Project: lams   File: AbstractEntityPersister.java   View Source Code Vote up 6 votes
private EntityLoader createUniqueKeyLoader(
		Type uniqueKeyType,
		String[] columns,
		LoadQueryInfluencers loadQueryInfluencers) {
	if ( uniqueKeyType.isEntityType() ) {
		String className = ( ( EntityType ) uniqueKeyType ).getAssociatedEntityName();
		uniqueKeyType = getFactory().getEntityPersister( className ).getIdentifierType();
	}
	return new EntityLoader(
			this,
			columns,
			uniqueKeyType,
			1,
			LockMode.NONE,
			getFactory(),
			loadQueryInfluencers
	);
}
 
Example 5
Project: lams   File: MetamodelGraphWalker.java   View Source Code Vote up 6 votes
private void visitCollectionElements(CollectionDefinition collectionDefinition) {
	final CollectionElementDefinition elementDefinition = collectionDefinition.getElementDefinition();
	strategy.startingCollectionElements( elementDefinition );

	final Type collectionElementType = elementDefinition.getType();
	if ( collectionElementType.isAnyType() ) {
		visitAnyDefinition( elementDefinition.toAnyMappingDefinition() );
	}
	else if ( collectionElementType.isComponentType() ) {
		visitCompositeDefinition( elementDefinition.toCompositeElementDefinition() );
	}
	else if ( collectionElementType.isEntityType() ) {
		if ( ! collectionDefinition.getCollectionPersister().isOneToMany() ) {
			final QueryableCollection queryableCollection = (QueryableCollection) collectionDefinition.getCollectionPersister();
			addAssociationKey(
					new AssociationKey(
							queryableCollection.getTableName(),
							queryableCollection.getElementColumnNames()
					)
			);
		}
		visitEntityDefinition( elementDefinition.toEntityDefinition() );
	}

	strategy.finishingCollectionElements( elementDefinition );
}
 
Example 6
Project: lams   File: EntityJoinWalker.java   View Source Code Vote up 5 votes
private boolean hasAssociation(CompositeType componentType) {
	for ( Type subType : componentType.getSubtypes() ) {
		if ( subType.isEntityType() ) {
			return true;
		}
		else if ( subType.isComponentType() && hasAssociation( ( (CompositeType) subType ) ) ) {
			return true;
		}
	}
	return false;
}
 
Example 7
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 5 votes
@Override
public void startingCollectionIndex(CollectionIndexDefinition indexDefinition) {
	final Type indexType = indexDefinition.getType();
	log.tracef(
			"%s Starting collection index graph : %s",
			StringHelper.repeat( ">>", fetchSourceStack.size() ),
			indexDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);

	final CollectionReference collectionReference = currentCollection();
	final CollectionFetchableIndex indexGraph = collectionReference.getIndexGraph();

	if ( indexType.isEntityType() || indexType.isComponentType() ) {
		if ( indexGraph == null ) {
			throw new WalkingException(
					"CollectionReference did not return an expected index graph : " +
							indexDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
		if ( !indexType.isAnyType() ) {
			pushToStack( (ExpandingFetchSource) indexGraph );
		}
	}
	else {
		if ( indexGraph != null ) {
			throw new WalkingException(
					"CollectionReference returned an unexpected index graph : " +
							indexDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
	}
}
 
Example 8
Project: lams   File: AbstractEntityTuplizer.java   View Source Code Vote up 5 votes
@Override
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) {
	final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
	final Object[] injectionValues = new Object[ extractedValues.length ];
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
		final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
		final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
		if ( virtualPropertyType.isEntityType() && ! idClassPropertyType.isEntityType() ) {
			if ( session == null ) {
				throw new AssertionError(
						"Deprecated version of getIdentifier (no session) was used but session was required"
				);
			}
			final String associatedEntityName = ( (EntityType) virtualPropertyType ).getAssociatedEntityName();
			final EntityKey entityKey = session.generateEntityKey(
					(Serializable) extractedValues[i],
					session.getFactory().getEntityPersister( associatedEntityName )
			);
			// it is conceivable there is a proxy, so check that first
			Object association = persistenceContext.getProxy( entityKey );
			if ( association == null ) {
				// otherwise look for an initialized version
				association = persistenceContext.getEntity( entityKey );
			}
			injectionValues[i] = association;
		}
		else {
			injectionValues[i] = extractedValues[i];
		}
	}
	virtualIdComponent.setPropertyValues( entity, injectionValues, entityMode );
}
 
Example 9
Project: lams   File: ActionQueue.java   View Source Code Vote up 5 votes
/**
 * Finds an acceptable batch for this entity to be a member as part of the {@link InsertActionSorter}
 * 
 * @param action The action being sorted
 * @param entityName The name of the entity affected by the action
 * @return An appropriate batch number; todo document this process better
 */
private Integer findBatchNumber(AbstractEntityInsertAction action, String entityName) {
	// loop through all the associated entities and make sure they have been
	// processed before the latest
	// batch associated with this entity type.

	// the current batch number is the latest batch for this entity type.
	Integer latestBatchNumberForType = latestBatches.get( entityName );

	// loop through all the associations of the current entity and make sure that they are processed
	// before the current batch number
	Object[] propertyValues = action.getState();
	Type[] propertyTypes = action.getPersister().getClassMetadata().getPropertyTypes();

	for ( int i = 0; i < propertyValues.length; i++ ) {
		Object value = propertyValues[i];
		Type type = propertyTypes[i];
		if ( type.isEntityType() && value != null ) {
			// find the batch number associated with the current association, if any.
			Integer associationBatchNumber = entityBatchNumber.get( value );
			if ( associationBatchNumber != null && associationBatchNumber.compareTo( latestBatchNumberForType ) > 0 ) {
				// create a new batch for this type. The batch number is the number of current batches.
				latestBatchNumberForType = actionBatches.size();
				latestBatches.put( entityName, latestBatchNumberForType );
				// since this entity will now be processed in the latest possible batch,
				// we can be assured that it will come after all other associations,
				// there's not need to continue checking.
				break;
			}
		}
	}
	return latestBatchNumberForType;
}
 
Example 10
Project: lams   File: CascadingActions.java   View Source Code Vote up 5 votes
@Override
public void noCascade(
		EventSource session,
		Object child,
		Object parent,
		EntityPersister persister,
		int propertyIndex) {
	if ( child == null ) {
		return;
	}
	Type type = persister.getPropertyTypes()[propertyIndex];
	if ( type.isEntityType() ) {
		String childEntityName = ((EntityType) type).getAssociatedEntityName( session.getFactory() );

		if ( !isInManagedState( child, session )
				&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
				&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
			String parentEntiytName = persister.getEntityName();
			String propertyName = persister.getPropertyNames()[propertyIndex];
			throw new TransientPropertyValueException(
					"object references an unsaved transient instance - save the transient instance before flushing",
					childEntityName,
					parentEntiytName,
					propertyName
			);

		}
	}
}
 
Example 11
Project: lams   File: ForeignKeys.java   View Source Code Vote up 5 votes
/**
 * Return null if the argument is an "unsaved" entity (ie. one with no existing database row), or the
 * input argument otherwise.  This is how Hibernate avoids foreign key constraint violations.
 *
 * @param value An entity attribute value
 * @param type An entity attribute type
 *
 * @return {@code null} if the argument is an unsaved entity; otherwise return the argument.
 */
private Object nullifyTransientReferences(final Object value, final Type type) {
	if ( value == null ) {
		return null;
	}
	else if ( type.isEntityType() ) {
		final EntityType entityType = (EntityType) type;
		if ( entityType.isOneToOne() ) {
			return value;
		}
		else {
			final String entityName = entityType.getAssociatedEntityName();
			return isNullifiable( entityName, value ) ? null : value;
		}
	}
	else if ( type.isAnyType() ) {
		return isNullifiable( null, value ) ? null : value;
	}
	else if ( type.isComponentType() ) {
		final CompositeType actype = (CompositeType) type;
		final Object[] subvalues = actype.getPropertyValues( value, session );
		final Type[] subtypes = actype.getSubtypes();
		boolean substitute = false;
		for ( int i = 0; i < subvalues.length; i++ ) {
			final Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] );
			if ( replacement != subvalues[i] ) {
				substitute = true;
				subvalues[i] = replacement;
			}
		}
		if ( substitute ) {
			// todo : need to account for entity mode on the CompositeType interface :(
			actype.setPropertyValues( value, subvalues, EntityMode.POJO );
		}
		return value;
	}
	else {
		return value;
	}
}
 
Example 12
Project: lams   File: Cascade.java   View Source Code Vote up 5 votes
private void cascadeAssociation(
		final Object parent,
		final Object child,
		final Type type,
		final CascadeStyle style,
		final Object anything,
		final boolean isCascadeDeleteEnabled) {
	if ( type.isEntityType() || type.isAnyType() ) {
		cascadeToOne( parent, child, type, style, anything, isCascadeDeleteEnabled );
	}
	else if ( type.isCollectionType() ) {
		cascadeCollection( parent, child, style, anything, (CollectionType) type );
	}
}
 
Example 13
Project: lams   File: FromElementFactory.java   View Source Code Vote up 4 votes
FromElement createElementJoin(QueryableCollection queryableCollection) throws SemanticException {
		FromElement elem;

		implied = true; //TODO: always true for now, but not if we later decide to support elements() in the from clause
		inElementsFunction = true;
		Type elementType = queryableCollection.getElementType();
		if ( !elementType.isEntityType() ) {
			throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
		}
		this.queryableCollection = queryableCollection;
		SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
		FromElement destination = null;
		String tableAlias = null;
		EntityPersister entityPersister = queryableCollection.getElementPersister();
		tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
		String associatedEntityName = entityPersister.getEntityName();
		EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
		// Create the FROM element for the target (the elements of the collection).
		destination = createAndAddFromElement(
				associatedEntityName,
				classAlias,
				targetEntityPersister,
				(EntityType) queryableCollection.getElementType(),
				tableAlias
		);
		// If the join is implied, then don't include sub-classes on the element.
		if ( implied ) {
			destination.setIncludeSubclasses( false );
		}
		fromClause.addCollectionJoinFromElementByPath( path, destination );
//		origin.addDestination(destination);
		// Add the query spaces.
		fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );

		CollectionType type = queryableCollection.getCollectionType();
		String role = type.getRole();
		String roleAlias = origin.getTableAlias();

		String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
		AssociationType elementAssociationType = sfh.getElementAssociationType( type );

		// Create the join element under the from element.
		JoinType joinType = JoinType.INNER_JOIN;
		JoinSequence joinSequence = sfh.createJoinSequence(
				implied,
				elementAssociationType,
				tableAlias,
				joinType,
				targetColumns
		);
		elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
		elem.setUseFromFragment( true );    // The associated entity is implied, but it must be included in the FROM.
		elem.setCollectionTableAlias( roleAlias );    // The collection alias is the role.
		return elem;
	}
 
Example 14
Project: lams   File: DotNode.java   View Source Code Vote up 4 votes
public void resolve(boolean generateJoin, boolean implicitJoin, String classAlias, AST parent)
		throws SemanticException {
	// If this dot has already been resolved, stop now.
	if ( isResolved() ) {
		return;
	}
	Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.

	// If there is no data type for this node, and we're at the end of the path (top most dot node), then
	// this might be a Java constant.
	if ( propertyType == null ) {
		if ( parent == null ) {
			getWalker().getLiteralProcessor().lookupConstant( this );
		}
		// If the propertyType is null and there isn't a parent, just
		// stop now... there was a problem resolving the node anyway.
		return;
	}

	if ( propertyType.isComponentType() ) {
		// The property is a component...
		checkLhsIsNotCollection();
		dereferenceComponent( parent );
		initText();
	}
	else if ( propertyType.isEntityType() ) {
		// The property is another class..
		checkLhsIsNotCollection();
		dereferenceEntity( (EntityType) propertyType, implicitJoin, classAlias, generateJoin, parent );
		initText();
	}
	else if ( propertyType.isCollectionType() ) {
		// The property is a collection...
		checkLhsIsNotCollection();
		dereferenceCollection( (CollectionType) propertyType, implicitJoin, false, classAlias, parent );
	}
	else {
		// Otherwise, this is a primitive type.
		if ( !CollectionProperties.isAnyCollectionProperty( propertyName ) ) {
			checkLhsIsNotCollection();
		}
		dereferenceType = DereferenceType.PRIMITIVE;
		initText();
	}
	setResolved();
}
 
Example 15
Project: lams   File: HqlSqlWalker.java   View Source Code Vote up 4 votes
@Override
	protected void prepareFromClauseInputTree(AST fromClauseInput) {
		if ( !isSubQuery() ) {
//			// inject param specifications to account for dynamic filter param values
//			if ( ! getEnabledFilters().isEmpty() ) {
//				Iterator filterItr = getEnabledFilters().values().iterator();
//				while ( filterItr.hasNext() ) {
//					FilterImpl filter = ( FilterImpl ) filterItr.next();
//					if ( ! filter.getFilterDefinition().getParameterNames().isEmpty() ) {
//						Iterator paramItr = filter.getFilterDefinition().getParameterNames().iterator();
//						while ( paramItr.hasNext() ) {
//							String parameterName = ( String ) paramItr.next();
//							// currently param filters *only* work with single-column parameter types;
//							// if that limitation is ever lifted, this logic will need to change to account for that
//							ParameterNode collectionFilterKeyParameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
//							DynamicFilterParameterSpecification paramSpec = new DynamicFilterParameterSpecification(
//									filter.getName(),
//									parameterName,
//									filter.getFilterDefinition().getParameterType( parameterName ),
//									 positionalParameterCount++
//							);
//							collectionFilterKeyParameter.setHqlParameterSpecification( paramSpec );
//							parameters.add( paramSpec );
//						}
//					}
//				}
//			}

			if ( isFilter() ) {
				// Handle collection-filter compilation.
				// IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
				QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
				Type collectionElementType = persister.getElementType();
				if ( !collectionElementType.isEntityType() ) {
					throw new QueryException( "collection of values in filter: this" );
				}

				String collectionElementEntityName = persister.getElementPersister().getEntityName();
				ASTFactory inputAstFactory = hqlParser.getASTFactory();
				AST fromElement = inputAstFactory.create( HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName );
				ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement );
				fromClauseInput.addChild( fromElement );
				// Show the modified AST.
				LOG.debug( "prepareFromClauseInputTree() : Filter - Added 'this' as a from element..." );
				queryTranslatorImpl.showHqlAst( hqlParser.getAST() );

				// Create a parameter specification for the collection filter...
				Type collectionFilterKeyType = sessionFactoryHelper.requireQueryableCollection( collectionFilterRole )
						.getKeyType();
				ParameterNode collectionFilterKeyParameter = (ParameterNode) astFactory.create( PARAM, "?" );
				CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(
						collectionFilterRole, collectionFilterKeyType, positionalParameterCount++
				);
				collectionFilterKeyParameter.setHqlParameterSpecification( collectionFilterKeyParameterSpec );
				parameters.add( collectionFilterKeyParameterSpec );
			}
		}
	}
 
Example 16
Project: lams   File: CastFunctionNode.java   View Source Code Vote up 4 votes
/**
 * Called from the hql-sql grammar after the children of the CAST have been resolved.
 *
 * @param inSelect Is this call part of the SELECT clause?
 */
public void resolve(boolean inSelect) {
	this.dialectCastFunction = getSessionFactoryHelper().findSQLFunction( "cast" );
	if ( dialectCastFunction == null ) {
		dialectCastFunction = CastFunction.INSTANCE;
	}

	this.expressionNode = (Node) getFirstChild();
	if ( expressionNode == null ) {
		throw new QueryException( "Could not resolve expression to CAST" );
	}
	if ( SqlNode.class.isInstance( expressionNode ) ) {
		final Type expressionType = ( (SqlNode) expressionNode ).getDataType();
		if ( expressionType != null ) {
			if ( expressionType.isEntityType() ) {
				throw new QueryException( "Expression to CAST cannot be an entity : " + expressionNode.getText() );
			}
			if ( expressionType.isComponentType() ) {
				throw new QueryException( "Expression to CAST cannot be a composite : " + expressionNode.getText() );
			}
			if ( expressionType.isCollectionType() ) {
				throw new QueryException( "Expression to CAST cannot be a collection : " + expressionNode.getText() );
			}
		}
	}

	this.typeNode = (IdentNode) expressionNode.getNextSibling();
	if ( typeNode == null ) {
		throw new QueryException( "Could not resolve requested type for CAST" );
	}

	final String typeName = typeNode.getText();
	this.castType = getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType( typeName );
	if ( castType == null ) {
		throw new QueryException( "Could not resolve requested type for CAST : " + typeName );
	}
	if ( castType.isEntityType() ) {
		throw new QueryException( "CAST target type cannot be an entity : " + expressionNode.getText() );
	}
	if ( castType.isComponentType() ) {
		throw new QueryException( "CAST target type cannot be a composite : " + expressionNode.getText() );
	}
	if ( castType.isCollectionType() ) {
		throw new QueryException( "CAST target type cannot be a collection : " + expressionNode.getText() );
	}
	setDataType( castType );
}
 
Example 17
Project: lams   File: AbstractCollectionReference.java   View Source Code Vote up 4 votes
private CollectionFetchableIndex buildIndexGraph(
		ExpandingCollectionQuerySpace collectionQuerySpace,
		boolean shouldIncludeJoins) {
	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(),
						shouldIncludeJoins
				);
				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(),
					shouldIncludeJoins
			);
			return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace );
		}
	}

	return null;
}
 
Example 18
Project: lams   File: AbstractCollectionReference.java   View Source Code Vote up 4 votes
private CollectionFetchableElement buildElementGraph(
		ExpandingCollectionQuerySpace collectionQuerySpace,
		boolean shouldIncludeJoins) {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	final Type type = persister.getElementType();
	if ( type.isAssociationType() ) {
		if ( type.isEntityType() ) {
			final EntityPersister elementPersister = persister.getFactory().getEntityPersister(
					( (EntityType) type ).getAssociatedEntityName()
			);
			final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
					collectionQuerySpace,
					elementPersister,
					CollectionPropertyNames.COLLECTION_ELEMENTS,
					(EntityType) persister.getElementType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					shouldIncludeJoins
			);
			return new CollectionFetchableElementEntityGraph( this, entityQuerySpace );
		}
		else if ( type.isAnyType() ) {
			return new CollectionFetchableElementAnyGraph( this );
		}
	}
	else if ( type.isComponentType() ) {
		final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
				collectionQuerySpace,
				new CompositePropertyMapping(
						(CompositeType) persister.getElementType(),
						(PropertyMapping) persister,
						""
				),
				CollectionPropertyNames.COLLECTION_ELEMENTS,
				(CompositeType) persister.getElementType(),
				collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
				collectionQuerySpace.canJoinsBeRequired(),
				shouldIncludeJoins
		);
		return new CollectionFetchableElementCompositeGraph( this, compositeQuerySpace );
	}

	return null;
}
 
Example 19
Project: lams   File: ForeignKeys.java   View Source Code Vote up 4 votes
private static void collectNonNullableTransientEntities(
		Nullifier nullifier,
		Object value,
		String propertyName,
		Type type,
		boolean isNullable,
		SessionImplementor session,
		NonNullableTransientDependencies nonNullableTransientEntities) {
	if ( value == null ) {
		return;
	}

	if ( type.isEntityType() ) {
		final EntityType entityType = (EntityType) type;
		if ( !isNullable
				&& !entityType.isOneToOne()
				&& nullifier.isNullifiable( entityType.getAssociatedEntityName(), value ) ) {
			nonNullableTransientEntities.add( propertyName, value );
		}
	}
	else if ( type.isAnyType() ) {
		if ( !isNullable && nullifier.isNullifiable( null, value ) ) {
			nonNullableTransientEntities.add( propertyName, value );
		}
	}
	else if ( type.isComponentType() ) {
		final CompositeType actype = (CompositeType) type;
		final boolean[] subValueNullability = actype.getPropertyNullability();
		if ( subValueNullability != null ) {
			final String[] subPropertyNames = actype.getPropertyNames();
			final Object[] subvalues = actype.getPropertyValues( value, session );
			final Type[] subtypes = actype.getSubtypes();
			for ( int j = 0; j < subvalues.length; j++ ) {
				collectNonNullableTransientEntities(
						nullifier,
						subvalues[j],
						subPropertyNames[j],
						subtypes[j],
						subValueNullability[j],
						session,
						nonNullableTransientEntities
				);
			}
		}
	}
}
 
Example 20
Project: lams   File: Cascade.java   View Source Code Vote up 2 votes
/**
 * Check if the association is a one to one in the logical model (either a shared-pk
 * or unique fk).
 *
 * @param type The type representing the attribute metadata
 *
 * @return True if the attribute represents a logical one to one association
 */
private boolean isLogicalOneToOne(Type type) {
	return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne();
}