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

The following are Jave code examples for showing how to use isComponentType() 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: AbstractCollectionPersister.java   View Source Code Vote up 6 votes
private void initCollectionPropertyMap(String aliasName, Type type, String[] columnAliases, String[] columnNames) {

		collectionPropertyColumnAliases.put( aliasName, columnAliases );
		collectionPropertyColumnNames.put( aliasName, columnNames );

		if ( type.isComponentType() ) {
			CompositeType ct = (CompositeType) type;
			String[] propertyNames = ct.getPropertyNames();
			for ( int i = 0; i < propertyNames.length; i++ ) {
				String name = propertyNames[i];
				collectionPropertyColumnAliases.put( aliasName + "." + name, columnAliases[i] );
				collectionPropertyColumnNames.put( aliasName + "." + name, columnNames[i] );
			}
		}

	}
 
Example 2
Project: lams   File: Example.java   View Source Code Vote up 6 votes
protected void addComponentTypedValues(
		String path, 
		Object component, 
		CompositeType type,
		List<TypedValue> list,
		Criteria criteria, 
		CriteriaQuery criteriaQuery) {
	if ( component != null ) {
		final String[] propertyNames = type.getPropertyNames();
		final Type[] subtypes = type.getSubtypes();
		final Object[] values = type.getPropertyValues( component, getEntityMode( criteria, criteriaQuery ) );
		for ( int i=0; i<propertyNames.length; i++ ) {
			final Object value = values[i];
			final Type subtype = subtypes[i];
			final String subpath = StringHelper.qualify( path, propertyNames[i] );
			if ( isPropertyIncluded( value, subpath, subtype ) ) {
				if ( subtype.isComponentType() ) {
					addComponentTypedValues( subpath, value, (CompositeType) subtype, list, criteria, criteriaQuery );
				}
				else {
					addPropertyTypedValue( value, subtype, list );
				}
			}
		}
	}
}
 
Example 3
Project: lams   File: PropertyFactory.java   View Source Code Vote up 6 votes
private static NonIdentifierAttributeNature decode(Type type) {
	if ( type.isAssociationType() ) {
		AssociationType associationType = (AssociationType) type;

		if ( type.isComponentType() ) {
			// an any type is both an association and a composite...
			return NonIdentifierAttributeNature.ANY;
		}

		return type.isCollectionType()
				? NonIdentifierAttributeNature.COLLECTION
				: NonIdentifierAttributeNature.ENTITY;
	}
	else {
		if ( type.isComponentType() ) {
			return NonIdentifierAttributeNature.COMPOSITE;
		}

		return NonIdentifierAttributeNature.BASIC;
	}
}
 
Example 4
Project: hibernate-ogm-ignite   File: IgnitePropertyHelper.java   View Source Code Vote up 6 votes
/**
 * Check if the property is part of the identifier of the entity.
 *
 * @param persister the {@link OgmEntityPersister} of the entity with the property
 * @param namesWithoutAlias the path to the property with all the aliases resolved
 * @return {@code true} if the property is part of the id, {@code false} otherwise.
 */
public boolean isIdProperty(OgmEntityPersister persister, List<String> namesWithoutAlias) {
	String join = StringHelper.join( namesWithoutAlias, "." );
	Type propertyType = persister.getPropertyType( namesWithoutAlias.get( 0 ) );
	String[] identifierColumnNames = persister.getIdentifierColumnNames();
	if ( propertyType.isComponentType() ) {
		String[] embeddedColumnNames = persister.getPropertyColumnNames( join );
		for ( String embeddedColumn : embeddedColumnNames ) {
			if ( !ArrayHelper.contains( identifierColumnNames, embeddedColumn ) ) {
				return false;
			}
		}
		return true;
	}
	return ArrayHelper.contains( identifierColumnNames, join );
}
 
Example 5
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 6
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 7
Project: lams   File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java   View Source Code Vote up 6 votes
@Override
public boolean startingAttribute(AttributeDefinition attributeDefinition) {
	log.tracef(
			"%s Starting attribute %s",
			StringHelper.repeat( ">>", fetchSourceStack.size() ),
			attributeDefinition
	);

	final Type attributeType = attributeDefinition.getType();

	final boolean isComponentType = attributeType.isComponentType();
	final boolean isAssociationType = attributeType.isAssociationType();
	final boolean isBasicType = ! ( isComponentType || isAssociationType );
	currentPropertyPath = currentPropertyPath.append( attributeDefinition.getName() );
	if ( isBasicType ) {
		return true;
	}
	else if ( isAssociationType ) {
		// also handles any type attributes...
		return handleAssociationAttribute( (AssociationAttributeDefinition) attributeDefinition );
	}
	else {
		return handleCompositeAttribute( attributeDefinition );
	}
}
 
Example 8
Project: lams   File: AbstractEntityPersister.java   View Source Code Vote up 6 votes
private void prepareEntityIdentifierDefinition() {
	if ( entityIdentifierDefinition != null ) {
		return;
	}
	final Type idType = getIdentifierType();

	if ( !idType.isComponentType() ) {
		entityIdentifierDefinition =
				EntityIdentifierDefinitionHelper.buildSimpleEncapsulatedIdentifierDefinition( this );
		return;
	}

	final CompositeType cidType = (CompositeType) idType;
	if ( !cidType.isEmbedded() ) {
		entityIdentifierDefinition =
				EntityIdentifierDefinitionHelper.buildEncapsulatedCompositeIdentifierDefinition( this );
		return;
	}

	entityIdentifierDefinition =
			EntityIdentifierDefinitionHelper.buildNonEncapsulatedCompositeIdentifierDefinition( this );
}
 
Example 9
Project: lams   File: Property.java   View Source Code Vote up 5 votes
public CascadeStyle getCascadeStyle() throws MappingException {
	Type type = value.getType();
	if ( type.isComponentType() ) {
		return getCompositeCascadeStyle( (CompositeType) type, cascade );
	}
	else if ( type.isCollectionType() ) {
		return getCollectionCascadeStyle( ( (Collection) value ).getElement().getType(), cascade );
	}
	else {
		return getCascadeStyle( cascade );			
	}
}
 
Example 10
Project: lams   File: Property.java   View Source Code Vote up 5 votes
private static CascadeStyle getCollectionCascadeStyle(Type elementType, String cascade) {
	if ( elementType.isComponentType() ) {
		return getCompositeCascadeStyle( (CompositeType) elementType, cascade );
	}
	else {
		return getCascadeStyle( cascade );
	}
}
 
Example 11
Project: lams   File: Example.java   View Source Code Vote up 5 votes
protected void appendComponentCondition(
		String path,
		Object component,
		CompositeType type,
		Criteria criteria,
		CriteriaQuery criteriaQuery,
		StringBuilder buf) {
	if ( component != null ) {
		final String[] propertyNames = type.getPropertyNames();
		final Object[] values = type.getPropertyValues( component, getEntityMode( criteria, criteriaQuery ) );
		final Type[] subtypes = type.getSubtypes();
		for ( int i=0; i<propertyNames.length; i++ ) {
			final String subPath = StringHelper.qualify( path, propertyNames[i] );
			final Object value = values[i];
			if ( isPropertyIncluded( value, subPath, subtypes[i] ) ) {
				final Type subtype = subtypes[i];
				if ( subtype.isComponentType() ) {
					appendComponentCondition(
							subPath,
							value,
							(CompositeType) subtype,
							criteria,
							criteriaQuery,
							buf
					);
				}
				else {
					appendPropertyCondition(
							subPath,
							value,
							criteria,
							criteriaQuery,
							buf
					);
				}
			}
		}
	}
}
 
Example 12
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 13
Project: lams   File: IdentNode.java   View Source Code Vote up 5 votes
private boolean resolveAsNakedComponentPropertyRefLHS(DotNode parent) {
	FromElement fromElement = locateSingleFromElement();
	if (fromElement == null) {
		return false;
	}

	Type componentType = getNakedPropertyType(fromElement);
	if ( componentType == null ) {
		throw new QueryException( "Unable to resolve path [" + parent.getPath() + "], unexpected token [" + getOriginalText() + "]" );
	}
	if (!componentType.isComponentType()) {
		throw new QueryException("Property '" + getOriginalText() + "' is not a component.  Use an alias to reference associations or collections.");
	}

	Type propertyType;
	String propertyPath = getText() + "." + getNextSibling().getText();
	try {
		// check to see if our "propPath" actually
		// represents a property on the persister
		propertyType = fromElement.getPropertyType(getText(), propertyPath);
	}
	catch (Throwable t) {
		// assume we do *not* refer to a property on the given persister
		return false;
	}

	setFromElement(fromElement);
	parent.setPropertyPath(propertyPath);
	parent.setDataType(propertyType);

	return true;
}
 
Example 14
Project: lams   File: EntityLoadQueryDetails.java   View Source Code Vote up 5 votes
private void addKeyManyToOnesToSession(ResultSetProcessingContextImpl context, ComponentType componentType, Object component ) {
	for ( int i = 0 ; i < componentType.getSubtypes().length ; i++ ) {
		final Type subType = componentType.getSubtypes()[ i ];
		final Object subValue = componentType.getPropertyValue( component, i, context.getSession() );
		if ( subType.isEntityType() ) {
			( (Session) context.getSession() ).buildLockRequest( LockOptions.NONE ).lock( subValue );
		}
		else if ( subType.isComponentType() ) {
			addKeyManyToOnesToSession( context, (ComponentType) subType, subValue  );
		}
	}
}
 
Example 15
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 16
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 17
Project: Layer-Query   File: CustomCriteriaQueryTranslator.java   View Source Code Vote up 4 votes
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 18
Project: lams   File: CriteriaQueryTranslator.java   View Source Code Vote up 4 votes
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 19
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 20
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
				);
			}
		}
	}
}