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] ); } } }
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; } }
private int getNumberOfParametersCoveredBy(Type[] subtypes) { int numberOfParameters = 0; for ( Type type : subtypes ) { if ( type.isComponentType() ) { numberOfParameters = numberOfParameters + getNumberOfParametersCoveredBy( ((ComponentType) type).getSubtypes() ); } else { numberOfParameters++; } } return numberOfParameters; }
private static CascadeStyle getCollectionCascadeStyle(Type elementType, String cascade) { if ( elementType.isComponentType() ) { return getCompositeCascadeStyle( (CompositeType) elementType, cascade ); } else { return getCascadeStyle( cascade ); } }
ComponentCollectionCriteriaInfoProvider(QueryableCollection persister) { this.persister = persister; if ( !persister.getElementType().isComponentType() ) { throw new IllegalArgumentException( "persister for role " + persister.getRole() + " is not a collection-of-component" ); } CompositeType componentType = (CompositeType) persister.getElementType(); String[] names = componentType.getPropertyNames(); Type[] types = componentType.getSubtypes(); for ( int i = 0; i < names.length; i++ ) { subTypes.put( names[i], types[i] ); } }
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; }
@Override public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) { final ArrayList<TypedValue> list = new ArrayList<TypedValue>(); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); if ( type.isComponentType() ) { final CompositeType compositeType = (CompositeType) type; final Type[] subTypes = compositeType.getSubtypes(); for ( Object value : values ) { for ( int i = 0; i < subTypes.length; i++ ) { final Object subValue = value == null ? null : compositeType.getPropertyValues( value, EntityMode.POJO )[i]; list.add( new TypedValue( subTypes[i], subValue ) ); } } } else { for ( Object value : values ) { list.add( criteriaQuery.getTypedValue( criteria, propertyName, value ) ); } } return list.toArray( new TypedValue[ list.size() ] ); }
/** * Returns whether the collection is a map-type and that the map element is defined as a Clob/NClob type. * * @return {@code true} if the element is a Clob/NClob type, otherwise {@code false}. */ private boolean isLobMapElementType() { if ( propertyValue instanceof org.hibernate.mapping.Map ) { final Type type = propertyValue.getElement().getType(); // we're only interested in basic types if ( !type.isComponentType() && !type.isAssociationType() ) { return ( type instanceof MaterializedClobType ) || ( type instanceof MaterializedNClobType ); } } return false; }
private boolean indicatesCollection(Type type) { if ( type.isCollectionType() ) { return true; } else if ( type.isComponentType() ) { Type[] subtypes = ( (CompositeType) type ).getSubtypes(); for ( int i = 0; i < subtypes.length; i++ ) { if ( indicatesCollection( subtypes[i] ) ) { return true; } } } return false; }
/** * Returns whether the revision type column of the map-key is part of the collection table's primary key. * * NOTE: It is safe to call this method, even for non-map collection types as this method will always return * {@code false} for non-map collection types. * * @return {@code true} if the revision type should be part of the primary key, otherwise {@code false}. */ private boolean isKeyRevisionTypeInId() { if ( propertyValue instanceof org.hibernate.mapping.Map ) { final Type type = propertyValue.getKey().getType(); if ( !type.isComponentType() && !type.isAssociationType() ) { return ( type instanceof MaterializedClobType ) || ( type instanceof MaterializedNClobType ); } } return false; }
private void findKeyManyToOneTargetIndices( ArrayList<Integer> keyManyToOneTargetIndices, OuterJoinableAssociation joinWithCompositeId, CompositeType componentType) { for ( Type subType : componentType.getSubtypes() ) { if ( subType.isEntityType() ) { Integer index = locateKeyManyToOneTargetIndex( joinWithCompositeId, (EntityType) subType ); if ( index != null ) { keyManyToOneTargetIndices.add( index ); } } else if ( subType.isComponentType() ) { findKeyManyToOneTargetIndices( keyManyToOneTargetIndices, joinWithCompositeId, (CompositeType) subType ); } } }
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); } }
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 ); }
/** * 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; } }
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 ); } }
@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() ); }
public void associationProcessed(OuterJoinableAssociation oja, int position) { associationsByAlias.put( oja.getRhsAlias(), oja ); positionsByAlias.put( oja.getRhsAlias(), position ); EntityPersister entityPersister = null; if ( oja.getJoinableType().isCollectionType() ) { entityPersister = ( ( QueryableCollection) oja.getJoinable() ).getElementPersister(); } else if ( oja.getJoinableType().isEntityType() ) { entityPersister = ( EntityPersister ) oja.getJoinable(); } if ( entityPersister != null && entityPersister.getIdentifierType().isComponentType() && ! entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() && hasAssociation( (CompositeType) entityPersister.getIdentifierType() ) ) { aliasesForAssociationsWithCompositesIds.add( oja.getRhsAlias() ); } }
@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() ); }
private void validateLhs(FromReferenceNode lhs) { // make sure the lhs is "assignable"... if ( !lhs.isResolved() ) { throw new UnsupportedOperationException( "cannot validate assignablity of unresolved node" ); } if ( lhs.getDataType().isCollectionType() ) { throw new QueryException( "collections not assignable in update statements" ); } else if ( lhs.getDataType().isComponentType() ) { throw new QueryException( "Components currently not assignable in update statements" ); } else if ( lhs.getDataType().isEntityType() ) { // currently allowed... } // TODO : why aren't these the same? if ( lhs.getImpliedJoin() != null || lhs.getFromElement().isImplied() ) { throw new QueryException( "Implied join paths are not assignable in update statements" ); } } }
public void setScalarColumnText(int i) throws SemanticException { if (nakedPropertyRef) { // do *not* over-write the column text, as that has already been // "rendered" during resolve ColumnHelper.generateSingleScalarColumn(this, i); } else { FromElement fe = getFromElement(); if (fe != null) { if ( fe.getQueryableCollection() != null && fe.getQueryableCollection().getElementType().isComponentType() ) { ColumnHelper.generateScalarColumns( this, getColumns(), i ); } else { setText(fe.renderScalarIdentifierSelect(i)); } } else { ColumnHelper.generateSingleScalarColumn(this, i); } } }