org.hibernate.type.Type.isCollectionType()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中org.hibernate.type.Type.isCollectionType()方法的一些代码示例,展示了Type.isCollectionType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Type.isCollectionType()方法的具体详情如下:
包路径:org.hibernate.type.Type
类名称:Type
方法名:isCollectionType

Type.isCollectionType介绍

[英]Return true if the implementation is castable to CollectionType. Essentially a polymorphic version of (type instanceof CollectionType.class)

A CollectionType is additionally an AssociationType; so if this method returns true, #isAssociationType() should also return true.
[中]如果实现可强制转换为CollectionType,则返回true。本质上是(type instanceof CollectionType.class)的多态版本
CollectionType另外是AssociationType;因此,如果这个方法返回true,#isAssociationType()也应该返回true。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

public boolean isCollectionValued() throws QueryException {
  //TODO: is there a better way?
  return collectionName != null && !getPropertyType().isCollectionType();
}

代码示例来源:origin: hibernate/hibernate-orm

public boolean isPlural() {
  return propertyMapping.getType().isCollectionType();
}

代码示例来源:origin: hibernate/hibernate-orm

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;
}

代码示例来源:origin: hibernate/hibernate-orm

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;
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void resolveInFunctionCall(boolean generateJoin, boolean implicitJoin) throws SemanticException {
  if ( isResolved() ) {
    return;
  }
  Type propertyType = prepareLhs();            // Prepare the left hand side and get the data type.
  if ( propertyType != null && propertyType.isCollectionType() ) {
    resolveIndex( null );
  }
  else {
    resolveFirstChild();
    super.resolve( generateJoin, implicitJoin );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

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);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private void checkLhsIsNotCollection() throws SemanticException {
  if ( getLhs().getDataType() != null && getLhs().getDataType().isCollectionType() ) {
    throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private static void cascadeAssociation(
    final CascadingAction action,
    final CascadePoint cascadePoint,
    final EventSource eventSource,
    final int componentPathStackDepth,
    final Object parent,
    final Object child,
    final Type type,
    final CascadeStyle style,
    final Object anything,
    final boolean isCascadeDeleteEnabled) {
  if ( type.isEntityType() || type.isAnyType() ) {
    cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled );
  }
  else if ( type.isCollectionType() ) {
    cascadeCollection(
        action,
        cascadePoint,
        eventSource,
        componentPathStackDepth,
        parent,
        child,
        style,
        anything,
        (CollectionType) type
    );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * 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;
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * 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;
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public void end(QueryTranslatorImpl q) throws QueryException {
  ignoreInitialJoin = false;
  Type propertyType = getPropertyType();
  if ( propertyType != null && propertyType.isCollectionType() ) {
    collectionRole = ( ( CollectionType ) propertyType ).getRole();
    collectionName = q.createNameForCollection( collectionRole );
    prepareForIndex( q );
  }
  else {
    columns = currentColumns();
    setType();
  }
  //important!!
  continuation = false;
}

代码示例来源:origin: hibernate/hibernate-orm

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 );			
  }
}

代码示例来源:origin: hibernate/hibernate-orm

Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() );
if ( returnType.isCollectionType() ) {
  String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
  addCollection( role, alias, fetchReturn.getPropertyResultsMap() );

代码示例来源:origin: hibernate/hibernate-orm

private boolean isNonIdentifierWhereConditionsRequired(String entityName, String propertyName, SessionImplementor session) {
    final Type propertyType = session.getSessionFactory().getMetamodel().entityPersister( entityName ).getPropertyType( propertyName );
    if ( propertyType.isCollectionType() ) {
      final CollectionType collectionType = (CollectionType) propertyType;
      final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() );
      if ( collectionElementType instanceof ComponentType ) {
        // required for Embeddables
        return true;
      }
      else if ( collectionElementType instanceof MaterializedClobType || collectionElementType instanceof MaterializedNClobType ) {
        // for Map<> using @Lob annotations
        return collectionType instanceof MapType;
      }
    }
    return false;
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public static LazyAttributeDescriptor from(
    Property property,
    int attributeIndex,
    int lazyIndex) {
  String fetchGroupName = property.getLazyGroup();
  if ( fetchGroupName == null ) {
    fetchGroupName = property.getType().isCollectionType()
        ? property.getName()
        : "DEFAULT";
  }
  return new LazyAttributeDescriptor(
      attributeIndex,
      lazyIndex,
      property.getName(),
      property.getType(),
      fetchGroupName
  );
}

代码示例来源:origin: hibernate/hibernate-orm

protected QueryableCollection getQueryableCollection(
    String entityName,
    String propertyName,
    SessionFactoryImplementor factory) throws HibernateException {
  final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
  final Type type = ownerMapping.toType( propertyName );
  if ( !type.isCollectionType() ) {
    throw new MappingException(
        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
    );
  }
  final String role = ( (CollectionType) type ).getRole();
  try {
    return (QueryableCollection) factory.getCollectionPersister( role );
  }
  catch ( ClassCastException cce ) {
    throw new QueryException( "collection role is not queryable: " + role );
  }
  catch ( Exception e ) {
    throw new QueryException( "collection role not found: " + role );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public void end(QueryTranslatorImpl q) throws QueryException {
  if ( !isCollectionValued() ) {
    Type type = getPropertyType();
    if ( type.isEntityType() ) {
      // "finish off" the join
      token( ".", q );
      token( null, q );
    }
    else if ( type.isCollectionType() ) {
      // default to element set if no elements() specified
      token( ".", q );
      token( CollectionPropertyNames.COLLECTION_ELEMENTS, q );
    }
  }
  super.end( q );
}

代码示例来源:origin: hibernate/hibernate-orm

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" );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private void evictCachedCollections(Type[] types, Serializable id, EventSource source)
      throws HibernateException {
    for ( Type type : types ) {
      if ( type.isCollectionType() ) {
        CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() );
        if ( collectionPersister.hasCache() ) {
          final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy();
          final Object ck = cache.generateCacheKey(
            id,
            collectionPersister,
            source.getFactory(),
            source.getTenantIdentifier()
          );
          final SoftLock lock = cache.lockItem( source, ck, null );
          cache.remove( source, ck );
          source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
        }
      }
      else if ( type.isComponentType() ) {
        CompositeType actype = (CompositeType) type;
        evictCachedCollections( actype.getSubtypes(), id, source );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private FromElement createCollectionJoin(JoinSequence collectionJoinSequence, String tableAlias)
      throws SemanticException {
    String text = queryableCollection.getTableName();
    AST ast = createFromElement( text );
    FromElement destination = (FromElement) ast;
    Type elementType = queryableCollection.getElementType();
    if ( elementType.isCollectionType() ) {
      throw new SemanticException( "Collections of collections are not supported!" );
    }
    destination.initializeCollection( fromClause, classAlias, tableAlias );
    destination.setType( JOIN_FRAGMENT );        // Tag this node as a JOIN.
    destination.setIncludeSubclasses( false );    // Don't include subclasses in the join.
    destination.setCollectionJoin( true );        // This is a clollection join.
    destination.setJoinSequence( collectionJoinSequence );
    destination.setOrigin( origin, false );
    destination.setCollectionTableAlias( tableAlias );
//        origin.addDestination( destination );
// This was the cause of HHH-242
//        origin.setType( FROM_FRAGMENT );            // Set the parent node type so that the AST is properly formed.
    origin.setText( "" );                        // The destination node will have all the FROM text.
    origin.setCollectionJoin( true );            // The parent node is a collection join too (voodoo - see JoinProcessor)
    fromClause.addCollectionJoinFromElementByPath( path, destination );
    fromClause.getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() );
    return destination;
  }

相关文章