Examples of QueryableCollection


Examples of org.hibernate.persister.collection.QueryableCollection

          String.format( "Non-Map attribute [%s] cannot be target of key subgraph", getAttributeName() )
      );
    }

    final AssociationType attributeType = (AssociationType) Helper.resolveType( sessionFactory(), attribute );
    final QueryableCollection collectionPersister = (QueryableCollection) attributeType.getAssociatedJoinable( sessionFactory() );
    final Type indexType = collectionPersister.getIndexType();

    if ( ! indexType.isAssociationType() ) {
      throw new IllegalArgumentException(
          String.format( "Map index [%s] is not an entity; cannot be target of key subgraph", getAttributeName() )
      );
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

    }
  }

  private void dereferenceCollection(String propertyName, String role, QueryTranslatorImpl q) throws QueryException {
    collectionRole = role;
    QueryableCollection collPersister = q.getCollectionPersister( role );
    String name = q.createNameForCollection( role );
    addJoin( name, collPersister.getCollectionType() );
    //if ( collPersister.hasWhere() ) join.addCondition( collPersister.getSQLWhereString(name) );
    collectionName = name;
    collectionOwnerName = currentName;
    currentName = name;
    currentProperty = propertyName;
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

  }

  private void prepareForIndex(QueryTranslatorImpl q) throws QueryException {

    QueryableCollection collPersister = q.getCollectionPersister( collectionRole );

    if ( !collPersister.hasIndex() ) throw new QueryException( "unindexed collection before []: " + path );
    String[] indexCols = collPersister.getIndexColumnNames();
    if ( indexCols.length != 1 ) throw new QueryException( "composite-index appears in []: " + path );
    //String[] keyCols = collPersister.getKeyColumnNames();

    JoinSequence fromJoins = new JoinSequence( q.getFactory() )
        .setUseThetaStyle( useThetaStyleJoin )
        .setRoot( collPersister, collectionName )
        .setNext( joinSequence.copy() );

    if ( !continuation ) addJoin( collectionName, collPersister.getCollectionType() );

    joinSequence.addCondition( collectionName + '.' + indexCols[0] + " = " ); //TODO: get SQL rendering out of here

    CollectionElement elem = new CollectionElement();
    elem.elementColumns = collPersister.getElementColumnNames(collectionName);
    elem.elementType = collPersister.getElementType();
    elem.isOneToMany = collPersister.isOneToMany();
    elem.alias = collectionName;
    elem.joinSequence = joinSequence;
    collectionElements.addLast( elem );
    setExpectingCollectionIndex();
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

      throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path );
    }

    if ( collectionElementType.isEntityType() ) {
      // an association
      QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole );
      Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister();
      String clazz = entityPersister.getEntityName();

      final String elementName;
      if ( collectionPersister.isOneToMany() ) {
        elementName = collectionName;
        //allow index() function:
        q.decoratePropertyMapping( elementName, collectionPersister );
      }
      else { //many-to-many
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

    boolean isSizeProperty = getNextSibling()!=null &&
      CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );

    if ( isSizeProperty ) indexed = true; //yuck!

    QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role );
    String propName = getPath();
    FromClause currentFromClause = getWalker().getCurrentFromClause();

    if ( getWalker().getStatementType() != SqlTokenTypes.SELECT && indexed && classAlias == null ) {
      // should indicate that we are processing an INSERT/UPDATE/DELETE
      // query with a subquery implied via a collection property
      // function. Here, we need to use the table name itself as the
      // qualification alias.
      // TODO : verify this works for all databases...
      // TODO : is this also the case in non-"indexed" scenarios?
      String alias = getLhs().getFromElement().getQueryable().getTableName();
      columns = getFromElement().toColumns( alias, propertyPath, false, true );
    }

    //We do not look for an existing join on the same path, because
    //it makes sense to join twice on the same collection role
    FromElementFactory factory = new FromElementFactory(
            currentFromClause,
            getLhs().getFromElement(),
            propName,
        classAlias,
            getColumns(),
            implicitJoin
    );
    FromElement elem = factory.createCollection( queryableCollection, role, joinType, fetch, indexed );

    if ( log.isDebugEnabled() ) {
      log.debug( "dereferenceCollection() : Created new FROM element for " + propName + " : " + elem );
    }

    setImpliedJoin( elem );
    setFromElement( elem )// This 'dot' expression now refers to the resulting from element.

    if ( isSizeProperty ) {
      elem.setText("");
      elem.setUseWhereFragment(false);
    }

    if ( !implicitJoin ) {
      EntityPersister entityPersister = elem.getEntityPersister();
      if ( entityPersister != null ) {
        getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
      }
    }
    getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() )// Always add the collection's query spaces.
  }
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

  public String getAssociatedEntityName(SessionFactoryImplementor factory)
      throws MappingException {
    try {
     
      QueryableCollection collectionPersister = (QueryableCollection) factory
          .getCollectionPersister( role );
     
      if ( !collectionPersister.getElementType().isEntityType() ) {
        throw new MappingException(
            "collection was not an association: " +
            collectionPersister.getRole()
          );
      }
     
      return collectionPersister.getElementPersister().getEntityName();
     
    }
    catch (ClassCastException cce) {
      throw new MappingException( "collection role is not queryable " + role );
    }
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

   * Used for collection filters
   */
  private void addFromAssociation(final String elementName, final String collectionRole)
      throws QueryException {
    //q.addCollection(collectionName, collectionRole);
    QueryableCollection persister = getCollectionPersister( collectionRole );
    Type collectionElementType = persister.getElementType();
    if ( !collectionElementType.isEntityType() ) {
      throw new QueryException( "collection of values in filter: " + elementName );
    }

    String[] keyColumnNames = persister.getKeyColumnNames();
    //if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole);

    String collectionName;
    JoinSequence join = new JoinSequence( getFactory() );
    collectionName = persister.isOneToMany() ?
        elementName :
        createNameForCollection( collectionRole );
    join.setRoot( persister, collectionName );
    if ( !persister.isOneToMany() ) {
      //many-to-many
      addCollection( collectionName, collectionRole );
      try {
        join.addJoin( ( AssociationType ) persister.getElementType(),
            elementName,
            JoinFragment.INNER_JOIN,
            persister.getElementColumnNames(collectionName) );
      }
      catch ( MappingException me ) {
        throw new QueryException( me );
      }
    }
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

//      }

      if ( isFilter() ) {
        // Handle collection-fiter compilation.
        // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
        QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
        Type collectionElementType = persister.getElementType();
        if ( !collectionElementType.isEntityType() ) {
          throw new QueryException( "collection of values in filter: this" );
        }

        String collectionElementEntityName = persister.getElementPersister().getEntityName();
        ASTFactory inputAstFactory = hqlParser.getASTFactory();
        AST fromElement = ASTUtil.create( inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName );
        ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement );
        fromClauseInput.addChild( fromElement );
        // Show the modified AST.
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

  }

  protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException {
    FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias );
    FromClause fromClause = fromElement.getFromClause();
    QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
    // Get the names of the columns used to link between the collection
    // owner and the collection elements.
    String[] keyColumnNames = persister.getKeyColumnNames();
    String fkTableAlias = persister.isOneToMany()
        ? fromElement.getTableAlias()
        : fromClause.getAliasGenerator().createName( collectionFilterRole );
    JoinSequence join = sessionFactoryHelper.createJoinSequence();
    join.setRoot( persister, fkTableAlias );
    if ( !persister.isOneToMany() ) {
      join.addJoin( ( AssociationType ) persister.getElementType(),
          fromElement.getTableAlias(),
          JoinFragment.INNER_JOIN,
          persister.getElementColumnNames( fkTableAlias ) );
    }
    join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
    fromElement.setJoinSequence( join );
    fromElement.setFilter( true );
    if ( log.isDebugEnabled() ) {
View Full Code Here

Examples of org.hibernate.persister.collection.QueryableCollection

    }
  }

  private void handleElements(FromReferenceNode collectionNode, String propertyName) {
    FromElement collectionFromElement = collectionNode.getFromElement();
    QueryableCollection queryableCollection = collectionFromElement.getQueryableCollection();

    String path = collectionNode.getPath() + "[]." + propertyName;
    log.debug( "Creating elements for " + path );

    fromElement = collectionFromElement;
    if ( !collectionFromElement.isCollectionOfValuesOrComponents() ) {
      getWalker().addQuerySpaces( queryableCollection.getElementPersister().getQuerySpaces() );
    }

    setDataType( queryableCollection.getElementType() );
    selectColumns = collectionFromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.