public boolean isScalar() throws SemanticException { // Default implementation: // If this node has a data type, and that data type is not an association, then this is scalar. Type type = getDataType(); return type != null && !type.isAssociationType(); // Moved here from SelectClause [jsd] }
private AssociationType getJoinedAssociationTypeOrNull(Join join) { if ( !JoinDefinedByMetadata.class.isInstance( join ) ) { return null; } final Type joinedType = ( (JoinDefinedByMetadata) join ).getJoinedPropertyType(); return joinedType.isAssociationType() ? (AssociationType) joinedType : null; }
@SuppressWarnings("SimplifiableIfStatement") private boolean isPropertyIncluded(Object value, String name, Type type) { if ( excludedProperties.contains( name ) ) { // was explicitly excluded return false; } if ( type.isAssociationType() ) { // associations are implicitly excluded return false; } return selector.include( value, name, type ); }
/** * 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; }
/** * 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 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; } }
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SharedSessionContractImplementor session) { final Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); final Type[] subTypes = virtualIdComponent.getSubtypes(); final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); final int length = subTypes.length; for ( int i = 0; i < length; i++ ) { if ( propertyValues[i] == null ) { throw new HibernateException( "No part of a composite identifier may be null" ); } //JPA 2 @MapsId + @IdClass points to the pk of the entity if ( subTypes[i].isAssociationType() && !copierSubTypes[i].isAssociationType() ) { propertyValues[i] = determineEntityId( propertyValues[i], (AssociationType) subTypes[i], session, sessionFactory ); } } mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
private int getSubclassPropertyTableNumber(String propertyName, String entityName) { // When there are duplicated property names in the subclasses // then propertyMapping.toType( propertyName ) may return an // incorrect Type. To ensure correct results, lookup the property type // using the concrete EntityPersister with the specified entityName // (since the concrete EntityPersister cannot have duplicated property names). final EntityPersister concreteEntityPersister; if ( getEntityName().equals( entityName ) ) { concreteEntityPersister = this; } else { concreteEntityPersister = getFactory().getMetamodel().entityPersister( entityName ); } Type type = concreteEntityPersister.getPropertyType( propertyName ); if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) { return 0; } final Integer tabnum = propertyTableNumbersByNameAndSubclass.get( entityName + '.' + propertyName ); return tabnum == null ? 0 : tabnum; }
/** * Check if eager of the association is overriden by anything. * * @param session session * @param entityName entity name * @param associationName association name * * @return null if there is no overriding, true if it is overridden to eager and false if it is overridden to lazy */ private static Boolean getOverridingEager( SharedSessionContractImplementor session, String entityName, String associationName, Type type) { if ( type.isAssociationType() || type.isCollectionType() ) { Boolean overridingEager = isEagerFetchProfile( session, entityName + "." + associationName ); if ( LOG.isDebugEnabled() ) { if ( overridingEager != null ) { LOG.debugf( "Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s", entityName, associationName, overridingEager ); } } return overridingEager; } return null; }
@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() ); }
@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 ); } }
componentPath += tokens.nextToken(); final Type type = provider.getType( componentPath ); if ( type.isAssociationType() ) {
@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() ); } } }
String rootPropertyName = StringHelper.root( propertyPath ); Type type = propertyMapping.toType( rootPropertyName ); if ( type.isAssociationType() ) { AssociationType assocType = (AssociationType) type; if ( assocType.useLHSPrimaryKey() ) {
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) { AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 ); appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator ); Type valueType = collectionPersister.getElementType(); if ( valueType.isAssociationType() ) { EntityType valueEntityType = (EntityType) valueType; Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister( valueEntityType.getAssociatedEntityName( sfi() ) ); SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment( elementTableAlias(), null, false ); appendSelectExpressions( fragment, selections, aliasGenerator ); } }
private DereferenceType resolveAsNakedPropertyRef() { FromElement fromElement = locateSingleFromElement(); if (fromElement == null) { return DereferenceType.UNKNOWN; } Queryable persister = fromElement.getQueryable(); if (persister == null) { return DereferenceType.UNKNOWN; } Type propertyType = getNakedPropertyType(fromElement); if (propertyType == null) { // assume this ident's text does *not* refer to a property on the given persister return DereferenceType.UNKNOWN; } if ((propertyType.isComponentType() || propertyType.isAssociationType() )) { return DereferenceType.COMPONENT_REF; } setFromElement(fromElement); String property = getText(); String[] columns = getWalker().isSelectStatement() ? persister.toColumns(fromElement.getTableAlias(), property) : persister.toColumns(property); String text = String.join(", ", columns); setText(columns.length == 1 ? text : "(" + text + ")"); setType(SqlTokenTypes.SQL_TOKEN); // these pieces are needed for usage in select clause super.setDataType(propertyType); nakedPropertyRef = true; return DereferenceType.PROPERTY_REF; }
/** * @deprecated See mainly {@link #buildEntityBasedAttribute} */ @Deprecated public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) { final Type type = property.getValue().getType(); // we need to dirty check collections, since they can cause an owner // version number increment // we need to dirty check many-to-ones with not-found="ignore" in order // to update the cache (not the database), since in this case a null // entity reference can lose information boolean alwaysDirtyCheck = type.isAssociationType() && ( (AssociationType) type ).isAlwaysDirtyChecked(); return new StandardProperty( property.getName(), type, lazyAvailable && property.isLazy(), property.isInsertable(), property.isUpdateable(), property.getValueGenerationStrategy(), property.isOptional(), alwaysDirtyCheck || property.isUpdateable(), property.isOptimisticLocked(), property.getCascadeStyle(), property.getValue().getFetchMode() ); }
private void visitCollectionIndex(CollectionDefinition collectionDefinition) { final CollectionIndexDefinition collectionIndexDefinition = collectionDefinition.getIndexDefinition(); if ( collectionIndexDefinition == null ) { return; } strategy.startingCollectionIndex( collectionIndexDefinition ); try { 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(); } } finally { strategy.finishingCollectionIndex( collectionIndexDefinition ); } }
private CollectionFetchableElement buildElementGraph() { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); final Type type = persister.getElementType(); if ( type.isAssociationType() ) { if ( type.isEntityType() ) { final EntityPersister elementPersister = persister.getFactory().getEntityPersister(
if ( persister.hasIndex() ) { final Type type = persister.getIndexType(); if ( type.isAssociationType() ) { if ( type.isEntityType() ) { final EntityPersister indexPersister = persister.getFactory().getEntityPersister(