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

The following are Jave code examples for showing how to use isAnyType() 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: 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 3
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 6 votes
@Override
public void finishingCollectionElements(CollectionElementDefinition elementDefinition) {
	final Type elementType = elementDefinition.getType();

	if ( elementType.isAnyType() ) {
		// nothing to do because the element graph was not pushed in #startingCollectionElement..
	}
	else if ( elementType.isComponentType() || elementType.isAssociationType()) {
		// pop it from the stack
		final ExpandingFetchSource popped = popFromStack();

		// validation
		if ( ! CollectionFetchableElement.class.isInstance( popped ) ) {
			throw new WalkingException( "Mismatched FetchSource from stack on pop" );
		}
	}

	log.tracef(
			"%s Finished collection element graph : %s",
			StringHelper.repeat( "<<", fetchSourceStack.size() ),
			elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);
}
 
Example 4
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 5
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 6
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 5 votes
@Override
public void startingCollectionElements(CollectionElementDefinition elementDefinition) {
	final Type elementType = elementDefinition.getType();
	log.tracef(
			"%s Starting collection element graph : %s",
			StringHelper.repeat( ">>", fetchSourceStack.size() ),
			elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
	);

	final CollectionReference collectionReference = currentCollection();
	final CollectionFetchableElement elementGraph = collectionReference.getElementGraph();

	if ( elementType.isAssociationType() || elementType.isComponentType() ) {
		if ( elementGraph == null ) {
			throw new IllegalStateException(
					"CollectionReference did not return an expected element graph : " +
							elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
		if ( !elementType.isAnyType() ) {
			pushToStack( (ExpandingFetchSource) elementGraph );
		}
	}
	else {
		if ( elementGraph != null ) {
			throw new IllegalStateException(
					"CollectionReference returned an unexpected element graph : " +
							elementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
			);
		}
	}
}
 
Example 7
Project: lams   File: MetamodelGraphWalker.java   View Source Code Vote up 5 votes
private void visitCollectionIndex(CollectionDefinition collectionDefinition) {
	final CollectionIndexDefinition collectionIndexDefinition = collectionDefinition.getIndexDefinition();
	if ( collectionIndexDefinition == null ) {
		return;
	}

	strategy.startingCollectionIndex( collectionIndexDefinition );

	log.debug( "Visiting index for collection :  " + currentPropertyPath.getFullPath() );
	currentPropertyPath = currentPropertyPath.append( "<index>" );

	try {
		final Type collectionIndexType = collectionIndexDefinition.getType();
		if ( collectionIndexType.isAnyType() ) {
			visitAnyDefinition( collectionIndexDefinition.toAnyMappingDefinition() );
		}
		else if ( collectionIndexType.isComponentType() ) {
			visitCompositeDefinition( collectionIndexDefinition.toCompositeDefinition() );
		}
		else if ( collectionIndexType.isAssociationType() ) {
			visitEntityDefinition( collectionIndexDefinition.toEntityDefinition() );
		}
	}
	finally {
		currentPropertyPath = currentPropertyPath.getParent();
	}

	strategy.finishingCollectionIndex( collectionIndexDefinition );
}
 
Example 8
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 9
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 10
Project: lams   File: Cascade.java   View Source Code Vote up 5 votes
/**
 * Cascade an action to a collection
 */
private void cascadeCollection(
		final Object parent,
		final Object child,
		final CascadeStyle style,
		final Object anything,
		final CollectionType type) {
	final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() );
	final Type elemType = persister.getElementType();

	final CascadePoint originalCascadePoint = cascadePoint;
	if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE) {
		cascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
	}

	//cascade to current collection elements
	if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
		cascadeCollectionElements(
			parent,
			child,
			type,
			style,
			elemType,
			anything,
			persister.isCascadeDeleteEnabled()
		);
	}

	cascadePoint = originalCascadePoint;
}
 
Example 11
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 12
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 13
Project: lams   File: AbstractCollectionPersister.java   View Source Code Vote up 4 votes
@Override
public CollectionIndexDefinition getIndexDefinition() {
	if ( ! hasIndex() ) {
		return null;
	}

	return new CollectionIndexDefinition() {
		@Override
		public CollectionDefinition getCollectionDefinition() {
			return AbstractCollectionPersister.this;
		}

		@Override
		public Type getType() {
			return getIndexType();
		}

		@Override
		public EntityDefinition toEntityDefinition() {
			if ( !getType().isEntityType() ) {
				throw new IllegalStateException( "Cannot treat collection index type as entity" );
			}
			return (EntityPersister) ( (AssociationType) getIndexType() ).getAssociatedJoinable( getFactory() );
		}

		@Override
		public CompositionDefinition toCompositeDefinition() {
			if ( ! getType().isComponentType() ) {
				throw new IllegalStateException( "Cannot treat collection index type as composite" );
			}
			return new CompositeCollectionElementDefinition() {
				@Override
				public String getName() {
					return "index";
				}

				@Override
				public CompositeType getType() {
					return (CompositeType) getIndexType();
				}

				@Override
				public boolean isNullable() {
					return false;
				}

				@Override
				public AttributeSource getSource() {
					// TODO: what if this is a collection w/in an encapsulated composition attribute?
					// should return the encapsulated composition attribute instead???
					return getOwnerEntityPersister();
				}

				@Override
				public Iterable<AttributeDefinition> getAttributes() {
					return CompositionSingularSubAttributesHelper.getCompositeCollectionIndexSubAttributes( this );
				}
				@Override
				public CollectionDefinition getCollectionDefinition() {
					return AbstractCollectionPersister.this;
				}
			};
		}

		@Override
		public AnyMappingDefinition toAnyMappingDefinition() {
			final Type type = getType();
			if ( ! type.isAnyType() ) {
				throw new IllegalStateException( "Cannot treat collection index type as ManyToAny" );
			}
			return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() );
		}
	};
}
 
Example 14
Project: lams   File: AbstractCollectionPersister.java   View Source Code Vote up 4 votes
@Override
public CollectionElementDefinition getElementDefinition() {
	return new CollectionElementDefinition() {
		@Override
		public CollectionDefinition getCollectionDefinition() {
			return AbstractCollectionPersister.this;
		}

		@Override
		public Type getType() {
			return getElementType();
		}

		@Override
		public AnyMappingDefinition toAnyMappingDefinition() {
			final Type type = getType();
			if ( ! type.isAnyType() ) {
				throw new IllegalStateException( "Cannot treat collection element type as ManyToAny" );
			}
			return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() );
		}

		@Override
		public EntityDefinition toEntityDefinition() {
			if ( !getType().isEntityType() ) {
				throw new IllegalStateException( "Cannot treat collection element type as entity" );
			}
			return getElementPersister();
		}

		@Override
		public CompositeCollectionElementDefinition toCompositeElementDefinition() {

			if ( ! getType().isComponentType() ) {
				throw new IllegalStateException( "Cannot treat entity collection element type as composite" );
			}

			return new CompositeCollectionElementDefinition() {
				@Override
				public String getName() {
					return "";
				}

				@Override
				public CompositeType getType() {
					return (CompositeType) getElementType();
				}

				@Override
				public boolean isNullable() {
					return false;
				}

				@Override
				public AttributeSource getSource() {
					// TODO: what if this is a collection w/in an encapsulated composition attribute?
					// should return the encapsulated composition attribute instead???
					return getOwnerEntityPersister();
				}

				@Override
				public Iterable<AttributeDefinition> getAttributes() {
					return CompositionSingularSubAttributesHelper.getCompositeCollectionElementSubAttributes( this );
				}

				@Override
				public CollectionDefinition getCollectionDefinition() {
					return AbstractCollectionPersister.this;
				}
			};
		}
	};
}
 
Example 15
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
				);
			}
		}
	}
}