Java 类org.hibernate.sql.JoinType 实例源码

项目:sjk    文件:AppDaoImpl.java   
@Override
public List<Rollinfo> searchForRolling(Short catalog, Integer subCatalog, int page, int rows, String keywords,
        String sort, String order) {
    Criteria cri = getSession().createCriteria(Rollinfo.class);
    Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);
    if (catalog != null) {
        appCriteria.add(Restrictions.eq("catalog", catalog));
    }
    if (subCatalog != null) {
        appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
    }

    if (keywords != null && !keywords.isEmpty()) {
        appCriteria.add(Restrictions.like("name", keywords, MatchMode.START));
    }

    if (sort != null && !sort.isEmpty()) {
        HibernateHelper.addOrder(appCriteria, sort, order);
    }
    cri.setMaxResults(rows);
    cri.setFirstResult(HibernateHelper.firstResult(page, rows));
    List<Rollinfo> list = HibernateHelper.list(cri);
    return list;
}
项目:lams    文件:JoinWalker.java   
/**
 * Add on association (one-to-one, many-to-one, or a collection) to a list 
 * of associations to be fetched by outerjoin (if necessary)
 */
private void addAssociationToJoinTreeIfNecessary(
        final AssociationType type,
        final String[] aliasedLhsColumns,
        final String alias,
        final PropertyPath path,
        int currentDepth,
        final JoinType joinType) throws MappingException {
    if ( joinType != JoinType.NONE ) {
        addAssociationToJoinTree(
                type, 
                aliasedLhsColumns, 
                alias, 
                path,
                currentDepth,
                joinType
        );
    }
}
项目:lams    文件:JoinWalker.java   
/**
 * Determine the appropriate type of join (if any) to use to fetch the
 * given association.
 *
 * @param persister The owner of the association.
 * @param path The path to the association
 * @param propertyNumber The property number representing the association.
 * @param associationType The association type.
 * @param metadataFetchMode The metadata-defined fetch mode.
 * @param metadataCascadeStyle The metadata-defined cascade style.
 * @param lhsTable The owner table
 * @param lhsColumns The owner join columns
 * @param nullable Is the association nullable.
 * @param currentDepth Current join depth
 * @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
 * {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
 * @throws MappingException ??
 */
protected JoinType getJoinType(
        OuterJoinLoadable persister,
        final PropertyPath path,
        int propertyNumber,
        AssociationType associationType,
        FetchMode metadataFetchMode,
        CascadeStyle metadataCascadeStyle,
        String lhsTable,
        String[] lhsColumns,
        final boolean nullable,
        final int currentDepth) throws MappingException {
    return getJoinType(
            associationType,
            metadataFetchMode,
            path,
            lhsTable,
            lhsColumns,
            nullable,
            currentDepth,
            metadataCascadeStyle
    );
}
项目:lams    文件:JoinWalker.java   
/**
 * Determine the appropriate associationType of join (if any) to use to fetch the
 * given association.
 *
 * @param associationType The association associationType.
 * @param config The metadata-defined fetch mode.
 * @param path The path to the association
 * @param lhsTable The owner table
 * @param lhsColumns The owner join columns
 * @param nullable Is the association nullable.
 * @param currentDepth Current join depth
 * @param cascadeStyle The metadata-defined cascade style.
 * @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
 * {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
 * @throws MappingException ??
 */
protected JoinType getJoinType(
        AssociationType associationType,
        FetchMode config,
        PropertyPath path,
        String lhsTable,
        String[] lhsColumns,
        boolean nullable,
        int currentDepth,
        CascadeStyle cascadeStyle) throws MappingException {
    if  ( !isJoinedFetchEnabled( associationType, config, cascadeStyle ) ) {
        return JoinType.NONE;
    }
    if ( isTooDeep(currentDepth) || ( associationType.isCollectionType() && isTooManyCollections() ) ) {
        return JoinType.NONE;
    }
    if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) {
        return JoinType.NONE;
    }
    return getJoinType( nullable, currentDepth );
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public List<Rollinfo> searchForRolling(Short catalog, Integer subCatalog, int page, int rows, String keywords,
        String sort, String order) {
    Criteria cri = getSession().createCriteria(Rollinfo.class);
    Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);
    if (catalog != null) {
        appCriteria.add(Restrictions.eq("catalog", catalog));
    }
    if (subCatalog != null) {
        appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
    }

    if (keywords != null && !keywords.isEmpty()) {
        appCriteria.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
    }

    if (sort != null && !sort.isEmpty()) {
        HibernateHelper.addOrder(appCriteria, sort, order);
    }
    cri.setMaxResults(rows);
    cri.setFirstResult(HibernateHelper.firstResult(page, rows));
    List<Rollinfo> list = HibernateHelper.list(cri);
    return list;
}
项目:lams    文件:CriteriaJoinWalker.java   
@Override
protected JoinType getJoinType(
        AssociationType associationType,
        FetchMode config,
        PropertyPath path,
        String lhsTable,
        String[] lhsColumns,
        boolean nullable,
        int currentDepth,
        CascadeStyle cascadeStyle) throws MappingException {
    return getJoinType(
            null,
            path,
            -1,
            associationType,
            config,
            cascadeStyle,
            lhsTable,
            lhsColumns,
            nullable,
            currentDepth
    );
}
项目:lams    文件:CriteriaQueryTranslator.java   
private void createAssociationPathCriteriaMap() {
    final Iterator<CriteriaImpl.Subcriteria> iter = rootCriteria.iterateSubcriteria();
    while ( iter.hasNext() ) {
        CriteriaImpl.Subcriteria crit = iter.next();
        String wholeAssociationPath = getWholeAssociationPath( crit );
        Object old = associationPathCriteriaMap.put( wholeAssociationPath, crit );
        if ( old != null ) {
            throw new QueryException( "duplicate association path: " + wholeAssociationPath );
        }
        JoinType joinType = crit.getJoinType();
        old = associationPathJoinTypesMap.put( wholeAssociationPath, joinType );
        if ( old != null ) {
            // TODO : not so sure this is needed...
            throw new QueryException( "duplicate association path: " + wholeAssociationPath );
        }
        if ( crit.getWithClause() != null ) {
            this.withClauseMap.put( wholeAssociationPath, crit.getWithClause() );
        }
    }
}
项目:lams    文件:OuterJoinableAssociation.java   
public static OuterJoinableAssociation createRoot(
        AssociationType joinableType,
        String alias,
        SessionFactoryImplementor factory) {
    return new OuterJoinableAssociation(
            new PropertyPath(),
            joinableType,
            null,
            null,
            alias,
            JoinType.LEFT_OUTER_JOIN,
            null,
            false,
            factory,
            Collections.EMPTY_MAP
    );
}
项目:lams    文件:OuterJoinableAssociation.java   
public OuterJoinableAssociation(
        PropertyPath propertyPath,
        AssociationType joinableType,
        String lhsAlias,
        String[] lhsColumns,
        String rhsAlias,
        JoinType joinType,
        String withClause,
        boolean hasRestriction,
        SessionFactoryImplementor factory,
        Map enabledFilters) throws MappingException {
    this.propertyPath = propertyPath;
    this.joinableType = joinableType;
    this.lhsAlias = lhsAlias;
    this.lhsColumns = lhsColumns;
    this.rhsAlias = rhsAlias;
    this.joinType = joinType;
    this.joinable = joinableType.getAssociatedJoinable(factory);
    this.rhsColumns = JoinHelper.getRHSColumnNames(joinableType, factory);
    this.on = joinableType.getOnCondition(rhsAlias, factory, enabledFilters)
        + ( withClause == null || withClause.trim().length() == 0 ? "" : " and ( " + withClause + " )" );
    this.hasRestriction = hasRestriction;
    this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
}
项目:lams    文件:AbstractEntityPersister.java   
protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) {
    // IMPL NOTE : all joins join to the pk of the driving table
    final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() );
    final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
    final int tableSpan = getSubclassTableSpan();
    // IMPL NOTE : notice that we skip the first table; it is the driving table!
    for ( int j = 1; j < tableSpan; j++ ) {
        final JoinType joinType = determineSubclassTableJoinType(
                j,
                innerJoin,
                includeSubclasses,
                treatAsDeclarations
        );

        if ( joinType != null && joinType != JoinType.NONE ) {
            join.addJoin(
                    getSubclassTableName( j ),
                    generateTableAlias( name, j ),
                    idCols,
                    getSubclassTableKeyColumns( j ),
                    joinType
            );
        }
    }
    return join;
}
项目:lams    文件:AbstractEntityPersister.java   
protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
    final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) );
    final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
    // IMPL NOTE : notice that we skip the first table; it is the driving table!
    for ( int i = 1; i < tableNumbers.length; i++ ) {
        final int j = tableNumbers[i];
        jf.addJoin( getSubclassTableName( j ),
                generateTableAlias( getRootAlias(), j ),
                keyCols,
                getSubclassTableKeyColumns( j ),
                isInverseSubclassTable( j ) || isNullableSubclassTable( j )
                        ? JoinType.LEFT_OUTER_JOIN
                        : JoinType.INNER_JOIN
        );
    }
    return jf;
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public long countForSearchingRolling(Short catalog, Integer subCatalog, String keywords) {
    Criteria cri = getSession().createCriteria(Rollinfo.class);
    Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);

    if (catalog != null) {
        appCriteria.add(Restrictions.eq("catalog", catalog));
    }
    if (subCatalog != null) {
        appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
    }

    if (keywords != null && !keywords.isEmpty()) {
        appCriteria.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
    }
    cri.setProjection(Projections.rowCount());
    List<Long> list = HibernateHelper.list(cri);
    return list.get(0);
}
项目:sjk    文件:AppDaoImpl.java   
@Override
public long countForSearchingRolling(Short catalog, Integer subCatalog, String keywords) {
    Criteria cri = getSession().createCriteria(Rollinfo.class);
    Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);

    if (catalog != null) {
        appCriteria.add(Restrictions.eq("catalog", catalog));
    }
    if (subCatalog != null) {
        appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
    }

    if (keywords != null && !keywords.isEmpty()) {
        appCriteria.add(Restrictions.like("name", keywords, MatchMode.START));
    }
    cri.setProjection(Projections.rowCount());
    List<Long> list = HibernateHelper.list(cri);
    return list.get(0);
}
项目:lams    文件:CriteriaImpl.java   
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
    this.alias = alias;
    this.path = path;
    this.parent = parent;
    this.joinType = joinType;
    this.withClause = withClause;
    this.hasRestriction = withClause != null;
    CriteriaImpl.this.subcriteriaList.add( this );
}
项目:lams    文件:JoinProcessor.java   
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 *
 * @return a JoinFragment.XXX join type.
 *
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static JoinType toHibernateJoinType(int astJoinType) {
    switch ( astJoinType ) {
        case LEFT_OUTER: {
            return JoinType.LEFT_OUTER_JOIN;
        }
        case INNER: {
            return JoinType.INNER_JOIN;
        }
        case RIGHT_OUTER: {
            return JoinType.RIGHT_OUTER_JOIN;
        }
        case FULL: {
            return JoinType.FULL_JOIN;
        }
        default: {
            throw new AssertionFailure( "undefined join type " + astJoinType );
        }
    }
}
项目:Layer-Query    文件:CustomCriteriaQueryTranslator.java   
private void createAssociationPathCriteriaMap() {
    final Iterator<CustomCriteriaImpl.Subcriteria> iter = rootCriteria.iterateSubcriteria();
    while ( iter.hasNext() ) {
        CustomCriteriaImpl.Subcriteria crit = iter.next();
        String wholeAssociationPath = getWholeAssociationPath( crit );
        Object old = associationPathCriteriaMap.put( wholeAssociationPath, crit );
        if ( old != null ) {
            throw new QueryException( "duplicate association path: " + wholeAssociationPath );
        }
        JoinType joinType = crit.getJoinType();
        old = associationPathJoinTypesMap.put( wholeAssociationPath, joinType );
        if ( old != null ) {
            // TODO : not so sure this is needed...
            throw new QueryException( "duplicate association path: " + wholeAssociationPath );
        }
        if ( crit.getWithClause() != null ) {
            this.withClauseMap.put( wholeAssociationPath, crit.getWithClause() );
        }
    }
}
项目:lams    文件:EntityJoinWalker.java   
protected JoinType getJoinType(
        OuterJoinLoadable persister,
        PropertyPath path,
        int propertyNumber,
        AssociationType associationType,
        FetchMode metadataFetchMode,
        CascadeStyle metadataCascadeStyle,
        String lhsTable,
        String[] lhsColumns,
        boolean nullable,
        int currentDepth) throws MappingException {
    // NOTE : we override this form here specifically to account for
    // fetch profiles.
    // TODO : how to best handle criteria queries?
    if ( lockOptions.getLockMode().greaterThan( LockMode.READ ) ) {
        return JoinType.NONE;
    }
    if ( isTooDeep( currentDepth )
            || ( associationType.isCollectionType() && isTooManyCollections() ) ) {
        return JoinType.NONE;
    }
    if ( !isJoinedFetchEnabledInMapping( metadataFetchMode, associationType )
            && !isJoinFetchEnabledByProfile( persister, path, propertyNumber ) ) {
        return JoinType.NONE;
    }
    if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) {
        return JoinType.NONE;
    }
    return getJoinType( nullable, currentDepth );
}
项目:lams    文件:JoinWalker.java   
/**
 * Process a particular association owned by the entity
 *
 * @param associationType The type representing the association to be
 * processed.
 * @param persister The owner of the association to be processed.
 * @param propertyNumber The property number for the association
 * (relative to the persister).
 * @param alias The entity alias
 * @param path The path to the association
 * @param nullable is the association nullable (which I think is supposed
 * to indicate inner/outer join semantics).
 * @param currentDepth The current join depth
 * @throws org.hibernate.MappingException ???
 */
private void walkEntityAssociationTree(
        final AssociationType associationType,
        final OuterJoinLoadable persister,
        final int propertyNumber,
        final String alias,
        final PropertyPath path,
        final boolean nullable,
        final int currentDepth) throws MappingException {
    String[] aliasedLhsColumns = JoinHelper.getAliasedLHSColumnNames(
            associationType, alias, propertyNumber, persister, getFactory()
    );
    String[] lhsColumns = JoinHelper.getLHSColumnNames(
            associationType, propertyNumber, persister, getFactory()
    );
    String lhsTable = JoinHelper.getLHSTableName(associationType, propertyNumber, persister);

    PropertyPath subPath = path.append( persister.getSubclassPropertyName(propertyNumber) );
    JoinType joinType = getJoinType(
            persister,
            subPath,
            propertyNumber,
            associationType,
            persister.getFetchMode( propertyNumber ),
            persister.getCascadeStyle( propertyNumber ),
            lhsTable,
            lhsColumns,
            nullable,
            currentDepth
    );
    addAssociationToJoinTreeIfNecessary(
            associationType,
            aliasedLhsColumns,
            alias,
            subPath,
            currentDepth,
            joinType
    );
}
项目:lams    文件:JoinWalker.java   
/**
 * Count the number of instances of Joinable which are actually
 * also instances of PersistentCollection which are being fetched
 * by outer join
 */
protected static final int countCollectionPersisters(List associations)
throws MappingException {
    int result = 0;
    Iterator iter = associations.iterator();
    while ( iter.hasNext() ) {
        OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
        if ( oj.getJoinType()==JoinType.LEFT_OUTER_JOIN &&
                oj.getJoinable().isCollection() &&
                ! oj.hasRestriction() ) {
            result++;
        }
    }
    return result;
}
项目:lams    文件:JoinWalker.java   
/**
 * Generate a select list of columns containing all properties of the entity classes
 */
protected final String selectString(List associations)
throws MappingException {

    if ( associations.size()==0 ) {
        return "";
    }
    else {
        StringBuilder buf = new StringBuilder( associations.size() * 100 );
        int entityAliasCount=0;
        int collectionAliasCount=0;
        for ( int i=0; i<associations.size(); i++ ) {
            OuterJoinableAssociation join = (OuterJoinableAssociation) associations.get(i);
            OuterJoinableAssociation next = (i == associations.size() - 1)
                    ? null
                    : ( OuterJoinableAssociation ) associations.get( i + 1 );
            final Joinable joinable = join.getJoinable();
            final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length )
                    ? null
                    : suffixes[entityAliasCount];
            final String collectionSuffix = ( collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.length )
                    ? null
                    : collectionSuffixes[collectionAliasCount];
            final String selectFragment = joinable.selectFragment(
                    next == null ? null : next.getJoinable(),
                    next == null ? null : next.getRHSAlias(),
                    join.getRHSAlias(),
                    entitySuffix,
                    collectionSuffix,
                    join.getJoinType()==JoinType.LEFT_OUTER_JOIN
            );
            if (selectFragment.trim().length() > 0) {
                buf.append(", ").append(selectFragment);
            }
            if ( joinable.consumesEntityAlias() ) entityAliasCount++;
            if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinType.LEFT_OUTER_JOIN ) collectionAliasCount++;
        }
        return buf.toString();
    }
}
项目:lams    文件:BasicCollectionJoinWalker.java   
protected JoinType getJoinType(
        OuterJoinLoadable persister,
        PropertyPath path,
        int propertyNumber,
        AssociationType associationType,
        FetchMode metadataFetchMode,
        CascadeStyle metadataCascadeStyle,
        String lhsTable,
        String[] lhsColumns,
        boolean nullable,
        int currentDepth) throws MappingException {
    JoinType joinType = super.getJoinType(
            persister,
            path,
            propertyNumber,
            associationType,
            metadataFetchMode,
            metadataCascadeStyle,
            lhsTable,
            lhsColumns,
            nullable,
            currentDepth
    );
    //we can use an inner join for the many-to-many
    if ( joinType==JoinType.LEFT_OUTER_JOIN && path.isRoot() ) {
        joinType=JoinType.INNER_JOIN;
    }
    return joinType;
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void addJoins(
        Join join,
        JoinFragment joinFragment,
        Joinable joinable) {

    final String rhsTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
            join.getRightHandSide().getUid()
    );
    if ( StringHelper.isEmpty( rhsTableAlias ) ) {
        throw new IllegalStateException( "Join's RHS table alias cannot be empty" );
    }

    final String lhsTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
            join.getLeftHandSide().getUid()
    );
    if ( lhsTableAlias == null ) {
        throw new IllegalStateException( "QuerySpace with that UID was not yet registered in the AliasResolutionContext" );
    }

    // add join fragments from the collection table -> element entity table ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    final String additionalJoinConditions = resolveAdditionalJoinCondition(
            rhsTableAlias,
            join.getAnyAdditionalJoinConditions( rhsTableAlias ),
            joinable,
            getJoinedAssociationTypeOrNull( join )
    );

    joinFragment.addJoin(
            joinable.getTableName(),
            rhsTableAlias,
            join.resolveAliasedLeftHandSideJoinConditionColumns( lhsTableAlias ),
            join.resolveNonAliasedRightHandSideJoinConditionColumns(),
            join.isRightHandSideRequired() ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN,
            additionalJoinConditions
    );
    joinFragment.addJoins(
            joinable.fromJoinFragment( rhsTableAlias, false, true ),
            joinable.whereJoinFragment( rhsTableAlias, false, true )
    );
}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
    this.alias = alias;
    this.path = path;
    this.parent = parent;
    this.joinType = joinType;
    this.withClause = withClause;
    this.hasRestriction = withClause != null;
    CustomCriteriaImpl.this.subcriteriaList.add(this);
}
项目:lams    文件:FromElementFactory.java   
private JoinSequence createJoinSequence(String roleAlias, JoinType joinType) {
    SessionFactoryHelper sessionFactoryHelper = fromClause.getSessionFactoryHelper();
    String[] joinColumns = getColumns();
    if ( collectionType == null ) {
        throw new IllegalStateException( "collectionType is null!" );
    }
    return sessionFactoryHelper.createJoinSequence( implied, collectionType, roleAlias, joinType, joinColumns );
}
项目:lams    文件:IdentNode.java   
public void resolveIndex(AST parent) throws SemanticException {
    // An ident node can represent an index expression if the ident
    // represents a naked property ref
    //      *Note: this makes the assumption (which is currently the case
    //      in the hql-sql grammar) that the ident is first resolved
    //      itself (addrExpr -> resolve()).  The other option, if that
    //      changes, is to call resolve from here; but it is
    //      currently un-needed overhead.
    if (!(isResolved() && nakedPropertyRef)) {
        throw new UnsupportedOperationException();
    }

    String propertyName = getOriginalText();
    if (!getDataType().isCollectionType()) {
        throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
    }

    // 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();
    JoinType joinType = JoinType.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.
}
项目:lams    文件:HqlSqlWalker.java   
@Override
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(),
                JoinType.INNER_JOIN,
                persister.getElementColumnNames( fkTableAlias )
        );
    }
    join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
    fromElement.setJoinSequence( join );
    fromElement.setFilter( true );
    LOG.debug( "createFromFilterElement() : processed filter FROM element." );
    return fromElement;
}
项目:lams    文件:FromParser.java   
public void start(QueryTranslatorImpl q) {
    entityName = null;
    collectionName = null;
    alias = null;
    afterIn = false;
    afterAs = false;
    afterClass = false;
    expectingJoin = false;
    expectingIn = false;
    expectingAs = false;
    memberDeclarations = false;
    expectingPathExpression = false;
    afterMemberDeclarations = false;
    joinType = JoinType.NONE;
}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
public JoinType getJoinType() {
    return joinType;
}
项目:lams    文件:JoinWalker.java   
/**
     * Add on association (one-to-one, many-to-one, or a collection) to a list 
     * of associations to be fetched by outerjoin 
     */
    private void addAssociationToJoinTree(
            final AssociationType type,
            final String[] aliasedLhsColumns,
            final String alias,
            final PropertyPath path,
            final int currentDepth,
            final JoinType joinType) throws MappingException {

        Joinable joinable = type.getAssociatedJoinable( getFactory() );

        // important to generate alias based on size of association collection
        // *before* adding this join to that collection
        String subalias = generateTableAlias( associations.size() + 1, path, joinable );

        // NOTE : it should be fine to continue to pass only filters below
        // (instead of LoadQueryInfluencers) since "from that point on" we
        // only need to worry about restrictions (and not say adding more
        // joins)
        OuterJoinableAssociation assoc = new OuterJoinableAssociation(
                path,
                type, 
                alias, 
                aliasedLhsColumns, 
                subalias, 
                joinType, 
                getWithClause(path),
                hasRestriction( path ),
                getFactory(),
                loadQueryInfluencers.getEnabledFilters()
        );
        assoc.validateJoin( path.getFullPath() );
        associations.add( assoc );

        int nextDepth = currentDepth + 1;
//      path = "";
        if ( !joinable.isCollection() ) {
            if (joinable instanceof OuterJoinLoadable) {
                walkEntityTree(
                    (OuterJoinLoadable) joinable, 
                    subalias,
                    path, 
                    nextDepth
                );
            }
        }
        else {
            if (joinable instanceof QueryableCollection) {
                walkCollectionTree(
                    (QueryableCollection) joinable, 
                    subalias, 
                    path, 
                    nextDepth
                );
            }
        }

    }
项目:lams    文件:JoinWalker.java   
/**
 * For a collection role, return a list of associations to be fetched by outerjoin
 */
private void walkCollectionTree(
        final QueryableCollection persister,
        final String alias,
        final PropertyPath path,
        final int currentDepth) throws MappingException {

    if ( persister.isOneToMany() ) {
        walkEntityTree(
                (OuterJoinLoadable) persister.getElementPersister(),
                alias,
                path,
                currentDepth
            );
    }
    else {
        Type type = persister.getElementType();
        if ( type.isAssociationType() ) {
            // a many-to-many;
            // decrement currentDepth here to allow join across the association table
            // without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit)
            AssociationType associationType = (AssociationType) type;
            String[] aliasedLhsColumns = persister.getElementColumnNames(alias);
            String[] lhsColumns = persister.getElementColumnNames();
            // if the current depth is 0, the root thing being loaded is the
            // many-to-many collection itself.  Here, it is alright to use
            // an inner join...
            boolean useInnerJoin = currentDepth == 0;
            final JoinType joinType = getJoinType(
                    associationType,
                    persister.getFetchMode(),
                    path,
                    persister.getTableName(),
                    lhsColumns,
                    !useInnerJoin,
                    currentDepth - 1, 
                    null //operations which cascade as far as the collection also cascade to collection elements
            );
            addAssociationToJoinTreeIfNecessary(
                    associationType,
                    aliasedLhsColumns,
                    alias,
                    path,
                    currentDepth - 1,
                    joinType
                );
        }
        else if ( type.isComponentType() ) {
            walkCompositeElementTree(
                    (CompositeType) type,
                    persister.getElementColumnNames(),
                    persister,
                    alias,
                    path,
                    currentDepth
                );
        }
    }

}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
@Override
public Criteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException {
    new Subcriteria(this, associationPath, alias, joinType);
    return this;
}
项目:lams    文件:JoinWalker.java   
protected void initPersisters(
        final List associations,
        final LockOptions lockOptions,
        final AssociationInitCallback callback) throws MappingException {
    final int joins = countEntityPersisters(associations);
    final int collections = countCollectionPersisters(associations);

    collectionOwners = collections==0 ? null : new int[collections];
    collectionPersisters = collections==0 ? null : new CollectionPersister[collections];
    collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections );

    this.lockOptions = lockOptions;

    persisters = new Loadable[joins];
    aliases = new String[joins];
    owners = new int[joins];
    ownerAssociationTypes = new EntityType[joins];
    lockModeArray = ArrayHelper.fillArray( lockOptions.getLockMode(), joins );

    int i=0;
    int j=0;
    Iterator iter = associations.iterator();
    while ( iter.hasNext() ) {
        final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
        if ( !oj.isCollection() ) {

            persisters[i] = (Loadable) oj.getJoinable();
            aliases[i] = oj.getRHSAlias();
            owners[i] = oj.getOwner(associations);
            ownerAssociationTypes[i] = (EntityType) oj.getJoinableType();
            callback.associationProcessed( oj, i );
            i++;

        }
        else {

            QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
            if ( oj.getJoinType()==JoinType.LEFT_OUTER_JOIN && ! oj.hasRestriction() ) {
                //it must be a collection fetch
                collectionPersisters[j] = collPersister;
                collectionOwners[j] = oj.getOwner(associations);
                j++;
            }

            if ( collPersister.isOneToMany() ) {
                persisters[i] = (Loadable) collPersister.getElementPersister();
                aliases[i] = oj.getRHSAlias();
                callback.associationProcessed( oj, i );
                i++;
            }
        }
    }

    if ( ArrayHelper.isAllNegative(owners) ) owners = null;
    if ( collectionOwners!=null && ArrayHelper.isAllNegative(collectionOwners) ) {
        collectionOwners = null;
    }
}
项目:lams    文件:CriteriaJoinWalker.java   
@Override
protected JoinType getJoinType(
        OuterJoinLoadable persister,
        final PropertyPath path,
        int propertyNumber,
        AssociationType associationType,
        FetchMode metadataFetchMode,
        CascadeStyle metadataCascadeStyle,
        String lhsTable,
        String[] lhsColumns,
        final boolean nullable,
        final int currentDepth) throws MappingException {
    final JoinType resolvedJoinType;
    if ( translator.isJoin( path.getFullPath() ) ) {
        resolvedJoinType = translator.getJoinType( path.getFullPath() );
    }
    else {
        if ( translator.hasProjection() ) {
            resolvedJoinType = JoinType.NONE;
        }
        else {
            FetchMode fetchMode = translator.getRootCriteria().getFetchMode( path.getFullPath() );
            if ( isDefaultFetchMode( fetchMode ) ) {
                if ( persister != null ) {
                    if ( isJoinFetchEnabledByProfile( persister, path, propertyNumber ) ) {
                        if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) {
                            resolvedJoinType = JoinType.NONE;
                        }
                        else if ( isTooDeep(currentDepth) || ( associationType.isCollectionType() && isTooManyCollections() ) ) {
                            resolvedJoinType = JoinType.NONE;
                        }
                        else {
                            resolvedJoinType = getJoinType( nullable, currentDepth );
                        }
                    }
                    else {
                        resolvedJoinType = super.getJoinType(
                                persister,
                                path,
                                propertyNumber,
                                associationType,
                                metadataFetchMode,
                                metadataCascadeStyle,
                                lhsTable,
                                lhsColumns,
                                nullable,
                                currentDepth
                        );
                    }
                }
                else {
                    resolvedJoinType = super.getJoinType(
                            associationType,
                            metadataFetchMode,
                            path,
                            lhsTable,
                            lhsColumns,
                            nullable,
                            currentDepth,
                            metadataCascadeStyle
                    );

                }
            }
            else {
                if ( fetchMode == FetchMode.JOIN ) {
                    isDuplicateAssociation( lhsTable, lhsColumns, associationType ); //deliberately ignore return value!
                    resolvedJoinType = getJoinType( nullable, currentDepth );
                }
                else {
                    resolvedJoinType = JoinType.NONE;
                }
            }
        }
    }
    return resolvedJoinType;
}
项目:lams    文件:CriteriaQueryTranslator.java   
public JoinType getJoinType(String path) {
    JoinType result = associationPathJoinTypesMap.get( path );
    return ( result == null ? JoinType.INNER_JOIN : result );
}
项目:lams    文件:OuterJoinableAssociation.java   
public JoinType getJoinType() {
    return joinType;
}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
@Override
public Criteria createAlias(String associationPath, String alias) {
    return createAlias(associationPath, alias, JoinType.INNER_JOIN);
}
项目:lams    文件:JoinSequence.java   
public JoinType getJoinType() {
    return joinType;
}
项目:Layer-Query    文件:CustomCriteriaImpl.java   
@Override
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
    return createCriteria(associationPath, alias, JoinType.parse(joinType));
}
项目:lams    文件:CriteriaImpl.java   
@Override
public Criteria createAlias(String associationPath, String alias) {
    return createAlias( associationPath, alias, JoinType.INNER_JOIN );
}
项目:lams    文件:CriteriaImpl.java   
@Override
public Criteria createAlias(String associationPath, String alias, JoinType joinType) {
    new Subcriteria( this, associationPath, alias, joinType );
    return this;
}