Package org.hibernate.persister.collection

Examples of org.hibernate.persister.collection.QueryableCollection


    return joinFragment;
  }

  private boolean isManyToManyRoot(Joinable joinable) {
    if ( joinable != null && joinable.isCollection() ) {
      QueryableCollection persister = ( QueryableCollection ) joinable;
      return persister.isManyToMany();
    }
    return false;
  }
View Full Code Here


  public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
  throws HibernateException {
    String role = criteriaQuery.getEntityName(criteria, propertyName) +
        '.'
        criteriaQuery.getPropertyName(propertyName);
    QueryableCollection cp = (QueryableCollection) criteriaQuery.getFactory()
        .getCollectionPersister(role);
    //String[] fk = StringHelper.qualify( "collection_", cp.getKeyColumnNames() );
    String[] fk = cp.getKeyColumnNames();
    String[] pk = ( (Loadable) cp.getOwnerEntityPersister() ).getIdentifierColumnNames(); //TODO: handle property-ref
    return "? " +
        op +
        " (select count(*) from " +
        cp.getTableName() +
        //" collection_ where " +
        " where " +
        new ConditionFragment()
            .setTableAlias( criteriaQuery.getSQLAlias(criteria, propertyName) )
            .setCondition(pk, fk)
View Full Code Here

    String entityName = criteriaQuery.getEntityName( criteria, propertyName );
    String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
    String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );

    SessionFactoryImplementor factory = criteriaQuery.getFactory();
    QueryableCollection collectionPersister = getQueryableCollection( entityName, actualPropertyName, factory );

    String[] collectionKeys = collectionPersister.getKeyColumnNames();
    String[] ownerKeys = ( ( Loadable ) factory.getEntityPersister( entityName ) ).getIdentifierColumnNames();

    String innerSelect = "(select 1 from " + collectionPersister.getTableName()
            + " where "
            + new ConditionFragment().setTableAlias( sqlAlias ).setCondition( ownerKeys, collectionKeys ).toFragmentString()
            + ")";

    return excludeEmpty()
View Full Code Here

    }

    // TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
    CollectionType type = (CollectionType) getDataType();
    String role = type.getRole();
    QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);

    String alias = null// DotNode uses null here...
    String columnTableAlias = getFromElement().getTableAlias();
    int joinType = JoinFragment.INNER_JOIN;
    boolean fetch = false;

    FromElementFactory factory = new FromElementFactory(
        getWalker().getCurrentFromClause(),
        getFromElement(),
        propertyName,
        alias,
        getFromElement().toColumns(columnTableAlias, propertyName, false),
        true
    );
    FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
    setFromElement(elem);
    getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces())// Always add the collection's query spaces.
  }
View Full Code Here

    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

    }
  }

  public boolean isManyToManyWith(OuterJoinableAssociation other) {
    if ( joinable.isCollection() ) {
      QueryableCollection persister = ( QueryableCollection ) joinable;
      if ( persister.isManyToMany() ) {
        return persister.getElementType() == other.getJoinableType();
      }
    }
    return false;
  }
View Full Code Here

    }
  }

  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

  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

    }
  }

  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

  }

  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

TOP

Related Classes of org.hibernate.persister.collection.QueryableCollection

Copyright © 2018 www.massapicom. 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.